Skip to content

Commit

Permalink
change version to 2.2
Browse files Browse the repository at this point in the history
fix android 12+
optimize some code?
  • Loading branch information
Chara White committed Jan 19, 2023
1 parent f72e0e9 commit 37dd3be
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 94 deletions.
43 changes: 26 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ MIUI Android11: PC模式下的快捷键依旧可用,PC模式的快捷键是另
| ------------------ | ---------- | ----------- |
| MIUI12.5 Android11 | ? | ? |
| MIUI13 Android11 |||
| MIUI13 Android12 | ? | ? |
| MIUI14 Android13 | ? ||
| MIUI13 Android12 | | |
| MIUI14 Android13 | ||
| 非MIUI系统 | N/A | ? * |

√ 表示经过测试,目前支持
Expand All @@ -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

Expand All @@ -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<String> 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)
![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)
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 = 4
versionName = "2.1"
versionCode = 5
versionName = "2.2"
}

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

}
}
}

Expand Down
30 changes: 0 additions & 30 deletions app/src/main/java/pub/chara/miuipadmeta/hook/AndroidHotkeyHooks.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,47 @@
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

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!")
Expand Down

This file was deleted.

0 comments on commit 37dd3be

Please sign in to comment.