Exemplo n.º 1
0
        /// <summary>
        /// Runs the Event log service on the Device, and provides its output to the LogReceiver.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <param name="device">The device.</param>
        /// <param name="logName">Name of the log.</param>
        /// <param name="rcvr">The RCVR.</param>
        /// <exception cref="AdbException">failed asking for log</exception>
        /// <exception cref="Managed.Adb.Exceptions.AdbCommandRejectedException"></exception>
        public void RunLogService(IPEndPoint address, Device device, String logName, LogReceiver rcvr)
        {
            using(var socket = ExecuteRawSocketCommand(address, device, "log:{0}".With(logName))) {
                byte[] data = new byte[16384];
                using(var ms = new MemoryStream(data)) {
                    int offset = 0;

                    while(true) {
                        int count;
                        if(rcvr != null && rcvr.IsCancelled) {
                            break;
                        }
                        var buffer = new byte[4 * 1024];

                        count = socket.Receive(buffer);
                        if(count < 0) {
                            break;
                        } else if(count == 0) {
                            try {
                                Thread.Sleep(WAIT_TIME * 5);
                            } catch(ThreadInterruptedException) {
                            }
                        } else {
                            ms.Write(buffer, offset, count);
                            offset += count;
                            if(rcvr != null) {
                                var d = ms.ToArray();
                                rcvr.ParseNewData(d, 0, d.Length);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Runs the Event log service on the Device, and provides its output to the LogReceiver.
 /// </summary>
 /// <param name="address">The address.</param>
 /// <param name="device">The device.</param>
 /// <param name="rcvr">The RCVR.</param>
 public void RunEventLogService(IPEndPoint address, Device device, LogReceiver rcvr)
 {
     RunLogService(address, device, "events", rcvr);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Runs the event log service.
 /// </summary>
 /// <param name="receiver">The receiver.</param>
 public void RunEventLogService(LogReceiver receiver)
 {
     AdbHelper.Instance.RunEventLogService(AndroidDebugBridge.SocketAddress, this, receiver);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Runs the log service.
 /// </summary>
 /// <param name="logname">The logname.</param>
 /// <param name="receiver">The receiver.</param>
 public void RunLogService(String logname, LogReceiver receiver)
 {
     AdbHelper.Instance.RunLogService(AndroidDebugBridge.SocketAddress, this, logname, receiver);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Runs the Event log service on the Device, and provides its output to the LogReceiver.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <param name="device">The device.</param>
        /// <param name="logName">Name of the log.</param>
        /// <param name="rcvr">The RCVR.</param>
        /// <exception cref="AdbException">failed asking for log</exception>
        /// <exception cref="Managed.Adb.Exceptions.AdbCommandRejectedException"></exception>
        public void RunLogService( IPEndPoint address, Device device, String logName, LogReceiver rcvr )
        {
            try {
                using ( var adbChan = new Socket ( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp ) ) {
                    adbChan.Connect ( address );
                    adbChan.Blocking = true;
                    // if the device is not -1, then we first tell adb we're looking to talk
                    // to a specific device
                    SetDevice ( adbChan, device );

                    var request = FormAdbRequest ( "log:" + logName );
                    if ( !Write ( adbChan, request ) ) {
                        throw new AdbException ( "failed asking for log" );
                    }

                    var resp = ReadAdbResponse ( adbChan, false /* readDiagString */);
                    if ( resp.Okay == false ) {
                        throw new AdbCommandRejectedException ( resp.Message );
                    }

                    byte[] data = new byte[16384];
                    using ( var ms = new MemoryStream ( data ) ) {
                        int offset = 0;

                        while ( true ) {
                            int count;
                            if ( rcvr != null && rcvr.IsCancelled ) {
                                break;
                            }
                            var buffer = new byte[4 * 1024];

                            count = adbChan.Receive ( buffer );
                            if ( count < 0 ) {
                                break;
                            } else if ( count == 0 ) {
                                try {
                                    Thread.Sleep ( WAIT_TIME * 5 );
                                } catch ( ThreadInterruptedException ie ) {
                                }
                            } else {
                                ms.Write ( buffer, offset, count );
                                offset += count;
                                if ( rcvr != null ) {
                                    var d = ms.ToArray ( );
                                    rcvr.ParseNewData ( d, 0, d.Length );
                                }
                            }
                        }
                    }
                }
            } finally {

            }
        }