Fix NoSuchMethodException for injectInputEvent()
Some devices with modified ROMs expose a different signature for injectInputEvent(). Fixes #2250 <https://github.com/Genymobile/scrcpy/issues/2250> PR #2946 <https://github.com/Genymobile/scrcpy/pull/2946> Signed-off-by: Romain Vimont <rom@rom1v.com>
This commit is contained in:
parent
b3ff1f6b3b
commit
b7a06278fe
1 changed files with 11 additions and 1 deletions
|
@ -16,6 +16,7 @@ public final class InputManager {
|
||||||
|
|
||||||
private final IInterface manager;
|
private final IInterface manager;
|
||||||
private Method injectInputEventMethod;
|
private Method injectInputEventMethod;
|
||||||
|
boolean alternativeInjectInputEventMethod;
|
||||||
|
|
||||||
private static Method setDisplayIdMethod;
|
private static Method setDisplayIdMethod;
|
||||||
|
|
||||||
|
@ -25,7 +26,12 @@ public final class InputManager {
|
||||||
|
|
||||||
private Method getInjectInputEventMethod() throws NoSuchMethodException {
|
private Method getInjectInputEventMethod() throws NoSuchMethodException {
|
||||||
if (injectInputEventMethod == null) {
|
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;
|
return injectInputEventMethod;
|
||||||
}
|
}
|
||||||
|
@ -33,6 +39,10 @@ public final class InputManager {
|
||||||
public boolean injectInputEvent(InputEvent inputEvent, int mode) {
|
public boolean injectInputEvent(InputEvent inputEvent, int mode) {
|
||||||
try {
|
try {
|
||||||
Method method = getInjectInputEventMethod();
|
Method method = getInjectInputEventMethod();
|
||||||
|
if (alternativeInjectInputEventMethod) {
|
||||||
|
// See <https://github.com/Genymobile/scrcpy/issues/2250>
|
||||||
|
return (boolean) method.invoke(manager, inputEvent, mode, 0);
|
||||||
|
}
|
||||||
return (boolean) method.invoke(manager, inputEvent, mode);
|
return (boolean) method.invoke(manager, inputEvent, mode);
|
||||||
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
|
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
|
||||||
Ln.e("Could not invoke method", e);
|
Ln.e("Could not invoke method", e);
|
||||||
|
|
Loading…
Reference in a new issue