From 3abafe1cf9edc7cc61f94c751d525a26a7a76f4d Mon Sep 17 00:00:00 2001 From: Alex Zhang Date: Sun, 2 Oct 2022 16:09:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E7=94=B5=E9=87=8F?= =?UTF-8?q?=E4=B8=8E=E6=80=A7=E8=83=BD=EF=BC=9A=E9=98=BB=E6=AD=A2=E6=9D=80?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=E5=BA=94=E7=94=A8=20(#186)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 新增:电量与性能:阻止杀后台应用 参考自 https://www.coolapk.com/feed/37905475?shareKey=ODVjZjU1ZGI1YmMyNjJmZjkxNjU~ by 向晚今天吃了咩@coolapk 已获授权 * 新增:电量与性能:使 Millet 更加激进 参考自 https://www.coolapk.com/feed/37574229?shareKey=YWNmMWQ4ZTY2MDI4NjJmZjkxOTg~ by 向晚今天吃了咩@coolapk 已获授权 * 电量与性能:阻止杀后台应用:更新描述 * 电量与性能:阻止杀后台应用:添加更多防杀 * 电量与性能:使 Millet 更加激进: 强制开启 Millet * 电量与性能:使 Millet 更加激进: 冻结延迟设置为3秒 * 电量与性能:使 Millet 更加激进: 允许 Millet 冻结活跃的应用 * 电量与性能:阻止杀后台应用:更新描述 * 电量与性能:允许 Millet 冻结活跃的应用: 检查使 Millet 更加激进 --- .../activity/SettingsActivity.kt | 9 +++ .../simplicitytools/hook/app/PowerKeeper.kt | 4 + .../hook/app/powerkeeper/DoNotClearApp.kt | 74 ++++++++++++++++++ .../powerkeeper/MakeMilletMoreAggressive.kt | 77 +++++++++++++++++++ app/src/main/res/values-zh-rCN/strings.xml | 6 ++ app/src/main/res/values/strings.xml | 6 ++ 6 files changed, 176 insertions(+) create mode 100644 app/src/main/java/com/lt2333/simplicitytools/hook/app/powerkeeper/DoNotClearApp.kt create mode 100644 app/src/main/java/com/lt2333/simplicitytools/hook/app/powerkeeper/MakeMilletMoreAggressive.kt diff --git a/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt b/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt index a0433bca..62a0a4bd 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/activity/SettingsActivity.kt @@ -505,6 +505,15 @@ class SettingsActivity : MIUIActivity() { TitleText(textId = R.string.scope_powerkeeper) TextSummaryWithSwitch(TextSummaryV(textId = R.string.lock_max_fps, tipsId = R.string.lock_max_fps_summary), SwitchV("lock_max_fps")) TextSummaryWithSwitch(TextSummaryV(textId = R.string.prevent_recovery_of_battery_optimization_white_list, tipsId = R.string.failed_after_restart), SwitchV("prevent_recovery_of_battery_optimization_white_list")) + TextSummaryWithSwitch(TextSummaryV(textId = R.string.do_not_clear_app, tipsId = R.string.do_not_clear_app_summary), SwitchV("do_not_clear_app")) + val makeMilletMoreAggressiveSwitchBinding = GetDataBinding({ safeSP.getBoolean("make_millet_more_aggressive", false) }) { view, flags, data -> + when (flags) { + 1 -> (view as Switch).isEnabled = data as Boolean + 2 -> view.visibility = if (data as Boolean) View.VISIBLE else View.GONE + } + } + TextSummaryWithSwitch(TextSummaryV(textId = R.string.make_millet_more_aggressive, tipsId = R.string.make_millet_more_aggressive_summary), SwitchV("make_millet_more_aggressive", dataBindingSend = makeMilletMoreAggressiveSwitchBinding.bindingSend)) + TextSummaryWithSwitch(TextSummaryV(textId = R.string.make_millet_ignore_active, tipsId = R.string.make_millet_ignore_active_summary), SwitchV("make_millet_ignore_active"), dataBindingRecv = makeMilletMoreAggressiveSwitchBinding.binding.getRecv(2)) TextSummaryArrow(TextSummaryV(textId = R.string.battery_optimization, tipsId = R.string.battery_optimization_summary, onClickListener = { try { val intent = Intent() diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/PowerKeeper.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/PowerKeeper.kt index fa78ba60..c6a0d8da 100644 --- a/app/src/main/java/com/lt2333/simplicitytools/hook/app/PowerKeeper.kt +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/PowerKeeper.kt @@ -1,6 +1,8 @@ package com.lt2333.simplicitytools.hook.app +import com.lt2333.simplicitytools.hook.app.powerkeeper.DoNotClearApp import com.lt2333.simplicitytools.hook.app.powerkeeper.LockMaxFps +import com.lt2333.simplicitytools.hook.app.powerkeeper.MakeMilletMoreAggressive import com.lt2333.simplicitytools.hook.app.powerkeeper.PreventRecoveryOfBatteryOptimizationWhitelist import com.lt2333.simplicitytools.util.xposed.base.AppRegister import de.robv.android.xposed.callbacks.XC_LoadPackage @@ -12,6 +14,8 @@ object PowerKeeper: AppRegister() { autoInitHooks(lpparam, LockMaxFps, //锁定最高刷新率 PreventRecoveryOfBatteryOptimizationWhitelist, //防止恢复电池优化白名单 + DoNotClearApp,//阻止杀后台 + MakeMilletMoreAggressive,//使 Millet 更激进 ) } } \ No newline at end of file diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/powerkeeper/DoNotClearApp.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/powerkeeper/DoNotClearApp.kt new file mode 100644 index 00000000..ebcce35f --- /dev/null +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/powerkeeper/DoNotClearApp.kt @@ -0,0 +1,74 @@ +package com.lt2333.simplicitytools.hook.app.powerkeeper + +import com.github.kyuubiran.ezxhelper.utils.findMethod +import com.github.kyuubiran.ezxhelper.utils.hookBefore +import com.lt2333.simplicitytools.util.hasEnable +import com.lt2333.simplicitytools.util.xposed.base.HookRegister + +object DoNotClearApp : HookRegister() { + override fun init() { + findMethod("com.miui.powerkeeper.statemachine.SleepModeControllerNew") { + name == "clearApp" + }.hookBefore { + hasEnable("do_not_clear_app") { + it.result = null + } + } + + findMethod("com.miui.powerkeeper.statemachine.PowerStateMachine") { + name == "clearAppWhenScreenOffTimeOut" + }.hookBefore { + hasEnable("do_not_clear_app") { + it.result = null + } + } + + findMethod("com.miui.powerkeeper.statemachine.PowerStateMachine") { + name == "clearAppWhenScreenOffTimeOutInNight" + }.hookBefore { + hasEnable("do_not_clear_app") { + it.result = null + } + } + + findMethod("com.miui.powerkeeper.powerchecker.PowerCheckerController") { + name == "clearApp" + }.hookBefore { + hasEnable("do_not_clear_app") { + it.result = null + } + } + + findMethod("com.miui.powerkeeper.powerchecker.PowerCheckerController") { + name == "autoKillApp" + }.hookBefore { + hasEnable("do_not_clear_app") { + it.result = null + } + } + + findMethod("com.miui.powerkeeper.statemachine.SleepModeController\$SleepProcessHelper") { + name == "killAppsInSleep" + }.hookBefore { + hasEnable("do_not_clear_app") { + it.result = null + } + } + + findMethod("com.miui.powerkeeper.statemachine.DynamicTurboPowerHandler") { + name == "clearApp" + }.hookBefore { + hasEnable("do_not_clear_app") { + it.result = null + } + } + + findMethod("miui.process.ProcessManager") { + name == "kill" + }.hookBefore { + hasEnable("do_not_clear_app") { + it.result = false + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lt2333/simplicitytools/hook/app/powerkeeper/MakeMilletMoreAggressive.kt b/app/src/main/java/com/lt2333/simplicitytools/hook/app/powerkeeper/MakeMilletMoreAggressive.kt new file mode 100644 index 00000000..ce642fe2 --- /dev/null +++ b/app/src/main/java/com/lt2333/simplicitytools/hook/app/powerkeeper/MakeMilletMoreAggressive.kt @@ -0,0 +1,77 @@ +package com.lt2333.simplicitytools.hook.app.powerkeeper + +import com.github.kyuubiran.ezxhelper.utils.findMethod +import com.github.kyuubiran.ezxhelper.utils.hookBefore +import com.lt2333.simplicitytools.util.hasEnable +import com.lt2333.simplicitytools.util.xposed.base.HookRegister + +object MakeMilletMoreAggressive : HookRegister() { + override fun init() { + findMethod("com.miui.powerkeeper.controller.FrozenAppController") { + name == "appIsAllowToFrozen" + }.hookBefore { + hasEnable("make_millet_more_aggressive") { + it.result = true + } + } + findMethod("com.miui.powerkeeper.controller.FrozenAppController\$FrozenUtil") { + name == "isHasRunningStateProcess" + }.hookBefore { + hasEnable("make_millet_more_aggressive") { + it.result = false + } + } + findMethod("com.miui.powerkeeper.controller.FrozenAppController\$FrozenUtil") { + name == "isExectingService" + }.hookBefore { + hasEnable("make_millet_more_aggressive") { + it.result = false + } + } + findMethod("com.miui.powerkeeper.controller.FrozenAppController\$FrozenUtil") { + name == "isReceivingBroadcast" + }.hookBefore { + hasEnable("make_millet_more_aggressive") { + it.result = false + } + } + findMethod("com.miui.powerkeeper.controller.FrozenAppController\$FrozenUtil") { + name == "isHasProcessOOMTooLow" + }.hookBefore { + hasEnable("make_millet_more_aggressive") { + it.result = false + } + } + findMethod("com.miui.powerkeeper.controller.FrozenAppController") { + name == "isHasNotification" + }.hookBefore { + hasEnable("make_millet_more_aggressive") { + it.result = false + } + } + findMethod("com.miui.powerkeeper.millet.MilletConfig") { + name == "getEnable" + }.hookBefore { + hasEnable("make_millet_more_aggressive") { + it.result = true + } + } + findMethod("com.miui.powerkeeper.controller.FrozenAppController\$AppStateFrozenControl") { + name == "frozenAppLater" && + parameterTypes.contentEquals(arrayOf(Int::class.java)) + }.hookBefore { + hasEnable("make_millet_more_aggressive") { + it.args[0] = 3000 + } + } + findMethod("com.miui.powerkeeper.controller.FrozenAppController\$AppStateFrozenControl") { + name == "isAllowFrozenNow" + }.hookBefore { + hasEnable("make_millet_more_aggressive") { + hasEnable("make_millet_ignore_active") { + it.result = true + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 6099a2b4..390342e5 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -226,4 +226,10 @@ 左右 预设 极客 + 阻止杀后台应用 + 可能造成耗电增加,建议配合“使 Millet 更加激进”食用,不建议配合墓碑、A1内存管理等会强制应用进入缓存的模块使用。 + 允许 Millet 在后台应用有通知、有服务运行、有进程运行的情况下冻结应用。\n不希望被冻结的应用可将省电策略设置为无限制\n启用前请先卸载墓碑和 NoANR 相关模块。 + 使 Millet 更加激进 + 允许 Millet 冻结活跃的应用 + 非常激进,可能会影响应用运行 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 17e13355..24a3cfd0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -230,4 +230,10 @@ Left or Right Preset Geek + Prevent killing background apps + May cause increased power consumption, recommended with \"Make Millet more aggressive\", NOT recommended for use with tombstones + Make Millet more aggressive + Allows Millet to freeze apps while background apps have notifications, services running, and processes running.\nApps that don\'t want to be frozen can set Battery saver to No restriction\nPlease uninstall tombstone and NoANR related modules before enabling. + Allow Millet to freeze active apps + Very aggressive and may affect application running