Example #1
0
 /// <summary>
 /// 发送一个广播
 /// </summary>
 /// <param name="broadcast">广播内容</param>
 /// <param name="intent"></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();;
 }
Example #2
0
        protected override int VisualMain()
        {
            IProcessBasedCommandResult step1Result = null, step2Result = null;

            step1Result = CmdStation.GetSuCommand(TargetDevice, "rm -rf /data/system/device_policies.xml")
                          .To(OutputPrinter)
                          .Execute();
            WriteExitCode(step1Result.ExitCode);
            step2Result = CmdStation.GetSuCommand(TargetDevice, "rm -rf /data/system/device_owner_2.xml")
                          .To(OutputPrinter)
                          .Execute();
            WriteExitCode(step2Result.ExitCode);

            if (step1Result.ExitCode == 0 && step2Result.ExitCode == 0)
            {
                bool rebootToSystem = Ux.DoYN(Res("EDeviceOwnerRemoverYNReboot"));
                if (rebootToSystem)
                {
                    TargetDevice.Reboot2System();
                }
                return(0);
            }
            else
            {
                return(1);
            }
        }
Example #3
0
 /// <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();
 }
Example #4
0
 /// <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();
 }
Example #5
0
 protected override int SetReciverAsDpm()
 {
     return(CmdStation.Register(GodPower
                                .GetSetIceBoxCommand())
            .To(OutputPrinter)
            .Execute()
            .ExitCode);
 }
Example #6
0
 /// <summary>
 /// 创建文件夹
 /// </summary>
 /// <param name="file"></param>
 public void Mkdir(string file)
 {
     var result = CmdStation
                  .GetShellCommand(Device, $"mkdir {file}")
                  .To(RaiseOutput)
                  .Execute()
                  .ThrowIfShellExitCodeNotEqualsZero();
 }
Example #7
0
 /// <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();
 }
Example #8
0
 /// <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();
 }
Example #9
0
 /// <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();
 }
Example #10
0
 /// <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();
 }
Example #11
0
 /// <summary>
 /// 重设显示区域
 /// </summary>
 public void ResetOverscan()
 {
     CmdStation
     .GetShellCommand(Device, $"wm overscan reset")
     .To(RaiseOutput)
     .Execute()
     .ThrowIfShellExitCodeNotEqualsZero();
 }
Example #12
0
 /// <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();
 }
Example #13
0
 /// <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();
 }
Example #14
0
 /// <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();
 }
Example #15
0
 /// <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();
 }
Example #16
0
 /// <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();
 }
Example #17
0
 /// <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();
 }
Example #18
0
 /// <summary>
 /// 重设Density
 /// </summary>
 /// <exception cref="Exceptions.AdbShellCommandFailedException"></exception>
 public void ResetDensity()
 {
     CmdStation
     .GetShellCommand(Device, $"wm density reset")
     .To(RaiseOutput)
     .Execute()
     .ThrowIfShellExitCodeNotEqualsZero();
 }
Example #19
0
 /// <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();
 }
Example #20
0
        /// <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());
        }
Example #21
0
        /// <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);
        }
Example #22
0
        protected override int VisualMain()
        {
            WriteInitInfo();
            var result = CmdStation.GetFastbootCommand(TargetDevice, "oem lock")
                         .To(OutputPrinter)
                         .Execute();

            WriteExitCode(result.ExitCode);
            return(result.ExitCode);
        }
Example #23
0
        /// <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));
        }
Example #24
0
        /// <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);
        }
Example #25
0
        /// <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();
        }
Example #26
0
        public void RemoveAccounts()
        {
            string command = string.Format(CMD_FORMAT, CMD_REMOVE_ACC);

            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);
 }
Example #28
0
        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();
        }
Example #29
0
        public void PushToDevice()
        {
            DirectoryInfo dirInfo = context.Tmp.DirInfo;
            string        path    = Path.Combine(dirInfo.FullName, PATH_OF_TMP_APK);

            CmdStation
            .GetAdbCommand($"push \"{path}\" {PATH_OF_ATMP_APK}")
            .To(RaiseOutput)
            .Execute()
            .ThrowIfExitCodeNotEqualsZero();
        }
Example #30
0
        public string ShowUsage()
        {
            string command = string.Format(CMD_FORMAT, "");

            return(CmdStation
                   .GetShellCommand(Device, command)
                   .To(RaiseOutput)
                   .Execute()
                   .ThrowIfExitCodeNotEqualsZero()
                   .Output.ToString());
        }