Ejemplo n.º 1
0
        public async Task ReadAsyncTest()
        {
            DummyTcpSocket tcpSocket = new DummyTcpSocket();
            AdbSocket      socket    = new AdbSocket(tcpSocket);

            // Read 100 bytes from a stream which has 101 bytes available
            byte[] data = new byte[101];
            for (int i = 0; i < 101; i++)
            {
                data[i] = (byte)i;
            }

            tcpSocket.InputStream.Write(data, 0, 101);
            tcpSocket.InputStream.Position = 0;

            // Buffer has a capacity of 101, but we'll only want to read 100 bytes
            byte[] received = new byte[101];

            await socket.ReadAsync(received, 100, CancellationToken.None);

            for (int i = 0; i < 100; i++)
            {
                Assert.AreEqual(received[i], (byte)i);
            }

            Assert.AreEqual(0, received[100]);
        }
Ejemplo n.º 2
0
        private void InitAdbSocket()
        {
            IPAddress  ipaddress  = IPAddress.Parse("127.0.0.1");
            IPEndPoint ipendpoint = new IPEndPoint(ipaddress, 5037);//the default .

            AdbSocket = new AdbSocket(ipendpoint);
        }
Ejemplo n.º 3
0
        public void IsOkayTest()
        {
            var okay = Encoding.ASCII.GetBytes("OKAY");
            var fail = Encoding.ASCII.GetBytes("FAIL");

            Assert.IsTrue(AdbSocket.IsOkay(okay));
            Assert.IsFalse(AdbSocket.IsOkay(fail));
        }
Ejemplo n.º 4
0
 public static void Test(string cmd)
 {
     using (AdbSocket socket = new AdbSocket(AdbClient.Instance.EndPoint))
     {
         socket.SendAdbRequest(cmd);
         var response = socket.ReadAdbResponse();
         Main.IO.Print(response.Message, ConsoleColor.Magenta);
     }
 }
Ejemplo n.º 5
0
        public void DisposeTest()
        {
            DummyTcpSocket tcpSocket = new DummyTcpSocket();
            AdbSocket socket = new AdbSocket(tcpSocket);

            Assert.IsTrue(socket.Connected);

            socket.Dispose();
            Assert.IsFalse(socket.Connected);
        }
Ejemplo n.º 6
0
        public void DisposeTest()
        {
            DummyTcpSocket tcpSocket = new DummyTcpSocket();
            AdbSocket      socket    = new AdbSocket(tcpSocket);

            Assert.IsTrue(socket.Connected);

            socket.Dispose();
            Assert.IsFalse(socket.Connected);
        }
Ejemplo n.º 7
0
        private void RunTest(Action <IAdbSocket> test, byte[] expectedDataSent)
        {
            DummyTcpSocket tcpSocket = new DummyTcpSocket();
            AdbSocket      socket    = new AdbSocket(tcpSocket);

            // Run the test.
            test(socket);

            // Validate the data that was sent over the wire.
            CollectionAssert.AreEqual(expectedDataSent, tcpSocket.GetBytesSent());
        }
Ejemplo n.º 8
0
        public void GetShellStreamTest()
        {
            DummyTcpSocket tcpSocket = new DummyTcpSocket();
            AdbSocket      socket    = new AdbSocket(tcpSocket);

            var stream = socket.GetShellStream();

            Assert.IsInstanceOfType(stream, typeof(ShellStream));

            var shellStream = (ShellStream)stream;

            Assert.AreEqual(tcpSocket.OutputStream, shellStream.Inner);
        }
Ejemplo n.º 9
0
        public void GetShellStreamTest()
        {
            DummyTcpSocket tcpSocket = new DummyTcpSocket();
            AdbSocket      socket    = new AdbSocket(tcpSocket);

            var stream = socket.GetShellStream();

            Assert.IsType <ShellStream>(stream);

            var shellStream = (ShellStream)stream;

            Assert.Equal(tcpSocket.OutputStream, shellStream.Inner);
        }
