/// <summary> /// Keep reading log messages until cancelled by the listener or closed. /// </summary> public void RunLogService(ILogListener listener, IDevice device, string logName) { using (var socket = new AdbRequest(EndPoint)) { socket.RunLogService(listener, device, logName); } }
/// <summary> /// Start an given activity in the given package. /// Throws an exception when starting fails. /// </summary> public void StartActivity(IDevice device, string packageName, string activityName, bool debuggable, int timeout, IStartActivityListener listener) { var component = packageName + "/" + activityName; var receiver = new StartActivityReceiver(listener); using (var socket = new AdbRequest(EndPoint)) { try { var args = new List <string>(); args.Add("start"); if (debuggable) { args.Add("-D"); } args.Add("-n"); args.Add(component); socket.ExecuteShellCommand(receiver, device, timeout, "am", args.ToArray()); } catch (Exception ex) { throw new AdbException(string.Format("Failed to start activity because: {0}", ex.Message)); } } }
/// <summary> /// Connect local port to JDWP thread on VM process pid. /// </summary> public void ForwardJdwp(IDevice device, int localPort, int pid) { using (var socket = new AdbRequest(EndPoint)) { try { socket.ForwardJdwp(device, localPort, pid); } catch (Exception ex) { throw new AdbException(string.Format("Failed to start activity because: {0}", ex.Message)); } } }
/// <summary> /// Get a system property of a device. /// Throws an exception when the request fails. /// </summary> public static string GetProperty(IDevice device, string propertyName, int timeout, bool errorIfFailed = true) { var receiver = new StringShellOutputReceiver(); using (var socket = new AdbRequest(EndPoint)) { try { socket.ExecuteShellCommand(receiver, device, timeout, "getprop", propertyName); } catch (Exception ex) { if (errorIfFailed) { throw new AdbException(string.Format("Failed to get property because: {0}", ex.Message)); } return(null); } } var result = receiver.ToString().Trim(' ', '\t', '\n', '\r'); return(string.IsNullOrEmpty(result) ? null : result); }
/// <summary> /// Get a system property of a device. /// Throws an exception when the request fails. /// </summary> public static string GetProperty(IDevice device, string propertyName, int timeout, bool errorIfFailed = true) { var receiver = new StringShellOutputReceiver(); using (var socket = new AdbRequest(EndPoint)) { try { socket.ExecuteShellCommand(receiver, device, timeout, "getprop", propertyName); } catch (Exception ex) { if (errorIfFailed) { throw new AdbException(string.Format("Failed to get property because: {0}", ex.Message)); } return null; } } var result = receiver.ToString().Trim(' ', '\t', '\n', '\r'); return string.IsNullOrEmpty(result) ? null : result; }
/// <summary> /// Start an given activity in the given package. /// Throws an exception when starting fails. /// </summary> public void StartActivity(IDevice device, string packageName, string activityName, bool debuggable, int timeout, IStartActivityListener listener) { var component = packageName + "/" + activityName; var receiver = new StartActivityReceiver(listener); using (var socket = new AdbRequest(EndPoint)) { try { var args = new List<string>(); args.Add("start"); if (debuggable) args.Add("-D"); args.Add("-n"); args.Add(component); socket.ExecuteShellCommand(receiver, device, timeout, "am", args.ToArray()); } catch (Exception ex) { throw new AdbException(string.Format("Failed to start activity because: {0}", ex.Message)); } } }