Skip to content

Commit

Permalink
Disable input events when necessary
Browse files Browse the repository at this point in the history
Disable input events on secondary displays before Android 10, even if
FLAG_PRESENTATION is not set.

Refs #1288 <#1288>
  • Loading branch information
rom1v committed Apr 16, 2020
1 parent cc22f46 commit 94a7f1a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
17 changes: 6 additions & 11 deletions server/src/main/java/com/genymobile/scrcpy/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ public interface RotationListener {
*/
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();
Expand All @@ -53,7 +50,6 @@ public Device(Options options) {

screenInfo = ScreenInfo.computeScreenInfo(displayInfo, options.getCrop(), options.getMaxSize(), options.getLockedVideoOrientation());
layerStack = displayInfo.getLayerStack();
isPresentationDisplay = (displayInfoFlags & DisplayInfo.FLAG_PRESENTATION) != 0;

registerRotationWatcher(new IRotationWatcher.Stub() {
@Override
Expand All @@ -73,8 +69,10 @@ public void onRotationChanged(int rotation) throws RemoteException {
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");
}
}

Expand Down Expand Up @@ -116,10 +114,7 @@ public static String getDeviceName() {
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public static boolean setDisplayId(InputEvent inputEvent, int displayId) {
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;
}
}
Expand Down

0 comments on commit 94a7f1a

Please sign in to comment.