/// <summary> /// 移动文件 /// </summary> /// <param name="src"></param> /// <param name="target"></param> /// <param name="isDir"></param> public void Move(string src, string target, bool isDir) { (isDir ? Executor.AdbShell(Device, $"mv -r {src} {target}") : Executor.AdbShell(Device, $"mv {src} {target}")) .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 获取设备上的所有用户 /// </summary> /// <param name="ignoreZeroUser">是否忽略0号用户</param> /// <returns>用户</returns> public UserInfo[] GetUsers(bool ignoreZeroUser = true) { var executeResult = Executor.AdbShell(Device, "pm list users") .ThrowIfShellExitCodeNotEqualsZero(); return(ParseOutput(executeResult.Output, ignoreZeroUser)); }
/// <summary> /// 自行指定KEY的值 /// </summary> /// <param name="key"></param> /// <returns></returns> public string Get(string key) { var exeResult = Executor.AdbShell( Device, $"getprop {key}"); return(exeResult.ExitCode == 0 ? exeResult.Output.ToString() : null); }
/// <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(); } Executor.AdbShell(Device, $"setprop {key} {value}") .ThrowIfShellExitCodeNotEqualsZero(); }
/// <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("dpm set-active-admin "); if (uid != null) { sb.Append($"--user {uid} "); } sb.Append(componentName); Executor.AdbShell(Device, sb.ToString()). ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// Set Profile Owner /// </summary> /// <param name="componentName"></param> /// <param name="uid"></param> /// <param name="name"></param> public void SetProfileOwner(string componentName, int?uid = null, string name = null) { StringBuilder sb = new StringBuilder(); sb.Append("dpm set-profile-owner "); if (uid != null) { sb.Append($"--user {uid} "); } if (name != null) { sb.Append($"--name {name} "); } sb.Append(componentName); Executor.AdbShell(Device, sb.ToString()). ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 移除某个用户 /// </summary> /// <param name="uid">UID</param> /// <returns></returns> public void RemoveUser(int uid) { Executor.AdbShell(Device, $"pm remove-user {uid}") .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 删除文件 /// </summary> /// <param name="file"></param> public void Delete(string file) { Executor.AdbShell(Device, $"rm -rf {file}") .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 发送一个广播 /// </summary> /// <param name="broadcast">广播内容</param> /// <param name="intent"></param> /// <exception cref="Exceptions.AdbShellCommandFailedException"></exception> public void Send(string broadcast, Intent intent = null) { Executor.AdbShell(Device, $"am broadcast -a {broadcast} {intent?.ToAdbArguments()}") .ThrowIfExitCodeNotEqualsZero();; }
/// <summary> /// 重设显示区域 /// </summary> public void ResetOverscan() { Executor.AdbShell(Device, $"wm overscan reset") .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) { Executor.AdbShell(Device, $"wm overscan {left} {top} {right} {bottom}") .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// CAT命令查看文件内容 /// </summary> /// <param name="file"></param> /// <returns></returns> public string Cat(string file) { return(Executor.AdbShell(Device, "cat " + file) .ThrowIfShellExitCodeNotEqualsZero().Output.ToString()); }
/// <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) { Executor.AdbShell(Device, $"input swipe {startX} {startY} {endX} {endY}") .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 模拟按键 /// </summary> /// <param name="keycode"></param> /// <exception cref="Exceptions.AdbShellCommandFailedException"></exception> public void PressKey(int keycode) { Executor.AdbShell(Device, $"input keyevent {keycode}") .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 启动服务 /// </summary> /// <param name="cn"></param> /// <param name="intent"></param> public void Start(ComponentName cn, Intent intent = null) { Executor.AdbShell(Device, $"am startservice -n {cn.ToString()} {intent?.ToString()}") .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 调用find命令寻找文件 /// </summary> /// <param name="name"></param> /// <returns></returns> public Output Find(string name) { return(Executor .AdbShell(Device, $"find {name}") .ThrowIfShellExitCodeNotEqualsZero().Output); }
/// <summary> /// 创建文件夹 /// </summary> /// <param name="file"></param> public void Mkdir(string file) { Executor.AdbShell(Device, $"mkdir {file}") .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 在目前的焦点文本框输入文本 /// </summary> /// <param name="text"></param> /// <exception cref="Exceptions.AdbShellCommandFailedException"></exception> public void InputText(string text) { Executor.AdbShell(Device, $"input text {text}") .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 重设Size /// </summary> /// <exception cref="Exceptions.AdbShellCommandFailedException"></exception> public void ResetSize() { Executor.AdbShell(Device, $"wm size reset") .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 点击屏幕上的位置 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <exception cref="Exceptions.AdbShellCommandFailedException"></exception> public void Tap(int x, int y) { Executor.AdbShell(Device, $"input tap {x} {y}") .ThrowIfShellExitCodeNotEqualsZero(); }
/// <summary> /// 重设Density /// </summary> /// <exception cref="Exceptions.AdbShellCommandFailedException"></exception> public void ResetDensity() { Executor.AdbShell(Device, $"wm density reset") .ThrowIfShellExitCodeNotEqualsZero(); }