diff --git a/app/src/main/java/com/parallelc/micts/ModuleMain.kt b/app/src/main/java/com/parallelc/micts/ModuleMain.kt index 9a92275..d49668d 100644 --- a/app/src/main/java/com/parallelc/micts/ModuleMain.kt +++ b/app/src/main/java/com/parallelc/micts/ModuleMain.kt @@ -14,6 +14,7 @@ import com.parallelc.micts.hooker.CSMSHooker import com.parallelc.micts.hooker.InvokeOmniHooker import com.parallelc.micts.hooker.LongPressHomeHooker import com.parallelc.micts.hooker.NavBarActionsConfigHooker +import com.parallelc.micts.hooker.NavBarEventHelperHooker import com.parallelc.micts.hooker.NavStubGestureEventManagerHooker import com.parallelc.micts.hooker.NavStubViewHooker import com.parallelc.micts.hooker.VIMSHooker @@ -78,6 +79,10 @@ class ModuleMain(base: XposedInterface, param: ModuleLoadedParam) : XposedModule hook(circleToSearchHelper.getDeclaredMethod("invokeOmni", Context::class.java, Int::class.java, Int::class.java), InvokeOmniHooker::class.java) }.onFailure { e -> log("hook CircleToSearchHelper fail", e) + }.recoverCatching { + NavBarEventHelperHooker.hook(param) + }.onFailure { e -> + log("hook NavBarEventHelper fail", e) }.isSuccess runCatching { diff --git a/app/src/main/java/com/parallelc/micts/hooker/NavBarEventHelperHooker.kt b/app/src/main/java/com/parallelc/micts/hooker/NavBarEventHelperHooker.kt new file mode 100644 index 0000000..5b95c46 --- /dev/null +++ b/app/src/main/java/com/parallelc/micts/hooker/NavBarEventHelperHooker.kt @@ -0,0 +1,52 @@ +package com.parallelc.micts.hooker + +import android.content.Context +import android.view.MotionEvent +import com.parallelc.micts.config.XposedConfig.CONFIG_NAME +import com.parallelc.micts.config.XposedConfig.DEFAULT_CONFIG +import com.parallelc.micts.config.XposedConfig.KEY_GESTURE_TRIGGER +import com.parallelc.micts.config.XposedConfig.KEY_VIBRATE +import com.parallelc.micts.module +import com.parallelc.micts.ui.activity.triggerCircleToSearch +import io.github.libxposed.api.XposedInterface.BeforeHookCallback +import io.github.libxposed.api.XposedInterface.Hooker +import io.github.libxposed.api.XposedModuleInterface.PackageLoadedParam +import io.github.libxposed.api.annotations.BeforeInvocation +import io.github.libxposed.api.annotations.XposedHooker +import java.lang.reflect.Field + +class NavBarEventHelperHooker { + companion object { + private lateinit var mContext: Field + + fun hook(param: PackageLoadedParam) { + val navStubGestureEventManager = param.classLoader.loadClass("com.miui.home.recents.cts.NavBarEventHelper") + mContext = navStubGestureEventManager.getDeclaredField("mContext") + mContext.isAccessible = true + module!!.hook(navStubGestureEventManager.getDeclaredMethod("onLongPress", MotionEvent::class.java), OnLongPressHooker::class.java) + } + + @XposedHooker + class OnLongPressHooker : Hooker { + companion object { + @JvmStatic + @BeforeInvocation + fun before(callback: BeforeHookCallback) { + val prefs = module!!.getRemotePreferences(CONFIG_NAME) + if (prefs.getBoolean(KEY_GESTURE_TRIGGER, DEFAULT_CONFIG[KEY_GESTURE_TRIGGER] as Boolean)) { + val context = runCatching { mContext.get(callback.thisObject) as? Context }.getOrNull() + triggerCircleToSearch( + 1, + context, + prefs.getBoolean( + KEY_VIBRATE, + DEFAULT_CONFIG[KEY_VIBRATE] as Boolean + ) + ) + callback.returnAndSkip(null) + } + } + } + } + } +} \ No newline at end of file