/// <summary> /// Forwards a port that remains until the current <see cref="AndroidController"/> instance is Disposed, or the device is unplugged /// </summary> /// <remarks>Only supports tcp: forward spec for now</remarks> /// <param name="device">Instance of <see cref="Device"/> to apply port forwarding to</param> /// <param name="localPort">Local port number</param> /// <param name="remotePort">Remote port number</param> /// <returns>True if successful, false if unsuccessful</returns> public static bool PortForward(Device device, int localPort, int remotePort) { bool success = false; AdbCommand adbCmd = Adb.FormAdbCommand(device, "forward", "tcp:" + localPort, "tcp:" + remotePort); using (StringReader r = new StringReader(ExecuteAdbCommand(adbCmd))) { if (r.ReadToEnd().Trim() == "") { success = true; } } return(success); }
/// <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(!Adb.ExecuteAdbCommand(Adb.FormAdbCommand(this, "install", "\"" + location + "\"").WithTimeout(timeout), true).Contains("Failure")); }
/// <summary> /// Pulls a full directory recursively from the device /// </summary> /// <param name="location">Path to folder to pull from device</param> /// <param name="destination">Directory on local computer to pull file to</param> /// <param name="timeout">The timeout for this operation in milliseconds (Default = -1)</param> /// <returns>True if directory is pulled, false if pull failed</returns> public bool PullDirectory(string location, string destination, int timeout = Command.DEFAULT_TIMEOUT) { AdbCommand adbCmd = Adb.FormAdbCommand(this, "pull", "\"" + (location.EndsWith("/") ? location : location + "/") + "\"", "\"" + destination + "\""); return(Adb.ExecuteAdbCommandReturnExitCode(adbCmd.WithTimeout(timeout)) == 0); }
/// <summary> /// Pushes a file to the device /// </summary> /// <param name="filePath">The path to the file on the computer you want to push</param> /// <param name="destinationFilePath">The desired full path of the file after pushing to the device (including file name and extension)</param> /// <param name="timeout">The timeout for this operation in milliseconds (Default = -1)</param> /// <returns>If the push was successful</returns> public bool PushFile(string filePath, string destinationFilePath, int timeout = Command.DEFAULT_TIMEOUT) { AdbCommand adbCmd = Adb.FormAdbCommand(this, "push", "\"" + filePath + "\"", "\"" + destinationFilePath + "\""); return(Adb.ExecuteAdbCommandReturnExitCode(adbCmd.WithTimeout(timeout)) == 0); }
/// <summary> /// Pulls a file from the device /// </summary> /// <param name="fileOnDevice">Path to file to pull from device</param> /// <param name="destinationDirectory">Directory on local computer to pull file to</param> /// /// <param name="timeout">The timeout for this operation in milliseconds (Default = -1)</param> /// <returns>True if file is pulled, false if pull failed</returns> public bool PullFile(string fileOnDevice, string destinationDirectory, int timeout = Command.DEFAULT_TIMEOUT) { AdbCommand adbCmd = Adb.FormAdbCommand(this, "pull", "\"" + fileOnDevice + "\"", "\"" + destinationDirectory + "\""); return(Adb.ExecuteAdbCommandReturnExitCode(adbCmd.WithTimeout(timeout)) == 0); }
private void RebootBootloaderThread() { Adb.ExecuteAdbCommandNoReturn(Adb.FormAdbCommand(this, "reboot", "bootloader")); }
private void RebootRecoveryThread() { Adb.ExecuteAdbCommandNoReturn(Adb.FormAdbCommand(this, "reboot", "recovery")); }
internal static string Devices() { return(ExecuteAdbCommand(Adb.FormAdbCommand("devices"))); }
internal static void KillServer() { ExecuteAdbCommandNoReturn(Adb.FormAdbCommand("kill-server")); }
internal static void StartServer() { ExecuteAdbCommandNoReturn(Adb.FormAdbCommand("start-server")); }
/// <summary> /// Installs an application from the local computer to the Android device /// </summary> /// <param name="location">Full path of apk on computer</param> /// <returns>True if install is successful, False if install fails for any reason</returns> public bool InstallApk(string location) { return(!Adb.ExecuteAdbCommand(Adb.FormAdbCommand(this, "install", "\"" + location + "\""), true).Contains("Failure")); }
/// <summary> /// Pulls a full directory recursively from the device /// </summary> /// <param name="location">Path to folder to pull from device</param> /// <param name="destination">Directory on local computer to pull file to</param> /// <returns>True if directory is pulled, false if pull failed</returns> public bool PullDirectory(string location, string destination) { AdbCommand adbCmd = Adb.FormAdbCommand(this, "pull", "\"" + (location.EndsWith("/") ? location : location + "/") + "\"", "\"" + destination + "\""); return(Adb.ExecuteAdbCommandReturnExitCode(adbCmd) == 0); }
/// <summary> /// Pushes a file to the device /// </summary> /// <param name="filePath">The path to the file on the computer you want to push</param> /// <param name="destinationFilePath">The desired full path of the file after pushing to the device (including file name and extension)</param> /// <returns>If the push was successful</returns> public bool PushFile(string filePath, string destinationFilePath) { AdbCommand adbCmd = Adb.FormAdbCommand(this, "push", "\"" + filePath + "\"", "\"" + destinationFilePath + "\""); return(Adb.ExecuteAdbCommandReturnExitCode(adbCmd) == 0); }
/// <summary> /// Pulls a file from the device /// </summary> /// <param name="fileOnDevice">Path to file to pull from device</param> /// <param name="destinationDirectory">Directory on local computer to pull file to</param> /// <returns>True if file is pulled, false if pull failed</returns> public bool PullFile(string fileOnDevice, string destinationDirectory) { AdbCommand adbCmd = Adb.FormAdbCommand(this, "pull", "\"" + fileOnDevice + "\"", "\"" + destinationDirectory + "\""); return(Adb.ExecuteAdbCommandReturnExitCode(adbCmd) == 0); }