Skip to content

Commit

Permalink
Remove obsolete alternative injection method
Browse files Browse the repository at this point in the history
The previous commit replaced the IInterface instance (the "input"
service) by the InputManager instance (retrieved by
InputManager.getInstance()).

Both define an "injectInputEvent" method, but the alternate version
(probably) does not concern the InputManager.

This reverts commit b7a0627.

PR #3190 <#3190>
  • Loading branch information
rom1v committed Apr 22, 2022
1 parent 7d8b72d commit 6a4a4a2
Showing 1 changed file with 1 addition and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public final class InputManager {

private final android.hardware.input.InputManager manager;
private Method injectInputEventMethod;
private boolean alternativeInjectInputEventMethod;

private static Method setDisplayIdMethod;

Expand All @@ -25,23 +24,14 @@ public InputManager(android.hardware.input.InputManager manager) {

private Method getInjectInputEventMethod() throws NoSuchMethodException {
if (injectInputEventMethod == null) {
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;
}
injectInputEventMethod = manager.getClass().getMethod("injectInputEvent", InputEvent.class, int.class);
}
return injectInputEventMethod;
}

public boolean injectInputEvent(InputEvent inputEvent, int mode) {
try {
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);
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
Ln.e("Could not invoke method", e);
Expand Down

0 comments on commit 6a4a4a2

Please sign in to comment.