Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/src/main/java/com/parallelc/micts/ModuleMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
}
}
}
Loading