Beispiel #1
0
        public void EntryPoint(ILeafUI _ui, IDevice device, IStorage storage, IEmbeddedFileManager emb, ICommandExecutor _executor)
        {
            //确保资源被正确释放
            using var ui       = _ui;
            using var executor = _executor;

            //显示UI后初始化一些细节
            ui.Show();
            InitUI(ui);

            //做出一系列警告与提示,只要一个不被同意,立刻再见
            if (!(DoAppCheck(ui, device, PackageName) && DoWarn(ui)))
            {
                ui.Shutdown(); //直接关闭UI
                return;        //退出函数
            }

            /* 正式开始流程 */

            //创建一个OutputBuilder
            OutputBuilder outputBuilder = new OutputBuilder();

            //接收并记录所有executor的输出
            outputBuilder.Register(executor);

            //将命令执行器输出定向到界面
            executor.OutputReceived += (s, e) => ui.WriteLineToDetails(e.Text);

            //构造一个dpmpro的控制器
            var dpmpro = new DpmPro(executor, emb, storage, device);

            //将dpmpro提取到临时目录
            SetProgress(ui, "Extract", 0);
            dpmpro.Extract();

            //推送dpmpro到设备
            SetProgress(ui, "Push", 20);
            dpmpro.PushToDevice();

            //移除账户
            SetProgress(ui, "RMAcc", 40);
            dpmpro.RemoveAccounts();

            //移除用户
            SetProgress(ui, "RMUser", 60);
            dpmpro.RemoveUsers();

            //使用可能的方式设置管理员,并记录结果
            SetProgress(ui, "SettingDpm", 80);

            var codeOfSetDeviceOwner = SetDeviceOwner(device, ui, ComponentName, executor, dpmpro).ExitCode;

            if (codeOfSetDeviceOwner == 0 &&      //如果设置成功并且
                (PackageName == "com.catchingnow.icebox" || //目标包名是冰箱
                 PackageName == "web1n.stopapp")) //小黑屋
            {
                //给予APPOPS权限
                executor.AdbShell(device, $"pm grant {PackageName} android.permission.GET_APP_OPS_STATS");
            }

            //使用输出解析器,对记录的输出进行解析
            DpmFailedMessageParser.Parse(codeOfSetDeviceOwner, outputBuilder.ToString(), out string tip, out string message);



            //在输出框写下简要信息与建议
            ui.WriteLineToDetails(message);
            ui.ShowMessage(message);

            //去除输出信息事件注册
            outputBuilder.Unregister(executor);

            //ui流程结束
            ui.Finish(tip);
        }
Beispiel #2
0
        public void EntryPoint()
        {
            using (UI)
            {
                UI.Show();  //显示ui
                InitUI();   //初始化ui


                ////执行前的一些检查与提示
                //SetProgress("Checking", 10);
                //if (!DoAppCheck()) return;//进行APP安装检查
                //if (!DoWarn()) return;//进行一系列提示与警告

                //做出一系列警告与提示,只要一个不被同意,立刻再见
                if (!(DoAppCheck() && DoWarn()))
                {
                    UI.Shutdown(); //直接关闭UI
                    return;        //退出函数
                }

                /* 正式开始流程 */

                //构造一个命令执行器
                using (CommandExecutor executor = new CommandExecutor())
                {
                    //创建一个OutputBuilder
                    OutputBuilder outputBuilder = new OutputBuilder();

                    //接收并记录所有executor的输出
                    outputBuilder.Register(executor);

                    //将命令执行器输出定向到界面
                    executor.To(e => UI.WriteOutput(e.Text));

                    //构造一个dpmpro的控制器
                    var dpmpro = new DpmPro(executor, CoreLib.Current, Device);

                    //将dpmpro提取到临时目录
                    SetProgress("Extract", 0);
                    dpmpro.Extract();

                    //推送dpmpro到设备
                    SetProgress("Push", 20);
                    dpmpro.PushToDevice();

                    //移除账户
                    SetProgress("RMAcc", 40);
                    dpmpro.RemoveAccounts();

                    //移除用户
                    SetProgress("RMUser", 60);
                    dpmpro.RemoveUsers();

                    //使用可能的方式设置管理员,并记录结果
                    SetProgress("SettingDpm", 80);
                    var codeOfSetDeviceOwner = SetDeviceOwner(executor, dpmpro).ExitCode;

                    if (codeOfSetDeviceOwner == 0 &&      //如果设置成功并且
                        (PackageName == "com.catchingnow.icebox" || //目标包名是冰箱
                         PackageName == "web1n.stopapp")) //小黑屋
                    {
                        //给予APPOPS权限
                        executor.AdbShell(Device, $"pm grant {PackageName} android.permission.GET_APP_OPS_STATS");
                    }

                    //使用输出解析器,对记录的输出进行解析
                    DpmFailedMessageParser.Parse(codeOfSetDeviceOwner, outputBuilder.ToString(), out string tip, out string message);



                    //在输出框写下简要信息与建议
                    UI.WriteLine(message);
                    UI.ShowMessage(message);

                    //去除输出信息事件注册
                    outputBuilder.Unregister(executor);

                    //ui流程结束
                    UI.Finish(tip);
                }
            }
        }