From 3f7b7976d5446228b5898455d6d1ba2ac7a16a1c Mon Sep 17 00:00:00 2001 From: DrDisagree Date: Thu, 5 Sep 2024 12:58:02 +0600 Subject: [PATCH] Add checks for method availability Signed-off-by: DrDisagree --- .../iconify/xposed/modules/OpQsHeader.kt | 38 ++++++++++++++++++- .../iconify/xposed/modules/utils/Helpers.kt | 36 +++++++++++++----- 2 files changed, 62 insertions(+), 12 deletions(-) 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 9d1195627..24c7d9009 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 @@ -72,6 +72,7 @@ import com.drdisagree.iconify.utils.color.monet.quantize.QuantizerCelebi import com.drdisagree.iconify.utils.color.monet.score.Score import com.drdisagree.iconify.xposed.ModPack import com.drdisagree.iconify.xposed.modules.utils.Helpers.findClassInArray +import com.drdisagree.iconify.xposed.modules.utils.Helpers.isMethodAvailable import com.drdisagree.iconify.xposed.modules.utils.SettingsLibUtils.Companion.getColorAttr import com.drdisagree.iconify.xposed.modules.utils.TouchAnimator import com.drdisagree.iconify.xposed.modules.utils.VibrationUtils @@ -83,6 +84,7 @@ import de.robv.android.xposed.XC_MethodHook import de.robv.android.xposed.XC_MethodReplacement import de.robv.android.xposed.XposedBridge.hookAllConstructors import de.robv.android.xposed.XposedBridge.hookAllMethods +import de.robv.android.xposed.XposedBridge.log import de.robv.android.xposed.XposedHelpers.callMethod import de.robv.android.xposed.XposedHelpers.callStaticMethod import de.robv.android.xposed.XposedHelpers.findAndHookMethod @@ -898,7 +900,15 @@ class OpQsHeader(context: Context?) : ModPack(context!!) { private fun toggleInternetState(v: View) { mHandler.post { if (mAccessPointController != null) { - if (mInternetDialogManager != null) { + if (isMethodAvailable( + mInternetDialogManager, + "create", + Boolean::class.java, + Boolean::class.java, + Boolean::class.java, + View::class.java + ) + ) { callMethod( mInternetDialogManager, "create", @@ -907,7 +917,29 @@ class OpQsHeader(context: Context?) : ModPack(context!!) { callMethod(mAccessPointController, "canConfigWifi"), v ) - } else if (mInternetDialogFactory != null) { + } else if (isMethodAvailable( + mInternetDialogManager, + "create", + View::class.java, + Boolean::class.java, + Boolean::class.java + ) + ) { + callMethod( + mInternetDialogManager, + "create", + v, + callMethod(mAccessPointController, "canConfigMobileData"), + callMethod(mAccessPointController, "canConfigWifi") + ) + } else if (isMethodAvailable( + mInternetDialogFactory, + "create", + Boolean::class.java, + Boolean::class.java, + View::class.java + ) + ) { callMethod( mInternetDialogFactory, "create", @@ -915,6 +947,8 @@ class OpQsHeader(context: Context?) : ModPack(context!!) { callMethod(mAccessPointController, "canConfigWifi"), v ) + } else { + log(TAG + "No internet dialog available") } } } diff --git a/app/src/main/java/com/drdisagree/iconify/xposed/modules/utils/Helpers.kt b/app/src/main/java/com/drdisagree/iconify/xposed/modules/utils/Helpers.kt index d0f6f9663..75fb4ab04 100644 --- a/app/src/main/java/com/drdisagree/iconify/xposed/modules/utils/Helpers.kt +++ b/app/src/main/java/com/drdisagree/iconify/xposed/modules/utils/Helpers.kt @@ -41,37 +41,37 @@ object Helpers { } private fun dumpClass(ourClass: Class<*>) { - val ms = ourClass.getDeclaredMethods() - log("\n\nClass: ${ourClass.getName()}") - log("extends: ${ourClass.superclass.getName()}") + val ms = ourClass.declaredMethods + log("\n\nClass: ${ourClass.name}") + log("extends: ${ourClass.superclass.name}") log("Subclasses:") - val scs = ourClass.getClasses() + val scs = ourClass.classes for (c in scs) { - log(c.getName()) + log(c.name) } log("Methods:") val cons = ourClass.declaredConstructors for (m in cons) { log(m.name + " - " + " - " + m.parameterCount) - val cs = m.getParameterTypes() + val cs = m.parameterTypes for (c in cs) { - log("\t\t" + c.getTypeName()) + log("\t\t" + c.typeName) } } for (m in ms) { log(m.name + " - " + m.returnType + " - " + m.parameterCount) - val cs = m.getParameterTypes() + val cs = m.parameterTypes for (c in cs) { - log("\t\t" + c.getTypeName()) + log("\t\t" + c.typeName) } } log("Fields:") val fs = ourClass.declaredFields for (f in fs) { - log("\t\t" + f.getName() + "-" + f.type.getName()) + log("\t\t" + f.name + "-" + f.type.name) } log("End dump\n\n") } @@ -181,6 +181,7 @@ object Helpers { return null } + @Suppress("SameParameterValue") private fun repeatString(str: String, times: Int): String { val result = StringBuilder() for (i in 0 until times) { @@ -199,6 +200,21 @@ object Helpers { return color } + fun isMethodAvailable( + target: Any?, + methodName: String, + vararg parameterTypes: Class<*> + ): Boolean { + if (target == null) return false + + return try { + target::class.java.getMethod(methodName, *parameterTypes) + true + } catch (ignored: NoSuchMethodException) { + false + } + } + val isPixelVariant: Boolean get() = Shell.cmd("[[ $(cmd overlay list | grep -oE '\\[x\\] IconifyComponentQSSP[0-9]+.overlay') ]] && echo 1 || echo 0") .exec().out[0] == "1"