新增:电量与性能:阻止杀后台应用 (#186)

* 新增:电量与性能:阻止杀后台应用

参考自 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 更加激进
This commit is contained in:
Alex Zhang
2022-10-02 16:09:49 +08:00
committed by GitHub
parent 6a70d0c20f
commit 3abafe1cf9
6 changed files with 176 additions and 0 deletions

View File

@@ -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()

View File

@@ -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 更激进
)
}
}

View File

@@ -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
}
}
}
}

View File

@@ -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
}
}
}
}
}

View File

@@ -226,4 +226,10 @@
<string name="left_or_right">左右</string>
<string name="preset">预设</string>
<string name="geek">极客</string>
<string name="do_not_clear_app">阻止杀后台应用</string>
<string name="do_not_clear_app_summary">可能造成耗电增加,建议配合“使 Millet 更加激进”食用不建议配合墓碑、A1内存管理等会强制应用进入缓存的模块使用。</string>
<string name="make_millet_more_aggressive_summary">允许 Millet 在后台应用有通知、有服务运行、有进程运行的情况下冻结应用。\n不希望被冻结的应用可将省电策略设置为无限制\n启用前请先卸载墓碑和 NoANR 相关模块。</string>
<string name="make_millet_more_aggressive">使 Millet 更加激进</string>
<string name="make_millet_ignore_active">允许 Millet 冻结活跃的应用</string>
<string name="make_millet_ignore_active_summary">非常激进,可能会影响应用运行</string>
</resources>

View File

@@ -230,4 +230,10 @@
<string name="left_or_right">Left or Right</string>
<string name="preset">Preset</string>
<string name="geek">Geek</string>
<string name="do_not_clear_app">Prevent killing background apps</string>
<string name="do_not_clear_app_summary">May cause increased power consumption, recommended with \"Make Millet more aggressive\", NOT recommended for use with tombstones</string>
<string name="make_millet_more_aggressive">Make Millet more aggressive</string>
<string name="make_millet_more_aggressive_summary">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.</string>
<string name="make_millet_ignore_active">Allow Millet to freeze active apps</string>
<string name="make_millet_ignore_active_summary">Very aggressive and may affect application running</string>
</resources>