-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set power mode on all physical displays
Android 10 and above support multiple physical displays. Apply power mode to all of them. Fixes #3716 <#3716>
- Loading branch information
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -277,6 +277,26 @@ 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) { | ||
// Change the power mode for all physical displays | ||
long[] physicalDisplayIds = SurfaceControl.getPhysicalDisplayIds(); | ||
if (physicalDisplayIds == null) { | ||
Ln.e("Could not get physical display ids"); | ||
return false; | ||
} | ||
|
||
boolean allOk = true; | ||
for (long physicalDisplayId : physicalDisplayIds) { | ||
IBinder binder = SurfaceControl.getPhysicalDisplayToken(physicalDisplayId); | ||
boolean ok = SurfaceControl.setDisplayPowerMode(binder, mode); | ||
if (!ok) { | ||
allOk = false; | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rom1v
Author
Collaborator
|
||
} | ||
return allOk; | ||
} | ||
|
||
// Older Android versions, only 1 display | ||
IBinder d = SurfaceControl.getBuiltInDisplay(); | ||
if (d == null) { | ||
Ln.e("Could not get built-in display"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For the future, @rom1v, I'd do those 3 lines like this:
allOk = SurfaceControl.setDisplayPowerMode(binder, mode) && allOk;
Or, if you don't like that way, there's also this way:
allOk = SurfaceControl.setDisplayPowerMode(binder, mode) ? allOk : false;
Just a suggestion you can consider for later time to shorten the codebase.