diff --git a/README.md b/README.md index 6167da7..d6591bc 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,8 @@ MIUI Android11: PC模式下的快捷键依旧可用,PC模式的快捷键是另 | ------------------ | ---------- | ----------- | | MIUI12.5 Android11 | ? | ? | | MIUI13 Android11 | √ | √ | -| MIUI13 Android12 | ? | ? | -| MIUI14 Android13 | ? | √ | +| MIUI13 Android12 | √ | √ | +| MIUI14 Android13 | √ | √ | | 非MIUI系统 | N/A | ? * | √ 表示经过测试,目前支持 @@ -30,11 +30,23 @@ MIUI Android11: PC模式下的快捷键依旧可用,PC模式的快捷键是另 +#### 在以下系统版本实机测试可以使用: + +小米平板5Pro MIUI稳定版13.0.8.0 Android11 + +小米平板5Pro MIUI稳定版13.0.10 Android11 + +小米平板5Pro MIUI稳定版13.1.4.0 Android12 + +小米平板5Pro MIUI开发版14.0.23.1.9 Android13 + ### 鸣谢 Special thanks -[MiuiPadESC](https://github.com/YifePlayte/MiuiPadESC) 配合此模块可以恢复ESC和禁用Win-D快捷键,实现远程桌面下全部键位可用 +本模块借鉴了 [MiuiPadESC](https://github.com/YifePlayte/MiuiPadESC) 的框架代码。 +[MiuiPadESC](https://github.com/YifePlayte/MiuiPadESC) 配合此模块可以恢复ESC和禁用Win-D快捷键,实现远程桌面下全部键位可用 +[MaxMiPadInput](https://github.com/YifePlayte/MaxMiPadInput) MIUI14 下 MiuiPadESC失效 需要用这个模块恢复ESC ### 实现方法 Implementation detail @@ -57,29 +69,26 @@ MIUI Android11: PC模式下的快捷键依旧可用,PC模式的快捷键是另 1. 同Android11 (但是这个类不在services.jar里在miui-services.jar里) -2. Android11的方法里的List被改成了 `com.android.server.policy.PhoneWindowManagerStubImpl`里的`private static final List DELIVE_META_APPS` 但是他是final的改不了 - - 实现方法:有这个函数 + (内部实现从setprop变成了`settings put system is_custom_shortcut_effective 0`) - ```java - public boolean interceptKeyWithMeta() { - WindowManagerPolicy.WindowState windowState = this.mFocusedWindow; - return windowState == null || !DELIVE_META_APPS.contains(windowState.getOwningPackage()); - } - ``` +2. 存在`com.android.server.policy.PhoneWindowManagerStubImpl.DELIVE_META_APPS` 被`com.android.server.policy.PhoneWindowManagerStubImpl.interceptKeyWithMeta()`使用 但是这个函数P用没有 - 直接hook这个函数固定返回false就行 + 所以和alt-tab的实现方法一样:直接hook `com.android.server.policy.PhoneWindowManager.interceptKeyBeforeDispatching` 如果有按下meta键就直接返回0不拦截 简单粗暴 3. 同Android11 #### Android13 -1. 同Android12(但是这个miui-services.jar不在system/framework里而在system_ext.img/framework里) -2. 同Android12 -3. 同Android11 +​ 同Android12 不需要单独适配 ### 截图 Screenshot ![Screenshot_2023-01-18-03-08-54-671_com.microsoft.rdc.androidx](README.assets/Screenshot_2023-01-18-03-08-54-671_com.microsoft.rdc.androidx-16741303149715.jpg) -![Screenshot_2023-01-18-03-09-31-674_com.microsoft.rdc.androidx](README.assets/Screenshot_2023-01-18-03-09-31-674_com.microsoft.rdc.androidx.jpg) \ No newline at end of file +![Screenshot_2023-01-18-03-09-31-674_com.microsoft.rdc.androidx](README.assets/Screenshot_2023-01-18-03-09-31-674_com.microsoft.rdc.androidx.jpg) + +### 第三方开源引用 Open Source License + +##### Apache License 2.0 + +[KyuubiRan/EzXHelper](https://github.com/KyuubiRan/EzXHelper) \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 4d847cd..28fface 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -10,8 +10,8 @@ android { applicationId = "pub.chara.miuipadmeta" minSdk = 30 targetSdk = 32 - versionCode = 4 - versionName = "2.1" + versionCode = 5 + versionName = "2.2" } buildTypes { diff --git a/app/src/main/java/pub/chara/miuipadmeta/MainHook.kt b/app/src/main/java/pub/chara/miuipadmeta/MainHook.kt index 2b3bcde..6f1653a 100644 --- a/app/src/main/java/pub/chara/miuipadmeta/MainHook.kt +++ b/app/src/main/java/pub/chara/miuipadmeta/MainHook.kt @@ -23,20 +23,10 @@ class MainHook : IXposedHookLoadPackage { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) { XposedBridge.log("MiuiPadMeta: Using Android 11 hooks.") initHooks(MIUIHotkeyHooksAndroid11) - initHooks(AndroidHotkeyHooks) - } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.S || Build.VERSION.SDK_INT == Build.VERSION_CODES.S_V2) { - XposedBridge.log("MiuiPadMeta: Using Android 12 hooks.") + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + XposedBridge.log("MiuiPadMeta: Using Android 12+ hooks.") initHooks(MIUIHotkeyHooksAndroid12) - initHooks(AndroidHotkeyHooks) - } else if (Build.VERSION.SDK_INT >= 33) { // Android 13 - XposedBridge.log("MiuiPadMeta: Using Android 13 hooks.") - initHooks(MIUIHotkeyHooksAndroid13) - initHooks(AndroidHotkeyHooks) - }/* else { // unsupported os version - XposedBridge.log("MiuiPadMeta: This version of Android is not supported. Only disable Alt-Tab will be used.") - initHooks(AndroidHotkeyHooks) - }*/ - + } } } diff --git a/app/src/main/java/pub/chara/miuipadmeta/hook/AndroidHotkeyHooks.kt b/app/src/main/java/pub/chara/miuipadmeta/hook/AndroidHotkeyHooks.kt deleted file mode 100644 index 80b405c..0000000 --- a/app/src/main/java/pub/chara/miuipadmeta/hook/AndroidHotkeyHooks.kt +++ /dev/null @@ -1,30 +0,0 @@ -package pub.chara.miuipadmeta.hook - -import android.content.Intent -import android.view.KeyEvent -import com.github.kyuubiran.ezxhelper.utils.* -import pub.chara.miuipadmeta.MyFakeList -import de.robv.android.xposed.XposedBridge - -object AndroidHotkeyHooks : BaseHook() { - override fun init() { - try { - findMethod("com.android.server.policy.PhoneWindowManager") { - name == "interceptKeyBeforeDispatching" - }.hookBefore { param -> - run { - val arg1: KeyEvent = param.args[1] as KeyEvent; - // alt-tab - if ((arg1.isAltPressed && arg1.keyCode == 61)) { - param.result = 0L; - } - } - } - - XposedBridge.log("MiuiPadMeta: AndroidHotkeyHooks success!") - } catch (e: Throwable) { - XposedBridge.log("MiuiPadMeta: AndroidHotkeyHooks failed!") - XposedBridge.log(e) - } - } -} \ No newline at end of file diff --git a/app/src/main/java/pub/chara/miuipadmeta/hook/MIUIHotkeyHooksAndroid11.kt b/app/src/main/java/pub/chara/miuipadmeta/hook/MIUIHotkeyHooksAndroid11.kt index 88936b7..b681a0e 100644 --- a/app/src/main/java/pub/chara/miuipadmeta/hook/MIUIHotkeyHooksAndroid11.kt +++ b/app/src/main/java/pub/chara/miuipadmeta/hook/MIUIHotkeyHooksAndroid11.kt @@ -1,5 +1,6 @@ package pub.chara.miuipadmeta.hook +import android.view.KeyEvent import com.github.kyuubiran.ezxhelper.utils.* import pub.chara.miuipadmeta.MyFakeList import de.robv.android.xposed.XposedBridge @@ -18,6 +19,21 @@ object MIUIHotkeyHooksAndroid11 : BaseHook() { name == "getEnableKsFeature" }.hookReturnConstant(false) XposedBridge.log("MiuiPadMeta: MIUIHotkeyHooksAndroid11 success!") + + + //disable alt-tab + //this works for any android version + findMethod("com.android.server.policy.PhoneWindowManager") { + name == "interceptKeyBeforeDispatching" + }.hookBefore { param -> + run { + val arg1: KeyEvent = param.args[1] as KeyEvent; + // alt-tab + if ((arg1.isAltPressed && arg1.keyCode == 61)) { + param.result = 0L; + } + } + } } catch (e: Throwable) { XposedBridge.log("MiuiPadMeta: MIUIHotkeyHooksAndroid11 failed!") XposedBridge.log(e) diff --git a/app/src/main/java/pub/chara/miuipadmeta/hook/MIUIHotkeyHooksAndroid12.kt b/app/src/main/java/pub/chara/miuipadmeta/hook/MIUIHotkeyHooksAndroid12.kt index b3fb45d..ab7a9f0 100644 --- a/app/src/main/java/pub/chara/miuipadmeta/hook/MIUIHotkeyHooksAndroid12.kt +++ b/app/src/main/java/pub/chara/miuipadmeta/hook/MIUIHotkeyHooksAndroid12.kt @@ -1,5 +1,6 @@ package pub.chara.miuipadmeta.hook +import android.view.KeyEvent import com.github.kyuubiran.ezxhelper.utils.* import pub.chara.miuipadmeta.MyFakeList import de.robv.android.xposed.XposedBridge @@ -7,16 +8,40 @@ import de.robv.android.xposed.XposedBridge object MIUIHotkeyHooksAndroid12 : BaseHook() { override fun init() { try { - // miui have a whitelist, only app in whitelist can receive meta key, else it is blocked - // force every package to be in whitelist + // 有这两个函数 但是都TM不起作用。。。源码反编译不完整 也看不太懂 应该interceptKeyWithMeta就是决定是否拦截meta的 和Android11的白名单机制一样 但是他就是P用没有。。。 + /* findMethod("com.android.server.policy.PhoneWindowManagerStubImpl") { name == "interceptKeyWithMeta" }.hookReturnConstant(false) - //disable miui hotkeys - findMethod("com.android.server.policy.MiuiKeyShortcutManager") { - name == "getEnableKsFeature" + findMethod("com.android.server.policy.PhoneWindowManagerStubImpl") { + name == "isPad" }.hookReturnConstant(false) + */ + //所以和alt-tab的实现方法一样:直接hook 如果有按下meta键就直接返回0不拦截 简单粗暴 + findMethod("com.android.server.policy.PhoneWindowManager") { + name == "interceptKeyBeforeDispatching" + }.hookBefore { param -> + run { + val arg1: KeyEvent = param.args[1] as KeyEvent; + // meta key and alt-tab 两个放同一个hook函数里 少用一个hook函数 提高一点性能 + if ((arg1.isMetaPressed) || (arg1.isAltPressed && arg1.keyCode == 61)) { + param.result = 0L; + } + } + } + + // disable miui hotkeys + // 用orNull为了兼容不是miui的设备 也可以禁用alt-tab + var methodOrNull = + findMethodOrNull("com.android.server.policy.MiuiKeyShortcutManager") { + name == "getEnableKsFeature" + } + if (methodOrNull == null) { + XposedBridge.log("MiuiPadMeta: MIUIHotkeyHooksAndroid12 hook getEnableKsFeature failed! (method not found)") + }else{ + methodOrNull.hookReturnConstant(false) + } XposedBridge.log("MiuiPadMeta: MIUIHotkeyHooksAndroid12 success!") } catch (e: Throwable) { XposedBridge.log("MiuiPadMeta: MIUIHotkeyHooksAndroid12 failed!") diff --git a/app/src/main/java/pub/chara/miuipadmeta/hook/MIUIHotkeyHooksAndroid13.kt b/app/src/main/java/pub/chara/miuipadmeta/hook/MIUIHotkeyHooksAndroid13.kt deleted file mode 100644 index f2ecc34..0000000 --- a/app/src/main/java/pub/chara/miuipadmeta/hook/MIUIHotkeyHooksAndroid13.kt +++ /dev/null @@ -1,27 +0,0 @@ -package pub.chara.miuipadmeta.hook - -import com.github.kyuubiran.ezxhelper.utils.* -import pub.chara.miuipadmeta.MyFakeList -import de.robv.android.xposed.XposedBridge - -// currently we are same as Android 12 -object MIUIHotkeyHooksAndroid13 : BaseHook() { - override fun init() { - try { - // miui have a whitelist, only app in whitelist can receive meta key, else it is blocked - // force every package to be in whitelist - findMethod("com.android.server.policy.PhoneWindowManagerStubImpl") { - name == "interceptKeyWithMeta" - }.hookReturnConstant(false) - - //disable miui hotkeys - findMethod("com.android.server.policy.MiuiKeyShortcutManager") { - name == "getEnableKsFeature" - }.hookReturnConstant(false) - XposedBridge.log("MiuiPadMeta: MIUIHotkeyHooksAndroid13 success!") - } catch (e: Throwable) { - XposedBridge.log("MiuiPadMeta: MIUIHotkeyHooksAndroid13 failed!") - XposedBridge.log(e) - } - } -} \ No newline at end of file