From 4c52d8e0897093200c3c818cdd0e7e4fbb256e83 Mon Sep 17 00:00:00 2001 From: Kaiming Hu Date: Wed, 17 Jul 2024 20:20:13 +0800 Subject: [PATCH] Fix "turn screen off" for Honor Android 14 devices Fixes #4823 PR #5109 Signed-off-by: Romain Vimont --- .../java/com/genymobile/scrcpy/device/Device.java | 14 +++++++++++++- .../genymobile/scrcpy/wrappers/SurfaceControl.java | 9 +++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/device/Device.java b/server/src/main/java/com/genymobile/scrcpy/device/Device.java index 46657a0591..5a1083fded 100644 --- a/server/src/main/java/com/genymobile/scrcpy/device/Device.java +++ b/server/src/main/java/com/genymobile/scrcpy/device/Device.java @@ -323,7 +323,19 @@ public boolean setClipboardText(String text) { * @param mode one of the {@code POWER_MODE_*} constants */ public static boolean setScreenPowerMode(int mode) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + boolean applyToMultiPhysicalDisplays = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + + if (applyToMultiPhysicalDisplays + && Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE + && Build.BRAND.equalsIgnoreCase("honor") + && SurfaceControl.hasGetBuildInDisplayMethod()) { + // Workaround for Honor devices with Android 14: + // - + // - + applyToMultiPhysicalDisplays = false; + } + + if (applyToMultiPhysicalDisplays) { // On Android 14, these internal methods have been moved to DisplayControl boolean useDisplayControl = Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && !SurfaceControl.hasGetPhysicalDisplayIdsMethod(); 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 2f24f2d27c..038e7ca052 100644 --- a/server/src/main/java/com/genymobile/scrcpy/wrappers/SurfaceControl.java +++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/SurfaceControl.java @@ -94,6 +94,15 @@ private static Method getGetBuiltInDisplayMethod() throws NoSuchMethodException return getBuiltInDisplayMethod; } + public static boolean hasGetBuildInDisplayMethod() { + try { + getGetBuiltInDisplayMethod(); + return true; + } catch (NoSuchMethodException e) { + return false; + } + } + public static IBinder getBuiltInDisplay() { try { Method method = getGetBuiltInDisplayMethod();