From b7a06278fee0dbfbb18b651ad563d9fb0797c8bc Mon Sep 17 00:00:00 2001 From: Thomas Rebele Date: Sat, 15 Jan 2022 16:27:51 +0100 Subject: [PATCH] Fix NoSuchMethodException for injectInputEvent() Some devices with modified ROMs expose a different signature for injectInputEvent(). Fixes #2250 PR #2946 Signed-off-by: Romain Vimont --- .../com/genymobile/scrcpy/wrappers/InputManager.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 e17b5a17..dc7bc8da 100644 --- a/server/src/main/java/com/genymobile/scrcpy/wrappers/InputManager.java +++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/InputManager.java @@ -16,6 +16,7 @@ public final class InputManager { private final IInterface manager; private Method injectInputEventMethod; + boolean alternativeInjectInputEventMethod; private static Method setDisplayIdMethod; @@ -25,7 +26,12 @@ public final class InputManager { private Method getInjectInputEventMethod() throws NoSuchMethodException { if (injectInputEventMethod == null) { - injectInputEventMethod = manager.getClass().getMethod("injectInputEvent", InputEvent.class, int.class); + try { + injectInputEventMethod = manager.getClass().getMethod("injectInputEvent", InputEvent.class, int.class); + } catch (NoSuchMethodException e) { + injectInputEventMethod = manager.getClass().getMethod("injectInputEvent", InputEvent.class, int.class, int.class); + alternativeInjectInputEventMethod = true; + } } return injectInputEventMethod; } @@ -33,6 +39,10 @@ public final class InputManager { public boolean injectInputEvent(InputEvent inputEvent, int mode) { try { Method method = getInjectInputEventMethod(); + if (alternativeInjectInputEventMethod) { + // See + return (boolean) method.invoke(manager, inputEvent, mode, 0); + } return (boolean) method.invoke(manager, inputEvent, mode); } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) { Ln.e("Could not invoke method", e);