From 57196b872c7488e5be73e9ab55a4d3ae1cc6793e Mon Sep 17 00:00:00 2001 From: Aether <59086566+AetherMagee@users.noreply.github.com> Date: Sun, 31 Mar 2024 20:18:00 +0300 Subject: [PATCH] fix: Volume button hook Before that, there was a single hook to always skip the method on call. As it turns out, the method was used widely in the app and broke a lot of things. This commit implements checks to avoid this behaviour. --- app/src/main/java/aether/killergram/neo/Hooks.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/aether/killergram/neo/Hooks.kt b/app/src/main/java/aether/killergram/neo/Hooks.kt index 56dc21a..28983a3 100644 --- a/app/src/main/java/aether/killergram/neo/Hooks.kt +++ b/app/src/main/java/aether/killergram/neo/Hooks.kt @@ -1,5 +1,7 @@ package aether.killergram.neo +import android.view.KeyEvent +import de.robv.android.xposed.XC_MethodHook import de.robv.android.xposed.XC_MethodReplacement import de.robv.android.xposed.XposedBridge @@ -86,7 +88,19 @@ class Hooks { XposedBridge.hookAllMethods( launchActivityClass, "dispatchKeyEvent", - XC_MethodReplacement.returnConstant(true) + object : XC_MethodHook() { + override fun beforeHookedMethod(param: MethodHookParam?) { + param?.args?.get(0)?.let { event -> + if (event is KeyEvent && + event.action == KeyEvent.ACTION_DOWN && + (event.keyCode == KeyEvent.KEYCODE_VOLUME_UP || event.keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) { + log("Nullified volume key press", "DEBUG") + param.result = true + } + } + super.beforeHookedMethod(param) + } + } ) } } \ No newline at end of file