From 322f1512ea806611eb37f508cd952bbbc050f853 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 15 Jul 2020 10:21:24 +0200 Subject: [PATCH] Inject WAKEUP instead of POWER To power the device on, inject KEYCODE_WAKEUP to avoid a possible race condition (the device might become off between the test isScreenOn() and the POWER keycode injection). --- server/src/main/java/com/genymobile/scrcpy/Controller.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/Controller.java b/server/src/main/java/com/genymobile/scrcpy/Controller.java index abfc434a..6ff8d208 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Controller.java +++ b/server/src/main/java/com/genymobile/scrcpy/Controller.java @@ -48,10 +48,10 @@ public class Controller { public void control() throws IOException { // on start, power on the device if (!device.isScreenOn()) { - device.injectKeycode(KeyEvent.KEYCODE_POWER); + device.injectKeycode(KeyEvent.KEYCODE_WAKEUP); // dirty hack - // After POWER is injected, the device is powered on asynchronously. + // After the keycode is injected, the device is powered on asynchronously. // To turn the device screen off while mirroring, the client will send a message that // would be handled before the device is actually powered on, so its effect would // be "canceled" once the device is turned back on. @@ -225,7 +225,7 @@ public class Controller { } private boolean pressBackOrTurnScreenOn() { - int keycode = device.isScreenOn() ? KeyEvent.KEYCODE_BACK : KeyEvent.KEYCODE_POWER; + int keycode = device.isScreenOn() ? KeyEvent.KEYCODE_BACK : KeyEvent.KEYCODE_WAKEUP; return device.injectKeycode(keycode); }