From c7378f4dc843d24699349812661867c07af3954d Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 31 Oct 2024 20:23:11 +0100 Subject: [PATCH] Extract setting display power to a separate method For consistency with the other actions. --- .../genymobile/scrcpy/control/Controller.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/control/Controller.java b/server/src/main/java/com/genymobile/scrcpy/control/Controller.java index 7add4ea9..76d62fa6 100644 --- a/server/src/main/java/com/genymobile/scrcpy/control/Controller.java +++ b/server/src/main/java/com/genymobile/scrcpy/control/Controller.java @@ -272,16 +272,7 @@ public class Controller implements AsyncProcessor, VirtualDisplayListener { break; case ControlMessage.TYPE_SET_DISPLAY_POWER: if (supportsInputEvents && displayId != Device.DISPLAY_ID_NONE) { - boolean on = msg.getOn(); - boolean setDisplayPowerOk = Device.setDisplayPower(displayId, on); - if (setDisplayPowerOk) { - keepDisplayPowerOff = !on; - Ln.i("Device display turned " + (on ? "on" : "off")); - if (cleanUp != null) { - boolean mustRestoreOnExit = !on; - cleanUp.setRestoreDisplayPower(mustRestoreOnExit); - } - } + setDisplayPower(msg.getOn()); } break; case ControlMessage.TYPE_ROTATE_DEVICE: @@ -677,4 +668,16 @@ public class Controller implements AsyncProcessor, VirtualDisplayListener { return data; } } + + private void setDisplayPower(boolean on) { + boolean setDisplayPowerOk = Device.setDisplayPower(displayId, on); + if (setDisplayPowerOk) { + keepDisplayPowerOff = !on; + Ln.i("Device display turned " + (on ? "on" : "off")); + if (cleanUp != null) { + boolean mustRestoreOnExit = !on; + cleanUp.setRestoreDisplayPower(mustRestoreOnExit); + } + } + } }