Disable input events when necessary
Disable input events on secondary displays before Android 10, even if FLAG_PRESENTATION is not set. Refs #1288 <https://github.com/Genymobile/scrcpy/issues/1288>
This commit is contained in:
parent
cc22f4622a
commit
94a7f1a0f8
3 changed files with 7 additions and 14 deletions
|
@ -36,10 +36,7 @@ public final class Device {
|
||||||
*/
|
*/
|
||||||
private final int layerStack;
|
private final int layerStack;
|
||||||
|
|
||||||
/**
|
private final boolean supportsInputEvents;
|
||||||
* The FLAG_PRESENTATION from the DisplayInfo
|
|
||||||
*/
|
|
||||||
private final boolean isPresentationDisplay;
|
|
||||||
|
|
||||||
public Device(Options options) {
|
public Device(Options options) {
|
||||||
displayId = options.getDisplayId();
|
displayId = options.getDisplayId();
|
||||||
|
@ -53,7 +50,6 @@ public final class Device {
|
||||||
|
|
||||||
screenInfo = ScreenInfo.computeScreenInfo(displayInfo, options.getCrop(), options.getMaxSize(), options.getLockedVideoOrientation());
|
screenInfo = ScreenInfo.computeScreenInfo(displayInfo, options.getCrop(), options.getMaxSize(), options.getLockedVideoOrientation());
|
||||||
layerStack = displayInfo.getLayerStack();
|
layerStack = displayInfo.getLayerStack();
|
||||||
isPresentationDisplay = (displayInfoFlags & DisplayInfo.FLAG_PRESENTATION) != 0;
|
|
||||||
|
|
||||||
registerRotationWatcher(new IRotationWatcher.Stub() {
|
registerRotationWatcher(new IRotationWatcher.Stub() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -73,8 +69,10 @@ public final class Device {
|
||||||
Ln.w("Display doesn't have FLAG_SUPPORTS_PROTECTED_BUFFERS flag, mirroring can be restricted");
|
Ln.w("Display doesn't have FLAG_SUPPORTS_PROTECTED_BUFFERS flag, mirroring can be restricted");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!supportsInputEvents()) {
|
// main display or any display on Android >= Q
|
||||||
Ln.w("Input events are not supported for displays with FLAG_PRESENTATION enabled for devices with API lower than 29");
|
supportsInputEvents = displayId == 0 || Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
|
||||||
|
if (!supportsInputEvents) {
|
||||||
|
Ln.w("Input events are not supported for secondary displays before Android 10");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,10 +114,7 @@ public final class Device {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean supportsInputEvents() {
|
public boolean supportsInputEvents() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
return supportsInputEvents;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return !isPresentationDisplay;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean injectInputEvent(InputEvent inputEvent, int mode) {
|
public boolean injectInputEvent(InputEvent inputEvent, int mode) {
|
||||||
|
|
|
@ -8,7 +8,6 @@ public final class DisplayInfo {
|
||||||
private final int flags;
|
private final int flags;
|
||||||
|
|
||||||
public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 0x00000001;
|
public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 0x00000001;
|
||||||
public static final int FLAG_PRESENTATION = 0x00000008;
|
|
||||||
|
|
||||||
public DisplayInfo(int displayId, Size size, int rotation, int layerStack, int flags) {
|
public DisplayInfo(int displayId, Size size, int rotation, int layerStack, int flags) {
|
||||||
this.displayId = displayId;
|
this.displayId = displayId;
|
||||||
|
|
|
@ -53,8 +53,7 @@ public final class InputManager {
|
||||||
method.invoke(inputEvent, displayId);
|
method.invoke(inputEvent, displayId);
|
||||||
return true;
|
return true;
|
||||||
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
|
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
|
||||||
// just a warning, it might happen on old devices
|
Ln.e("Cannot associate a display id to the input event", e);
|
||||||
Ln.w("Cannot associate a display id to the input event");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue