From c33a147fd0e9fbd3a5add6f0190eea909d74c26d Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 17 Oct 2019 23:14:18 +0200 Subject: [PATCH] Fix "turn screen off" on Android Q Call getInternalDisplayToken(), which retrieve the id of the first physical display (which is not necessarily 0 anymore). Fixes --- .../src/main/java/com/genymobile/scrcpy/Device.java | 2 +- .../genymobile/scrcpy/wrappers/SurfaceControl.java | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/Device.java b/server/src/main/java/com/genymobile/scrcpy/Device.java index 0246b216..708b9516 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Device.java +++ b/server/src/main/java/com/genymobile/scrcpy/Device.java @@ -161,7 +161,7 @@ public final class Device { * @param mode one of the {@code SCREEN_POWER_MODE_*} constants */ public void setScreenPowerMode(int mode) { - IBinder d = SurfaceControl.getBuiltInDisplay(0); + IBinder d = SurfaceControl.getBuiltInDisplay(); if (d == null) { Ln.e("Could not get built-in display"); return; diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/SurfaceControl.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/SurfaceControl.java index ba37da0d..bef6e5d9 100644 --- a/server/src/main/java/com/genymobile/scrcpy/wrappers/SurfaceControl.java +++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/SurfaceControl.java @@ -92,7 +92,7 @@ public final class SurfaceControl { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { getBuiltInDisplayMethod = CLASS.getMethod("getBuiltInDisplay", int.class); } else { - getBuiltInDisplayMethod = CLASS.getMethod("getPhysicalDisplayToken", long.class); + getBuiltInDisplayMethod = CLASS.getMethod("getInternalDisplayToken"); } } catch (NoSuchMethodException e) { Ln.e("Could not find method", e); @@ -101,13 +101,19 @@ public final class SurfaceControl { return getBuiltInDisplayMethod; } - public static IBinder getBuiltInDisplay(int builtInDisplayId) { + public static IBinder getBuiltInDisplay() { Method method = getGetBuiltInDisplayMethod(); if (method == null) { return null; } try { - return (IBinder) method.invoke(null, builtInDisplayId); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { + // call getBuiltInDisplay(0) + return (IBinder) method.invoke(null, 0); + } + + // call getInternalDisplayToken() + return (IBinder) method.invoke(null); } catch (InvocationTargetException | IllegalAccessException e) { Ln.e("Could not invoke " + method.getName(), e); return null;