public void RefreshDevice() { var ds = new List <string>(); var result = ExtCommand.Shell("adb", "devices"); foreach (Match mch in Regex.Matches(result.Result, "\\n.*\\tdevice")) { string x = mch.Value; x = x.Substring(0, x.LastIndexOf("device")).Trim(); ds.Add(x); if (pml.FirstOrDefault(t => t.Device == x) == null) { PhoneModel pm = new PhoneModel(CQs, _logger); pm.Device = x; pm.phoneStatus = PhoneStatus.OnLine; string modresult = ExtCommand.Shell("adb", $"-s {pm.Device} shell getprop ro.product.model").Result; pm.Model = modresult.Trim(); //push 安装用的jar 包 var ss = ExtCommand.Shell("adb", $"-s {pm.Device} push {Path.Combine(Directory.GetCurrentDirectory(), @"Tools\DialogDetect.jar")} /data/local/tmp/").Result; _logger.LogInformation(ss); pml.Add(pm); } } pml.Where(t => !ds.Contains(t.Device)).ToList().ForEach(t => t.phoneStatus = PhoneStatus.OffLine); pml.Where(t => t.phoneStatus == PhoneStatus.OffLine && ds.Contains(t.Device)).ToList().ForEach(t => t.phoneStatus = PhoneStatus.OnLine); }
private void initPhone() { var result = ExtCommand.Shell("adb", "devices").Result; var result2 = ExtCommand.Shell("adb devices").Result; foreach (Match mch in Regex.Matches(result, "\\n.*\\tdevice")) { string x = mch.Value; x = x.Substring(0, x.LastIndexOf("device")).Trim(); if (pml.FirstOrDefault(t => t.Device == x) == null) { PhoneModel pm = new PhoneModel(CQs, _logger); pm.Device = x; pm.phoneStatus = PhoneStatus.OnLine; string modresult = ExtCommand.Shell("adb", $"-s {pm.Device} shell getprop ro.product.model").Result; pm.Model = modresult.Trim(); //push 安装用的jar 包 var ss = ExtCommand.Shell("adb", $"-s {pm.Device} push {Path.Combine(Directory.GetCurrentDirectory(), @"Tools/DialogDetect.jar")} /data/local/tmp/").Result; _logger.LogInformation(ss); pml.Add(pm); } } }
public bool installApk(string apkFile, string packageName) { if (!string.IsNullOrEmpty(packageName)) { var unstall = ExtCommand.Shell("adb", $"-s {Device} uninstall {packageName}").Result; _logger.LogInformation($"unstall:{unstall}"); if (LastInstallApk != null && LastInstallApk.PackageName == packageName) { LastInstallApk = null; } } //var push = ExtCommand.Shell("adb", $"-s {device} push {apk} /sdcard/").Result; var uiautomator = ExtCommand.Shell("adb", $"-s {Device} shell uiautomator runtest DialogDetect.jar -c com.zhongan.test.DetectMain"); var install = ExtCommand.Shell("adb", $"-s {Device} install -r {apkFile}"); var installResult = install.Result; var uiautomatorResult = uiautomator.Result; if (installResult.ToLower().Contains("success") || installResult.Contains("[-99]")) { this.LastInstallApk = new ApkInfo(apkFile, packageName); _logger.LogInformation($"{this.Device}:install {apkFile} is sucess!"); _logger.LogInformation($"{installResult}"); return(true); } else { _logger.LogError($"{this.Device}:install {apkFile} is fail!"); _logger.LogError($"{installResult}"); return(false); } }