Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Add support for emulator devices #44

Merged
merged 1 commit into from
Jun 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions SharpAdbClient.Tests/DeviceDataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ public void CreateFromDeviceDataUnauthorizedTest()
Assert.AreEqual<DeviceState>(DeviceState.Unauthorized, device.State);
}

[TestMethod]
public void CreateFromEmulatorTest()
{
string data = "emulator-5586 host features:shell_2";

var device = DeviceData.CreateFromAdbData(data);
Assert.AreEqual<string>("emulator-5586", device.Serial);
Assert.AreEqual<DeviceState>(DeviceState.Host, device.State);
Assert.AreEqual("shell_2", device.Features);
}

[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void CreateFromInvalidDatatest()
Expand Down
24 changes: 17 additions & 7 deletions SharpAdbClient/DeviceData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class DeviceData
/// A regular expression that can be used to parse the device information that is returned
/// by the Android Debut Bridge.
/// </summary>
internal const string DeviceDataRegex = @"^([a-z0-9_-]+(?:\s?[\.a-z0-9_-]+)?(?:\:\d{1,})?)\s+(device|offline|unknown|bootloader|recovery|download|unauthorized)(?:\s+product:([^:]+)\s+model\:([\S]+)\s+device\:([\S]+))?$";
internal const string DeviceDataRegex = @"^(?<serial>[a-zA-Z0-9_-]+(?:\s?[\.a-zA-Z0-9_-]+)?(?:\:\d{1,})?)\s+(?<state>device|offline|unknown|bootloader|recovery|download|unauthorized|host)(\s+features:(?<features>[^:]+))?(?:\s+product:(?<product>[^:]+)\s+model\:(?<model>[\S]+)\s+device\:(?<device>[\S]+))?$";

/// <summary>
/// Gets or sets the device serial number.
Expand Down Expand Up @@ -63,6 +63,15 @@ public string Name
set;
}

/// <summary>
/// Gets or sets the features available on the device.
/// </summary>
public string Features
{
get;
set;
}

/// <summary>
/// Creates a new instance of the <see cref="DeviceData"/> class based on
/// data retrieved from the Android Debug Bridge.
Expand All @@ -81,16 +90,17 @@ public static DeviceData CreateFromAdbData(string data)
{
return new DeviceData()
{
Serial = m.Groups[1].Value,
State = GetStateFromString(m.Groups[2].Value),
Model = m.Groups[4].Value,
Product = m.Groups[3].Value,
Name = m.Groups[5].Value
Serial = m.Groups["serial"].Value,
State = GetStateFromString(m.Groups["state"].Value),
Model = m.Groups["model"].Value,
Product = m.Groups["product"].Value,
Name = m.Groups["name"].Value,
Features = m.Groups["features"].Value
};
}
else
{
throw new ArgumentException("Invalid device list data");
throw new ArgumentException($"Invalid device list data '{data}'");
}
}

Expand Down