Skip to content

Commit

Permalink
Fix "turn screen off" for Honor Android 14 devices
Browse files Browse the repository at this point in the history
  • Loading branch information
eiyooooo authored and FreedomBen committed Aug 2, 2024
1 parent b676b20 commit 4c52d8e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
14 changes: 13 additions & 1 deletion server/src/main/java/com/genymobile/scrcpy/device/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:
// - <https://github.com/Genymobile/scrcpy/issues/4823>
// - <https://github.com/Genymobile/scrcpy/issues/4943>
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 4c52d8e

Please sign in to comment.