Fix bug 2290852: Screen wakes up in my pocket while listening to music

When the screen is off keyguard is open but hidden by another activity
make sure that non-waking events like volume key or track ball press
do not turn the screen back on.

Change-Id: Ie6b191360b903b54388a6f65680ccc3264a51dd8
Signed-off-by: Mike Lockwood <lockwood@android.com>
diff --git a/policy/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/com/android/internal/policy/impl/PhoneWindowManager.java
index 2143f52..2f9faae 100755
--- a/policy/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -1620,14 +1620,20 @@
     public int interceptKeyTq(RawInputEvent event, boolean screenIsOn) {
         int result = ACTION_PASS_TO_USER;
         final boolean isWakeKey = isWakeKeyTq(event);
-        final boolean keyguardShowing = keyguardIsShowingTq();
+        // If screen is off then we treat the case where the keyguard is open but hidden
+        // the same as if it were open and in front.
+        // This will prevent any keys other than the power button from waking the screen
+        // when the keyguard is hidden by another activity.
+        final boolean keyguardActive = (screenIsOn ?
+                                        mKeyguardMediator.isShowingAndNotHidden() :
+                                        mKeyguardMediator.isShowing());
 
         if (false) {
             Log.d(TAG, "interceptKeyTq event=" + event + " keycode=" + event.keycode
-                  + " screenIsOn=" + screenIsOn + " keyguardShowing=" + keyguardShowing);
+                  + " screenIsOn=" + screenIsOn + " keyguardActive=" + keyguardActive);
         }
 
-        if (keyguardShowing) {
+        if (keyguardActive) {
             if (screenIsOn) {
                 // when the screen is on, always give the event to the keyguard
                 result |= ACTION_PASS_TO_USER;
@@ -1721,7 +1727,7 @@
                         mShouldTurnOffOnKeyUp = false;
                         boolean gohome = (mEndcallBehavior & ENDCALL_HOME) != 0;
                         boolean sleeps = (mEndcallBehavior & ENDCALL_SLEEPS) != 0;
-                        if (keyguardShowing
+                        if (keyguardActive
                                 || (sleeps && !gohome)
                                 || (gohome && !goHome() && sleeps)) {
                             // they must already be on the keyguad or home screen,