mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-03 14:49:29 +00:00
Workaround for NoSuchMethodException: injectInputEvent (fixes #2250)
This commit is contained in:
parent
25a4135935
commit
28ada35ff2
1 changed files with 26 additions and 4 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 = false;
|
||||||
|
|
||||||
private static Method setDisplayIdMethod;
|
private static Method setDisplayIdMethod;
|
||||||
|
|
||||||
|
@ -25,19 +26,40 @@ public final class InputManager {
|
||||||
|
|
||||||
private Method getInjectInputEventMethod() throws NoSuchMethodException {
|
private Method getInjectInputEventMethod() throws NoSuchMethodException {
|
||||||
if (injectInputEventMethod == null) {
|
if (injectInputEventMethod == null) {
|
||||||
|
try {
|
||||||
injectInputEventMethod = manager.getClass().getMethod("injectInputEvent", InputEvent.class, int.class);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean injectInputEvent(InputEvent inputEvent, int mode) {
|
public boolean injectInputEvent(InputEvent inputEvent, int mode) {
|
||||||
try {
|
try {
|
||||||
Method method = getInjectInputEventMethod();
|
Method method = getInjectInputEventMethod();
|
||||||
|
if(alternativeInjectInputEventMethod)
|
||||||
|
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) {
|
|
||||||
Ln.e("Could not invoke method", e);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
catch(NoSuchMethodException e) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(e.getMessage());
|
||||||
|
sb.append("\ncandidates: ");
|
||||||
|
for(Method m : manager.getClass().getMethods()) {
|
||||||
|
if(m.getName().equals("injectInputEvent")) {
|
||||||
|
sb.append("\n ").append(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
e = new NoSuchMethodException(sb.toString());
|
||||||
|
Ln.e("Could not invoke method", e);
|
||||||
|
}
|
||||||
|
catch (InvocationTargetException | IllegalAccessException e) {
|
||||||
|
Ln.e("Could not invoke method", e);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Method getSetDisplayIdMethod() throws NoSuchMethodException {
|
private static Method getSetDisplayIdMethod() throws NoSuchMethodException {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue