From afc8cc5091e661f22ace9c96effc2fb85892b35d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BB=80=E6=BC=93=E4=B8=A8Sevtinge?= <89193494+Sevtinge@users.noreply.github.com> Date: Mon, 1 Apr 2024 00:16:23 +0800 Subject: [PATCH] opt: delete InitPackageResources (fix: some apps crash, like global home) --- .../com/sevtinge/hyperceiler/XposedInit.java | 28 +------------- .../sevtinge/hyperceiler/module/app/Home.java | 5 +++ .../module/app/SecurityCenter.java | 3 ++ .../module/hook/home/other/AllowShareApk.java | 12 ------ .../hook/home/title/EnableIconMonetColor.kt | 21 ++++++++-- .../hook/securitycenter/SidebarLineCustom.kt | 38 +++++++++++++++++-- .../systemui/navigation/HandleLineCustom.java | 4 +- .../module/hook/tsmclient/AutoNfc.kt | 16 +++++++- 8 files changed, 78 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/com/sevtinge/hyperceiler/XposedInit.java b/app/src/main/java/com/sevtinge/hyperceiler/XposedInit.java index 461b6f9ec4..71068fac26 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/XposedInit.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/XposedInit.java @@ -39,7 +39,7 @@ import de.robv.android.xposed.callbacks.XC_InitPackageResources; import de.robv.android.xposed.callbacks.XC_LoadPackage; -public class XposedInit extends BaseXposedInit implements IXposedHookInitPackageResources, IXposedHookZygoteInit, IXposedHookLoadPackage { +public class XposedInit extends BaseXposedInit implements IXposedHookZygoteInit, IXposedHookLoadPackage { private final String TAG = "HyperCeiler"; @Override @@ -72,30 +72,4 @@ public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Th init(lpparam); new SystemFrameworkForCorePatch().handleLoadPackage(lpparam); } - - @Override - public void handleInitPackageResources(XC_InitPackageResources.InitPackageResourcesParam resparam) throws Throwable { - switch (resparam.packageName) { - case "com.miui.tsmclient": - if (mPrefsMap.getBoolean("tsmclient_auto_nfc")) { - AutoNfc.INSTANCE.initResource(resparam); - } - break; - - case "com.miui.home": - if (mPrefsMap.getBoolean("home_other_icon_monet_color")) { - EnableIconMonetColor.INSTANCE.initResource(resparam); - } - if (mPrefsMap.getBoolean("home_other_allow_share_apk")) { - new AllowShareApk().initResource(resparam); - } - break; - - case "com.miui.securitycenter": - if (mPrefsMap.getBoolean("security_center_sidebar_line_color")) { - SidebarLineCustom.INSTANCE.initResource(resparam); - } - break; - } - } } diff --git a/app/src/main/java/com/sevtinge/hyperceiler/module/app/Home.java b/app/src/main/java/com/sevtinge/hyperceiler/module/app/Home.java index 6bb6582541..71d26541e8 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/module/app/Home.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/module/app/Home.java @@ -111,6 +111,7 @@ import com.sevtinge.hyperceiler.module.hook.home.title.DisableHideFile; import com.sevtinge.hyperceiler.module.hook.home.title.DisableHideTheme; import com.sevtinge.hyperceiler.module.hook.home.title.DownloadAnimation; +import com.sevtinge.hyperceiler.module.hook.home.title.EnableIconMonetColor; import com.sevtinge.hyperceiler.module.hook.home.title.EnableIconMonoChrome; import com.sevtinge.hyperceiler.module.hook.home.title.FakeNonDefaultIcon; import com.sevtinge.hyperceiler.module.hook.home.title.FixAnimation; @@ -300,6 +301,10 @@ public void handleLoadPackage() { initHook(EnableMoreSetting.INSTANCE, mMoreSetting); initHook(EnableHideGestureLine.INSTANCE, mMoreSetting); } + + //reshook + initHook(EnableIconMonetColor.INSTANCE, mPrefsMap.getBoolean("home_other_icon_monet_color")); + initHook(new AllowShareApk(), mPrefsMap.getBoolean("home_other_allow_share_apk")); } } diff --git a/app/src/main/java/com/sevtinge/hyperceiler/module/app/SecurityCenter.java b/app/src/main/java/com/sevtinge/hyperceiler/module/app/SecurityCenter.java index 02456626b8..b7a87c43a8 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/module/app/SecurityCenter.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/module/app/SecurityCenter.java @@ -144,5 +144,8 @@ public void handleLoadPackage() { // initHook(new EnableGameSpeed(), mPrefsMap.getBoolean("security_center_game_speed")); + //reshook + initHook(SidebarLineCustom.INSTANCE, mPrefsMap.getBoolean("security_center_sidebar_line_color")); + } } diff --git a/app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/other/AllowShareApk.java b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/other/AllowShareApk.java index 570de45593..00516a94d9 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/other/AllowShareApk.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/other/AllowShareApk.java @@ -20,11 +20,8 @@ import android.content.Context; -import com.sevtinge.hyperceiler.R; import com.sevtinge.hyperceiler.module.base.BaseHook; -import de.robv.android.xposed.callbacks.XC_InitPackageResources; - public class AllowShareApk extends BaseHook{ @Override public void init() throws NoSuchMethodException { @@ -51,13 +48,4 @@ protected void before(MethodHookParam param) { //mResHook.setResReplacement("com.miui.home", "XML", "file_paths", R.xml.hook_home_file_paths); } - - public void initResource(XC_InitPackageResources.InitPackageResourcesParam resparam) throws Throwable { - try { - resparam.res.setReplacement("com.miui.home", "xml", "file_paths", R.xml.hook_home_file_paths); - //resparam.res.setReplacement("com.miui.home", "xml", "launcher_settings", R.xml.hook_home_launcher_settings); - } catch (Exception e) { - logE(String.valueOf(e)); - } - } } diff --git a/app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/title/EnableIconMonetColor.kt b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/title/EnableIconMonetColor.kt index ad959daf6f..507de2624e 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/title/EnableIconMonetColor.kt +++ b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/home/title/EnableIconMonetColor.kt @@ -20,14 +20,29 @@ package com.sevtinge.hyperceiler.module.hook.home.title import android.annotation.SuppressLint import android.content.res.Resources +import android.graphics.* import com.sevtinge.hyperceiler.module.base.BaseHook import com.sevtinge.hyperceiler.module.base.BaseXposedInit import de.robv.android.xposed.callbacks.XC_InitPackageResources object EnableIconMonetColor : BaseHook() { - override fun init() {} - + @SuppressLint("DiscouragedApi") + override fun init() { + val monet = "system_accent1_100" + val monoColorId = Resources.getSystem().getIdentifier(monet, "color", "android") + var monoColor = Resources.getSystem().getColor(monoColorId, null) + if (BaseXposedInit.mPrefsMap.getBoolean("home_other_use_edit_color")) { + monoColor = mPrefsMap.getInt("home_other_your_color_qwq", -1) + } + mResHook.setObjectReplacement( + "com.miui.home", + "color", + "monochrome_default", + Color.valueOf(monoColor) + ) + } +/* @SuppressLint("DiscouragedApi") fun initResource(resParam: XC_InitPackageResources.InitPackageResourcesParam) { val monet = "system_accent1_100" @@ -50,5 +65,5 @@ object EnableIconMonetColor : BaseHook() { // ColorEntries.toString(), // "Monet" // ) - } + }*/ } diff --git a/app/src/main/java/com/sevtinge/hyperceiler/module/hook/securitycenter/SidebarLineCustom.kt b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/securitycenter/SidebarLineCustom.kt index bd0b2cc4f5..b7b4443cae 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/module/hook/securitycenter/SidebarLineCustom.kt +++ b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/securitycenter/SidebarLineCustom.kt @@ -24,8 +24,40 @@ import de.robv.android.xposed.callbacks.XC_InitPackageResources object SidebarLineCustom : BaseHook() { - override fun init() {} - + override fun init() { + val mSidebarLineColorDefault = + mPrefsMap.getInt("security_center_sidebar_line_color_default", -1294740525) + val mSidebarLineColorDark = + mPrefsMap.getInt("security_center_sidebar_line_color_dark", -6842473) + val mSidebarLineColorLight = + mPrefsMap.getInt("security_center_sidebar_line_color_light", -872415232) + logI( + TAG, + "com.miui.securitycenter", + "mSidebarLineColorDefault is $mSidebarLineColorDefault" + ) + logI(TAG, "com.miui.securitycenter", "mSidebarLineColorDark is $mSidebarLineColorDark") + logI(TAG, "com.miui.securitycenter", "mSidebarLineColorLight is $mSidebarLineColorLight") + mResHook.setResReplacement( + "com.miui.securitycenter", + "color", + "sidebar_line_color", + mSidebarLineColorDefault + ) + mResHook.setResReplacement( + "com.miui.securitycenter", + "color", + "sidebar_line_color_dark", + mSidebarLineColorLight + ) + mResHook.setResReplacement( + "com.miui.securitycenter", + "color", + "sidebar_line_color_light", + mSidebarLineColorDark + ) + } +/* fun initResource(resParam: XC_InitPackageResources.InitPackageResourcesParam) { val mSidebarLineColorDefault = mPrefsMap.getInt("security_center_sidebar_line_color_default", -1294740525) @@ -58,7 +90,7 @@ object SidebarLineCustom : BaseHook() { "sidebar_line_color_light", mSidebarLineColorDark ) - } + }*/ } diff --git a/app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/navigation/HandleLineCustom.java b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/navigation/HandleLineCustom.java index 4c61b518b3..f6c412cc01 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/navigation/HandleLineCustom.java +++ b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/systemui/navigation/HandleLineCustom.java @@ -16,8 +16,8 @@ public void init() throws NoSuchMethodException { int mNavigationHandleDarkColor = mPrefsMap.getInt("system_ui_navigation_handle_custom_color_dark", -1); mResHook.setObjectReplacement("com.android.systemui", "color", - "navigation_bar_home_handle_dark_color", mNavigationHandleDarkColor); + "navigation_bar_home_handle_dark_color", mNavigationHandleLightColor); mResHook.setObjectReplacement("com.android.systemui", "color", - "navigation_bar_home_handle_light_color", mNavigationHandleLightColor); + "navigation_bar_home_handle_light_color", mNavigationHandleDarkColor); } } diff --git a/app/src/main/java/com/sevtinge/hyperceiler/module/hook/tsmclient/AutoNfc.kt b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/tsmclient/AutoNfc.kt index 9da98ba8c7..392e1943ca 100644 --- a/app/src/main/java/com/sevtinge/hyperceiler/module/hook/tsmclient/AutoNfc.kt +++ b/app/src/main/java/com/sevtinge/hyperceiler/module/hook/tsmclient/AutoNfc.kt @@ -72,8 +72,20 @@ object AutoNfc : BaseHook() { } } } + mResHook.setResReplacement( + "com.miui.tsmclient", + "string", + "nfc_off_hint", + R.string.tsmclient_nfc_turning_on + ) + mResHook.setResReplacement( + "com.miui.tsmclient", + "string", + "immediately_open", + R.string.tsmclient_nfc_turn_on_manually + ) } - +/* fun initResource(resparam: XC_InitPackageResources.InitPackageResourcesParam) { val moduleRes = XModuleResources.createInstance(mModulePath, resparam.res) resparam.res.setReplacement( @@ -88,7 +100,7 @@ object AutoNfc : BaseHook() { "immediately_open", moduleRes.fwd(R.string.tsmclient_nfc_turn_on_manually) ) - } + }*/ private suspend fun waitNFCEnable(context: Context, nfcAdapter: NfcAdapter) { repeat(15) {