From 5036b43b0aaf70e2b230b8cb5b9dc2d09fb61f90 Mon Sep 17 00:00:00 2001 From: DrDisagree Date: Wed, 4 Sep 2024 23:13:39 +0600 Subject: [PATCH] Handle some missing methods and fields Signed-off-by: DrDisagree --- .../iconify/xposed/modules/HeaderClockA14.kt | 16 ++++++++-- .../iconify/xposed/modules/OpQsHeader.kt | 31 ++++++++++++++++--- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/drdisagree/iconify/xposed/modules/HeaderClockA14.kt b/app/src/main/java/com/drdisagree/iconify/xposed/modules/HeaderClockA14.kt index c237c6e99..8e977e63e 100644 --- a/app/src/main/java/com/drdisagree/iconify/xposed/modules/HeaderClockA14.kt +++ b/app/src/main/java/com/drdisagree/iconify/xposed/modules/HeaderClockA14.kt @@ -333,7 +333,17 @@ class HeaderClockA14(context: Context?) : ModPack(context!!) { } }) - try { + val hasSwitchAllContentToParent = qsPanelClass.declaredMethods.any { + it.name == "switchAllContentToParent" + } + val hasSwitchToParentMethod = qsPanelClass.declaredMethods.any { method -> + method.name == "switchToParent" && + method.parameterTypes.contentEquals( + arrayOf(View::class.java, ViewGroup::class.java, Int::class.java) + ) + } + + if (hasSwitchAllContentToParent && hasSwitchToParentMethod) { hookAllMethods(qsPanelClass, "switchAllContentToParent", object : XC_MethodHook() { override fun beforeHookedMethod(param: MethodHookParam) { if (!showHeaderClock) return @@ -403,7 +413,7 @@ class HeaderClockA14(context: Context?) : ModPack(context!!) { } ) } - } catch (ignored: Throwable) { // Some ROMs don't have this method switchAllContentToParent() + } else { // Some ROMs don't have this method switchAllContentToParent() hookAllMethods( qsPanelControllerBase, "onInit", @@ -439,7 +449,7 @@ class HeaderClockA14(context: Context?) : ModPack(context!!) { val targetParentId = mContext.resources.getIdentifier( "quick_settings_panel", "id", - mContext.packageName + SYSTEMUI_PACKAGE ) if (parent.id == targetParentId) { diff --git a/app/src/main/java/com/drdisagree/iconify/xposed/modules/OpQsHeader.kt b/app/src/main/java/com/drdisagree/iconify/xposed/modules/OpQsHeader.kt index e4d76e709..b03e6d682 100644 --- a/app/src/main/java/com/drdisagree/iconify/xposed/modules/OpQsHeader.kt +++ b/app/src/main/java/com/drdisagree/iconify/xposed/modules/OpQsHeader.kt @@ -480,7 +480,18 @@ class OpQsHeader(context: Context?) : ModPack(context!!) { override fun afterHookedMethod(param: MethodHookParam) { if (!showOpQsHeaderView) return - val mQsPanel = getObjectField(param.thisObject, "mQSPanel") as LinearLayout + val mQsPanel = try { + getObjectField(param.thisObject, "mQSPanel") + } catch (ignored: Throwable) { + (param.thisObject as FrameLayout).findViewById( + mContext.resources.getIdentifier( + "quick_settings_panel", + "id", + SYSTEMUI_PACKAGE + ) + ) + } as LinearLayout + val isLandscape = mContext.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE @@ -499,7 +510,17 @@ class OpQsHeader(context: Context?) : ModPack(context!!) { } }) - try { + val hasSwitchAllContentToParent = qsPanelClass.declaredMethods.any { + it.name == "switchAllContentToParent" + } + val hasSwitchToParentMethod = qsPanelClass.declaredMethods.any { method -> + method.name == "switchToParent" && + method.parameterTypes.contentEquals( + arrayOf(View::class.java, ViewGroup::class.java, Int::class.java) + ) + } + + if (hasSwitchAllContentToParent && hasSwitchToParentMethod) { hookAllMethods(qsPanelClass, "switchAllContentToParent", object : XC_MethodHook() { override fun beforeHookedMethod(param: MethodHookParam) { if (!showOpQsHeaderView) return @@ -512,7 +533,7 @@ class OpQsHeader(context: Context?) : ModPack(context!!) { val targetParentId = mContext.resources.getIdentifier( "quick_settings_panel", "id", - mContext.packageName + SYSTEMUI_PACKAGE ) if (parent.id == targetParentId) { @@ -569,7 +590,7 @@ class OpQsHeader(context: Context?) : ModPack(context!!) { } ) } - } catch (ignored: Throwable) { // Some ROMs don't have this method switchAllContentToParent() + } else { // Some ROMs don't have this method switchAllContentToParent() hookAllMethods( qsPanelControllerBase, "onInit", @@ -605,7 +626,7 @@ class OpQsHeader(context: Context?) : ModPack(context!!) { val targetParentId = mContext.resources.getIdentifier( "quick_settings_panel", "id", - mContext.packageName + SYSTEMUI_PACKAGE ) if (parent.id == targetParentId) {