Skip to content

Commit

Permalink
Inject WAKEUP instead of POWER
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
rom1v committed Jul 15, 2020
1 parent 30714ab commit 322f151
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions server/src/main/java/com/genymobile/scrcpy/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ private void initPointers() {
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.
Expand Down Expand Up @@ -225,7 +225,7 @@ private boolean injectScroll(Position position, int hScroll, int vScroll) {
}

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);
}

Expand Down

0 comments on commit 322f151

Please sign in to comment.