Add InputManagerGlobal for Android 14 beta 3
Parts of the InputManager class have been moved to a new InputManagerGlobal class in Android 14 preview. Fixes #4074 <https://github.com/Genymobile/scrcpy/issues/4074> PR #4075 <https://github.com/Genymobile/scrcpy/pull/4075> Signed-off-by: Romain Vimont <rom@rom1v.com>
This commit is contained in:
parent
d3c2955fb9
commit
5bd7514871
2 changed files with 14 additions and 4 deletions
|
@ -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_RESULT = 1;
|
||||||
public static final int INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH = 2;
|
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 Method injectInputEventMethod;
|
||||||
|
|
||||||
private static Method setDisplayIdMethod;
|
private static Method setDisplayIdMethod;
|
||||||
private static Method setActionButtonMethod;
|
private static Method setActionButtonMethod;
|
||||||
|
|
||||||
public InputManager(android.hardware.input.InputManager manager) {
|
public InputManager(Object manager) {
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,11 +62,21 @@ public final class ServiceManager {
|
||||||
return displayManager;
|
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() {
|
public static InputManager getInputManager() {
|
||||||
if (inputManager == null) {
|
if (inputManager == null) {
|
||||||
try {
|
try {
|
||||||
Method getInstanceMethod = android.hardware.input.InputManager.class.getDeclaredMethod("getInstance");
|
Class<?> inputManagerClass = getInputManagerClass();
|
||||||
android.hardware.input.InputManager im = (android.hardware.input.InputManager) getInstanceMethod.invoke(null);
|
Method getInstanceMethod = inputManagerClass.getDeclaredMethod("getInstance");
|
||||||
|
Object im = getInstanceMethod.invoke(null);
|
||||||
inputManager = new InputManager(im);
|
inputManager = new InputManager(im);
|
||||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
|
|
Loading…
Reference in a new issue