예제 #1
0
        /// <summary>
        /// 获取完整的电池信息
        /// </summary>
        /// <returns></returns>
        public BatteryInfo GetBatteryInfo()
        {
            var output  = executor.AdbShell(device, "dumpsys battery").ThrowIfError().Output.All;
            var matches = regex.Matches(output);
            var dict    = new Dictionary <string, string>();

            foreach (Match match in matches)
            {
                string key   = match.Result("${key}").TrimStart();
                string value = match.Result("${value}").TrimEnd();
                dict.Add(key, value);
            }
            return(new BatteryInfo
            {
                Status = TryGetInt(dict, "status"),
                Technology = dict["technology"],
                Level = TryGetInt(dict, "level"),
                CurrentNow = TryGetInt(dict, "current now"),
                Health = TryGetInt(dict, "health"),
                WirelessPowered = TryGetBool(dict, "Wireless powered"),
                USBPowered = TryGetBool(dict, "USB powered"),
                ACPowered = TryGetBool(dict, "AC powered"),
                Scale = TryGetInt(dict, "scale"),
                Present = TryGetBool(dict, "present"),
                Temperature = TryGetInt(dict, "temperature"),
                Voltage = TryGetInt(dict, "voltage"),
                MaxChargingCurrent = TryGetInt(dict, "Max charging current"),
                MaxCharingVoltage = TryGetInt(dict, "Max charging voltage")
            });
        }
예제 #2
0
        /// <summary>
        /// 捕获,并保存到电脑指定文件夹
        /// </summary>
        /// <param name="savePath"></param>
        public void CaptureAndSaveToFile(string savePath)
        {
            var tmpPath = GenerateTmpFilePath();

            executor.AdbShell(device, $"screencap -p  {tmpPath}").ThrowIfError();
            executor.Adb(device, $"pull {tmpPath} \"{savePath}\"").ThrowIfError();
            executor.AdbShell(device, $"rm  {tmpPath}").ThrowIfError();
        }
예제 #3
0
        /// <summary>
        /// 获取设备上的所有用户
        /// </summary>
        /// <param name="ignoreZeroUser">是否忽略0号用户</param>
        /// <returns>用户</returns>
        public UserInfo[] GetUsers(bool ignoreZeroUser = true)
        {
            var executeResult = executor.AdbShell(device, "pm list users");

            if (executeResult.ExitCode != 0)
            {
                return(null);
            }
            else
            {
                return(ParseOutput(executeResult.Output, ignoreZeroUser));
            }
        }
예제 #4
0
        /// <summary>
        /// 截图
        /// </summary>
        /// <exception cref="CommandErrorException">命令执行失败</exception>
        /// <exception cref="CommandCancelledException">命令被外部进程终止</exception>
        /// <returns>保存到PC上的截图文件名</returns>
        public FileInfo Cap(bool wakeUpDevice = true)
        {
            if (wakeUpDevice)
            {
                new KeyInputer(device, executor).RaiseKeyEvent(AndroidKeyCode.WakeUp);
            }
            string fileName   = GenerateUniqueFileName();
            string pcFileName = Path.Combine(tmpDir, fileName);

            executor.AdbShell(device, $"screencap -p /sdcard/{fileName}").ThrowIfError();
            executor.Adb(device, $"pull /sdcard/{fileName} {pcFileName}").ThrowIfError();
            executor.AdbShell(device, $"rm /sdcard/{fileName}");
            return(new FileInfo(pcFileName));
        }
예제 #5
0
        /// <summary>
        /// 获取运行时间
        /// </summary>
        /// <returns></returns>
        public double GetRunningSeconds()
        {
            var output = executor.AdbShell(device, "cat /proc/uptime").ThrowIfError().Output.All;
            var match  = regex.Match(output);

            if (match.Success)
            {
                return(double.Parse(match.Result("${uptime}")));
            }
            else
            {
                throw new Exception("Could not parse the output");
            }
        }
예제 #6
0
 public void EntryPoint(ILeafUI ui, IDevice device, ICommandExecutor executor)
 {
     using (ui)
     {
         using (executor)
         {
             ui.Show();
             ui.EAgree("本模块将玉石俱焚,并且效果不一定完美,你真的需要这么做吗?如果你只是想要移除某个冻结软件,请前往该软件设置进行卸载");
             executor.OutputReceived += (s, e) => ui.WriteLineToDetails(e.Text);
             executor.AdbShell(device, "su -c rm - rf / data / system / device_policies.xml");
             executor.AdbShell(device, "su -c rm -rf /data/system/device_owner_2.xml");
             device.Reboot2System();
             ui.Finish(StatusMessages.Success);
         }
     }
 }
