/// <summary> /// 截图 /// </summary> public void Capture() { CmdStation.GetShellCommand(Device, $"/system/bin/screencap -p {TmpPath}") .To(RaiseOutput) .Execute(). ThrowIfExitCodeNotEqualsZero(); }
/// <summary> /// 发送一个广播 /// </summary> /// <param name="broadcast">广播内容</param> /// <exception cref="Exceptions.AdbShellCommandFailedException"></exception> public void Send(string broadcast, Intent intent = null) { CmdStation.GetShellCommand(Device, $"am broadcast -a {broadcast} {intent?.ToAdbArguments()}") .Execute() .ThrowIfExitCodeNotEqualsZero();; }
/// <summary> /// 点击屏幕上的位置 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <exception cref="Exceptions.AdbShellCommandFailedException"></exception> public void Tap(int x, int y) { CmdStation.GetShellCommand(Device, $"input tap {x} {y}") .To(RaiseOutput) .Execute() .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 发送收紧内存的命令 /// adb command example:adb shell am send-trim-memory 12345 RUNNING_LOW /// </summary> /// <param name="pid"></param> /// <param name="level"></param> /// <exception cref="Exceptions.AdbShellCommandFailedException"></exception> public void TrimMemory(int pid, TrimMemoryLevel level) { CmdStation.GetShellCommand(Device, $"am send-trim-memory {pid} {level}") .To(RaiseOutput) .Execute() .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 启动一个组件,例如某个activity /// </summary> /// <param name="componentName"></param> /// <param name="intent"></param> /// <exception cref="Exceptions.AdbShellCommandFailedException"></exception> public void StartComponent(ComponentName componentName, Intent intent = null) { CmdStation.GetShellCommand(Device, $"am start -n {componentName.ToString()} {intent?.ToAdbArguments()}") .To(RaiseOutput) .Execute() .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 启动一个服务 /// </summary> /// <param name="pkgName"></param> /// <param name="className"></param> /// <param name="intent"></param> /// <exception cref="Exceptions.AdbShellCommandFailedException"></exception> public void Start(string pkgName, string className, Intent intent) { CmdStation.GetShellCommand(Device, $"am startservice -n {pkgName}/.{className} {intent?.ToString()}") .To(RaiseOutput) .Execute() .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 模拟在屏幕上滑动 /// </summary> /// <param name="startX"></param> /// <param name="startY"></param> /// <param name="endX"></param> /// <param name="endY"></param> /// <exception cref="Exceptions.AdbShellCommandFailedException"></exception> public void Swipe(int startX, int startY, int endX, int endY) { CmdStation.GetShellCommand(Device, $"input swipe {startX} {startY} {endX} {endY}") .To(RaiseOutput) .Execute() .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 在目前的焦点文本框输入文本 /// </summary> /// <param name="text"></param> /// <exception cref="Exceptions.AdbShellCommandFailedException"></exception> public void InputText(string text) { CmdStation.GetShellCommand(Device, $"input text {text}") .To(RaiseOutput) .Execute() .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 启动一个Activity /// </summary> /// <param name="pkgName"></param> /// <param name="activityClassName"></param> /// <param name="intent"></param> /// <exception cref="Exceptions.AdbShellCommandFailedException"></exception> public void StartActivity(string pkgName, string activityClassName, Intent intent = null) { CmdStation.GetShellCommand(Device, $"am start -n {pkgName}/.{activityClassName} {intent?.ToAdbArguments()}") .To(RaiseOutput) .Execute() .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 启动一个动作 /// </summary> /// <param name="action"></param> /// <param name="intent"></param> /// <exception cref="Exceptions.AdbShellCommandFailedException"></exception> public void StartAction(string action, Intent intent) { CmdStation.GetShellCommand(Device, $"am start -a {action} {intent?.ToAdbArguments()}") .To(RaiseOutput) .Execute() .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 启动一个Category /// </summary> /// <param name="category"></param> /// <param name="intent"></param> /// <exception cref="Exceptions.AdbShellCommandFailedException"></exception> public void StartCategory(string category, Intent intent) { CmdStation.GetShellCommand(Device, $"am start -c {category} {intent?.ToAdbArguments()}") .To(RaiseOutput) .Execute() .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 强制停止某个APP /// adb command:adb shell am force-stop com.qihoo360.mobilesafe /// </summary> /// <param name="pkgName"></param> /// <exception cref="Exceptions.AdbShellCommandFailedException"></exception> public void ForceStop(string pkgName) { CmdStation.GetShellCommand(Device, $"am force-stop {pkgName}") .To(RaiseOutput) .Execute() .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 创建文件夹 /// </summary> /// <param name="file"></param> public void Mkdir(string file) { var result = CmdStation .GetShellCommand(Device, $"mkdir {file}") .To(RaiseOutput) .Execute() .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 模拟按键 /// </summary> /// <param name="keycode"></param> /// <exception cref="Exceptions.AdbShellCommandFailedException"></exception> public void PressKey(int keycode) { CmdStation.GetShellCommand(Device, $"input keyevent {keycode}") .To(RaiseOutput) .Execute() .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 重设显示区域 /// </summary> public void ResetOverscan() { CmdStation .GetShellCommand(Device, $"wm overscan reset") .To(RaiseOutput) .Execute() .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 设置显示区域 /// </summary> /// <param name="left">左边的留白像素</param> /// <param name="top">顶部的留白像素</param> /// <param name="right">右边的留白像素</param> /// <param name="bottom">底部的留白像素</param> public void SetOverscan(int left, int top, int right, int bottom) { CmdStation .GetShellCommand(Device, $"wm overscan {left} {top} {right} {bottom}") .To(RaiseOutput) .Execute() .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 重设Density /// </summary> /// <exception cref="Exceptions.AdbShellCommandFailedException"></exception> public void ResetDensity() { CmdStation .GetShellCommand(Device, $"wm density reset") .To(RaiseOutput) .Execute() .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 移除某个用户 /// </summary> /// <param name="uid">UID</param> /// <returns></returns> public void RemoveUser(int uid) { CmdStation .GetShellCommand(Device, $"pm remove-user {uid}") .To(RaiseOutput) .Execute() .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// CAT命令查看文件内容 /// </summary> /// <param name="file"></param> /// <returns></returns> public string Cat(string file) { var result = CmdStation.GetShellCommand(Device, "cat " + file) .To(RaiseOutput) .Execute() .ThrowIfShellExitCodeNotEqualsZero(); return(result.Output.ToString()); }
/// <summary> /// 复制文件 /// </summary> /// <param name="src"></param> /// <param name="target"></param> /// <param name="isDir"></param> public void Copy(string src, string target, bool isDir) { var command = isDir ? CmdStation.GetShellCommand(Device, $"cp -r {src} {target}") : CmdStation.GetShellCommand(Device, $"cp {src} {target}"); command.To(RaiseOutput) .Execute() .ThrowIfShellExitCodeNotEqualsZero(); }
public void RemoveAccounts() { string command = string.Format(CMD_FORMAT, CMD_REMOVE_ACC); CmdStation .GetShellCommand(Device, command) .To(RaiseOutput) .Execute() .ThrowIfExitCodeNotEqualsZero(); }
/// <summary> /// 自行指定KEY的值 /// </summary> /// <param name="key"></param> /// <returns></returns> public string Get(string key) { var exeResult = CmdStation.GetShellCommand( Device, $"getprop {key}") .To(RaiseOutput) .Execute(); return(exeResult.ExitCode == 0 ? exeResult.Output.ToString() : null); }
/// <summary> /// 调用find命令寻找文件 /// </summary> /// <param name="name"></param> /// <returns></returns> public Output Find(string name) { var result = CmdStation .GetShellCommand(Device, $"find {name}") .To(RaiseOutput) .Execute() .ThrowIfShellExitCodeNotEqualsZero(); return(result.Output); }
/// <summary> /// 获取设备上的所有用户 /// </summary> /// <param name="ignoreZeroUser">是否忽略0号用户</param> /// <returns>用户</returns> public UserInfo[] GetUsers(bool ignoreZeroUser = true) { var executeResult = CmdStation .GetShellCommand(Device, "pm list users") .To(RaiseOutput) .Execute() .ThrowIfShellExitCodeNotEqualsZero(); return(ParseOutput(executeResult.Output, ignoreZeroUser)); }
public string ShowUsage() { string command = string.Format(CMD_FORMAT, ""); return(CmdStation .GetShellCommand(Device, command) .To(RaiseOutput) .Execute() .ThrowIfExitCodeNotEqualsZero() .Output.ToString()); }
public void SetDeviceOwner(string componentName) { string setDeviceOwnerArg = $"{CMD_SET_DEVICE_OWNER} {componentName}"; string command = string.Format(CMD_FORMAT, setDeviceOwnerArg); CmdStation .GetShellCommand(Device, command) .To(RaiseOutput) .Execute() .ThrowIfExitCodeNotEqualsZero(); }
protected virtual int SetReciverAsDpm() { WriteLineAndSetTip(Res("DPMSetting")); CmdStation .GetShellCommand(TargetDevice, $"dpm set-device-owner {DpmAppPackageName}/{ReceiverClassName}") .To(OutputPrinter) .Execute(); ThrowIfCanceled(); return(0); }
/// <summary> ///设置 build.prop /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <exception cref="Exceptions.AdbShellCommandFailedException"></exception> public void Set(string key, string value) { if (!Device.HaveSU()) { throw new DeviceHasNoSuException(); } CmdStation.GetShellCommand(Device, $"setprop {key} {value}") .To(RaiseOutput) .Execute() .ThrowIfShellExitCodeNotEqualsZero(); }
protected override int VisualMain() { WriteInitInfo(); new ActivityManager(TargetDevice).StartActivity("me.piebridge.brevent", "ui.BreventActivity"); Thread.Sleep(DELAY_AFTER_LAUNCH); var result = CmdStation .GetShellCommand(TargetDevice, $"sh {SH_PATH}") .To(OutputPrinter) .Execute(); WriteExitCode(result.ExitCode); return(result.ExitCode); }
/// <summary> /// Set active admin /// </summary> /// <param name="componentName"></param> /// <param name="uid"></param> public void SetActiveAdmin(string componentName, int?uid = null) { StringBuilder sb = new StringBuilder(); sb.Append("set-active-admin "); if (uid != null) { sb.Append($"--user {uid} "); } sb.Append(componentName); CmdStation.GetShellCommand(Device, sb.ToString()) .To(RaiseOutput) .Execute(). ThrowIfShellExitCodeNotEqualsZero(); }