From ddc1e0262c50bfe200c2ef4bd47d4f4852d17586 Mon Sep 17 00:00:00 2001 From: wuderek Date: Fri, 9 Jun 2023 06:03:09 +0000 Subject: [PATCH] Add InputManagerGlobal for Android 14 beta 3 Parts of the InputManager class have been moved to a new InputManagerGlobal class in Android 14 preview. PR #4075 Signed-off-by: Romain Vimont --- .../genymobile/scrcpy/wrappers/InputManager.java | 4 ++-- .../genymobile/scrcpy/wrappers/ServiceManager.java | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/InputManager.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/InputManager.java index 32bf42527b..ef0a4f508d 100644 --- a/server/src/main/java/com/genymobile/scrcpy/wrappers/InputManager.java +++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/InputManager.java @@ -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; } diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/ServiceManager.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/ServiceManager.java index ee2f0fa978..3fb0ffa46b 100644 --- a/server/src/main/java/com/genymobile/scrcpy/wrappers/ServiceManager.java +++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/ServiceManager.java @@ -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);