Ejemplo n.º 10
0
        private async Task <RemoteAdbDevice> Connect(IPEndPoint endpoint)
        {
            this.EndPoint = endpoint;
            _socket       = new AdbSocket(endpoint);
            //_socket.Connect(endpoint);
            var cmd = Command.CreateConnectCommand();

            _socket.Send(cmd, cmd.Length);
            var connectionPacket = await ReceivePacket(true);

            StartReading();
            return(this);
        }
Ejemplo n.º 11
0
        public void ReadSyncResponse()
        {
            DummyTcpSocket tcpSocket = new DummyTcpSocket();
            AdbSocket      socket    = new AdbSocket(tcpSocket);

            using (StreamWriter writer = new StreamWriter(tcpSocket.InputStream, Encoding.ASCII, 4, true))
            {
                writer.Write("DENT");
            }

            tcpSocket.InputStream.Position = 0;

            Assert.AreEqual(SyncCommand.DENT, socket.ReadSyncResponse());
        }
Ejemplo n.º 12
0
        public void ReadSyncString()
        {
            DummyTcpSocket tcpSocket = new DummyTcpSocket();
            AdbSocket      socket    = new AdbSocket(tcpSocket);

            using (BinaryWriter writer = new BinaryWriter(tcpSocket.InputStream, Encoding.ASCII, true))
            {
                writer.Write(5);
                writer.Write(Encoding.ASCII.GetBytes("Hello"));
                writer.Flush();
            }

            tcpSocket.InputStream.Position = 0;

            Assert.AreEqual("Hello", socket.ReadSyncString());
        }
Ejemplo n.º 13
0
        public void ReadAdbFailResponseTest()
        {
            DummyTcpSocket tcpSocket = new DummyTcpSocket();
            AdbSocket      socket    = new AdbSocket(tcpSocket);

            using (StreamWriter writer = new StreamWriter(tcpSocket.InputStream, Encoding.ASCII, 4, true))
            {
                writer.Write("FAIL");
                writer.Write(17.ToString("X4"));
                writer.Write("This did not work");
            }

            tcpSocket.InputStream.Position = 0;

            var response = socket.ReadAdbResponse();
        }
Ejemplo n.º 14
0
        public async Task ReadStringAsyncTest()
        {
            DummyTcpSocket tcpSocket = new DummyTcpSocket();
            AdbSocket      socket    = new AdbSocket(tcpSocket);

            using (BinaryWriter writer = new BinaryWriter(tcpSocket.InputStream, Encoding.ASCII, true))
            {
                writer.Write(Encoding.ASCII.GetBytes(5.ToString("X4")));
                writer.Write(Encoding.ASCII.GetBytes("Hello"));
                writer.Flush();
            }

            tcpSocket.InputStream.Position = 0;

            Assert.AreEqual("Hello", await socket.ReadStringAsync(CancellationToken.None));
        }
Ejemplo n.º 15
0
        public void ReadAdbOkayResponseTest()
        {
            DummyTcpSocket tcpSocket = new DummyTcpSocket();
            AdbSocket      socket    = new AdbSocket(tcpSocket);

            using (StreamWriter writer = new StreamWriter(tcpSocket.InputStream, Encoding.ASCII, 4, true))
            {
                writer.Write("OKAY");
            }

            tcpSocket.InputStream.Position = 0;

            var response = socket.ReadAdbResponse();

            Assert.IsTrue(response.IOSuccess);
            Assert.AreEqual(string.Empty, response.Message);
            Assert.IsTrue(response.Okay);
            Assert.IsFalse(response.Timeout);
        }
Ejemplo n.º 16
0
        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());
        }
Ejemplo n.º 17
0
        public void ReadSyncString()
        {
            DummyTcpSocket tcpSocket = new DummyTcpSocket();
            AdbSocket socket = new AdbSocket(tcpSocket);

            using (BinaryWriter writer = new BinaryWriter(tcpSocket.InputStream, Encoding.ASCII, true))
            {
                writer.Write(5);
                writer.Write(Encoding.ASCII.GetBytes("Hello"));
                writer.Flush();
            }

            tcpSocket.InputStream.Position = 0;

            Assert.AreEqual("Hello", socket.ReadSyncString());
        }
