Skip to content

Commit 0c3666a

Browse files
committed
fix: mCheckLongPress removed due to action 2
1 parent eabec79 commit 0c3666a

File tree

3 files changed

+65
-36
lines changed

3 files changed

+65
-36
lines changed

app/src/main/java/com/parallelc/micts/ModuleMain.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import android.os.Build
66
import android.os.Bundle
77
import android.os.IBinder
88
import android.os.SystemClock
9-
import android.view.MotionEvent
109
import com.parallelc.micts.hooker.LongPressHomeHooker
1110
import com.parallelc.micts.hooker.NavStubViewHooker
1211
import com.parallelc.micts.hooker.ReturnFalseHooker
@@ -74,12 +73,7 @@ class ModuleMain(base: XposedInterface, param: ModuleLoadedParam) : XposedModule
7473
}
7574

7675
runCatching {
77-
val navStubView = param.classLoader.loadClass("com.miui.home.recents.NavStubView")
78-
runCatching { navStubView.getDeclaredField("mCheckLongPress") }
79-
.onSuccess { throw Exception("mCheckLongPress exists") }
80-
.onFailure {
81-
hook(navStubView.getDeclaredMethod("onTouchEvent", MotionEvent::class.java), NavStubViewHooker::class.java)
82-
}
76+
NavStubViewHooker.hook(param)
8377
}.onFailure { e ->
8478
log("hook NavStubView fail", e)
8579
}

app/src/main/java/com/parallelc/micts/hooker/NavStubViewHooker.kt

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,75 @@
11
package com.parallelc.micts.hooker
22

3+
import android.view.MotionEvent
34
import android.view.View
45
import android.view.ViewConfiguration
56
import com.parallelc.micts.module
67
import com.parallelc.micts.triggerCircleToSearch
78
import io.github.libxposed.api.XposedInterface.AfterHookCallback
89
import io.github.libxposed.api.XposedInterface.Hooker
10+
import io.github.libxposed.api.XposedModuleInterface.PackageLoadedParam
911
import io.github.libxposed.api.annotations.AfterInvocation
1012
import io.github.libxposed.api.annotations.XposedHooker
13+
import java.lang.reflect.Field
14+
import kotlin.math.abs
1115

1216
@XposedHooker
13-
class NavStubViewHooker : Hooker {
17+
class NavStubViewHooker {
1418
companion object {
15-
private val mCheckLongPress = Runnable {
16-
runCatching {
17-
triggerCircleToSearch()
18-
}.onFailure { e ->
19-
module.log("NavStubViewHooker mCheckLongPress fail", e)
20-
}
19+
private lateinit var mCurrAction: Field
20+
private lateinit var mCurrX: Field
21+
private lateinit var mInitX: Field
22+
private lateinit var mCurrY: Field
23+
private lateinit var mInitY: Field
24+
25+
fun hook(param: PackageLoadedParam) {
26+
val navStubView = param.classLoader.loadClass("com.miui.home.recents.NavStubView")
27+
runCatching { navStubView.getDeclaredField("mCheckLongPress") }
28+
.onSuccess { throw Exception("mCheckLongPress exists") }
29+
.onFailure {
30+
mCurrAction = navStubView.getDeclaredField("mCurrAction")
31+
mCurrAction.isAccessible = true
32+
mCurrX = navStubView.getDeclaredField("mCurrX")
33+
mCurrX.isAccessible = true
34+
mInitX = navStubView.getDeclaredField("mInitX")
35+
mInitX.isAccessible = true
36+
mCurrY = navStubView.getDeclaredField("mCurrY")
37+
mCurrY.isAccessible = true
38+
mInitY = navStubView.getDeclaredField("mInitY")
39+
mInitY.isAccessible = true
40+
module.hook(navStubView.getDeclaredMethod("onTouchEvent", MotionEvent::class.java), OnTouchEventHooker::class.java)
41+
}
2142
}
2243

23-
@JvmStatic
24-
@AfterInvocation
25-
fun after(callback: AfterHookCallback) {
26-
val view = callback.thisObject as View
27-
view.removeCallbacks(this.mCheckLongPress)
28-
runCatching {
29-
val mCurrAction = callback.thisObject!!.javaClass.getDeclaredField("mCurrAction")
30-
mCurrAction.isAccessible = true
31-
if (mCurrAction.getInt(callback.thisObject) == 0) {
32-
view.postDelayed(this.mCheckLongPress, ViewConfiguration.getLongPressTimeout().toLong())
44+
class OnTouchEventHooker : Hooker {
45+
companion object {
46+
private val mCheckLongPress = Runnable {
47+
runCatching {
48+
triggerCircleToSearch()
49+
}.onFailure { e ->
50+
module.log("NavStubViewHooker mCheckLongPress fail", e)
51+
}
52+
}
53+
54+
@JvmStatic
55+
@AfterInvocation
56+
fun after(callback: AfterHookCallback) {
57+
runCatching {
58+
val view = callback.thisObject as View
59+
when(mCurrAction.getInt(callback.thisObject)) {
60+
0 -> view.postDelayed(mCheckLongPress, ViewConfiguration.getLongPressTimeout().toLong()) // DOWN
61+
2 -> { // HOLD
62+
if (abs(mCurrX.getFloat(callback.thisObject) - mInitX.getFloat(callback.thisObject)) > 4 ||
63+
abs(mCurrY.getFloat(callback.thisObject) - mInitY.getFloat(callback.thisObject)) > 4)
64+
view.removeCallbacks(mCheckLongPress)
65+
else {}
66+
}
67+
else -> view.removeCallbacks(mCheckLongPress)
68+
}
69+
}.onFailure { e ->
70+
module.log("NavStubViewHooker onTouchEvent fail", e)
71+
}
3372
}
34-
}.onFailure { e ->
35-
module.log("NavStubViewHooker onTouchEvent fail", e)
3673
}
3774
}
3875
}

app/src/main/java/com/parallelc/micts/hooker/VIMSHooker.kt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import java.lang.reflect.Method
1818

1919
class VIMSHooker {
2020
companion object {
21-
private var contextualSearchKey: Int? = null
22-
private var contextualSearchPackageName: Int? = null
21+
private var contextualSearchKey: Int = 0
22+
private var contextualSearchPackageName: Int = 0
2323

2424
@SuppressLint("PrivateApi")
2525
fun hook(param: SystemServerLoadedParam) {
@@ -59,14 +59,12 @@ class VIMSHooker {
5959
@JvmStatic
6060
@BeforeInvocation
6161
fun before(callback: BeforeHookCallback) {
62-
callback.args[0]?.let {
63-
when (it) {
64-
contextualSearchKey -> {
65-
callback.returnAndSkip("omni.entry_point")
66-
}
67-
contextualSearchPackageName -> {
68-
callback.returnAndSkip("com.google.android.googlequicksearchbox")
69-
}
62+
when (callback.args[0]) {
63+
contextualSearchKey -> {
64+
callback.returnAndSkip("omni.entry_point")
65+
}
66+
contextualSearchPackageName -> {
67+
callback.returnAndSkip("com.google.android.googlequicksearchbox")
7068
}
7169
}
7270
}

0 commit comments

Comments
 (0)