From 5bd75148716496755dc32daab21a322f51dc58ca 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. Fixes #4074 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 32bf4252..ef0a4f50 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 ee2f0fa9..69803971 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 final class ServiceManager { 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 = getInstanceMethod.invoke(null); inputManager = new InputManager(im); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new AssertionError(e);