예제 #7
0
 private void InputImpl(object para)
 {
     Task.Run(() =>
     {
         try
         {
             ETapper._app.RunOnUIThread(() =>
             {
                 Input.CanExecuteProp = false;
             });
             AndroidKeyCode code = (AndroidKeyCode)para;
             executor.AdbShell(Device, $"input keyevent {(int)code}");
         }
         catch (Exception e)
         {
             SLogger <ETapper> .Warn($"can not input key {para}", e);
         }
         finally
         {
             ETapper._app.RunOnUIThread(() =>
             {
                 Input.CanExecuteProp = true;
             });
         }
     });
 }
예제 #8
0
 public void Main(ILeafUI ui, IDevice device, ICommandExecutor executor)
 {
     using (ui)
     {
         ui.Title = this.GetName();
         ui.Icon  = this.GetIconBytes();
         ui.Show();
         executor.OutputReceived += (s, e) => ui.WriteOutput(e.Text);
         ui.Closing += (s, e) =>
         {
             executor.Dispose();
             return(true);
         };
         executor.AdbShell(device, "settings put secure user_setup_complete 1");
         executor.AdbShell(device, "settings put global device_provisioned 1");
         ui.Finish();
     }
 }
 public void Main(ILeafUI ui, ICommandExecutor executor, IDevice device)
 {
     using (ui) {
         ui.Title = "流体手势激活器";
         ui.Show();
         executor.OutputReceived += (s, e) => ui.WriteOutput(e.Text);
         executor.AdbShell(device, "");
         ui.Finish();
     }
 }
예제 #10
0
        /// <summary>
        /// 刷新缓存
        /// </summary>
        public void Refresh()
        {
            cache.Clear();
            var exeResult = executor.AdbShell(device, $"getprop");
            var matches   = propRegex.Matches(exeResult.Output);

            foreach (Match match in matches)
            {
                cache.Add(match.Result("${pname}"), match.Result("${pvalue}"));
            }
        }
예제 #11
0
 /// <summary>
 /// 获取剩余电量
 /// </summary>
 /// <returns></returns>
 public int?GetBatteryLevel()
 {
     try
     {
         string output = executor.AdbShell(device, "dumpsys battery | grep level").Output.LineAll[0];
         return(Convert.ToInt32(output.Split(':')[1].TrimStart()));
     }
     catch (Exception e)
     {
         logger.Debug($"Get Battery info fail {e}");
         return(null);
     }
 }
예제 #12
0
        /// <summary>
        /// 获取
        /// </summary>
        /// <returns></returns>
        public Stat[] GetCpuStats()
        {
            List <Stat> stats  = new List <Stat>();
            var         output = executor.AdbShell(device, "cat /proc/stat").ThrowIfError().Output.All;

            foreach (Match match in _regex.Matches(output))
            {
                stats.Add(new Stat()
                {
                    User        = int.Parse(match.Result("${user}")),
                    Nice        = int.Parse(match.Result("${nice}")),
                    System      = int.Parse(match.Result("${system}")),
                    SoftIrq     = int.Parse(match.Result("${softirq}")),
                    StealStolen = int.Parse(match.Result("${stealstolen}")),
                    Guset       = int.Parse(match.Result("${guest}")),
                    Idle        = int.Parse(match.Result("${idle}")),
                    Iowait      = int.Parse(match.Result("${iowait}")),
                    Irq         = int.Parse(match.Result("${irq}")),
                });
            }
            return(stats.ToArray());
        }
예제 #13
0
        /// <summary>
        /// 用所有可能的方法设置设备管理员,并返回结果
        /// </summary>
        /// <param name="device"></param>
        /// <param name="executor"></param>
        /// <param name="dpmpro"></param>
        /// <returns></returns>
        static CommandResult SetDeviceOwner(IDevice targetDevice, ILeafUI ui, string componentName, ICommandExecutor executor, DpmPro dpmpro)
        {
            //先用自带dpm进行设置
            CommandResult result = executor.AdbShell(targetDevice, "dpm set-device-owner", componentName);

            //如果返回值为127,也就是说这设备连dpm都阉割了,就询问用户是否用dpmpro来设置设备管理员
            if (result.ExitCode == 127 && ui.DoYN(text["UseDpmPro"]))
            {
                //用dpmpro设置设备管理员,并记录结果(覆盖普通dpm设置器的记录)
                result = dpmpro.SetDeviceOwner(componentName);
            }
            return(result);
        }
