private void StartMinicapServerThread() { AdbCmd.ExecuteAdbCommandNoReturn(AdbCmd.FormAdbCommand("forward--remove -all")); AdbCmd.ExecuteAdbCommandNoReturn(AdbCmd.FormAdbCommand("forward --no-rebind tcp:1313 localabstract:minicap")); AdbCmd.ExecuteAdbCommandNoReturn(AdbCmd.FormAdbCommand("shell LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/minicap -P 1080x1920@1080x1920/0")); //AdbCmd.ExecuteAdbCommandNoReturn(AdbCmd.FormAdbShellCommand(this, "LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/minicap -P 1080x1920@1080x1920/0")); }
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); } }
/// <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); }
/// <summary> /// Sets a build property value /// </summary> /// <remarks>If <paramref name="key"/> does not exist or device does not have root, returns false, and does not set any values</remarks> /// <param name="key">Build property key to set</param> /// <param name="newValue">Value you wish to set <paramref name="key"/> to</param> /// <returns>True if new value set, false if not</returns> public bool SetProp(string key, string newValue) { string before; if (!prop.TryGetValue(key, out before)) { return(false); } if (!device.HasRoot) { return(false); } AdbCommand adbCmd = AdbCmd.FormAdbShellCommand(device, true, "setprop", key, newValue); AdbCmd.ExecuteAdbCommandNoReturn(adbCmd); Update(); string after; if (!prop.TryGetValue(key, out after)) { return(false); } return(newValue == after); }
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; } } }
/// <summary> /// Releases all resources used by <see cref="XiaomiController"/> /// </summary> /// <remarks>Needs to be called when application has finished using <see cref="XiaomiController"/></remarks> public void Dispose() { if (AdbCmd.ServerRunning) { AdbCmd.ExecuteAdbCommandNoReturn(AdbCmd.FormAdbCommand("forward--remove - all")); AdbCmd.KillServer(); Thread.Sleep(1000); } AdbCmd.KillServer(); ResourceFolderManager.Unregister(ANDROID_CONTROLLER_TMP_FOLDER); instance = null; }
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> /// 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> /// 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> /// 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 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); }
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; } }
/// <summary> /// Updates Internal Device List /// </summary> /// <remarks>Call this before checking for Devices, or setting a new Device, for most updated results</remarks> public void UpdateDeviceList() { connectedDevices.Clear(); if (SN(AdbCmd.Devices().Replace("List of devices attached", "")).Length > 0 || SN(Fastboot.Devices()).Length > 0) { IsConnected = true; } else if (Miuidl.Port().Length > 0) { connectedDevices.Add(Miuidl.Port()); IsConnected = true; } else { IsConnected = false; } }
/// <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); }
private DeviceState SetState() { string state = null; getstate(AdbCmd.Devices()); getstate(Fastboot.Devices()); if (state == null) { state = mode; } if (state == null) { IsEdl(); state = mode.ToString(); } switch (state) { case "device": return(DeviceState.ONLINE); case "recovery": return(DeviceState.RECOVERY); case "fastboot": OemInfo(); return(DeviceState.FASTBOOT); case "sideload": return(DeviceState.SIDELOAD); case "unauthorized": return(DeviceState.UNAUTHORIZED); case "9008": return(DeviceState.EDL); case "900E": return(DeviceState.QDL); default: return(DeviceState.UNKNOWN); } }
//void PushFile(); //void PullFile(); /// <summary> /// Mounts connected Android device's file system as specified /// </summary> /// <param name="type">The desired <see cref="MountType"/> (RW or RO)</param> /// <returns>True if remount is successful, False if remount is unsuccessful</returns> /// <example>The following example shows how you can mount the file system as Read-Writable or Read-Only /// <code> /// // This example demonstrates mounting the Android device's file system as Read-Writable /// using System; /// using Mrivai.Pelitabangsa; /// /// class Program /// { /// static void Main(string[] args) /// { /// AndroidController android = AndroidController.Instance; /// Device device; /// /// Console.WriteLine("Waiting For Device..."); /// android.WaitForDevice(); //This will wait until a device is connected to the computer /// device = android.ConnectedDevices[0]; //Sets device to the first Device in the collection /// /// Console.WriteLine("Connected Device - {0}", device.SerialNumber); /// /// Console.WriteLine("Mounting System as RW..."); /// Console.WriteLine("Mount success? - {0}", device.RemountSystem(MountType.RW)); /// } /// } /// /// // The example displays the following output (if mounting is successful): /// // Waiting For Device... /// // Connected Device - {serial # here} /// // Mounting System as RW... /// // Mount success? - true /// </code> /// </example> public bool RemountSystem(MountType type) { if (!device.HasRoot) { return(false); } AdbCommand adbCmd = AdbCmd.FormAdbShellCommand(device, true, "mount", string.Format("-o remount,{0} -t yaffs2 {1} /system", type.ToString().ToLower(), systemMount.Block)); AdbCmd.ExecuteAdbCommandNoReturn(adbCmd); UpdateMountPoints(); if (systemMount.MountType == type) { return(true); } return(false); }
/// <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 PressButtonThread() { var res = AdbCmd.ExecuteAdbCommand(AdbCmd.FormAdbShellCommand(this, false, "input", "keyevent", keys)); }
/// <summary> /// disable diagnostic mode /// </summary> public void DisableDiagMode() { AdbCmd.ExecuteAdbCommandNoReturn(AdbCmd.FormAdbShellCommand(this, true, "setprop sys.usb.config adb,mtp")); }
private void PowerOffThread() { AdbCmd.ExecuteAdbCommandNoReturn(AdbCmd.FormAdbShellCommand(this, "su", "- c poweroff")); }
private void DataDisableThread() { AdbCmd.ExecuteAdbCommandNoReturn(AdbCmd.FormAdbShellCommand(this, "svc", "data disable")); }
/// <summary> /// swipe devices screen /// </summary> public bool GetScreen() { return(AdbCmd.GetSS()); //return XiaomiController.Instance.ResourceDirectory + "SS.png"; }
private void SwipeThread() { AdbCmd.ExecuteAdbCommandNoReturn(AdbCmd.FormAdbShellCommand(this, false, "input", "swipe", swipecommand)); }
private void AdbBackupThread() { AdbCmd.ExecuteAdbCommand(AdbCmd.FormAdbCommand(adbcommand)); }
private void InputTextThread() { AdbCmd.ExecuteAdbCommandNoReturn(AdbCmd.FormAdbShellCommand(this, false, "input", "text", inputcommand)); }
private void AdbRestoreThread() { AdbCmd.ExecuteAdbCommand(AdbCmd.FormAdbCommand(adbcommand)); }
/// <summary> /// sideload device via adb /// </summary> private void SideloadThread() { AdbCmd.ExecuteAdbCommand(AdbCmd.FormAdbCommand(adbsideloadcmd)); }
private void TapThread() { AdbCmd.ExecuteAdbCommandNoReturn(AdbCmd.FormAdbShellCommand(this, false, "input", "tap", tapcommand)); }