From 94a7f1a0f84cb4bc998e7eb117517209e3ca5584 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 15 Apr 2020 21:11:00 +0200 Subject: [PATCH] Disable input events when necessary Disable input events on secondary displays before Android 10, even if FLAG_PRESENTATION is not set. Refs #1288 --- .../main/java/com/genymobile/scrcpy/Device.java | 17 ++++++----------- .../java/com/genymobile/scrcpy/DisplayInfo.java | 1 - .../scrcpy/wrappers/InputManager.java | 3 +-- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/Device.java b/server/src/main/java/com/genymobile/scrcpy/Device.java index afa9f165..0c43dd34 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Device.java +++ b/server/src/main/java/com/genymobile/scrcpy/Device.java @@ -36,10 +36,7 @@ public final class Device { */ private final int layerStack; - /** - * The FLAG_PRESENTATION from the DisplayInfo - */ - private final boolean isPresentationDisplay; + private final boolean supportsInputEvents; public Device(Options options) { displayId = options.getDisplayId(); @@ -53,7 +50,6 @@ public final class Device { screenInfo = ScreenInfo.computeScreenInfo(displayInfo, options.getCrop(), options.getMaxSize(), options.getLockedVideoOrientation()); layerStack = displayInfo.getLayerStack(); - isPresentationDisplay = (displayInfoFlags & DisplayInfo.FLAG_PRESENTATION) != 0; registerRotationWatcher(new IRotationWatcher.Stub() { @Override @@ -73,8 +69,10 @@ public final class Device { Ln.w("Display doesn't have FLAG_SUPPORTS_PROTECTED_BUFFERS flag, mirroring can be restricted"); } - if (!supportsInputEvents()) { - Ln.w("Input events are not supported for displays with FLAG_PRESENTATION enabled for devices with API lower than 29"); + // main display or any display on Android >= Q + 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() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - return true; - } - return !isPresentationDisplay; + return supportsInputEvents; } public boolean injectInputEvent(InputEvent inputEvent, int mode) { diff --git a/server/src/main/java/com/genymobile/scrcpy/DisplayInfo.java b/server/src/main/java/com/genymobile/scrcpy/DisplayInfo.java index 50bc94aa..4b8036f8 100644 --- a/server/src/main/java/com/genymobile/scrcpy/DisplayInfo.java +++ b/server/src/main/java/com/genymobile/scrcpy/DisplayInfo.java @@ -8,7 +8,6 @@ public final class DisplayInfo { private final int flags; 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) { this.displayId = displayId; diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/InputManager.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/InputManager.java index 36d07353..e17b5a17 100644 --- a/server/src/main/java/com/genymobile/scrcpy/wrappers/InputManager.java +++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/InputManager.java @@ -53,8 +53,7 @@ public final class InputManager { method.invoke(inputEvent, displayId); return true; } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) { - // just a warning, it might happen on old devices - Ln.w("Cannot associate a display id to the input event"); + Ln.e("Cannot associate a display id to the input event", e); return false; } }