Allow FLAG_SHOW_WHEN_LOCKED to apply to dialogs

Previous fix to keep non-show-when-locked windows hid dialogs from
activities that had asked to be show-when-locked. That was too
restrictive.

Fixes bug 13225149.

Change-Id: I39ae9d7cbcc9b5109257f732d027bda3a2de65e4
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index 951925b..3f4bcd4 100755
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -153,6 +153,7 @@
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.util.HashSet;
 
 /**
  * WindowManagerPolicy implementation for the Android phone UI.  This
@@ -408,7 +409,7 @@
     static final Rect mTmpNavigationFrame = new Rect();
     
     WindowState mTopFullscreenOpaqueWindowState;
-    boolean mHideWindowBehindKeyguard;
+    HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
     boolean mTopIsFullscreen;
     boolean mForceStatusBar;
     boolean mForceStatusBarFromKeyguard;
@@ -2935,7 +2936,7 @@
     @Override
     public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
         mTopFullscreenOpaqueWindowState = null;
-        mHideWindowBehindKeyguard = false;
+        mAppsToBeHidden.clear();
         mForceStatusBar = false;
         mForceStatusBarFromKeyguard = false;
         
@@ -2978,12 +2979,17 @@
 
             final boolean showWhenLocked = (attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0;
             if (appWindow) {
+                if (showWhenLocked) {
+                    mAppsToBeHidden.remove(win.getAppToken());
+                } else {
+                    mAppsToBeHidden.add(win.getAppToken());
+                }
                 if (attrs.x == 0 && attrs.y == 0
                         && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
                         && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
                     if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
                     mTopFullscreenOpaqueWindowState = win;
-                    if (!mHideWindowBehindKeyguard) {
+                    if (mAppsToBeHidden.isEmpty()) {
                         if (showWhenLocked) {
                             if (DEBUG_LAYOUT) Slog.v(TAG, "Setting mHideLockScreen to true by win " + win);
                             mHideLockScreen = true;
@@ -3001,8 +3007,6 @@
                     if ((attrs.flags & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
                         mAllowLockscreenWhenOn = true;
                     }
-                } else if (!showWhenLocked) {
-                    mHideWindowBehindKeyguard = true;
                 }
             }
         }