diff --git a/SharpAdbClient.Tests/DeviceDataTests.cs b/SharpAdbClient.Tests/DeviceDataTests.cs index 55d2ac77..d5fa02b8 100644 --- a/SharpAdbClient.Tests/DeviceDataTests.cs +++ b/SharpAdbClient.Tests/DeviceDataTests.cs @@ -32,6 +32,17 @@ public void CreateFromDeviceDataUnauthorizedTest() Assert.AreEqual(DeviceState.Unauthorized, device.State); } + [TestMethod] + public void CreateFromEmulatorTest() + { + string data = "emulator-5586 host features:shell_2"; + + var device = DeviceData.CreateFromAdbData(data); + Assert.AreEqual("emulator-5586", device.Serial); + Assert.AreEqual(DeviceState.Host, device.State); + Assert.AreEqual("shell_2", device.Features); + } + [TestMethod] [ExpectedException(typeof(ArgumentException))] public void CreateFromInvalidDatatest() diff --git a/SharpAdbClient/DeviceData.cs b/SharpAdbClient/DeviceData.cs index 6d536cab..08148c2e 100644 --- a/SharpAdbClient/DeviceData.cs +++ b/SharpAdbClient/DeviceData.cs @@ -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. /// - 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 = @"^(?[a-zA-Z0-9_-]+(?:\s?[\.a-zA-Z0-9_-]+)?(?:\:\d{1,})?)\s+(?device|offline|unknown|bootloader|recovery|download|unauthorized|host)(\s+features:(?[^:]+))?(?:\s+product:(?[^:]+)\s+model\:(?[\S]+)\s+device\:(?[\S]+))?$"; /// /// Gets or sets the device serial number. @@ -63,6 +63,15 @@ public string Name set; } + /// + /// Gets or sets the features available on the device. + /// + public string Features + { + get; + set; + } + /// /// Creates a new instance of the class based on /// data retrieved from the Android Debug Bridge. @@ -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}'"); } }