/// <summary> /// 用所有可能的方法设置设备管理员,并返回结果 /// </summary> /// <param name="device"></param> /// <param name="executor"></param> /// <param name="dpmpro"></param> /// <returns></returns> private ICommandResult SetDeviceOwner(CommandExecutor executor, DpmPro dpmpro) { ICommandResult result = null; //先用自带dpm进行设置 result = executor.AdbShell(Device, "dpm set-device-owner", ComponentName); //如果返回值为127,也就是说这设备连dpm都阉割了,就询问用户是否用dpmpro来设置设备管理员 if (result.ExitCode == 127 && UI.DoYN(TextManager["UseDpmPro"])) { //用dpmpro设置设备管理员,并记录结果(覆盖普通dpm设置器的记录) result = dpmpro.SetDeviceOwner(ComponentName); } return(result); }
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); }
/// <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); }
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); } } }