/// <summary> /// Gets the environment variables currently defined on a device. /// </summary> /// <param name="client"> /// The connection to the adb server. /// </param> /// <param name="device"> /// The device for which to list the environment variables. /// </param> /// <returns> /// A dictionary containing the environment variables of the device, and their values. /// </returns> public static Dictionary <string, string> GetEnvironmentVariables(this IAdbClient client, DeviceData device) { var receiver = new EnvironmentVariablesReceiver(); client.ExecuteRemoteCommand(EnvironmentVariablesReceiver.PrintEnvCommand, device, receiver); return(receiver.EnvironmentVariables); }
/// <summary> /// Gets the properties of a device. /// </summary> /// <param name="client"> /// The connection to the adb server. /// </param> /// <param name="device"> /// The device for which to list the properties. /// </param> /// <returns> /// A dictionary containing the properties of the device, and their values. /// </returns> public static Dictionary <string, string> GetProperties(this IAdbClient client, DeviceData device) { var receiver = new GetPropReceiver(); client.ExecuteRemoteCommand(GetPropReceiver.GetpropCommand, device, receiver); return(receiver.Properties); }
public static string ExecuteRemoteCommandSync(this IAdbClient client, DeviceData dev, string command) { var finished = false; var retv = ""; var recv = new CommandRecv(); recv.Finished = (result) => { finished = true; retv = result; }; client.ExecuteRemoteCommand(command, dev, recv); while (!finished) { Thread.Sleep(32); } return(retv); }
/// <summary> /// Executes a shell command on the remote device /// </summary> /// <param name="client"> /// An instance of a class that implements the <see cref="IAdbClient"/> interface. /// </param> /// <param name="command">The command to execute</param> /// <param name="device">The device to execute on</param> /// <param name="rcvr">The shell output receiver</param> public static void ExecuteRemoteCommand(this IAdbClient client, string command, DeviceData device, IShellOutputReceiver rcvr) { try { client.ExecuteRemoteCommand(command, device, rcvr, CancellationToken.None, int.MaxValue); } catch (AggregateException ex) { if (ex.InnerExceptions.Count == 1) { throw ex.InnerException; } else { throw; } } }
public byte[] GetScreenshot() { var isConnected = EnsureAdbServerRunning(); if (isConnected == false) { return(Array.Empty <byte>()); } var device = _adbClient.GetDevices()[0]; const string screenshotPathOnDevice = "/sdcard/DCIM/raid.png"; _adbClient.ExecuteRemoteCommand($"screencap -p {screenshotPathOnDevice}", device, new DebugReceiver()); using var memoryStream = new MemoryStream(); using var adbSocket = new AdbSocket(_adbClient.EndPoint); using var syncService = _syncServiceFactory.Create(adbSocket, device); syncService.Pull(screenshotPathOnDevice, memoryStream, null, CancellationToken.None); return(memoryStream.ToArray()); }
/// <summary> /// Executes a shell command on the device. /// </summary> /// <param name="device"> /// The device on which to run the command. /// </param> /// <param name="client"> /// The <see cref="IAdbClient"/> to use when executing the command. /// </param> /// <param name="command"> /// The command to execute. /// </param> /// <param name="receiver"> /// Optionally, a <see cref="IShellOutputReceiver"/> that processes the command output. /// </param> public static void ExecuteShellCommand(this DeviceData device, IAdbClient client, string command, IShellOutputReceiver receiver) { client.ExecuteRemoteCommand(command, device, receiver); }
/// <summary> /// Executes a shell command on the remote device /// </summary> /// <param name="client"> /// An instance of a class that implements the <see cref="IAdbClient"/> interface. /// </param> /// <param name="command">The command to execute</param> /// <param name="device">The device to execute on</param> /// <param name="rcvr">The shell output receiver</param> public static void ExecuteRemoteCommand(this IAdbClient client, string command, DeviceData device, IShellOutputReceiver rcvr) { client.ExecuteRemoteCommand(command, device, rcvr, CancellationToken.None, int.MaxValue).Wait(); }