Ejemplo n.º 18
0
        public async Task ReadStringAsyncTest()
        {
            DummyTcpSocket tcpSocket = new DummyTcpSocket();
            AdbSocket socket = new AdbSocket(tcpSocket);

            using (BinaryWriter writer = new BinaryWriter(tcpSocket.InputStream, Encoding.ASCII, true))
            {
                writer.Write(Encoding.ASCII.GetBytes(5.ToString("X4")));
                writer.Write(Encoding.ASCII.GetBytes("Hello"));
                writer.Flush();
            }

            tcpSocket.InputStream.Position = 0;

            Assert.AreEqual("Hello", await socket.ReadStringAsync(CancellationToken.None));
        }
Ejemplo n.º 19
0
        public void ReadAdbOkayResponseTest()
        {
            DummyTcpSocket tcpSocket = new DummyTcpSocket();
            AdbSocket socket = new AdbSocket(tcpSocket);

            using (StreamWriter writer = new StreamWriter(tcpSocket.InputStream, Encoding.ASCII, 4, true))
            {
                writer.Write("OKAY");
            }

            tcpSocket.InputStream.Position = 0;

            var response = socket.ReadAdbResponse();
            Assert.IsTrue(response.IOSuccess);
            Assert.AreEqual(string.Empty, response.Message);
            Assert.IsTrue(response.Okay);
            Assert.IsFalse(response.Timeout);
        }
Ejemplo n.º 20
0
        public void ReadAdbFailResponseTest()
        {
            DummyTcpSocket tcpSocket = new DummyTcpSocket();
            AdbSocket socket = new AdbSocket(tcpSocket);

            using (StreamWriter writer = new StreamWriter(tcpSocket.InputStream, Encoding.ASCII, 4, true))
            {
                writer.Write("FAIL");
                writer.Write(17.ToString("X4"));
                writer.Write("This did not work");
            }

            tcpSocket.InputStream.Position = 0;

            var response = socket.ReadAdbResponse();
        }
Ejemplo n.º 21
0
        public async Task ReadAsyncTest()
        {
            DummyTcpSocket tcpSocket = new DummyTcpSocket();
            AdbSocket socket = new AdbSocket(tcpSocket);

            // Read 100 bytes from a stream which has 101 bytes available
            byte[] data = new byte[101];
            for (int i = 0; i < 101; i++)
            {
                data[i] = (byte)i;
            }

            tcpSocket.InputStream.Write(data, 0, 101);
            tcpSocket.InputStream.Position = 0;

            // Buffer has a capacity of 101, but we'll only want to read 100 bytes
            byte[] received = new byte[101];

            await socket.ReadAsync(received, 100, CancellationToken.None);

            for (int i = 0; i < 100; i++)
            {
                Assert.AreEqual(received[i], (byte)i);
            }

            Assert.AreEqual(0, received[100]);
        }
Ejemplo n.º 22
0
        public void GetShellStreamTest()
        {
            DummyTcpSocket tcpSocket = new DummyTcpSocket();
            AdbSocket socket = new AdbSocket(tcpSocket);

            var stream = socket.GetShellStream();
            Assert.IsInstanceOfType(stream, typeof(ShellStream));

            var shellStream = (ShellStream)stream;
            Assert.AreEqual(tcpSocket.InputStream, shellStream.Inner);
        }
Ejemplo n.º 23
0
        private void RunTest(Action<IAdbSocket> test, byte[] expectedDataSent)
        {
            DummyTcpSocket tcpSocket = new DummyTcpSocket();
            AdbSocket socket = new AdbSocket(tcpSocket);

            // Run the test.
            test(socket);

            // Validate the data that was sent over the wire.
            CollectionAssert.AreEqual(expectedDataSent, tcpSocket.GetBytesSent());
        }
Ejemplo n.º 24
0
        public void ReadSyncResponse()
        {
            DummyTcpSocket tcpSocket = new DummyTcpSocket();
            AdbSocket socket = new AdbSocket(tcpSocket);

            using (StreamWriter writer = new StreamWriter(tcpSocket.InputStream, Encoding.ASCII, 4, true))
            {
                writer.Write("DENT");
            }

            tcpSocket.InputStream.Position = 0;

            Assert.AreEqual(SyncCommand.DENT, socket.ReadSyncResponse());
        }