Skip to content

Commit

Permalink
Merge pull request #106 from shamork/patch-prioritize-the-use-of-tran…
Browse files Browse the repository at this point in the history
…sport_id

When connecting devices, prioritize the use of transport_id
  • Loading branch information
wherewhere authored Jun 5, 2024
2 parents 987a519 + c5ab21a commit 0d6bccf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
9 changes: 8 additions & 1 deletion AdvancedSharpAdbClient.Tests/Dummys/DummyAdbSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,14 @@ public void SetDevice(DeviceData device)
// to a specific device
if (device != null)
{
SendAdbRequest($"host:transport:{device.Serial}");
if (uint.TryParse(device.TransportId, out uint tid))
{
SendAdbRequest($"host:transport-id:{tid}");
}
else
{
SendAdbRequest($"host:transport:{device.Serial}");
}

try
{
Expand Down
4 changes: 3 additions & 1 deletion AdvancedSharpAdbClient/AdbSocket.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ public async Task SetDeviceAsync(DeviceData device, CancellationToken cancellati
// to a specific device
if (device != null)
{
await SendAdbRequestAsync($"host:transport:{device.Serial}", cancellationToken).ConfigureAwait(false);
await (uint.TryParse(device.TransportId, out uint tid)
? SendAdbRequestAsync($"host:transport-id:{tid}", cancellationToken).ConfigureAwait(false)
: SendAdbRequestAsync($"host:transport:{device.Serial}", cancellationToken).ConfigureAwait(false));

try
{
Expand Down
9 changes: 8 additions & 1 deletion AdvancedSharpAdbClient/AdbSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,14 @@ public void SetDevice(DeviceData device)
// to a specific device
if (device != null)
{
SendAdbRequest($"host:transport:{device.Serial}");
if (uint.TryParse(device.TransportId, out uint tid))
{
SendAdbRequest($"host:transport-id:{tid}");
}
else
{
SendAdbRequest($"host:transport:{device.Serial}");
}

try
{
Expand Down
8 changes: 4 additions & 4 deletions AdvancedSharpAdbClient/Models/DeviceData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public DeviceData(string data) : this()
/// <summary>
/// <see langword="false"/> if <see cref="DeviceData"/> does not have a valid serial number; otherwise, <see langword="true"/>.
/// </summary>
public bool IsEmpty => string.IsNullOrEmpty(Serial);
public bool IsEmpty => !uint.TryParse(TransportId, out _) && string.IsNullOrEmpty(Serial);

/// <summary>
/// Creates a new instance of the <see cref="DeviceData"/> class based on
Expand Down Expand Up @@ -208,9 +208,9 @@ public override int GetHashCode()
/// <inheritdoc/>
public override string ToString()
{
if (string.IsNullOrEmpty(Serial))
if (IsEmpty)
{
return $"An empty {GetType()} without {nameof(Serial)}";
return $"An empty {GetType()} without {nameof(TransportId)} and {nameof(Serial)}";
}

StringBuilder builder =
Expand Down Expand Up @@ -283,7 +283,7 @@ public static ref DeviceData EnsureDevice(ref DeviceData device, [CallerArgument
{
if (device.IsEmpty)
{
throw new ArgumentOutOfRangeException(nameof(device), "You must specific a serial number for the device");
throw new ArgumentOutOfRangeException(nameof(device), "You must specific a transport ID or serial number for the device");
}
return ref device;
}
Expand Down

0 comments on commit 0d6bccf

Please sign in to comment.