Skip to content

Commit

Permalink
change version to 2
Browse files Browse the repository at this point in the history
should support android 12 and android 13
  • Loading branch information
Chara White committed Jan 19, 2023
1 parent 9412bda commit ea5ba69
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 30 deletions.
54 changes: 40 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -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快捷键,实现远程桌面下全部键位可用
Expand All @@ -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<String> 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)
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId = "pub.chara.miuipadmeta"
minSdk = 30
targetSdk = 32
versionCode = 2
versionName = "1.1"
versionCode = 3
versionName = "2"
}

buildTypes {
Expand Down
26 changes: 18 additions & 8 deletions app/src/main/java/pub/chara/miuipadmeta/MainHook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}*/

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

0 comments on commit ea5ba69

Please sign in to comment.