Handle keyguard visibility states separately. DO NOT MERGE

Previous to this change the forceHiding variable was a boolean. This
change recognizes the different configurations of the keyguard by
defining separate states for forceHiding and testing for window
visibility differently in each state.

Fixes bug 6786114.

Change-Id: I3460c45ea6da772a4ff76bb016de7aa4b051a673
diff --git a/services/java/com/android/server/wm/WindowAnimator.java b/services/java/com/android/server/wm/WindowAnimator.java
index db3b2bd..62cf711 100644
--- a/services/java/com/android/server/wm/WindowAnimator.java
+++ b/services/java/com/android/server/wm/WindowAnimator.java
@@ -32,6 +32,13 @@
 public class WindowAnimator {
     private static final String TAG = "WindowAnimator";
 
+    // mForceHiding states.
+    private static final int KEYGUARD_NOT_SHOWN     = 0;
+    private static final int KEYGUARD_ANIMATING_IN  = 1;
+    private static final int KEYGUARD_SHOWN         = 2;
+    private static final int KEYGUARD_ANIMATING_OUT = 3;
+    int mForceHiding;
+
     final WindowManagerService mService;
     final Context mContext;
     final WindowManagerPolicy mPolicy;
@@ -39,7 +46,6 @@
     ArrayList<WindowStateAnimator> mWinAnimators = new ArrayList<WindowStateAnimator>();
 
     boolean mAnimating;
-    boolean mForceHiding;
     WindowState mWindowAnimationBackground;
     int mWindowAnimationBackgroundColor;
     int mAdjResult;
@@ -279,8 +285,16 @@
                         }
                         mService.mFocusMayChange = true;
                     }
-                    if (win.isReadyForDisplay() && winAnimator.mAnimationIsEntrance) {
-                        mForceHiding = true;
+                    if (win.isReadyForDisplay()) {
+                        if (nowAnimating) {
+                            if (winAnimator.mAnimationIsEntrance) {
+                                mForceHiding = KEYGUARD_ANIMATING_IN;
+                            } else {
+                                mForceHiding = KEYGUARD_ANIMATING_OUT;
+                            }
+                        } else {
+                            mForceHiding = KEYGUARD_SHOWN;
+                        }
                     }
                     if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG,
                             "Force hide " + mForceHiding
@@ -292,9 +306,12 @@
                             + " hidden=" + win.mRootToken.hidden
                             + " anim=" + win.mWinAnimator.mAnimation);
                 } else if (mPolicy.canBeForceHidden(win, win.mAttrs)) {
+                    final boolean hideWhenLocked =
+                            (winAnimator.mAttrFlags & FLAG_SHOW_WHEN_LOCKED) == 0;
                     final boolean changed;
-                    if (mForceHiding && (!winAnimator.isAnimating()
-                            || (winAnimator.mAttrFlags & FLAG_SHOW_WHEN_LOCKED) == 0)) {
+                    if (((mForceHiding == KEYGUARD_ANIMATING_IN)
+                                && (!winAnimator.isAnimating() || hideWhenLocked))
+                            || ((mForceHiding == KEYGUARD_SHOWN) && hideWhenLocked)) {
                         changed = win.hideLw(false, false);
                         if (WindowManagerService.DEBUG_VISIBILITY && changed) Slog.v(TAG,
                                 "Now policy hidden: " + win);
@@ -411,7 +428,7 @@
     }
 
     private void performAnimationsLocked() {
-        mForceHiding = false;
+        mForceHiding = KEYGUARD_NOT_SHOWN;
         mDetachedWallpaper = null;
         mWindowAnimationBackground = null;
         mWindowAnimationBackgroundColor = 0;