예제 #14
0
 public void EntryPoint(ILeafUI ui, IDevice device, ICommandExecutor executor)
 {
     using (ui)
     {
         using (executor)
         {
             var text = ClassTextReaderCache.Acquire <EShizukuActivator>();
             ui.Show();
             ui.AppPropertyCheck(device, PKG_NAME);
             ui.ShowMessage(text["launchFirst"]);
             var result = executor.AdbShell(device, $"sh {SH_PATH}");
             ui.Finish(result.ExitCode == 0 ? StatusMessages.Success : StatusMessages.Failed);
         }
     }
 }
예제 #15
0
        /// <summary>
        /// 获取
        /// </summary>
        /// <exception cref="CommandErrorException">命令执行失败</exception>
        /// <returns>内存相关信息</returns>
        public MemoryInfo Get()
        {
            var output = executor.AdbShell(device, INFO_READ_COMMAND).ThrowIfError().Output.All;
            Dictionary <string, int> info = new Dictionary <string, int>();

            foreach (Match match in infoRegex.Matches(output))
            {
                info.Add(match.Result("${key}"), int.Parse(match.Result("${num}")));
            }
            return(new MemoryInfo()
            {
                Total = info["MemTotal"],
                Free = info["MemFree"],
                Available = info["MemAvailable"],
                Buffers = info["Buffers"]
            });
        }
예제 #16
0
#pragma warning disable CA1822 // 将成员标记为 static
        public void EntryPoint(ILeafUI ui, IDevice device, ICommandExecutor executor)
#pragma warning restore CA1822 // 将成员标记为 static
        {
            using (ui)
            {
                using (executor)
                {
                    executor.OutputReceived += (s, e) => ui.WriteLineToDetails(e.Text);
                    var text = ClassTextReaderCache.Acquire <EShizukuActivator>();
                    ui.Show();
                    ui.AppPropertyCheck(device, PKG_NAME);
                    ui.ShowMessage(text["launchFirst"]);

                    var result = executor.AdbShell(device, $"sh {SH_PATH}");
                    ui.Finish(result.ExitCode == 0 ? StatusMessages.Success : StatusMessages.Failed);
                }
            }
        }
예제 #17
0
        /// <summary>
        /// 获取设备上的所有用户
        /// </summary>
        /// <param name="ignoreZeroUser">是否忽略0号用户</param>
        /// <exception cref="CommandErrorException">命令无法执行</exception>
        /// <returns>用户</returns>
        public UserInfo[] GetUsers(bool ignoreZeroUser = true)
        {
            var executeResult = executor.AdbShell(device, "pm list users").ThrowIfError();

            return(ParseOutput(executeResult.Output, ignoreZeroUser));
        }
예제 #18
0
 /// <summary>
 /// 重设Size
 /// </summary>
 /// <exception cref="CommandErrorException"></exception>
 public void ResetSize()
 {
     executor.AdbShell(device, "wm size reset").ThrowIfError();
 }
예제 #19
0
        /// <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);
        }
예제 #20
0
 /// <summary>
 /// 触发键入事件
 /// </summary>
 /// <param name="code"></param>
 /// <returns></returns>
 public ICommandResult RaiseKeyEvent(int code)
 {
     return(executor.AdbShell(device, $"input keyevent {code}"));
 }
예제 #21
0
        public int RemoveUsers()
        {
            string command = string.Format(CMD_FORMAT, CMD_REMOVE_USER);

            return(executor.AdbShell(device, command).ExitCode);
        }
예제 #22
0
 public CommandResult StartActivity(string pkgName, string activityClassName, Intent intent = null)
 {
     return(executor.AdbShell(device, $"am start {pkgName}/.{activityClassName} {intent?.ToAdbArguments()}"));
 }
예제 #23
0
파일: Cat.cs 프로젝트: yqym2019/AutumnBox
 /// <summary>
 /// 读取
 /// </summary>
 /// <param name="fileName"></param>
 /// <exception cref="CommandErrorException">命令执行失败</exception>
 /// <returns>文件的文本内容</returns>
 public string Read(string fileName)
 {
     return(executor.AdbShell(device, $"cat {fileName}")
            .ThrowIfError()
            .Output);
 }