/// <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); } } } } } }
/// <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 { } }