Skip to content

Commit 2e17584

Browse files
committed
feat: long press home button
1 parent b0aa0d6 commit 2e17584

File tree

10 files changed

+295
-188
lines changed

10 files changed

+295
-188
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
## 操作步骤
88

9-
1. `桌面设置-系统导航方式`里,选择`全面屏手势`,关闭`隐藏手势提示线`
9+
1. 安装最新版[Google](https://play.google.com/store/apps/details?id=com.google.android.googlequicksearchbox)应用,开启`自启动`权限,`省电策略`选择`无限制`
1010

1111

12-
2. 安装最新版[Google](https://play.google.com/store/apps/details?id=com.google.android.googlequicksearchbox)应用,开启`自启动`权限,`省电策略`选择`无限制`
12+
2. 安装并启用模块,重启手机
1313

1414

15-
3. 安装并启用模块,重启手机
15+
3. 执行相应的动作触发
16+
- 如果是全面屏手势,需要在`桌面设置-系统导航方式`里,关闭`隐藏手势提示线`,之后长按底部小白条触发
17+
- 如果是经典导航键(三按钮),需要在`桌面设置-系统导航方式-按键快捷方式-长按Home键`里,选择`语音助手`,之后长按Home键触发
1618

1719

18-
4. 长按底部小白条,如果没有反应,尝试在`设置-应用设置-右上角其他设置-默认应用设置-助手和语音输入-数字助理应用`里选择Google
20+
4. 如果没有反应,尝试在`设置-应用设置-右上角其他设置-默认应用设置-助手和语音输入-数字助理应用`里选择Google

README_en.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ Enable Circle to Search for Xiaomi System Launcher
66

77
## Usage
88

9-
1. In `Home Screen Settings - System Navigation`, select `Gestures` and turn off `Hide full screen indicator`
9+
1. Install the latest version of [Google](https://play.google.com/store/apps/details?id=com.google.android.googlequicksearchbox). In Google's `App info`, turn on `Autostart` if it exists and select `No restrictions` in `Battery saver`
1010

1111

12-
2. Install the latest version of [Google](https://play.google.com/store/apps/details?id=com.google.android.googlequicksearchbox). In Google's `App info`, turn on `Autostart` if it exists and select `No restrictions` in `Battery saver`
12+
2. Install and enable the module, restart your phone
1313

1414

15-
3. Install and enable the module, restart your phone
15+
3. Perform the action to trigger
16+
- For `Gesture`, turn off `Hide full screen indicator` in `Home Screen Settings - System Navigation`, and then long press the navigation handle at the bottom to trigger
17+
- For `Buttons`, select `Launch Google Assistant` in `Home Screen Settings - System Navigation - Button shortcuts - Long press the Home button`, and then long press the home button to trigger
1618

1719

18-
4. Long press the navigation handle at the bottom to trigger. If it doesn't work, try to select Google in `Settings - Apps - Manage apps - Other Settings in the upper right corner - Default apps - Assist & voice input - Digital Assistant App`
20+
4. If it doesn't work, try to select Google in `Settings - Apps - Manage apps - Other Settings in the upper right corner - Default apps - Assist & voice input - Digital Assistant App`

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

Lines changed: 0 additions & 180 deletions
This file was deleted.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.parallelc.micts
2+
3+
import android.annotation.SuppressLint
4+
import android.content.Context
5+
import android.os.Build
6+
import android.os.Bundle
7+
import android.os.IBinder
8+
import android.os.SystemClock
9+
import android.view.MotionEvent
10+
import com.parallelc.micts.hooker.ContextualSearchIntentHooker
11+
import com.parallelc.micts.hooker.LongPressHomeHooker
12+
import com.parallelc.micts.hooker.NavStubViewHooker
13+
import com.parallelc.micts.hooker.ResourcesHooker
14+
import com.parallelc.micts.hooker.ReturnFalseHooker
15+
import com.parallelc.micts.hooker.ReturnTrueHooker
16+
import io.github.libxposed.api.XposedInterface
17+
import io.github.libxposed.api.XposedModule
18+
import io.github.libxposed.api.XposedModuleInterface.ModuleLoadedParam
19+
import io.github.libxposed.api.XposedModuleInterface.PackageLoadedParam
20+
import io.github.libxposed.api.XposedModuleInterface.SystemServerLoadedParam
21+
22+
@SuppressLint("PrivateApi")
23+
fun triggerCircleToSearch() {
24+
val bundle = Bundle()
25+
bundle.putLong("invocation_time_ms", SystemClock.elapsedRealtime())
26+
bundle.putInt("omni.entry_point", 1)
27+
val iVims = Class.forName("com.android.internal.app.IVoiceInteractionManagerService\$Stub")
28+
val asInterfaceMethod = iVims.getMethod("asInterface", IBinder::class.java)
29+
val getServiceMethod = Class.forName("android.os.ServiceManager").getMethod("getService", String::class.java)
30+
val vimsInstance = asInterfaceMethod.invoke(null, getServiceMethod.invoke(null, "voiceinteraction")) ?: return
31+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
32+
val showSessionFromSession = vimsInstance.javaClass.getDeclaredMethod("showSessionFromSession", IBinder::class.java, Bundle::class.java, Integer.TYPE, String::class.java)
33+
showSessionFromSession.invoke(vimsInstance, null, bundle, 7, "hyperOS_home")
34+
} else {
35+
val showSessionFromSession = vimsInstance.javaClass.getDeclaredMethod("showSessionFromSession", IBinder::class.java, Bundle::class.java, Integer.TYPE)
36+
showSessionFromSession.invoke(vimsInstance, null, bundle, 7)
37+
}
38+
}
39+
40+
lateinit var module: ModuleMain
41+
42+
class ModuleMain(base: XposedInterface, param: ModuleLoadedParam) : XposedModule(base, param) {
43+
44+
init {
45+
module = this
46+
}
47+
48+
@SuppressLint("PrivateApi")
49+
override fun onSystemServerLoaded(param: SystemServerLoadedParam) {
50+
super.onSystemServerLoaded(param)
51+
52+
runCatching {
53+
LongPressHomeHooker.hook(param)
54+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE) return
55+
ResourcesHooker.hook(param)
56+
val vims = param.classLoader.loadClass("com.android.server.voiceinteraction.VoiceInteractionManagerService\$VoiceInteractionManagerServiceStub")
57+
hook(vims.getDeclaredMethod("getContextualSearchIntent", Bundle::class.java), ContextualSearchIntentHooker::class.java)
58+
}.onFailure { e ->
59+
log("hook system fail", e)
60+
}
61+
}
62+
63+
override fun onPackageLoaded(param: PackageLoadedParam) {
64+
super.onPackageLoaded(param)
65+
if (param.packageName != "com.miui.home" || !param.isFirstPackage) return
66+
67+
runCatching {
68+
val circleToSearchHelper = param.classLoader.loadClass("com.miui.home.recents.cts.CircleToSearchHelper")
69+
hook(circleToSearchHelper.getDeclaredMethod("isSceneForbid", Context::class.java, Int::class.java), ReturnFalseHooker::class.java)
70+
hook(circleToSearchHelper.getDeclaredMethod("hasCtsFeature", Context::class.java), ReturnTrueHooker::class.java)
71+
hook(circleToSearchHelper.getDeclaredMethod("isSettingsLongPressHomeAssistantEnabled", Context::class.java), ReturnTrueHooker::class.java)
72+
hook(circleToSearchHelper.getDeclaredMethod("isThirdHome", Context::class.java), ReturnFalseHooker::class.java)
73+
return
74+
}.onFailure { e ->
75+
log("hook CircleToSearchHelper fail", e)
76+
}
77+
78+
runCatching {
79+
val navStubView = param.classLoader.loadClass("com.miui.home.recents.NavStubView")
80+
runCatching { navStubView.getDeclaredField("mCheckLongPress") }
81+
.onSuccess { throw Exception("mCheckLongPress exists") }
82+
.onFailure {
83+
hook(navStubView.getDeclaredMethod("onTouchEvent", MotionEvent::class.java), NavStubViewHooker::class.java)
84+
}
85+
}.onFailure { e ->
86+
log("hook NavStubView fail", e)
87+
}
88+
}
89+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.parallelc.micts.hooker
2+
3+
import android.content.Intent
4+
import io.github.libxposed.api.XposedInterface.AfterHookCallback
5+
import io.github.libxposed.api.XposedInterface.Hooker
6+
import io.github.libxposed.api.annotations.AfterInvocation
7+
import io.github.libxposed.api.annotations.XposedHooker
8+
9+
@XposedHooker
10+
class ContextualSearchIntentHooker : Hooker {
11+
companion object {
12+
@JvmStatic
13+
@AfterInvocation
14+
fun after(callback: AfterHookCallback) {
15+
(callback.result as Intent).putExtra("com.android.contextualsearch.flag_secure_found", false)
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)