Skip to content

Commit

Permalink
Add InputManagerGlobal for Android 14 beta 3
Browse files Browse the repository at this point in the history
Parts of the InputManager class have been moved to a new
InputManagerGlobal class in Android 14 preview.

PR #4075 <#4075>

Signed-off-by: Romain Vimont <[email protected]>
  • Loading branch information
DerekWuYD authored and rom1v committed Jun 9, 2023
1 parent a3cdf1a commit ddc1e02
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public final class InputManager {
public static final int INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT = 1;
public static final int INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH = 2;

private final android.hardware.input.InputManager manager;
private final Object manager;
private Method injectInputEventMethod;

private static Method setDisplayIdMethod;
private static Method setActionButtonMethod;

public InputManager(android.hardware.input.InputManager manager) {
public InputManager(Object manager) {
this.manager = manager;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,21 @@ public static DisplayManager getDisplayManager() {
return displayManager;
}

public static Class<?> getInputManagerClass() {
try {
// Parts of the InputManager class have been moved to a new InputManagerGlobal class in Android 14 preview
return Class.forName("android.hardware.input.InputManagerGlobal");
} catch (ClassNotFoundException e) {
return android.hardware.input.InputManager.class;
}
}

public static InputManager getInputManager() {
if (inputManager == null) {
try {
Method getInstanceMethod = android.hardware.input.InputManager.class.getDeclaredMethod("getInstance");
android.hardware.input.InputManager im = (android.hardware.input.InputManager) getInstanceMethod.invoke(null);
Class<?> inputManagerClass = getInputManagerClass();
Method getInstanceMethod = inputManagerClass.getDeclaredMethod("getInstance");
Object im = (android.hardware.input.InputManager) getInstanceMethod.invoke(null);
inputManager = new InputManager(im);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new AssertionError(e);
Expand Down

0 comments on commit ddc1e02

Please sign in to comment.