Skip to content

Commit 872965b

Browse files
Sascha PrueterAndroid (Google) Code Review
authored andcommitted
Merge "Use a consistent policy for filtering wake keys." into jb-mr1-dev
2 parents 1b3b254 + 1c2e494 commit 872965b

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

@@ -935,8 +935,8 @@ private void notifyScreenOnLocked(KeyguardViewManager.ShowListener showListener)
935935
* @see #handleWakeWhenReady
936936
* @see #onWakeKeyWhenKeyguardShowingTq(int)
937937
*/
938-
private void wakeWhenReadyLocked(int keyCode) {
939-
if (DBG_WAKE) Log.d(TAG, "wakeWhenReadyLocked(" + keyCode + ")");
938+
private void wakeWhenReady(int keyCode) {
939+
if (DBG_WAKE) Log.d(TAG, "wakeWhenReady(" + keyCode + ")");
940940

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

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

10671027
/**
@@ -1073,17 +1033,14 @@ private boolean isWakeKeyWhenKeyguardShowing(int keyCode, boolean isDocked) {
10731033
* The 'Tq' suffix is per the documentation in {@link WindowManagerPolicy}.
10741034
* Be sure not to take any action that takes a long time; any significant
10751035
* action should be posted to a handler.
1076-
*
1077-
* @return Whether we poked the wake lock (and turned the screen on)
10781036
*/
1079-
public boolean onWakeMotionWhenKeyguardShowingTq() {
1037+
public void onWakeMotionWhenKeyguardShowingTq() {
10801038
if (DEBUG) Log.d(TAG, "onWakeMotionWhenKeyguardShowing()");
10811039

10821040
// give the keyguard view manager a chance to adjust the state of the
10831041
// keyguard based on the key that woke the device before poking
10841042
// the wake lock
1085-
wakeWhenReadyLocked(KeyEvent.KEYCODE_UNKNOWN);
1086-
return true;
1043+
wakeWhenReady(KeyEvent.KEYCODE_UNKNOWN);
10871044
}
10881045

10891046
public void keyguardDone(boolean authenticated, boolean wakeup) {
@@ -1350,7 +1307,7 @@ private void adjustStatusBarLocked() {
13501307
}
13511308

13521309
/**
1353-
* Handle message sent by {@link #wakeWhenReadyLocked(int)}
1310+
* Handle message sent by {@link #wakeWhenReady(int)}
13541311
* @param keyCode The key that woke the device.
13551312
* @see #WAKE_WHEN_READY
13561313
*/

0 commit comments

Comments
 (0)