Esempio n. 1
0
        public async Task <string> ExecuteShellCommandAsync(Device device, string command)
        {
            using (var socket = new AdbSocket())
            {
                // Set the device that the command should be executed on.
                await socket.SetDeviceAsync(device);

                // Send the command.
                await socket.WriteAsync(FormAdbRequest($"shell:{command}"));

                // Read and verify the response.
                var resp = await socket.ReadResponseAsync();

                if (resp != "OKAY")
                {
                    throw new AdbException($"An error occurred when executing the remote shell command: {command}");
                }

                // The response to a shell command doesn't have a length header so we just read and return the entire thing.
                using (var reader = new StreamReader(socket.Stream))
                {
                    return(await reader.ReadToEndAsync());
                }
            }
        }
Esempio n. 2
0
 public void Dispose()
 {
     if (_socket != null)
     {
         _socket.Dispose();
         _socket = null;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Gets all the devices currently connected to the computer.
        /// </summary>
        /// <returns>A collection of <see cref="Device"/>.</returns>
        public async Task <IEnumerable <Device> > GetDevicesAsync()
        {
            using (var socket = new AdbSocket())
            {
                // Send the request and verify the response code.
                await socket.WriteAsync(FormAdbRequest("host:devices-l"));

                var resp = await socket.ReadResponseAsync();

                // If the exception is thrown we don't need to worry about reading the rest of the incoming data because the socket will get closed.
                if (resp != "OKAY")
                {
                    throw new AdbException("An error occurred when getting the connected devices.");
                }

                // Get the response and split it into individual lines (in the event of multiple devices).
                var deviceStrings = (await socket.ReadAdbStringAsync()).Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                // Generate a device from each line.
                return(deviceStrings.Select(s => Device.FromString(s)));
            }
        }
Esempio n. 4
0
 public AdbSyncService()
 {
     _socket = new AdbSocket();
     _ascii  = Encoding.ASCII;
 }