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
        /// <summary>
        /// Begins the sync (file transfer) service on the current socket.
        /// </summary>
        /// <returns>The <see cref="AdbSyncService"/> instance.</returns>
        public async Task BeginSyncAsync(Device device)
        {
            await _socket.SetDeviceAsync(device);

            await _socket.WriteAsync(AdbClient.FormAdbRequest("sync:"));

            var resp = await _socket.ReadResponseAsync();

            if (resp != "OKAY")
            {
                throw new AdbException("An error occurred when beginning the sync service.");
            }
        }