public void Main(ILeafUI ui, ILogger logger, IDevice devices) { //获取安卓版本 var androidVersion = new DeviceBuildPropGetter(devices).GetAndroidVersion(); //消除X号 string st1; using (ui) { ui.Title = "正在设置"; ui.Icon = this.GetIconBytes(); ui.Show(); ui.Progress = 10; ui.WriteLine("正在检测安卓版本"); ui.WriteOutput(androidVersion.ToString()); ui.WriteLine("正在应用设置"); st1 = new AdbCommand().V2N(androidVersion, devices).Replace("\r\n\r\n", "\r\n"); ui.WriteOutput(st1); ui.Progress = 80; var ynReboot = ui.DoChoice(st1 + "\r\n 是否重启测试一下结果", "现在重启", "再等等"); if (ynReboot == true) { devices.Reboot2System(); } ui.Title = "设置完成"; ui.WriteLine("设置完成"); ui.Progress = 100; ui.Finish(); return; } }
public void EntryPoint(ILeafUI _ui, IDevice device, ICommandExecutor _executor) { using var ui = _ui; using var executor = _executor; var text = ClassTextReaderCache.Acquire(this.GetType()); ui.Show(); ui.EAgree(text["notice"]); Version androidVersion = new DeviceBuildPropGetter(device).GetAndroidVersion(); executor.OutputReceived += (s, e) => ui.WriteLineToDetails(e.Text); ui.WriteLineToDetails("Accessibility service run-on-demand || Aggressive Doze on Android 7.0+ (non-root)"); var result = executor.AdbShell(device, GRANT_PRE, WRITE_SECURE_SETTINGS); Count(result); ui.WriteLineToDetails("Doze on the Go || Aggressive Doze"); result = executor.AdbShell(device, GRANT_PRE, DUMP); Count(result); ui.WriteLineToDetails("Wake-up Tracker"); result = executor.AdbShell(device, GRANT_PRE, READ_LOGS); Count(result); ui.WriteLineToDetails("Background-free enforcement on Android 8+ (non-root)"); if (androidVersion != null && androidVersion >= new Version("8.0")) { result = executor.AdbShell(device, GRANT_PRE, GET_APP_OPS_STATS); Count(result); } result = executor.AdbShell(device, "am force-stop", PKG_NAME); Count(result); ui.WriteLineToDetails($"successed: {successed} failed:{error}"); ui.Finish(text["tip"]); }
protected override int VisualMain() { WriteInitInfo(); IDevice device = DeviceSelectedOnCreating; Version androidVersion = new DeviceBuildPropGetter(device).GetAndroidVersion(); CommandExecutor.Result result; using (var executor = new CommandExecutor()) { executor.To(OutputPrinter); WriteLine("Accessibility service run-on-demand || Aggressive Doze on Android 7.0+ (non-root)"); result = executor.AdbShell(device, GRANT_PRE, WRITE_SECURE_SETTINGS); Count(result); WriteLine("Doze on the Go || Aggressive Doze"); result = executor.AdbShell(device, GRANT_PRE, DUMP); Count(result); WriteLine("Wake-up Tracker"); result = executor.AdbShell(device, GRANT_PRE, READ_LOGS); Count(result); WriteLine("Background-free enforcement on Android 8+ (non-root)"); if (androidVersion != null && androidVersion >= new Version("8.0")) { result = executor.AdbShell(device, GRANT_PRE, GET_APP_OPS_STATS); Count(result); } result = executor.AdbShell(device, "am force-stop", PKG_NAME); Count(result); WriteLine($"successed: {successed} failed:{error}"); return(OK); } }
public override bool Check(DeviceBasicInfo targetDevice) { Logger.Debug(this, "android version checking"); Version result = new Version(1, 0); Task.Run(() => { Thread.Sleep(1000); result = new DeviceBuildPropGetter(targetDevice.Serial).GetAndroidVersion(); BoxHelper.CloseLoadingDialog(); }); BoxHelper.ShowLoadingDialog(); Logger.Debug(this, $"Min{version} Device{result}"); if (result == null) { var fmt = App.Current.Resources["msgAndroidVersionCheckFailedFormat"].ToString(); return(BoxHelper.ShowChoiceDialog( "Warning", String.Format(fmt, version.ToString(3)), "btnCancel", "btnContinue").ToBool()); } if (result < version) { string tooLowFmt = App.Current.Resources["msgAndroidVersionTooLowFmt"].ToString(); string msg = String.Format(tooLowFmt, version.ToString(3)); BoxHelper.ShowMessageDialog("Warning", msg); return(false); } return(true); }
protected override int VisualMain() { WriteInitInfo(); Version androidVersion = new DeviceBuildPropGetter(TargetDevice).GetAndroidVersion(); IProcessBasedCommandResult result = null; result = CmdStation.GetShellCommand(TargetDevice, $"pm grant {PKG_NAME} android.permission.WRITE_SECURE_SETTINGS") .To(OutputPrinter) .Execute(); WriteExitCode(result.ExitCode); ThrowIfCanceled(); result = CmdStation.GetShellCommand(TargetDevice, $"pm grant {PKG_NAME} android.permission.DUMP") .To(OutputPrinter) .Execute(); WriteExitCode(result.ExitCode); ThrowIfCanceled(); result = CmdStation.GetShellCommand(TargetDevice, $"pm grant {PKG_NAME} android.permission.READ_LOGS") .To(OutputPrinter) .Execute(); WriteExitCode(result.ExitCode); ThrowIfCanceled(); if (androidVersion.Major >= 8) { result = CmdStation.GetShellCommand(TargetDevice, $"pm grant {PKG_NAME} android.permission.READ_APP_OPS_STATS") .To(OutputPrinter) .Execute(); WriteExitCode(result.ExitCode); ThrowIfCanceled(); } result = CmdStation.GetShellCommand(TargetDevice, $"am force-stop " + PKG_NAME) .To(OutputPrinter) .Execute(); WriteExitCode(result.ExitCode); ThrowIfCanceled(); return(0); }
public void EntryPoint(ILeafUI ui, IDevice device, IClassTextDictionary text) { using (ui) { ui.Title = this.GetName(); ui.Icon = this.GetIconBytes(); ui.Show(); ui.EAgree(text["notice"]); using (var executor = new CommandExecutor()) { Version androidVersion = new DeviceBuildPropGetter(device).GetAndroidVersion(); executor.OutputReceived += (s, e) => ui.WriteOutput(e.Text); ui.WriteLine("Accessibility service run-on-demand || Aggressive Doze on Android 7.0+ (non-root)"); var result = executor.AdbShell(device, GRANT_PRE, WRITE_SECURE_SETTINGS); Count(result); ui.WriteLine("Doze on the Go || Aggressive Doze"); result = executor.AdbShell(device, GRANT_PRE, DUMP); Count(result); ui.WriteLine("Wake-up Tracker"); result = executor.AdbShell(device, GRANT_PRE, READ_LOGS); Count(result); ui.WriteLine("Background-free enforcement on Android 8+ (non-root)"); if (androidVersion != null && androidVersion >= new Version("8.0")) { result = executor.AdbShell(device, GRANT_PRE, GET_APP_OPS_STATS); Count(result); } result = executor.AdbShell(device, "am force-stop", PKG_NAME); Count(result); ui.WriteLine($"successed: {successed} failed:{error}"); ui.Finish(text["tip"]); } } }
/// <summary> /// 主方法 /// </summary> /// <param name="toolKit"></param> /// <returns></returns> protected override Output MainMethod(ToolKit <FlowArgs> toolKit) { AndroidShellV2 shell = new AndroidShellV2(toolKit.Args.DevBasicInfo.Serial); AdvanceOutputBuilder builder = new AdvanceOutputBuilder(); Version crtVersion = new DeviceBuildPropGetter(toolKit.Args.DevBasicInfo.Serial).GetAndroidVersion(); builder.Register(shell); allSuccessful = shell.Execute("pm grant com.oasisfeng.greenify android.permission.WRITE_SECURE_SETTINGS").IsSuccessful; allSuccessful = shell.Execute("pm grant com.oasisfeng.greenify android.permission.DUMP").IsSuccessful; allSuccessful = shell.Execute("pm grant com.oasisfeng.greenify android.permission.READ_LOGS").IsSuccessful; if (crtVersion?.Major >= 8) { allSuccessful = shell.Execute("pm grant com.oasisfeng.greenify android.permission.READ_APP_OPS_STATS").IsSuccessful; } allSuccessful = shell.Execute("am force-stop com.oasisfeng.greenify").IsSuccessful; return(builder.Result); }
/// <summary> /// 版本检查 /// </summary> /// <param name="device"></param> /// <param name="minVersion"></param> /// <returns></returns> private static bool VersionCheck(IDevice device, Version minVersion) { var propGetter = new DeviceBuildPropGetter(device); return(propGetter.GetAndroidVersion() >= minVersion); }