/// <summary>
        /// 以SU权限执行Shell命令
        /// </summary>
        /// <param name="device"></param>
        /// <param name="sh"></param>
        /// <param name="suCheck"></param>
        /// <exception cref="Exceptions.DeviceHasNoSuException"></exception>
        /// <returns></returns>
        public static Tuple <Output, int> Su(this IDevice device, string sh, bool suCheck = true)
        {
            if (suCheck)
            {
                device.ThrowIfHaveNoSu();
            }
            var cmd    = new SuCommand(device, sh);
            var result = cmd.Execute();

            return(new Tuple <Output, int>(result.Output, result.ExitCode));
        }
Exemple #2
0
        protected override int VisualMain()
        {
            //var warnMsg = CoreLib.Current.Languages.Get("EObsoleteAndTryImageHelper");
            //Ux.Warn(warnMsg);
            //return ERR;
            string       savePath     = null;
            DialogResult dialogResult = DialogResult.No;

            App.RunOnUIThread(() =>
            {
                FolderBrowserDialog fbd = new FolderBrowserDialog
                {
                    Description = "请选择保存路径"
                };
                dialogResult = fbd.ShowDialog();
                savePath     = fbd.SelectedPath;
            });

            var finder = new DeviceImageFinder(TargetDevice);

            WriteLineAndSetTip("寻找Boot文件中");
            var path = finder.PathOf(DeviceImage.Recovery);

            if (path == null)
            {
                WriteLineAndSetTip("寻找路径失败");
                return(ERR);
            }
            else
            {
                WriteLine("寻找成功:" + path);
            }
            WriteLineAndSetTip("正在复制到临时目录");
            var tmpPath  = $"{Adb.AdbTmpPathOnDevice}/tmp.img";
            var cpResult = new SuCommand(TargetDevice, $"cp {path} {tmpPath}")
                           .To(OutputPrinter)
                           .Execute();
            var pullResult = new AdbCommand(TargetDevice, $"pull {tmpPath} \"{Path.Combine(savePath, "recovery.img")}\"")
                             .To(OutputPrinter)
                             .Execute();

            return(OK);
        }
        /// <summary>
        /// 检查是否有SU权限
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        public static bool HaveSU(this IDevice device)
        {
            var command = new SuCommand(device, "ls");

            return(command.Execute().ExitCode == 0);
        }