public void UpdateDeviceList() { string deviceList = null; _connectedDevices.Clear(); deviceList = Adb.Devices(); if (deviceList.Length > 29) { using (StringReader s = new StringReader(deviceList)) { string line = null; while (!(s.Peek() == -1)) { line = s.ReadLine(); if (line.StartsWith("List") || line.StartsWith("\r\n") || string.IsNullOrEmpty(line.Trim())) { continue; } if (!(line.IndexOf('\t') == -1)) { line = line.Substring(0, line.IndexOf('\t')); _connectedDevices.Add(line); } } } } }
public void Dispose() { if (Adb.ServerRunning) { Adb.KillServer(); Thread.Sleep(1000); } AndroidController._instance = null; }
public bool RemountSystem(MountType _type) { if (!_device.HasRoot) { return(false); } AdbCommand adbCmd = Adb.FormAdbShellCommand(_device, true, "mount", "-o", "remount,rw", "/system"); Adb.ExecuteAdbCommandNoReturn(adbCmd); if (_device.FileSystem.SystemMountInfo.MountType == _type) { return(true); } else { return(false); } }
private DeviceState SetState() { string state = null; using (StringReader r = new StringReader(Adb.Devices())) { string line = null; while (!(r.Peek() == -1)) { line = r.ReadLine(); if (!(line == null)) { if (line.Contains(_serialNumber)) { state = line.Substring(line.IndexOf('\t') + 1); } } } } switch (state) { case "device": return(DeviceState.ONLINE); case "recovery": return(DeviceState.RECOVERY); case "sideload": return(DeviceState.SIDELOAD); case "unauthorized": return(DeviceState.UNAUTHORIZED); default: return(DeviceState.UNKNOWN); } }
public ListingType FileOrDirectory(string location) { if (!_device.BusyBox.IsInstalled) { return(ListingType.ERR); } AdbCommand isFile = Adb.FormAdbShellCommand(_device, false, string.Format(IS_FILE, location)); AdbCommand isDir = Adb.FormAdbShellCommand(_device, false, string.Format(IS_DIRECTORY, location)); string _isFile = Adb.ExecuteAdbCommand(isFile); string _isDir = Adb.ExecuteAdbCommand(isDir); if (_isFile.Contains("1")) { return(ListingType.FILE); } else if (_isDir.Contains("1")) { return(ListingType.DIRECTORY); } return(ListingType.NONE); }
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 = Adb.FormAdbShellCommand(_device, true, "busybox", "ls", "-a", "-p", "l", location); } else { cmd = Adb.FormAdbShellCommand(_device, true, "ls", "-a", "-p", "-l", location); } using (StringReader reader = new StringReader(Adb.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); }
public static void RunAdbShellCommandNoReturn(Device dev, bool root, string cmd, params object[] args) { Adb.ExecuteAdbCommandNoReturn(Adb.FormAdbShellCommand(dev, root, cmd, args)); }
public static string RunAdbCommand(Device dev, string cmd, params object[] args) { return(Adb.ExecuteAdbCommand(Adb.FormAdbCommand(dev, cmd, args))); }
static internal string Devices() { return(ExecuteAdbCommand(Adb.FormAdbCommand("devices"))); }
static internal void KillServer() { ExecuteAdbCommandNoReturn(Adb.FormAdbCommand("kill-server")); }
static internal void StartServer() { ExecuteAdbCommandNoReturn(Adb.FormAdbCommand("start-server")); }