diff --git a/app/build.gradle b/app/build.gradle index 377d33f..af6d2b6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -22,6 +22,9 @@ android { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } + debug { + debuggable false + } } compileOptions { sourceCompatibility JavaVersion.VERSION_17 diff --git a/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/PowerKeeperHook.kt b/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/PowerKeeperHook.kt index 772ac34..312fea3 100644 --- a/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/PowerKeeperHook.kt +++ b/app/src/main/java/moe/chenxy/miuiextra/hooker/entity/PowerKeeperHook.kt @@ -10,6 +10,8 @@ import android.util.ArrayMap import android.util.ArraySet import android.util.Log import com.highcapable.yukihookapi.hook.entity.YukiBaseHooker +import com.highcapable.yukihookapi.hook.factory.constructor +import com.highcapable.yukihookapi.hook.factory.method import com.highcapable.yukihookapi.hook.type.android.ContextClass import com.highcapable.yukihookapi.hook.type.android.LooperClass import com.highcapable.yukihookapi.hook.type.android.MessageClass @@ -29,13 +31,13 @@ object PowerKeeperHook : YukiBaseHooker() { override fun onHook() { val isOldVersion = getIsNonSupportedVersion() mainPrefs.reload() - "com.miui.powerkeeper.statemachine.DisplayFrameSetting".hook { + + "com.miui.powerkeeper.statemachine.DisplayFrameSetting".toClass().apply { // Init for Chen Policy - injectMember { - constructor { - param(ContextClass, LooperClass) - } - afterHook { + constructor { + param(ContextClass, LooperClass) + }.hook { + after { mainPrefs.reload() val mContext = XposedHelpers.getObjectField(this.instance, "mContext") as Context @@ -143,16 +145,23 @@ object PowerKeeperHook : YukiBaseHooker() { // Force Enable Custom Mode if PowerKeeper supported this if (!isOldVersion) { - injectMember { - method { - name = "parseCustomModeSwitchFromDb" - param(StringClass) - } - afterHook { + method { + name = "parseCustomModeSwitchFromDb" + param(StringClass) + }.hook { + after { val mIsCustomFpsSwitch = XposedHelpers.getObjectField(this.instance, "mIsCustomFpsSwitch") val mIsNativeSupported = mIsCustomFpsSwitch != null && (mIsCustomFpsSwitch as String) == "true" + val mContext = XposedHelpers.getObjectField( + this.instance, + "mContext" + ) as Context + + if (mIsNativeSupported) { + Settings.Global.putString(mContext.contentResolver, "custom_mode_is_native_supported", "true") + } mainPrefs.reload() if (mainPrefs.getBoolean( @@ -160,10 +169,6 @@ object PowerKeeperHook : YukiBaseHooker() { false ) && !mIsNativeSupported ) { - val mContext = XposedHelpers.getObjectField( - this.instance, - "mContext" - ) as Context Settings.System.putString( mContext.contentResolver, "custom_mode_switch", @@ -176,16 +181,15 @@ object PowerKeeperHook : YukiBaseHooker() { ) } } - }.ignoredNoSuchMemberFailure() + } } // Disable Miui Refresh Rate Policy - injectMember { - method { - name = "setScreenEffect" - param(StringClass, IntType, IntType) - } - beforeHook { + method { + name = "setScreenEffect" + param(StringClass, IntType, IntType) + }.hook { + before { val cookie = this.args[2] as Int val fps = this.args[1] as Int mainPrefs.reload() @@ -237,12 +241,11 @@ object PowerKeeperHook : YukiBaseHooker() { // Get App Refresh Rate Policy from Cloud if using Chen Policy if (isOldVersion && mainPrefs.getBoolean("force_enable_refresh_custom", false)) { - injectMember { - method { - name = "handleMessage" - param(MessageClass) - } - afterHook { + method { + name = "handleMessage" + param(MessageClass) + }.hook { + after { // 3 == Game 4 == Apps 5 == Video val message = this.args[0] as Message if (message.what == 4) { @@ -258,23 +261,21 @@ object PowerKeeperHook : YukiBaseHooker() { } } } + } - injectMember { - method { - name = "onPkgExistentChanged" - param("com.miui.powerkeeper.event.EventsAggregator\$EventResult") - } - afterHook { - val mContext = - XposedHelpers.getObjectField(this.instance, "mContext") as Context - setAllCustomAppToTopApp(mContext) - } + method { + name = "onPkgExistentChanged" + param("com.miui.powerkeeper.event.EventsAggregator\$EventResult") + }.hook { + after { + val mContext = + XposedHelpers.getObjectField(this.instance, "mContext") as Context + setAllCustomAppToTopApp(mContext) } } } } - private fun setCurrentUserFpsAsFinal(thiz: Any) { val mUserFPS = XposedHelpers.getIntField(thiz, "mUserFps") val mContext = @@ -351,7 +352,7 @@ object PowerKeeperHook : YukiBaseHooker() { XposedHelpers.setObjectField(mThiz, "mTopApps", mCurrentTopApps) } - fun addNewBlackListAppsToList(context: Context, packageName: String) { + private fun addNewBlackListAppsToList(context: Context, packageName: String) { val listStr = Settings.Global.getString(context.contentResolver, SETTINGS_CUSTOM_ARRAY_KEY) val listArr = listStrToArr(listStr) if (!listArr.contains(packageName)) { @@ -370,7 +371,7 @@ object PowerKeeperHook : YukiBaseHooker() { } } - fun removeAppsFromList(context: Context, packageName: String) { + private fun removeAppsFromList(context: Context, packageName: String) { val listStr = Settings.Global.getString(context.contentResolver, SETTINGS_CUSTOM_ARRAY_KEY) val listArr = listStrToArr(listStr) if (listArr.contains(packageName)) { @@ -387,7 +388,7 @@ object PowerKeeperHook : YukiBaseHooker() { ) } - fun listArrToStr(list: ArrayList): String { + private fun listArrToStr(list: ArrayList): String { return list.joinToString(separator = ",") } @@ -395,13 +396,13 @@ object PowerKeeperHook : YukiBaseHooker() { return ArrayList(listStr.split(",")) } - fun checkAppInBlackList(context: Context, pkgName: String): Boolean { + private fun checkAppInBlackList(context: Context, pkgName: String): Boolean { val listStr = Settings.Global.getString(context.contentResolver, SETTINGS_CUSTOM_ARRAY_KEY) val list = listStrToArr(listStr) return list.contains(pkgName) } - fun setAllCustomAppToTopApp(context: Context) { + private fun setAllCustomAppToTopApp(context: Context) { val listStr = Settings.Global.getString(context.contentResolver, SETTINGS_CUSTOM_ARRAY_KEY) if (mCustomTopApps.isEmpty()) { diff --git a/app/src/main/java/moe/chenxy/miuiextra/view/activity/SettingsActivity.kt b/app/src/main/java/moe/chenxy/miuiextra/view/activity/SettingsActivity.kt index e9cab2f..92cde04 100644 --- a/app/src/main/java/moe/chenxy/miuiextra/view/activity/SettingsActivity.kt +++ b/app/src/main/java/moe/chenxy/miuiextra/view/activity/SettingsActivity.kt @@ -318,14 +318,16 @@ class SettingsActivity : AppCompatActivity() { } private fun listenMiuiCustomMode(customModePerf: SwitchPreferenceCompat) { - if (Settings.System.getString(context?.contentResolver, "custom_mode_switch") == "true") { - customModePerf.isChecked = true; + val isNativeSupported = Settings.Global.getString(context?.contentResolver, "custom_mode_is_native_supported") == "true" + if (Settings.System.getString(context?.contentResolver, "custom_mode_switch") == "true" && isNativeSupported) { + // Only set Checked when native supported. this solved custom mode can't disable after enabled + customModePerf.isChecked = true } if (Settings.System.getString(context?.contentResolver, "custom_mode_is_chen_policy") == "true") { customModePerf.summaryOn = "Using Chen Custom Policy Mode" } else { - customModePerf.summaryOn = "Using MIUI Official Policy Mode" + customModePerf.summaryOn = "Using MIUI Official Policy Mode" + if (isNativeSupported) " (Native Supported)" else " (Force Enabled)" } customModePerf.setOnPreferenceChangeListener { _, _ ->