public override int Execute([NotNull] CommandContext context, [NotNull] DevicesListCommandSettings settings) { try { var adb = new Adb(settings?.Home); var devices = adb.GetDevices(); if ((settings?.Format ?? OutputFormat.None) == OutputFormat.None) { OutputHelper.OutputTable( devices, new[] { "Serial", "Emulator", "Device", "Model", "Product" }, i => new[] { i.Serial, i.IsEmulator.ToString(), i.Device, i.Model, i.Product }); } else { OutputHelper.Output(devices, settings.Format); } } catch (SdkToolFailedExitException sdkEx) { Program.WriteException(sdkEx); return(1); } return(0); }
public async Task GetDevicesAllStates() { // arrange var output = new List <string> { "List of devices attached", "PHILIPS W732\tdevice", "0123456789ABCDE\tunauthorized", "0123456789ABCDE\toffline" }; var processManager = new TestProcessManager(); processManager.AddProcess(output); var adb = new Adb(processManager); // act var devices = (await adb.GetDevices()).ToList(); // assert processManager.Stub.AssertWasCalled(_ => _.CreateProcess(Arg <string> .Is.Anything, Arg <string> .Matches(commands => commands.Contains("devices")))); Assert.AreEqual(3, devices.Count); Assert.IsTrue(devices.ElementAt(0).State == DeviceState.Online); Assert.IsTrue(devices.ElementAt(1).State == DeviceState.Unauthorized); Assert.IsTrue(devices.ElementAt(2).State == DeviceState.Offline); }
public override int Execute([NotNull] CommandContext context, [NotNull] DeviceInfoCommandSettings settings) { try { var adb = new Adb(settings?.Home); var devices = adb.GetDevices(); var deviceFilterSpecified = settings.Devices?.Any() ?? false; var results = new List <DeviceWrapper>(); foreach (var device in devices) { // If filtering on device, check that this is in the list if (deviceFilterSpecified && !settings.Devices.Any(d => IsPropertyMatch(device.Serial, d))) { continue; } var props = adb.GetProperties(device.Serial, settings.Properties); if (settings.Format == OutputFormat.None) { var rule = new Rule(device.Serial); AnsiConsole.Render(rule); OutputHelper.OutputTable(props, new[] { "Property Name", "Property Value" }, i => new[] { i.Key, i.Value }); AnsiConsole.WriteLine(); } results.Add(new DeviceWrapper { Device = device, Properties = adb.GetProperties(device.Serial, settings.Properties) }); } if (settings.Format != OutputFormat.None) { OutputHelper.Output(results, settings.Format); } } catch (SdkToolFailedExitException sdkEx) { Program.WriteException(sdkEx); return(1); } return(0); }
public async Task GetDevicesInvalidState() { // arrange var output = new List <string> { "List of devices attached", "0123456789ABCDE\tinvalidstate" }; var processManager = new TestProcessManager(); processManager.AddProcess(output); var adb = new Adb(processManager); // act + assert await AsyncAssert.Throws <UnexpectedOutputException>(async() => (await adb.GetDevices()).ToList()); }
public void RefreshDevices() { var devices = adb.GetDevices().Where(x => x.Model == "Quest"); var changed = devices.Count() != _devices.Count || devices.Any(d => !_devices.Any(x => x.Device == d)); if (changed) { _devices = devices.Select(d => { return(new AdbDevice { Device = d, Name = adb.GetDeviceName(d.Serial), }); }).ToList(); if (_devices.Count == 0) { _devices.Add(new AdbDevice()); } DevicesChanged?.Invoke(); } }
public async Task RestartServerMessagIgnoreAtDevicesList() { //Arrange var output = new List <string> { "adb server is out of date. killing...", "* daemon started successfully *", "List of devices attached", "YT910X72U3 device" }; var processManager = new TestProcessManager(); processManager.AddProcess(output); var adb = new Adb(processManager); //Act var devices = await adb.GetDevices(); //Assert Assert.AreEqual(1, devices.Count()); Assert.AreEqual("YT910X72U3", devices.First().SerialNumber); Assert.AreEqual(DeviceState.Online, devices.First().State); }