Пример #1
0
        /// <inheritdoc/>
        public void Install(DeviceData device, Stream apk, params string[] arguments)
        {
            this.EnsureDevice(device);

            if (apk == null)
            {
                throw new ArgumentNullException(nameof(apk));
            }

            if (!apk.CanRead || !apk.CanSeek)
            {
                throw new ArgumentOutOfRangeException(nameof(apk), "The apk stream must be a readable and seekable stream");
            }

            StringBuilder requestBuilder = new StringBuilder();

            requestBuilder.Append("exec:cmd package 'install' ");

            if (arguments != null)
            {
                foreach (var argument in arguments)
                {
                    requestBuilder.Append(" ");
                    requestBuilder.Append(argument);
                }
            }

            // add size parameter [required for streaming installs]
            // do last to override any user specified value
            requestBuilder.Append($" -S {apk.Length}");

            using (IAdbSocket socket = this.adbSocketFactory(this.EndPoint))
            {
                this.SetDevice(socket, device);

                socket.SendAdbRequest(requestBuilder.ToString());
                var response = socket.ReadAdbResponse();

                byte[] buffer = new byte[32 * 1024];
                int    read   = 0;

                while ((read = apk.Read(buffer, 0, buffer.Length)) > 0)
                {
                    socket.Send(buffer, read);
                }

                read = socket.Read(buffer);
                var value = Encoding.UTF8.GetString(buffer, 0, read);

                if (!string.Equals(value, "Success\n"))
                {
                    throw new AdbException(value);
                }
            }
        }
Пример #2
0
        public void HandlePacket(AdbPacket newPacket)
        {
            if (RemoteId == 0)
            {
                RemoteId = newPacket.arg1;
            }
            var okay = Command.CreateOkCommand(LocalId, RemoteId);

            _sock.Send(okay, okay.Length);
            _outputBlock.Post(newPacket.Data);
        }
Пример #3
0
        public AdbStream(IAdbSocket sock, uint localId)
        {
            _sock        = sock;
            this.LocalId = localId;

            _outputBlock = new BufferBlock <byte[]>();
            _inputBlock  = new ActionBlock <byte[]>(bytes =>
            {
                var buff = Command.CreateWriteCommand(LocalId, RemoteId, bytes);
                OnWriting?.Invoke(this, EventArgs.Empty);
                if (RemoteId == 0)
                {
                    throw new Exception("Remote stream not established yet!");
                }
                _sock.Send(buff, buff.Length);
            });
            Block = DataflowBlock.Encapsulate(_inputBlock, _outputBlock);
        }
Пример #4
0
        public AdbLocalStream(IAdbSocket sock, uint localId, Encoding encoding, CancellationToken ct)
        {
            _sock        = sock;
            _oStream     = sock.GetShellStream();
            _outputBlock = new BufferBlock <byte[]>();
            _inputBlock  = new ActionBlock <byte[]>(bytes =>
            {
                var buff = Command.CreateWriteCommand(LocalId, RemoteId, bytes);
                OnWriting?.Invoke(this, EventArgs.Empty);
                if (RemoteId == 0)
                {
                    throw new Exception("Remote stream not established yet!");
                }
                _sock.Send(buff, buff.Length);
            });
            Block = DataflowBlock.Encapsulate(_inputBlock, _outputBlock);

            HandleData(encoding, ct).ConfigureAwait(false);
        }