Remove flicker from transitions.

Change state progressions to handle animation/layout separation.
Also added debug as needed.

Fixes bug 6360835.
Fixes bug 6206366.
Fixes bug 6286371.
Fixes bug 6240494.

Change-Id: I1079756a7e3e35ebb9f711f02d005bde9bf65ef0
diff --git a/services/java/com/android/server/wm/WindowAnimator.java b/services/java/com/android/server/wm/WindowAnimator.java
index 7611a0f..f946f6c 100644
--- a/services/java/com/android/server/wm/WindowAnimator.java
+++ b/services/java/com/android/server/wm/WindowAnimator.java
@@ -75,6 +75,9 @@
     DimAnimator mDimAnimator = null;
     DimAnimator.Parameters mDimParams = null;
 
+    static final int WALLPAPER_ACTION_PENDING = 1;
+    int mPendingActions;
+
     WindowAnimator(final WindowManagerService service, final Context context,
             final WindowManagerPolicy policy) {
         mService = service;
@@ -364,7 +367,9 @@
             for (int i=unForceHiding.size()-1; i>=0; i--) {
                 Animation a = mPolicy.createForceHideEnterAnimation(wallpaperInUnForceHiding);
                 if (a != null) {
-                    unForceHiding.get(i).setAnimation(a);
+                    final WindowStateAnimator winAnimator = unForceHiding.get(i);
+                    winAnimator.setAnimation(a);
+                    winAnimator.mAnimationIsEntrance = true;
                 }
             }
         }
@@ -421,13 +426,16 @@
         mWindowAnimationBackgroundColor = 0;
 
         updateWindowsAndWallpaperLocked();
+        if ((mPendingLayoutChanges & WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
+            mPendingActions |= WALLPAPER_ACTION_PENDING;
+        }
 
         if (mTokenMayBeDrawn) {
             testTokenMayBeDrawnLocked();
         }
     }
 
-    void animate() {
+    synchronized void animate() {
         mPendingLayoutChanges = 0;
         mCurrentTime = SystemClock.uptimeMillis();
         mBulkUpdateParams = 0;
@@ -554,4 +562,8 @@
             mAnimDh = animDh;
         }
     }
+
+    synchronized void clearPendingActions() {
+        mPendingActions = 0;
+    }
 }