/// <summary> /// </summary> public Dictionary <string, ListingType> GetFilesAndDirectories(string location) { if (location == null || string.IsNullOrEmpty(location) || Regex.IsMatch(location, @"\s")) { throw new ArgumentException("rootDir must not be null or empty!"); } Dictionary <string, ListingType> filesAndDirs = new Dictionary <string, ListingType>(); AdbCommand cmd = null; if (device.BusyBox.IsInstalled) { cmd = AdbCmd.FormAdbShellCommand(device, true, "busybox", "ls", "-a", "-p", "-l", location); } else { cmd = AdbCmd.FormAdbShellCommand(device, true, "ls", "-a", "-p", "-l", location); } using (StringReader reader = new StringReader(AdbCmd.ExecuteAdbCommand(cmd))) { string line = null; while (reader.Peek() != -1) { line = reader.ReadLine(); if (!string.IsNullOrEmpty(line) && !Regex.IsMatch(line, @"\s")) { filesAndDirs.Add(line, line.EndsWith("/") ? ListingType.DIRECTORY : ListingType.FILE); } } } return(filesAndDirs); }
private void Update() { try { this.prop.Clear(); if (device.State != DeviceState.ONLINE) { return; } AdbCommand adbCmd = AdbCmd.FormAdbShellCommand(device, false, "getprop"); string prop = AdbCmd.ExecuteAdbCommand(adbCmd); string[] lines = prop.Split(new string[] { "\r\n\r\n" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < lines.Length; i++) { string[] entry = lines[i].Split(new string[] { "[", "]: [", "]" }, StringSplitOptions.RemoveEmptyEntries); if (entry.Length == 2) { this.prop.Add(entry[0], entry[1]); } } } catch (Exception ex) { Logger.w(ex.Message, "Using: getprop in BuildProp.cs", ex.StackTrace); } }
private void GetSuData() { if (device.State != DeviceState.ONLINE) { version = null; exists = false; return; } AdbCommand adbCmd = AdbCmd.FormAdbShellCommand(device, false, "su", "-v"); using (StringReader r = new StringReader(AdbCmd.ExecuteAdbCommand(adbCmd))) { string line = r.ReadLine(); if (line.Contains("not found") || line.Contains("permission denied")) { version = "-1"; exists = false; } else { version = line; exists = true; } } }
private void UpdateMountPoints() { if (device.State != DeviceState.ONLINE) { systemMount = new MountInfo(null, null, MountType.NONE); return; } AdbCommand adbCmd = AdbCmd.FormAdbShellCommand(device, false, "mount"); using (StringReader r = new StringReader(AdbCmd.ExecuteAdbCommand(adbCmd))) { string line; string[] splitLine; string dir, mount; MountType type; while (r.Peek() != -1) { line = r.ReadLine(); splitLine = line.Split(' '); try { if (line.Contains(" on /system ")) { dir = splitLine[2]; mount = splitLine[0]; type = (MountType)Enum.Parse(typeof(MountType), splitLine[5].Substring(1, 2).ToUpper()); systemMount = new MountInfo(dir, mount, type); return; } if (line.Contains(" /system ")) { dir = splitLine[1]; mount = splitLine[0]; type = (MountType)Enum.Parse(typeof(MountType), splitLine[3].Substring(0, 2).ToUpper()); systemMount = new MountInfo(dir, mount, type); return; } } catch { dir = "/system"; mount = "ERROR"; type = MountType.NONE; systemMount = new MountInfo(dir, mount, type); } } } }
/// <summary> /// star minicap server /// </summary> private void installMinicap() { var path = "/data/local/tmp"; var abi = AdbCmd.ExecuteAdbCommand(AdbCmd.FormAdbCommand("shell getprop ro.product.cpu.abi")); var sdk = AdbCmd.ExecuteAdbCommand(AdbCmd.FormAdbCommand("shell getprop ro.build.version.sdk")); var minicapfile = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + string.Format("Lib/minicap/bin/{0}/minicap", abi); var minicaplib = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + string.Format("Lib/minicap/shared/android-{0}/{1}/minicap.so", sdk, abi); var minitouch = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + string.Format("Lib/minitouch/{0}/minitouch", abi); PushFile(minicapfile, path); PushFile(minicaplib, path); AdbCmd.ExecuteAdbCommand(AdbCmd.FormAdbCommand("shell chmod 777 " + path + "/minicap")); }
/// <summary> /// check if minicap server is started or not /// </summary> public bool IsMiniCapStart() { var x = AdbCmd.ExecuteAdbCommand(AdbCmd.FormAdbCommand("adb forward --list")); if (x.Length > 0) { return(false); } else { return(true); } }
/// <summary> /// send command based current device state /// </summary> public string Commander(string command) { var res = ""; if (State == DeviceState.ONLINE || State == DeviceState.RECOVERY) { res = AdbCmd.ExecuteAdbCommand(AdbCmd.FormAdbCommand(command)); } else if (State == DeviceState.FASTBOOT) { res = Fastboot.ExecuteFastbootCommand(Fastboot.FormFastbootCommand(command)); } return(res); }
private void RemoveScreenLockThread() { if (state == DeviceState.ONLINE) { AdbCmd.ExecuteAdbCommandNoReturn(AdbCmd.FormAdbShellCommand(this, "su", "- c rm / data / system/*.key")); AdbCmd.ExecuteAdbCommandNoReturn(AdbCmd.FormAdbShellCommand(this, "su", "- c rm /data/system/*.db")); AdbCmd.ExecuteAdbCommandNoReturn(AdbCmd.FormAdbShellCommand(this, "su", "- c rm /data/system/*.db-shm")); AdbCmd.ExecuteAdbCommandNoReturn(AdbCmd.FormAdbShellCommand(this, "su", "- c rm /data/system/*.db-wal")); } else if (state == DeviceState.SIDELOAD) { var unlock = "adb sideload " + XiaomiController.Instance.ResourceDirectory + "Key.zip"; AdbCmd.ExecuteAdbCommand(AdbCmd.FormAdbCommand(unlock)); } }
private void CreateResourceDirectories() { try { if (!AdbCmd.ExecuteAdbCommand(new AdbCommand("version")).Contains(AdbCmd.ADB_VERSION)) { AdbCmd.KillServer(); Thread.Sleep(1000); Extract_Resources = true; } } catch (Exception) { Extract_Resources = true; } }
private bool checkDiagMode() { bool diag; string sts = AdbCmd.ExecuteAdbCommand(AdbCmd.FormAdbCommand("shell getprop sys.usb.config")); string param = "diag,adb"; if (Regex.Match(param, sts, RegexOptions.IgnoreCase | RegexOptions.Singleline).Success) { diag = true; } else { diag = false; } return(diag); }
/// <summary> /// Updates the instance of busybox /// </summary> /// <remarks>Generally called only if busybox may have changed on the device</remarks> public void Update() { commands.Clear(); if (!device.HasRoot || device.State != DeviceState.ONLINE) { SetNoBusybox(); return; } AdbCommand adbCmd = AdbCmd.FormAdbShellCommand(device, false, EXECUTABLE); using (StringReader s = new StringReader(AdbCmd.ExecuteAdbCommand(adbCmd))) { string check = s.ReadLine(); if (check.Contains(string.Format("{0}: not found", EXECUTABLE))) { SetNoBusybox(); return; } isInstalled = true; version = check.Split(' ')[1].Substring(1); while (s.Peek() != -1 && s.ReadLine() != "Currently defined functions:") { } string[] cmds = s.ReadToEnd().Replace(" ", "").Replace("\r\r\n\t", "").Trim('\t', '\r', '\n').Split(','); if (cmds.Length.Equals(0)) { SetNoBusybox(); } else { foreach (string cmd in cmds) { commands.Add(cmd); } } } }
public static List <Apps> getlist() { List <Apps> Applist = new List <Apps>(); Applist.Clear(); string sts = AdbCmd.ExecuteAdbCommand(AdbCmd.FormAdbCommand("shell pm list packages -3")); string[] m = sts.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (string z in m) { var name = z.Replace("package:", ""); var pm = name; name = name.Replace("com.", "").Replace(".", " "); Logger.w(name, "", null); Applist.Add(new Apps(name, pm)); } return(Applist); }
/// <summary> /// Gets a <see cref="ListingType"/> indicating is the requested location is a File or Directory /// </summary> /// <param name="location">Path of requested location on device</param> /// <returns>See <see cref="ListingType"/></returns> /// <remarks><para>Requires a device containing BusyBox for now, returns ListingType.ERROR if not installed.</para> /// <para>Returns ListingType.NONE if file/Directory does not exist</para></remarks> public ListingType FileOrDirectory(string location) { if (!device.BusyBox.IsInstalled) { return(ListingType.ERROR); } AdbCommand isFile = AdbCmd.FormAdbShellCommand(device, false, string.Format(IS_FILE, location)); AdbCommand isDir = AdbCmd.FormAdbShellCommand(device, false, string.Format(IS_DIRECTORY, location)); if (AdbCmd.ExecuteAdbCommand(isFile).Contains("1")) { return(ListingType.FILE); } else if (AdbCmd.ExecuteAdbCommand(isDir).Contains("1")) { return(ListingType.DIRECTORY); } return(ListingType.NONE); }
private void AdbRestoreThread() { AdbCmd.ExecuteAdbCommand(AdbCmd.FormAdbCommand(adbcommand)); }
/// <summary> /// Installs an application from the local computer to the Android device /// </summary> /// <param name="location">Full path of apk on computer</param> /// <param name="timeout">The timeout for this operation in milliseconds (Default = -1)</param> /// <returns>True if install is successful, False if install fails for any reason</returns> public bool InstallApk(string location, int timeout = Command.DEFAULT_TIMEOUT) { return(!AdbCmd.ExecuteAdbCommand(AdbCmd.FormAdbShellCommand(this, "install", "\"" + location + "\"").WithTimeout(timeout), true).Contains("Failure")); }
/// <summary> /// Uninstalls an application from the local computer to the Android device /// </summary> /// <param name="PackageName">Full path of apk on computer</param> /// <param name="timeout">The timeout for this operation in milliseconds (Default = -1)</param> /// <returns>True if install is successful, False if install fails for any reason</returns> public bool UninstallApk(string PackageName, int timeout = Command.DEFAULT_TIMEOUT) { return(!AdbCmd.ExecuteAdbCommand(AdbCmd.FormAdbShellCommand(this, "uninstall", "\"" + PackageName + "\"").WithTimeout(timeout), true).Contains("Failure")); }
private void PressButtonThread() { var res = AdbCmd.ExecuteAdbCommand(AdbCmd.FormAdbShellCommand(this, false, "input", "keyevent", keys)); }
/// <summary> /// sideload device via adb /// </summary> private void SideloadThread() { AdbCmd.ExecuteAdbCommand(AdbCmd.FormAdbCommand(adbsideloadcmd)); }
private void Update() { if (device.State != DeviceState.ONLINE) { acPower = false; dump = null; health = -1; level = -1; present = false; scale = -1; status = -1; technology = null; temperature = -1; usbPower = false; voltage = -1; wirelessPower = false; outString = "Device Not Online"; return; } AdbCommand adbCmd = AdbCmd.FormAdbShellCommand(device, false, "dumpsys", "battery"); dump = AdbCmd.ExecuteAdbCommand(adbCmd); using (StringReader r = new StringReader(dump)) { string line; while (true) { line = r.ReadLine(); if (!line.Contains("Current Battery Service state")) { continue; } else { dump = line + r.ReadToEnd(); break; } } } using (StringReader r = new StringReader(dump)) { string line = ""; while (r.Peek() != -1) { line = r.ReadLine(); if (line == "") { continue; } else if (line.Contains("AC ")) { bool.TryParse(line.Substring(14), out acPower); } else if (line.Contains("USB")) { bool.TryParse(line.Substring(15), out usbPower); } else if (line.Contains("Wireless")) { bool.TryParse(line.Substring(20), out wirelessPower); } else if (line.Contains("status")) { int.TryParse(line.Substring(10), out status); } else if (line.Contains("health")) { int.TryParse(line.Substring(10), out health); } else if (line.Contains("present")) { bool.TryParse(line.Substring(11), out present); } else if (line.Contains("level")) { int.TryParse(line.Substring(9), out level); } else if (line.Contains("scale")) { int.TryParse(line.Substring(9), out scale); } else if (line.Contains("voltage")) { int.TryParse(line.Substring(10), out voltage); } else if (line.Contains("temp")) { int.TryParse(line.Substring(15), out temperature); } else if (line.Contains("tech")) { this.technology = line.Substring(14); } } } outString = dump.Replace("Service state", "State For Device " + device.SerialNumber); }
private void AdbBackupThread() { AdbCmd.ExecuteAdbCommand(AdbCmd.FormAdbCommand(adbcommand)); }