Add lock or sleep power button behavior.

This changelist defines a new short-press button behavior,
which will lock the device or put the device to sleep if
already locked. This enables use-cases where the power button
should first return to the lock screen.

Bug: 194002900
Test: manual
Change-Id: I3098e6244563cb62facb7b0b35300e656b744c7c
This commit is contained in:
Bryce Lee
2021-07-18 10:06:57 -07:00
parent 12989af9e7
commit 8cc7529a2f

View File

@@ -261,6 +261,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
static final int SHORT_PRESS_POWER_GO_HOME = 4;
static final int SHORT_PRESS_POWER_CLOSE_IME_OR_GO_HOME = 5;
static final int SHORT_PRESS_POWER_LOCK_OR_SLEEP = 6;
// must match: config_LongPressOnPowerBehavior in config.xml
static final int LONG_PRESS_POWER_NOTHING = 0;
@@ -976,6 +977,14 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
break;
}
case SHORT_PRESS_POWER_LOCK_OR_SLEEP: {
if (keyguardOn()) {
sleepDefaultDisplayFromPowerButton(eventTime, 0);
} else {
lockNow(null /*options*/);
}
break;
}
}
}
}