Skip to content

Commit c5ab21a

Browse files
committed
Set DeviceData empty to TransportId and Serial all empty
1 parent 5e3d826 commit c5ab21a

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

AdvancedSharpAdbClient.Tests/Dummys/DummyAdbSocket.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,14 @@ public void SetDevice(DeviceData device)
146146
// to a specific device
147147
if (device != null)
148148
{
149-
if(!string.IsNullOrWhiteSpace(device.TransportId) && uint.TryParse(device.TransportId,out var tid))
149+
if (uint.TryParse(device.TransportId, out uint tid))
150+
{
150151
SendAdbRequest($"host:transport-id:{tid}");
152+
}
151153
else
154+
{
152155
SendAdbRequest($"host:transport:{device.Serial}");
156+
}
153157

154158
try
155159
{

AdvancedSharpAdbClient/AdbSocket.Async.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,9 @@ public async Task SetDeviceAsync(DeviceData device, CancellationToken cancellati
262262
// to a specific device
263263
if (device != null)
264264
{
265-
if(!string.IsNullOrWhiteSpace(device.TransportId) && uint.TryParse(device.TransportId,out var tid))
266-
await SendAdbRequestAsync($"host:transport-id:{tid}", cancellationToken).ConfigureAwait(false);
267-
else
268-
await SendAdbRequestAsync($"host:transport:{device.Serial}", cancellationToken).ConfigureAwait(false);
265+
await (uint.TryParse(device.TransportId, out uint tid)
266+
? SendAdbRequestAsync($"host:transport-id:{tid}", cancellationToken).ConfigureAwait(false)
267+
: SendAdbRequestAsync($"host:transport:{device.Serial}", cancellationToken).ConfigureAwait(false));
269268

270269
try
271270
{

AdvancedSharpAdbClient/AdbSocket.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,14 @@ public void SetDevice(DeviceData device)
401401
// to a specific device
402402
if (device != null)
403403
{
404-
if(!string.IsNullOrWhiteSpace(device.TransportId) && uint.TryParse(device.TransportId,out var tid))
404+
if (uint.TryParse(device.TransportId, out uint tid))
405+
{
405406
SendAdbRequest($"host:transport-id:{tid}");
407+
}
406408
else
409+
{
407410
SendAdbRequest($"host:transport:{device.Serial}");
411+
}
408412

409413
try
410414
{

AdvancedSharpAdbClient/Models/DeviceData.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public DeviceData(string data) : this()
107107
/// <summary>
108108
/// <see langword="false"/> if <see cref="DeviceData"/> does not have a valid serial number; otherwise, <see langword="true"/>.
109109
/// </summary>
110-
public bool IsEmpty => string.IsNullOrEmpty(Serial);
110+
public bool IsEmpty => !uint.TryParse(TransportId, out _) && string.IsNullOrEmpty(Serial);
111111

112112
/// <summary>
113113
/// Creates a new instance of the <see cref="DeviceData"/> class based on
@@ -208,9 +208,9 @@ public override int GetHashCode()
208208
/// <inheritdoc/>
209209
public override string ToString()
210210
{
211-
if (string.IsNullOrEmpty(Serial))
211+
if (IsEmpty)
212212
{
213-
return $"An empty {GetType()} without {nameof(Serial)}";
213+
return $"An empty {GetType()} without {nameof(TransportId)} and {nameof(Serial)}";
214214
}
215215

216216
StringBuilder builder =
@@ -283,7 +283,7 @@ public static ref DeviceData EnsureDevice(ref DeviceData device, [CallerArgument
283283
{
284284
if (device.IsEmpty)
285285
{
286-
throw new ArgumentOutOfRangeException(nameof(device), "You must specific a serial number for the device");
286+
throw new ArgumentOutOfRangeException(nameof(device), "You must specific a transport ID or serial number for the device");
287287
}
288288
return ref device;
289289
}

0 commit comments

Comments
 (0)