Skip to content

Commit 1c2e494

Browse files
author
Jeff Brown
committed
Use a consistent policy for filtering wake keys.
Previously wake keys were filtered differently depending on whether a keyguard was showing. If the user disables the keyguard then no filtering was applied, which means that the volume key may wake your device while in your pocket. This change ensures that we use the same policy consistently regardless of whether keyguard is showing. The behavior is otherwise the same. Removed the "Locked" suffix on a method that was actually being called without a lock held and which in fact does not require it. Bug: 7481025 Change-Id: I704c71ca009bc5437f349f858b9de7c77ea73e4b
1 parent 0f4d5df commit 1c2e494

File tree

2 files changed

+49
-60
lines changed

2 files changed

+49
-60
lines changed

policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3168,8 +3168,7 @@ public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
31683168

31693169
if (lidOpen) {
31703170
if (keyguardIsShowingTq()) {
3171-
mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(
3172-
KeyEvent.KEYCODE_POWER, mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED);
3171+
mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(KeyEvent.KEYCODE_POWER);
31733172
} else {
31743173
mPowerManager.wakeUp(SystemClock.uptimeMillis());
31753174
}
@@ -3388,11 +3387,10 @@ public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean i
33883387
// When the screen is off and the key is not injected, determine whether
33893388
// to wake the device but don't pass the key to the application.
33903389
result = 0;
3391-
if (down && isWakeKey) {
3390+
if (down && isWakeKey && isWakeKeyWhenScreenOff(keyCode)) {
33923391
if (keyguardActive) {
3393-
// If the keyguard is showing, let it decide what to do with the wake key.
3394-
mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(keyCode,
3395-
mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED);
3392+
// If the keyguard is showing, let it wake the device when ready.
3393+
mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(keyCode);
33963394
} else {
33973395
// Otherwise, wake the device ourselves.
33983396
result |= ACTION_WAKE_UP;
@@ -3614,6 +3612,40 @@ public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean i
36143612
return result;
36153613
}
36163614

3615+
/**
3616+
* When the screen is off we ignore some keys that might otherwise typically
3617+
* be considered wake keys. We filter them out here.
3618+
*
3619+
* {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
3620+
* is always considered a wake key.
3621+
*/
3622+
private boolean isWakeKeyWhenScreenOff(int keyCode) {
3623+
switch (keyCode) {
3624+
// ignore volume keys unless docked
3625+
case KeyEvent.KEYCODE_VOLUME_UP:
3626+
case KeyEvent.KEYCODE_VOLUME_DOWN:
3627+
case KeyEvent.KEYCODE_VOLUME_MUTE:
3628+
return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
3629+
3630+
// ignore media and camera keys
3631+
case KeyEvent.KEYCODE_MUTE:
3632+
case KeyEvent.KEYCODE_HEADSETHOOK:
3633+
case KeyEvent.KEYCODE_MEDIA_PLAY:
3634+
case KeyEvent.KEYCODE_MEDIA_PAUSE:
3635+
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
3636+
case KeyEvent.KEYCODE_MEDIA_STOP:
3637+
case KeyEvent.KEYCODE_MEDIA_NEXT:
3638+
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
3639+
case KeyEvent.KEYCODE_MEDIA_REWIND:
3640+
case KeyEvent.KEYCODE_MEDIA_RECORD:
3641+
case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
3642+
case KeyEvent.KEYCODE_CAMERA:
3643+
return false;
3644+
}
3645+
return true;
3646+
}
3647+
3648+
36173649
/** {@inheritDoc} */
36183650
@Override
36193651
public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) {

policy/src/com/android/internal/policy/impl/keyguard/KeyguardViewMediator.java

Lines changed: 11 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public class KeyguardViewMediator {
175175
* Does not turn on screen, held while a call to {@link KeyguardViewManager#wakeWhenReadyTq(int)}
176176
* is called to make sure the device doesn't sleep before it has a chance to poke
177177
* the wake lock.
178-
* @see #wakeWhenReadyLocked(int)
178+
* @see #wakeWhenReady(int)
179179
*/
180180
private PowerManager.WakeLock mWakeAndHandOff;
181181

@@ -933,8 +933,8 @@ private void notifyScreenOnLocked(KeyguardViewManager.ShowListener showListener)
933933
* @see #handleWakeWhenReady
934934
* @see #onWakeKeyWhenKeyguardShowingTq(int)
935935
*/
936-
private void wakeWhenReadyLocked(int keyCode) {
937-
if (DBG_WAKE) Log.d(TAG, "wakeWhenReadyLocked(" + keyCode + ")");
936+
private void wakeWhenReady(int keyCode) {
937+
if (DBG_WAKE) Log.d(TAG, "wakeWhenReady(" + keyCode + ")");
938938

939939
/**
940940
* acquire the handoff lock that will keep the cpu running. this will
@@ -1012,54 +1012,14 @@ public void onReceive(Context context, Intent intent) {
10121012
* action should be posted to a handler.
10131013
*
10141014
* @param keyCode The keycode of the key that woke the device
1015-
* @param isDocked True if the device is in the dock
1016-
* @return Whether we poked the wake lock (and turned the screen on)
10171015
*/
1018-
public boolean onWakeKeyWhenKeyguardShowingTq(int keyCode, boolean isDocked) {
1016+
public void onWakeKeyWhenKeyguardShowingTq(int keyCode) {
10191017
if (DEBUG) Log.d(TAG, "onWakeKeyWhenKeyguardShowing(" + keyCode + ")");
10201018

1021-
if (isWakeKeyWhenKeyguardShowing(keyCode, isDocked)) {
1022-
// give the keyguard view manager a chance to adjust the state of the
1023-
// keyguard based on the key that woke the device before poking
1024-
// the wake lock
1025-
wakeWhenReadyLocked(keyCode);
1026-
return true;
1027-
} else {
1028-
return false;
1029-
}
1030-
}
1031-
1032-
/**
1033-
* When the keyguard is showing we ignore some keys that might otherwise typically
1034-
* be considered wake keys. We filter them out here.
1035-
*
1036-
* {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
1037-
* is always considered a wake key.
1038-
*/
1039-
private boolean isWakeKeyWhenKeyguardShowing(int keyCode, boolean isDocked) {
1040-
switch (keyCode) {
1041-
// ignore volume keys unless docked
1042-
case KeyEvent.KEYCODE_VOLUME_UP:
1043-
case KeyEvent.KEYCODE_VOLUME_DOWN:
1044-
case KeyEvent.KEYCODE_VOLUME_MUTE:
1045-
return isDocked;
1046-
1047-
// ignore media and camera keys
1048-
case KeyEvent.KEYCODE_MUTE:
1049-
case KeyEvent.KEYCODE_HEADSETHOOK:
1050-
case KeyEvent.KEYCODE_MEDIA_PLAY:
1051-
case KeyEvent.KEYCODE_MEDIA_PAUSE:
1052-
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
1053-
case KeyEvent.KEYCODE_MEDIA_STOP:
1054-
case KeyEvent.KEYCODE_MEDIA_NEXT:
1055-
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
1056-
case KeyEvent.KEYCODE_MEDIA_REWIND:
1057-
case KeyEvent.KEYCODE_MEDIA_RECORD:
1058-
case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
1059-
case KeyEvent.KEYCODE_CAMERA:
1060-
return false;
1061-
}
1062-
return true;
1019+
// give the keyguard view manager a chance to adjust the state of the
1020+
// keyguard based on the key that woke the device before poking
1021+
// the wake lock
1022+
wakeWhenReady(keyCode);
10631023
}
10641024

10651025
/**
@@ -1071,17 +1031,14 @@ private boolean isWakeKeyWhenKeyguardShowing(int keyCode, boolean isDocked) {
10711031
* The 'Tq' suffix is per the documentation in {@link WindowManagerPolicy}.
10721032
* Be sure not to take any action that takes a long time; any significant
10731033
* action should be posted to a handler.
1074-
*
1075-
* @return Whether we poked the wake lock (and turned the screen on)
10761034
*/
1077-
public boolean onWakeMotionWhenKeyguardShowingTq() {
1035+
public void onWakeMotionWhenKeyguardShowingTq() {
10781036
if (DEBUG) Log.d(TAG, "onWakeMotionWhenKeyguardShowing()");
10791037

10801038
// give the keyguard view manager a chance to adjust the state of the
10811039
// keyguard based on the key that woke the device before poking
10821040
// the wake lock
1083-
wakeWhenReadyLocked(KeyEvent.KEYCODE_UNKNOWN);
1084-
return true;
1041+
wakeWhenReady(KeyEvent.KEYCODE_UNKNOWN);
10851042
}
10861043

10871044
public void keyguardDone(boolean authenticated, boolean wakeup) {
@@ -1348,7 +1305,7 @@ private void adjustStatusBarLocked() {
13481305
}
13491306

13501307
/**
1351-
* Handle message sent by {@link #wakeWhenReadyLocked(int)}
1308+
* Handle message sent by {@link #wakeWhenReady(int)}
13521309
* @param keyCode The key that woke the device.
13531310
* @see #WAKE_WHEN_READY
13541311
*/

0 commit comments

Comments
 (0)