-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8b265f
commit 6b2170f
Showing
5 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
app/src/main/java/nep/timeline/cirno/hooks/android/input/InputMethodManagerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package nep.timeline.cirno.hooks.android.input; | ||
|
||
import android.os.Build; | ||
import android.view.inputmethod.InputMethodInfo; | ||
|
||
import java.util.Map; | ||
|
||
import de.robv.android.xposed.XC_MethodHook; | ||
import de.robv.android.xposed.XposedHelpers; | ||
import nep.timeline.cirno.entity.AppRecord; | ||
import nep.timeline.cirno.framework.AbstractMethodHook; | ||
import nep.timeline.cirno.framework.MethodHook; | ||
import nep.timeline.cirno.services.ActivityManagerService; | ||
import nep.timeline.cirno.services.AppService; | ||
import nep.timeline.cirno.services.FreezerService; | ||
import nep.timeline.cirno.threads.FreezerHandler; | ||
import nep.timeline.cirno.utils.InputMethodData; | ||
|
||
public class InputMethodManagerService extends MethodHook { | ||
public InputMethodManagerService(ClassLoader classLoader) { | ||
super(classLoader); | ||
} | ||
|
||
@Override | ||
public String getTargetClass() { | ||
return "com.android.server.inputmethod.InputMethodManagerService"; | ||
} | ||
|
||
@Override | ||
public String getTargetMethod() { | ||
return "setInputMethodLocked"; | ||
} | ||
|
||
@Override | ||
public Object[] getTargetParam() { | ||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) | ||
return new Object[] { String.class, int.class, int.class }; | ||
return new Object[] { String.class, int.class }; | ||
} | ||
|
||
@Override | ||
public XC_MethodHook getTargetHook() { | ||
return new AbstractMethodHook() { | ||
@Override | ||
protected void beforeMethod(MethodHookParam param) { | ||
String id = (String) param.args[0]; | ||
if (id == null) | ||
return; | ||
|
||
Object settings = XposedHelpers.getObjectField(param.thisObject, "mSettings"); | ||
|
||
synchronized (InputMethodData.class) { | ||
if (InputMethodData.instance == null) { | ||
InputMethodData.instance = param.thisObject; | ||
if (settings != null) { | ||
Object map = XposedHelpers.getObjectField(settings, "mMethodMap"); | ||
if (map != null) { | ||
if (map.getClass().getTypeName().equals("com.android.server.inputmethod.InputMethodMap")) | ||
InputMethodData.inputMethods = (Map<String, InputMethodInfo>) XposedHelpers.getObjectField(map, "mMap"); | ||
else | ||
InputMethodData.inputMethods = (Map<String, InputMethodInfo>) map; | ||
} | ||
else | ||
InputMethodData.inputMethods = null; | ||
} | ||
else | ||
InputMethodData.inputMethods = null; | ||
} | ||
|
||
Map<String, InputMethodInfo> inputMethodMap = InputMethodData.inputMethods; | ||
if (inputMethodMap == null) | ||
return; | ||
|
||
InputMethodInfo inputMethodInfo = inputMethodMap.get(id); | ||
|
||
if (inputMethodInfo != null && !inputMethodInfo.equals(InputMethodData.currentInputMethodInfo)) { | ||
InputMethodData.currentInputMethodInfo = inputMethodInfo; | ||
AppRecord appRecord = AppService.get(inputMethodInfo.getPackageName(), (settings == null) ? ActivityManagerService.getCurrentOrTargetUserId() : (int) XposedHelpers.callMethod(settings, "getUserId")); | ||
if (appRecord != InputMethodData.currentInputMethodApp) { | ||
AppRecord oldApp = InputMethodData.currentInputMethodApp; | ||
InputMethodData.currentInputMethodApp = appRecord; | ||
if (appRecord != null) | ||
FreezerService.thaw(appRecord); | ||
if (oldApp != null) | ||
FreezerHandler.sendFreezeMessage(oldApp, 3000); | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
app/src/main/java/nep/timeline/cirno/utils/InputMethodData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package nep.timeline.cirno.utils; | ||
|
||
import android.view.inputmethod.InputMethodInfo; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import nep.timeline.cirno.entity.AppRecord; | ||
|
||
public class InputMethodData { | ||
public static volatile Object instance; | ||
public static Map<String, InputMethodInfo> inputMethods = new HashMap<>(); | ||
public static InputMethodInfo currentInputMethodInfo; | ||
public static AppRecord currentInputMethodApp; | ||
} |