Skip to content

Commit 2cb7838

Browse files
committed
代码过长,缩进换行。
加点注释,随时跑路。
1 parent bff87ea commit 2cb7838

File tree

1 file changed

+62
-28
lines changed

1 file changed

+62
-28
lines changed

app/src/main/java/com/xposed/miuiime/MainHook.java

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,67 +19,101 @@
1919
import static de.robv.android.xposed.XposedHelpers.getStaticObjectField;
2020

2121
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");
2324
boolean isA10;
2425
boolean isA11;
2526

2627
@Override
2728
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;
2932
checkVersion();
33+
//检查是否为小米定制输入法
3034
final boolean isNonCustomize = !miuiImeList.contains(lpparam.packageName);
3135
if (isNonCustomize) {
32-
33-
Class<?> clazz = findClass("android.inputmethodservice.InputMethodServiceInjector", lpparam.classLoader);
36+
Class<?> clazz = findClass("android.inputmethodservice.InputMethodServiceInjector",
37+
lpparam.classLoader);
3438
hookSIsImeSupport(clazz);
3539
XposedBridge.log("Hooked ServiceInjector: " + lpparam.packageName);
3640
if (isA10) {
3741
hookIsXiaoAiEnable(clazz);
3842
XposedBridge.log("Hooked IsXiaoAiEnable: " + lpparam.packageName);
3943
} 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 {
4350
// 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+
});
4856
XposedBridge.log("Hooked customizeBottomViewColor: " + lpparam.packageName);
4957
}
5058
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));
5263
XposedBridge.log("Hooked deleteNotSupportIme: " + lpparam.packageName);
5364
} 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() {
6470
@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);
6790
}
6891
});
69-
XposedBridge.log("Hooked getSupportIme Method: " + lpparam.packageName);
70-
}
71-
});
7292
}
7393
}
7494

95+
/**
96+
* 跳过包名检查,直接开启输入法优化
97+
*
98+
* @param clazz 声明或继承字段的类
99+
*/
75100
private void hookSIsImeSupport(Class<?> clazz) {
76101
XposedHelpers.setStaticIntField(clazz, "sIsImeSupport", 1);
77102
}
78103

104+
/**
105+
* 小爱语音输入按钮失效修复
106+
*
107+
* @param clazz 声明或继承方法的类
108+
*/
79109
private void hookIsXiaoAiEnable(Class<?> clazz) {
80-
findAndHookMethod(clazz, "isXiaoAiEnable", XC_MethodReplacement.returnConstant(false));
110+
findAndHookMethod(clazz, "isXiaoAiEnable",
111+
XC_MethodReplacement.returnConstant(false));
81112
}
82113

114+
/**
115+
* 检查Android版本
116+
*/
83117
public void checkVersion() {
84118
switch (Build.VERSION.SDK_INT) {
85119
case 30:

0 commit comments

Comments
 (0)