public void KillAdbServer() { var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); runner.KillAdbServer(); _processManager.Verify(pm => pm.Run(s_adbPath, "kill-server", TimeSpan.FromMinutes(5)), Times.Once); }
public void KillAdbServer() { var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); runner.KillAdbServer(); VerifyAdbCall("kill-server"); }
private string?GetDeviceToUse(ILogger logger, AdbRunner runner, string apkRequiredArchitecture) { var allDevicesAndTheirArchitectures = runner.GetAttachedDevicesAndArchitectures(); if (allDevicesAndTheirArchitectures.Count == 1) { // There's only one device, so -s argument isn't needed but still check if (!allDevicesAndTheirArchitectures.Values.Contains(apkRequiredArchitecture, StringComparer.InvariantCultureIgnoreCase)) { logger.LogWarning($"Single device available has architecture '{allDevicesAndTheirArchitectures.Values.First()}', != '{apkRequiredArchitecture}'. Package installation will likely fail, but we'll try anyways."); } return(null); // null = Use default device } else if (allDevicesAndTheirArchitectures.Count > 1) { if (allDevicesAndTheirArchitectures.Any(kvp => kvp.Value != null && kvp.Value.Equals(apkRequiredArchitecture, StringComparison.OrdinalIgnoreCase))) { var firstAvailableCompatible = allDevicesAndTheirArchitectures.Where(kvp => kvp.Value != null && kvp.Value.Equals(apkRequiredArchitecture, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); logger.LogInformation($"Using first-found compatible device of {allDevicesAndTheirArchitectures.Count} total- serial: '{firstAvailableCompatible.Key}' - Arch: {firstAvailableCompatible.Value}"); return(firstAvailableCompatible.Key); } else { logger.LogWarning($"No devices found with architecture '{apkRequiredArchitecture}'. Just returning first available device; installation will likely fail, but we'll try anyways."); return(allDevicesAndTheirArchitectures.Keys.First()); } } logger.LogError("No attached device detected"); return(null); }
protected override Task <ExitCode> InvokeInternal(ILogger logger) { logger.LogInformation("Getting state of ADB and attached Android device(s)"); try { var runner = new AdbRunner(logger); string state = runner.GetAdbState(); if (string.IsNullOrEmpty(state)) { state = "No device attached"; } logger.LogInformation($"ADB Version info:{Environment.NewLine}{runner.GetAdbVersion()}"); logger.LogInformation($"ADB State ('device' if physically attached):{Environment.NewLine}{state}"); logger.LogInformation($"List of devices:"); var deviceAndArchList = runner.GetAttachedDevicesWithProperties("architecture"); foreach (string device in deviceAndArchList.Keys) { logger.LogInformation($"Device: '{device}' - Architecture: {deviceAndArchList[device]}"); } return(Task.FromResult(ExitCode.SUCCESS)); } catch (Exception toLog) { logger.LogCritical(toLog, $"Error: {toLog.Message}"); return(Task.FromResult(ExitCode.GENERAL_FAILURE)); } }
public void RebootAndroidDevice() { var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); runner.RebootAndroidDevice(); VerifyAdbCall("reboot"); }
public void RunInstrumentation(string instrumentationName) { string fakeApkName = Path.GetRandomFileName(); var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); ProcessExecutionResults result; var fakeArgs = new Dictionary <string, string>() { { "arg1", "value1" }, { "arg2", "value2" } }; result = runner.RunApkInstrumentation(fakeApkName, instrumentationName, fakeArgs, TimeSpan.FromSeconds(123)); Assert.Equal(0, result.ExitCode); result = runner.RunApkInstrumentation(fakeApkName, instrumentationName, new Dictionary <string, string>(), TimeSpan.FromSeconds(456)); Assert.Equal(0, result.ExitCode); if (string.IsNullOrEmpty(instrumentationName)) { VerifyAdbCall("shell", "am", "instrument", "-e", "arg1", "value1", "-e", "arg2", "value2", "-w", fakeApkName); VerifyAdbCall("shell", "am", "instrument", "-w", fakeApkName); } else { VerifyAdbCall("shell", "am", "instrument", "-e", "arg1", "value1", "-e", "arg2", "value2", "-w", $"{fakeApkName}/{instrumentationName}"); VerifyAdbCall("shell", "am", "instrument", "-w", $"{fakeApkName}/{instrumentationName}"); } }
public void StartAdbServer() { var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); runner.StartAdbServer(); VerifyAdbCall("start-server"); }
public void ClearAdbLog() { var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); runner.ClearAdbLog(); VerifyAdbCall("logcat", "-c"); }
public void ClearAdbLog() { var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); runner.ClearAdbLog(); _processManager.Verify(pm => pm.Run(s_adbPath, "logcat -c", TimeSpan.FromMinutes(5)), Times.Once); }
public void RunInstrumentation(string instrumentationName) { string fakeApkName = Path.GetRandomFileName(); var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); ProcessExecutionResults result; var fakeArgs = new Dictionary <string, string>() { { "arg1", "value1" }, { "arg2", "value2" } }; result = runner.RunApkInstrumentation(fakeApkName, instrumentationName, fakeArgs, TimeSpan.FromSeconds(123)); Assert.Equal(0, result.ExitCode); result = runner.RunApkInstrumentation(fakeApkName, instrumentationName, new Dictionary <string, string>(), TimeSpan.FromSeconds(456)); Assert.Equal(0, result.ExitCode); if (string.IsNullOrEmpty(instrumentationName)) { _processManager.Verify(pm => pm.Run(s_adbPath, $"shell am instrument -e arg1 value1 -e arg2 value2 -w {fakeApkName}", TimeSpan.FromSeconds(123)), Times.Once); _processManager.Verify(pm => pm.Run(s_adbPath, $"shell am instrument -w {fakeApkName}", TimeSpan.FromSeconds(456)), Times.Once); } else { _processManager.Verify(pm => pm.Run(s_adbPath, $"shell am instrument -e arg1 value1 -e arg2 value2 -w {fakeApkName}/{instrumentationName}", TimeSpan.FromSeconds(123)), Times.Once); _processManager.Verify(pm => pm.Run(s_adbPath, $"shell am instrument -w {fakeApkName}/{instrumentationName}", TimeSpan.FromSeconds(456)), Times.Once); } }
public void RebootAndroidDevice() { var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); string result = runner.RebootAndroidDevice(); _processManager.Verify(pm => pm.Run(s_adbPath, "reboot", TimeSpan.FromMinutes(5)), Times.Once); }
public void GetAdbState() { var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); string result = runner.GetAdbState(); VerifyAdbCall("get-state"); Assert.Equal("device", result); }
public void GetAdbState() { var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); string result = runner.GetAdbState(); _processManager.Verify(pm => pm.Run(s_adbPath, "get-state", TimeSpan.FromMinutes(5)), Times.Once); Assert.Equal("device", result); }
public void GetDevice() { var requiredArchitecture = "x86_64"; var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); var result = runner.GetDevice(requiredArchitectures: new[] { requiredArchitecture }); VerifyAdbCall("devices", "-l"); Assert.Contains(_fakeDeviceList, d => d.DeviceSerial == result.DeviceSerial); }
public void KillApk() { var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); string fakeApkName = $"{Path.GetRandomFileName()}"; int exitCode = runner.KillApk(fakeApkName); VerifyAdbCall("shell", "am", "kill", "--user", "all", fakeApkName); Assert.Equal(0, exitCode); }
public void KillApk() { var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); string fakeApkName = $"{Path.GetRandomFileName()}"; int exitCode = runner.KillApk(fakeApkName); _processManager.Verify(pm => pm.Run(s_adbPath, $"shell am kill --user all {fakeApkName}", TimeSpan.FromMinutes(5)), Times.Once); Assert.Equal(0, exitCode); }
public void GetDeviceToUse() { var requiredArchitecture = "x86_64"; var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); var result = runner.GetDeviceToUse(_mainLog.Object, requiredArchitecture, "architecture"); _processManager.Verify(pm => pm.Run(s_adbPath, "devices -l", TimeSpan.FromSeconds(30)), Times.Once); Assert.True(_fakeDeviceList.ContainsKey(new Tuple <string, string>(result, requiredArchitecture))); }
public void GetDeviceWithArchitecture() { var requiredArchitecture = "x86"; var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); var result = runner.GetDevice(loadArchitecture: true, requiredArchitectures: new[] { requiredArchitecture }); VerifyAdbCall("devices", "-l"); VerifyAdbCall("-s", result.DeviceSerial, "shell", "getprop", "ro.product.cpu.abi"); Assert.Contains(_fakeDeviceList, d => d.DeviceSerial == result.DeviceSerial && d.Architecture == result.Architecture); }
public void GetDeviceWithAppAndApiVersion() { var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); var device = _fakeDeviceList.Single(d => d.ApiVersion == 31 && d.InstalledApplications.Contains("net.dot.E")); var result = runner.GetDevice(requiredInstalledApp: "net.dot.E", requiredApiVersion: 31); VerifyAdbCall("devices", "-l"); Assert.Equal(device.DeviceSerial, result.DeviceSerial); Assert.Equal(device.ApiVersion, result.ApiVersion); }
public void DumpBugReport() { var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); string pathToDumpBugReport = Path.Join(s_scratchAndOutputPath, $"{Path.GetRandomFileName()}.zip"); runner.DumpBugReport(pathToDumpBugReport); _processManager.Verify(pm => pm.Run(s_adbPath, $"bugreport {pathToDumpBugReport}", TimeSpan.FromMinutes(5)), Times.Once); Assert.Equal("Sample BugReport Output", File.ReadAllText(pathToDumpBugReport)); }
public void DumpAdbLog() { var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); string pathToDumpLogTo = Path.Join(s_scratchAndOutputPath, $"{Path.GetRandomFileName()}.log"); runner.DumpAdbLog(pathToDumpLogTo); _processManager.Verify(pm => pm.Run(s_adbPath, "logcat -d ", TimeSpan.FromMinutes(2)), Times.Once); Assert.Equal("Sample LogCat Output", File.ReadAllText(pathToDumpLogTo)); }
public void DumpAdbLog() { var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); string pathToDumpLogTo = Path.Join(s_scratchAndOutputPath, $"{Path.GetRandomFileName()}.log"); runner.TryDumpAdbLog(pathToDumpLogTo); VerifyAdbCall("logcat", "-d", ""); Assert.Equal("Sample LogCat Output", File.ReadAllText(pathToDumpLogTo)); }
public void InstallApk() { var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); string fakeApkPath = Path.Join(s_scratchAndOutputPath, $"{Path.GetRandomFileName()}.apk"); File.Create(fakeApkPath).Close(); int exitCode = runner.InstallApk(fakeApkPath); VerifyAdbCall("install", fakeApkPath); Assert.Equal(0, exitCode); }
public void GetDeviceWithApiVersion() { var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); var device = _fakeDeviceList.Single(d => d.ApiVersion == 30); var result = runner.GetDevice(loadArchitecture: true, requiredApiVersion: 30); VerifyAdbCall("devices", "-l"); Assert.Equal(device.DeviceSerial, result.DeviceSerial); Assert.Equal(device.ApiVersion, result.ApiVersion); Assert.Equal(device.Architecture, result.Architecture); }
public void WaitForDevice() { var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); string fakeDeviceName = $"emulator-{new Random().Next(9999)}"; runner.SetActiveDevice(fakeDeviceName); runner.WaitForDevice(); runner.SetActiveDevice(null); runner.WaitForDevice(); _processManager.Verify(pm => pm.Run(s_adbPath, $"wait-for-device", TimeSpan.FromMinutes(5)), Times.Exactly(2)); }
public void InstallApk() { var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); string fakeApkPath = Path.Join(s_scratchAndOutputPath, $"{Path.GetRandomFileName()}.apk"); File.Create(fakeApkPath).Close(); int exitCode = runner.InstallApk(fakeApkPath); _processManager.Verify(pm => pm.Run(s_adbPath, $"install \"{fakeApkPath}\"", TimeSpan.FromMinutes(5)), Times.Once); Assert.Equal(0, exitCode); }
public void DumpBugReport() { var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); string pathToDumpBugReport = Path.Join(s_scratchAndOutputPath, Path.GetRandomFileName()); runner.GetDevice(requiredDeviceId: _fakeDeviceList.First().DeviceSerial); runner.DumpBugReport(pathToDumpBugReport); VerifyAdbCall("bugreport", $"{pathToDumpBugReport}.zip"); Assert.Equal("Sample BugReport Output", File.ReadAllText($"{pathToDumpBugReport}.zip")); }
public void WaitForDevice() { s_bootCompleteCheckTimes = 0; // Force simulating device is offline var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); string fakeDeviceName = $"emulator-{new Random().Next(9999)}"; runner.SetActiveDevice(fakeDeviceName); runner.WaitForDevice(); s_bootCompleteCheckTimes = 0; // Force simulating device is offline runner.SetActiveDevice(null); runner.WaitForDevice(); _processManager.Verify(pm => pm.Run(s_adbPath, "wait-for-device", TimeSpan.FromMinutes(5)), Times.Exactly(2)); _processManager.Verify(pm => pm.Run(s_adbPath, "shell getprop sys.boot_completed", TimeSpan.FromMinutes(5)), Times.Exactly(4)); }
public void ListDevicesAndArchitectures() { var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); var result = runner.GetAttachedDevicesWithProperties("architecture"); _processManager.Verify(pm => pm.Run(s_adbPath, "devices -l", TimeSpan.FromSeconds(30)), Times.Once); // Ensure it called, parsed the three random device names and found all three architectures foreach (var fakeDeviceInfo in _fakeDeviceList.Keys) { _processManager.Verify(pm => pm.Run(s_adbPath, $"-s {fakeDeviceInfo.Item1} shell getprop ro.product.cpu.abi", TimeSpan.FromSeconds(30)), Times.Once); Assert.Equal(fakeDeviceInfo.Item2, result[fakeDeviceInfo.Item1]); } Assert.Equal(4, result.Count); }
public void WaitForDevice() { s_bootCompleteCheckTimes = 0; // Force simulating device is offline var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); string fakeDeviceName = $"emulator-{new Random().Next(9999)}"; runner.SetActiveDevice(new AndroidDevice(fakeDeviceName)); runner.WaitForDevice(); s_bootCompleteCheckTimes = 0; // Force simulating device is offline runner.SetActiveDevice(null); runner.WaitForDevice(); VerifyAdbCall(Times.Exactly(2), "wait-for-device"); VerifyAdbCall(Times.Exactly(2), "-s", fakeDeviceName, "shell", "getprop", "sys.boot_completed"); VerifyAdbCall(Times.Exactly(2), "shell", "getprop", "sys.boot_completed"); }