Skip to content

Commit

Permalink
Add checks for method availability
Browse files Browse the repository at this point in the history
Signed-off-by: DrDisagree <[email protected]>
  • Loading branch information
Mahmud0808 committed Sep 5, 2024
1 parent de4171e commit 3f7b797
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -907,14 +917,38 @@ 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",
callMethod(mAccessPointController, "canConfigMobileData"),
callMethod(mAccessPointController, "canConfigWifi"),
v
)
} else {
log(TAG + "No internet dialog available")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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"
Expand Down

0 comments on commit 3f7b797

Please sign in to comment.