From 1c2e4948a1f0e803171389427212321973ea66b8 Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Tue, 6 Nov 2012 16:32:01 -0800 Subject: [PATCH] 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 --- .../policy/impl/PhoneWindowManager.java | 44 +++++++++++-- .../impl/keyguard/KeyguardViewMediator.java | 65 ++++--------------- 2 files changed, 49 insertions(+), 60 deletions(-) diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java index 406f644fab950..5397a29cda3b3 100755 --- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java @@ -3168,8 +3168,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { if (lidOpen) { if (keyguardIsShowingTq()) { - mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq( - KeyEvent.KEYCODE_POWER, mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED); + mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(KeyEvent.KEYCODE_POWER); } else { mPowerManager.wakeUp(SystemClock.uptimeMillis()); } @@ -3388,11 +3387,10 @@ public class PhoneWindowManager implements WindowManagerPolicy { // When the screen is off and the key is not injected, determine whether // to wake the device but don't pass the key to the application. result = 0; - if (down && isWakeKey) { + if (down && isWakeKey && isWakeKeyWhenScreenOff(keyCode)) { if (keyguardActive) { - // If the keyguard is showing, let it decide what to do with the wake key. - mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(keyCode, - mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED); + // If the keyguard is showing, let it wake the device when ready. + mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(keyCode); } else { // Otherwise, wake the device ourselves. result |= ACTION_WAKE_UP; @@ -3614,6 +3612,40 @@ public class PhoneWindowManager implements WindowManagerPolicy { return result; } + /** + * When the screen is off we ignore some keys that might otherwise typically + * be considered wake keys. We filter them out here. + * + * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it + * is always considered a wake key. + */ + private boolean isWakeKeyWhenScreenOff(int keyCode) { + switch (keyCode) { + // ignore volume keys unless docked + case KeyEvent.KEYCODE_VOLUME_UP: + case KeyEvent.KEYCODE_VOLUME_DOWN: + case KeyEvent.KEYCODE_VOLUME_MUTE: + return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED; + + // ignore media and camera keys + case KeyEvent.KEYCODE_MUTE: + case KeyEvent.KEYCODE_HEADSETHOOK: + case KeyEvent.KEYCODE_MEDIA_PLAY: + case KeyEvent.KEYCODE_MEDIA_PAUSE: + case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: + case KeyEvent.KEYCODE_MEDIA_STOP: + case KeyEvent.KEYCODE_MEDIA_NEXT: + case KeyEvent.KEYCODE_MEDIA_PREVIOUS: + case KeyEvent.KEYCODE_MEDIA_REWIND: + case KeyEvent.KEYCODE_MEDIA_RECORD: + case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: + case KeyEvent.KEYCODE_CAMERA: + return false; + } + return true; + } + + /** {@inheritDoc} */ @Override public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) { diff --git a/policy/src/com/android/internal/policy/impl/keyguard/KeyguardViewMediator.java b/policy/src/com/android/internal/policy/impl/keyguard/KeyguardViewMediator.java index d0fa81e9b5ded..b9ff3fbb5a18b 100644 --- a/policy/src/com/android/internal/policy/impl/keyguard/KeyguardViewMediator.java +++ b/policy/src/com/android/internal/policy/impl/keyguard/KeyguardViewMediator.java @@ -175,7 +175,7 @@ public class KeyguardViewMediator { * Does not turn on screen, held while a call to {@link KeyguardViewManager#wakeWhenReadyTq(int)} * is called to make sure the device doesn't sleep before it has a chance to poke * the wake lock. - * @see #wakeWhenReadyLocked(int) + * @see #wakeWhenReady(int) */ private PowerManager.WakeLock mWakeAndHandOff; @@ -933,8 +933,8 @@ public class KeyguardViewMediator { * @see #handleWakeWhenReady * @see #onWakeKeyWhenKeyguardShowingTq(int) */ - private void wakeWhenReadyLocked(int keyCode) { - if (DBG_WAKE) Log.d(TAG, "wakeWhenReadyLocked(" + keyCode + ")"); + private void wakeWhenReady(int keyCode) { + if (DBG_WAKE) Log.d(TAG, "wakeWhenReady(" + keyCode + ")"); /** * acquire the handoff lock that will keep the cpu running. this will @@ -1012,54 +1012,14 @@ public class KeyguardViewMediator { * action should be posted to a handler. * * @param keyCode The keycode of the key that woke the device - * @param isDocked True if the device is in the dock - * @return Whether we poked the wake lock (and turned the screen on) */ - public boolean onWakeKeyWhenKeyguardShowingTq(int keyCode, boolean isDocked) { + public void onWakeKeyWhenKeyguardShowingTq(int keyCode) { if (DEBUG) Log.d(TAG, "onWakeKeyWhenKeyguardShowing(" + keyCode + ")"); - if (isWakeKeyWhenKeyguardShowing(keyCode, isDocked)) { - // give the keyguard view manager a chance to adjust the state of the - // keyguard based on the key that woke the device before poking - // the wake lock - wakeWhenReadyLocked(keyCode); - return true; - } else { - return false; - } - } - - /** - * When the keyguard is showing we ignore some keys that might otherwise typically - * be considered wake keys. We filter them out here. - * - * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it - * is always considered a wake key. - */ - private boolean isWakeKeyWhenKeyguardShowing(int keyCode, boolean isDocked) { - switch (keyCode) { - // ignore volume keys unless docked - case KeyEvent.KEYCODE_VOLUME_UP: - case KeyEvent.KEYCODE_VOLUME_DOWN: - case KeyEvent.KEYCODE_VOLUME_MUTE: - return isDocked; - - // ignore media and camera keys - case KeyEvent.KEYCODE_MUTE: - case KeyEvent.KEYCODE_HEADSETHOOK: - case KeyEvent.KEYCODE_MEDIA_PLAY: - case KeyEvent.KEYCODE_MEDIA_PAUSE: - case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: - case KeyEvent.KEYCODE_MEDIA_STOP: - case KeyEvent.KEYCODE_MEDIA_NEXT: - case KeyEvent.KEYCODE_MEDIA_PREVIOUS: - case KeyEvent.KEYCODE_MEDIA_REWIND: - case KeyEvent.KEYCODE_MEDIA_RECORD: - case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: - case KeyEvent.KEYCODE_CAMERA: - return false; - } - return true; + // give the keyguard view manager a chance to adjust the state of the + // keyguard based on the key that woke the device before poking + // the wake lock + wakeWhenReady(keyCode); } /** @@ -1071,17 +1031,14 @@ public class KeyguardViewMediator { * The 'Tq' suffix is per the documentation in {@link WindowManagerPolicy}. * Be sure not to take any action that takes a long time; any significant * action should be posted to a handler. - * - * @return Whether we poked the wake lock (and turned the screen on) */ - public boolean onWakeMotionWhenKeyguardShowingTq() { + public void onWakeMotionWhenKeyguardShowingTq() { if (DEBUG) Log.d(TAG, "onWakeMotionWhenKeyguardShowing()"); // give the keyguard view manager a chance to adjust the state of the // keyguard based on the key that woke the device before poking // the wake lock - wakeWhenReadyLocked(KeyEvent.KEYCODE_UNKNOWN); - return true; + wakeWhenReady(KeyEvent.KEYCODE_UNKNOWN); } public void keyguardDone(boolean authenticated, boolean wakeup) { @@ -1348,7 +1305,7 @@ public class KeyguardViewMediator { } /** - * Handle message sent by {@link #wakeWhenReadyLocked(int)} + * Handle message sent by {@link #wakeWhenReady(int)} * @param keyCode The key that woke the device. * @see #WAKE_WHEN_READY */