Disable display power for virtual displays

If displayId == Device.DISPLAY_ID_NONE, then the display is virtual: its
power mode cannot be changed.

PR #5418 <https://github.com/Genymobile/scrcpy/pull/5418>
This commit is contained in:
Romain Vimont 2024-10-29 00:41:02 +01:00
parent 58a0fbbf2e
commit 569c37cec1
2 changed files with 6 additions and 6 deletions

View File

@ -137,12 +137,10 @@ public final class CleanUp {
} }
} }
if (Device.isScreenOn()) { if (Device.isScreenOn() && displayId != Device.DISPLAY_ID_NONE) {
if (powerOffScreen) { if (powerOffScreen) {
if (displayId != Device.DISPLAY_ID_NONE) {
Ln.i("Power off screen"); Ln.i("Power off screen");
Device.powerOffScreen(displayId); Device.powerOffScreen(displayId);
}
} else if (restoreDisplayPower) { } else if (restoreDisplayPower) {
Ln.i("Restoring display power"); Ln.i("Restoring display power");
Device.setDisplayPower(true); Device.setDisplayPower(true);

View File

@ -271,7 +271,7 @@ public class Controller implements AsyncProcessor, VirtualDisplayListener {
setClipboard(msg.getText(), msg.getPaste(), msg.getSequence()); setClipboard(msg.getText(), msg.getPaste(), msg.getSequence());
break; break;
case ControlMessage.TYPE_SET_DISPLAY_POWER: case ControlMessage.TYPE_SET_DISPLAY_POWER:
if (supportsInputEvents) { if (supportsInputEvents && displayId != Device.DISPLAY_ID_NONE) {
boolean on = msg.getOn(); boolean on = msg.getOn();
boolean setDisplayPowerOk = Device.setDisplayPower(on); boolean setDisplayPowerOk = Device.setDisplayPower(on);
if (setDisplayPowerOk) { if (setDisplayPowerOk) {
@ -311,6 +311,7 @@ public class Controller implements AsyncProcessor, VirtualDisplayListener {
private boolean injectKeycode(int action, int keycode, int repeat, int metaState) { private boolean injectKeycode(int action, int keycode, int repeat, int metaState) {
if (keepDisplayPowerOff && action == KeyEvent.ACTION_UP && (keycode == KeyEvent.KEYCODE_POWER || keycode == KeyEvent.KEYCODE_WAKEUP)) { if (keepDisplayPowerOff && action == KeyEvent.ACTION_UP && (keycode == KeyEvent.KEYCODE_POWER || keycode == KeyEvent.KEYCODE_WAKEUP)) {
assert displayId != Device.DISPLAY_ID_NONE;
scheduleDisplayPowerOff(); scheduleDisplayPowerOff();
} }
return injectKeyEvent(action, keycode, repeat, metaState, Device.INJECT_MODE_ASYNC); return injectKeyEvent(action, keycode, repeat, metaState, Device.INJECT_MODE_ASYNC);
@ -510,6 +511,7 @@ public class Controller implements AsyncProcessor, VirtualDisplayListener {
} }
if (keepDisplayPowerOff) { if (keepDisplayPowerOff) {
assert displayId != Device.DISPLAY_ID_NONE;
scheduleDisplayPowerOff(); scheduleDisplayPowerOff();
} }
return pressReleaseKeycode(KeyEvent.KEYCODE_POWER, Device.INJECT_MODE_ASYNC); return pressReleaseKeycode(KeyEvent.KEYCODE_POWER, Device.INJECT_MODE_ASYNC);