mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-07-29 04:08:56 +00:00
Simplify InputManager wrapper
Use the public InputManager API. PR #6009 <https://github.com/Genymobile/scrcpy/pull/6009> Signed-off-by: Romain Vimont <rom@rom1v.com>
This commit is contained in:
parent
d2cc930975
commit
41ed40f5f9
1 changed files with 9 additions and 22 deletions
|
@ -1,5 +1,6 @@
|
||||||
package com.genymobile.scrcpy.wrappers;
|
package com.genymobile.scrcpy.wrappers;
|
||||||
|
|
||||||
|
import com.genymobile.scrcpy.FakeContext;
|
||||||
import com.genymobile.scrcpy.util.Ln;
|
import com.genymobile.scrcpy.util.Ln;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
@ -16,40 +17,26 @@ 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_RESULT = 1;
|
||||||
public static final int INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH = 2;
|
public static final int INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH = 2;
|
||||||
|
|
||||||
private final Object manager;
|
private final android.hardware.input.InputManager manager;
|
||||||
private Method injectInputEventMethod;
|
|
||||||
private long lastPermissionLogDate;
|
private long lastPermissionLogDate;
|
||||||
|
|
||||||
|
private static Method injectInputEventMethod;
|
||||||
private static Method setDisplayIdMethod;
|
private static Method setDisplayIdMethod;
|
||||||
private static Method setActionButtonMethod;
|
private static Method setActionButtonMethod;
|
||||||
|
|
||||||
static InputManager create() {
|
static InputManager create() {
|
||||||
try {
|
android.hardware.input.InputManager manager = (android.hardware.input.InputManager) FakeContext.get()
|
||||||
Class<?> inputManagerClass = getInputManagerClass();
|
.getSystemService(FakeContext.INPUT_SERVICE);
|
||||||
Method getInstanceMethod = inputManagerClass.getDeclaredMethod("getInstance");
|
return new InputManager(manager);
|
||||||
Object im = getInstanceMethod.invoke(null);
|
|
||||||
return new InputManager(im);
|
|
||||||
} catch (ReflectiveOperationException e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Class<?> getInputManagerClass() {
|
private InputManager(android.hardware.input.InputManager manager) {
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private InputManager(Object manager) {
|
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Method getInjectInputEventMethod() throws NoSuchMethodException {
|
private static Method getInjectInputEventMethod() throws NoSuchMethodException {
|
||||||
if (injectInputEventMethod == null) {
|
if (injectInputEventMethod == null) {
|
||||||
injectInputEventMethod = manager.getClass().getMethod("injectInputEvent", InputEvent.class, int.class);
|
injectInputEventMethod = android.hardware.input.InputManager.class.getMethod("injectInputEvent", InputEvent.class, int.class);
|
||||||
}
|
}
|
||||||
return injectInputEventMethod;
|
return injectInputEventMethod;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue