diff --git a/README.md b/README.md index 6e486ee..6167da7 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,35 @@ # MiuiPadMeta -为小米平板5系列恢复键盘Meta/Win键功能,同时禁用Alt-Tab快捷键,目前支持Android11 MIUI,其他 Android 版本仅支持禁用Alt-Tab +为小米平板5系列恢复键盘Meta/Win键功能,同时禁用Alt-Tab快捷键,适配了Android11-13的MIUI -Restore Meta/Win key function on Mi Pad 5 series, and disable Alt-Tab hotkey, currently supported Android11 MIUI, only disable Alt-Tab hotkey is supported on other Android versions +Restore Meta/Win key function on Mi Pad 5 series, and disable Alt-Tab hotkey, adapted for Android 11-13 MIUI -PC模式下的快捷键依旧可用,PC模式的快捷键是另一套逻辑实现 +MIUI Android11: PC模式下的快捷键依旧可用,PC模式的快捷键是另一套逻辑实现 ### 系统版本支持情况 OS version support -| 系统版本 | 恢复Meta键 | 禁用Alt-Tab | -| ---------------- | ---------- | ----------- | -| MIUI12 Android11 | ? | ? | -| MIUI13 Android11 | √ | √ | -| MIUI13 Android12 | ? | ? | -| MIUI14 Android13 | × | √ | -| 非MIUI系统 | N/A | ? * | +| 系统版本 | 恢复Meta键 | 禁用Alt-Tab | +| ------------------ | ---------- | ----------- | +| MIUI12.5 Android11 | ? | ? | +| MIUI13 Android11 | √ | √ | +| MIUI13 Android12 | ? | ? | +| MIUI14 Android13 | ? | √ | +| 非MIUI系统 | N/A | ? * | √ 表示经过测试,目前支持 -?表示没有经过测试,可能支持 +? 表示没有经过测试,可能支持 -×表示经过测试,目前不支持 +× 表示经过测试,目前不支持 > *禁用Alt-Tab理论上在所有Android系统上支持。 + + ### 鸣谢 Special thanks [MiuiPadESC](https://github.com/YifePlayte/MiuiPadESC) 配合此模块可以恢复ESC和禁用Win-D快捷键,实现远程桌面下全部键位可用 @@ -51,9 +53,33 @@ PC模式下的快捷键依旧可用,PC模式的快捷键是另一套逻辑实 实现方法:hook `com.android.server.policy.PhoneWindowManager.interceptKeyBeforeDispatching` 如果是Alt-Tab则不继续运行 - +#### Android12 + +1. 同Android11 (但是这个类不在services.jar里在miui-services.jar里) + +2. Android11的方法里的List被改成了 `com.android.server.policy.PhoneWindowManagerStubImpl`里的`private static final List DELIVE_META_APPS` 但是他是final的改不了 + + 实现方法:有这个函数 + + ```java + public boolean interceptKeyWithMeta() { + WindowManagerPolicy.WindowState windowState = this.mFocusedWindow; + return windowState == null || !DELIVE_META_APPS.contains(windowState.getOwningPackage()); + } + ``` + + 直接hook这个函数固定返回false就行 + +3. 同Android11 + +#### Android13 + +1. 同Android12(但是这个miui-services.jar不在system/framework里而在system_ext.img/framework里) +2. 同Android12 +3. 同Android11 + ### 截图 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-16741304903162.jpg) +![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 diff --git a/app/build.gradle.kts b/app/build.gradle.kts index bd75952..4391efc 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 = 2 - versionName = "1.1" + versionCode = 3 + versionName = "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 30cf178..2b3bcde 100644 --- a/app/src/main/java/pub/chara/miuipadmeta/MainHook.kt +++ b/app/src/main/java/pub/chara/miuipadmeta/MainHook.kt @@ -4,12 +4,10 @@ import android.os.Build import com.github.kyuubiran.ezxhelper.init.EzXHelperInit import com.github.kyuubiran.ezxhelper.utils.Log import com.github.kyuubiran.ezxhelper.utils.Log.logexIfThrow -import pub.chara.miuipadmeta.hook.BaseHook -import pub.chara.miuipadmeta.hook.MIUIHotkeyHooks import de.robv.android.xposed.IXposedHookLoadPackage import de.robv.android.xposed.XposedBridge import de.robv.android.xposed.callbacks.XC_LoadPackage -import pub.chara.miuipadmeta.hook.AndroidHotkeyHooks +import pub.chara.miuipadmeta.hook.* private const val PACKAGE_NAME_HOOKED = "android" private const val TAG = "MiuiPadMeta" @@ -22,11 +20,23 @@ class MainHook : IXposedHookLoadPackage { EzXHelperInit.setLogTag(TAG) EzXHelperInit.setToastTag(TAG) // Init hooks - if (Build.VERSION.SDK_INT != Build.VERSION_CODES.R) { - XposedBridge.log("MiuiPadMeta: Not Android 11, not guaranteed to work.") - } - initHooks(MIUIHotkeyHooks) - initHooks(AndroidHotkeyHooks) + 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.") + 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/MIUIHotkeyHooks.kt b/app/src/main/java/pub/chara/miuipadmeta/hook/MIUIHotkeyHooksAndroid11.kt similarity index 74% rename from app/src/main/java/pub/chara/miuipadmeta/hook/MIUIHotkeyHooks.kt rename to app/src/main/java/pub/chara/miuipadmeta/hook/MIUIHotkeyHooksAndroid11.kt index ebd460a..88936b7 100644 --- a/app/src/main/java/pub/chara/miuipadmeta/hook/MIUIHotkeyHooks.kt +++ b/app/src/main/java/pub/chara/miuipadmeta/hook/MIUIHotkeyHooksAndroid11.kt @@ -4,7 +4,7 @@ import com.github.kyuubiran.ezxhelper.utils.* import pub.chara.miuipadmeta.MyFakeList import de.robv.android.xposed.XposedBridge -object MIUIHotkeyHooks : BaseHook() { +object MIUIHotkeyHooksAndroid11 : BaseHook() { override fun init() { try { // miui have a whitelist, only app in whitelist can receive meta key, else it is blocked @@ -16,12 +16,10 @@ object MIUIHotkeyHooks : BaseHook() { //disable miui hotkeys findMethod("com.android.server.policy.MiuiKeyShortcutManager") { name == "getEnableKsFeature" - }.hookBefore { param -> - param.result = false - } - XposedBridge.log("MiuiPadMeta: MIUIHotkeyHooks success!") + }.hookReturnConstant(false) + XposedBridge.log("MiuiPadMeta: MIUIHotkeyHooksAndroid11 success!") } catch (e: Throwable) { - XposedBridge.log("MiuiPadMeta: MIUIHotkeyHooks failed!") + 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 new file mode 100644 index 0000000..b3fb45d --- /dev/null +++ b/app/src/main/java/pub/chara/miuipadmeta/hook/MIUIHotkeyHooksAndroid12.kt @@ -0,0 +1,26 @@ +package pub.chara.miuipadmeta.hook + +import com.github.kyuubiran.ezxhelper.utils.* +import pub.chara.miuipadmeta.MyFakeList +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 + 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: MIUIHotkeyHooksAndroid12 success!") + } catch (e: Throwable) { + XposedBridge.log("MiuiPadMeta: MIUIHotkeyHooksAndroid12 failed!") + XposedBridge.log(e) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/pub/chara/miuipadmeta/hook/MIUIHotkeyHooksAndroid13.kt b/app/src/main/java/pub/chara/miuipadmeta/hook/MIUIHotkeyHooksAndroid13.kt new file mode 100644 index 0000000..f2ecc34 --- /dev/null +++ b/app/src/main/java/pub/chara/miuipadmeta/hook/MIUIHotkeyHooksAndroid13.kt @@ -0,0 +1,27 @@ +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