|
19 | 19 | import static de.robv.android.xposed.XposedHelpers.getStaticObjectField; |
20 | 20 |
|
21 | 21 | public class MainHook implements IXposedHookLoadPackage { |
22 | | - final static List<String> miuiImeList = Arrays.asList("com.iflytek.inputmethod.miui", "com.sohu.inputmethod.sogou.xiaomi", "com.baidu.input_mi", "com.miui.catcherpatch"); |
| 22 | + final static List<String> miuiImeList = Arrays.asList("com.iflytek.inputmethod.miui", |
| 23 | + "com.sohu.inputmethod.sogou.xiaomi", "com.baidu.input_mi", "com.miui.catcherpatch"); |
23 | 24 | boolean isA10; |
24 | 25 | boolean isA11; |
25 | 26 |
|
26 | 27 | @Override |
27 | 28 | public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) { |
28 | | - if (!PropertyUtils.get("ro.miui.support_miui_ime_bottom", "0").equals("1")) return; |
| 29 | + //检查是否支持全面屏优化 |
| 30 | + if (!PropertyUtils.get("ro.miui.support_miui_ime_bottom", "0").equals("1")) |
| 31 | + return; |
29 | 32 | checkVersion(); |
| 33 | + //检查是否为小米定制输入法 |
30 | 34 | final boolean isNonCustomize = !miuiImeList.contains(lpparam.packageName); |
31 | 35 | if (isNonCustomize) { |
32 | | - |
33 | | - Class<?> clazz = findClass("android.inputmethodservice.InputMethodServiceInjector", lpparam.classLoader); |
| 36 | + Class<?> clazz = findClass("android.inputmethodservice.InputMethodServiceInjector", |
| 37 | + lpparam.classLoader); |
34 | 38 | hookSIsImeSupport(clazz); |
35 | 39 | XposedBridge.log("Hooked ServiceInjector: " + lpparam.packageName); |
36 | 40 | if (isA10) { |
37 | 41 | hookIsXiaoAiEnable(clazz); |
38 | 42 | XposedBridge.log("Hooked IsXiaoAiEnable: " + lpparam.packageName); |
39 | 43 | } else |
40 | | - findAndHookMethod("com.android.internal.policy.PhoneWindow", lpparam.classLoader, "setNavigationBarColor", int.class, new XC_MethodHook() { |
41 | | - @Override |
42 | | - protected void afterHookedMethod(MethodHookParam param) throws Throwable { |
| 44 | + //将导航栏颜色赋值给输入法优化的底图 |
| 45 | + findAndHookMethod("com.android.internal.policy.PhoneWindow", |
| 46 | + lpparam.classLoader, "setNavigationBarColor", |
| 47 | + int.class, new XC_MethodHook() { |
| 48 | + @Override |
| 49 | + protected void afterHookedMethod(MethodHookParam param) throws Throwable { |
43 | 50 | // 0xff747474, 0x66747474 |
44 | | - int color = 0xFFFFFFFF - (int) param.args[0]; |
45 | | - XposedHelpers.callStaticMethod(clazz, "customizeBottomViewColor", true, param.args[0], color | 0xFF000000, color | 0x66000000); |
46 | | - } |
47 | | - }); |
| 51 | + int color = 0xFFFFFFFF - (int) param.args[0]; |
| 52 | + XposedHelpers.callStaticMethod(clazz, "customizeBottomViewColor", |
| 53 | + true, param.args[0], color | 0xFF000000, color | 0x66000000); |
| 54 | + } |
| 55 | + }); |
48 | 56 | XposedBridge.log("Hooked customizeBottomViewColor: " + lpparam.packageName); |
49 | 57 | } |
50 | 58 | if (isA10) { |
51 | | - findAndHookMethod("android.inputmethodservice.InputMethodServiceInjector$MiuiSwitchInputMethodListener", lpparam.classLoader, "deleteNotSupportIme", XC_MethodReplacement.returnConstant(null)); |
| 59 | + //针对A10的修复切换输入法列表 |
| 60 | + findAndHookMethod("android.inputmethodservice.InputMethodServiceInjector$MiuiSwitchInputMethodListener", |
| 61 | + lpparam.classLoader, "deleteNotSupportIme", |
| 62 | + XC_MethodReplacement.returnConstant(null)); |
52 | 63 | XposedBridge.log("Hooked deleteNotSupportIme: " + lpparam.packageName); |
53 | 64 | } else { |
54 | | - findAndHookMethod("android.inputmethodservice.InputMethodModuleManager", lpparam.classLoader, "loadDex", ClassLoader.class, String.class, new XC_MethodHook() { |
55 | | - @Override |
56 | | - protected void afterHookedMethod(MethodHookParam param) throws Throwable { |
57 | | - final Class<?> clazz = findClass("com.miui.inputmethod.InputMethodBottomManager", (ClassLoader) param.args[0]); |
58 | | - if (isNonCustomize) { |
59 | | - hookSIsImeSupport(clazz); |
60 | | - hookIsXiaoAiEnable(clazz); |
61 | | - XposedBridge.log("Hooked MiuiBottomView: " + lpparam.packageName); |
62 | | - } |
63 | | - findAndHookMethod(clazz, "getSupportIme", new XC_MethodReplacement() { |
| 65 | + //获取常用语的ClassLoader |
| 66 | + findAndHookMethod("android.inputmethodservice.InputMethodModuleManager", |
| 67 | + lpparam.classLoader, "loadDex", |
| 68 | + ClassLoader.class, String.class, |
| 69 | + new XC_MethodHook() { |
64 | 70 | @Override |
65 | | - protected Object replaceHookedMethod(MethodHookParam param) throws Throwable { |
66 | | - return ((InputMethodManager) getObjectField(getStaticObjectField(clazz, "sBottomViewHelper"), "mImm")).getEnabledInputMethodList(); |
| 71 | + protected void afterHookedMethod(MethodHookParam param) throws Throwable { |
| 72 | + final Class<?> clazz = findClass("com.miui.inputmethod.InputMethodBottomManager", |
| 73 | + (ClassLoader) param.args[0]); |
| 74 | + if (isNonCustomize) { |
| 75 | + hookSIsImeSupport(clazz); |
| 76 | + hookIsXiaoAiEnable(clazz); |
| 77 | + XposedBridge.log("Hooked MiuiBottomView: " + lpparam.packageName); |
| 78 | + } |
| 79 | + //针对A11的修复切换输入法列表 |
| 80 | + findAndHookMethod(clazz, "getSupportIme", |
| 81 | + new XC_MethodReplacement() { |
| 82 | + @Override |
| 83 | + protected Object replaceHookedMethod(MethodHookParam param) throws Throwable { |
| 84 | + return ((InputMethodManager) getObjectField( |
| 85 | + getStaticObjectField(clazz, "sBottomViewHelper"), |
| 86 | + "mImm")).getEnabledInputMethodList(); |
| 87 | + } |
| 88 | + }); |
| 89 | + XposedBridge.log("Hooked getSupportIme Method: " + lpparam.packageName); |
67 | 90 | } |
68 | 91 | }); |
69 | | - XposedBridge.log("Hooked getSupportIme Method: " + lpparam.packageName); |
70 | | - } |
71 | | - }); |
72 | 92 | } |
73 | 93 | } |
74 | 94 |
|
| 95 | + /** |
| 96 | + * 跳过包名检查,直接开启输入法优化 |
| 97 | + * |
| 98 | + * @param clazz 声明或继承字段的类 |
| 99 | + */ |
75 | 100 | private void hookSIsImeSupport(Class<?> clazz) { |
76 | 101 | XposedHelpers.setStaticIntField(clazz, "sIsImeSupport", 1); |
77 | 102 | } |
78 | 103 |
|
| 104 | + /** |
| 105 | + * 小爱语音输入按钮失效修复 |
| 106 | + * |
| 107 | + * @param clazz 声明或继承方法的类 |
| 108 | + */ |
79 | 109 | private void hookIsXiaoAiEnable(Class<?> clazz) { |
80 | | - findAndHookMethod(clazz, "isXiaoAiEnable", XC_MethodReplacement.returnConstant(false)); |
| 110 | + findAndHookMethod(clazz, "isXiaoAiEnable", |
| 111 | + XC_MethodReplacement.returnConstant(false)); |
81 | 112 | } |
82 | 113 |
|
| 114 | + /** |
| 115 | + * 检查Android版本 |
| 116 | + */ |
83 | 117 | public void checkVersion() { |
84 | 118 | switch (Build.VERSION.SDK_INT) { |
85 | 119 | case 30: |
|
0 commit comments