Reset layout needed at each animation step.

The member variable WindowAnimator.mPendingLayoutChanges was never
being reset to 0. Consequently once it was set it was causing endless
calls to the layout method.

Fixes bug 6208114, 6220403, 6219546.

Fixed NPE in RecentsPanelView.

Change-Id: Ie529b8f31e535543cb5ae0af9447146306b14eeb
diff --git a/services/java/com/android/server/wm/WindowAnimator.java b/services/java/com/android/server/wm/WindowAnimator.java
index b3dbee1..28dd0ba 100644
--- a/services/java/com/android/server/wm/WindowAnimator.java
+++ b/services/java/com/android/server/wm/WindowAnimator.java
@@ -23,7 +23,7 @@
  * on behalf of WindowManagerService.
  */
 public class WindowAnimator {
-    private static final String TAG = "WindowAnimations";
+    private static final String TAG = "WindowAnimator";
 
     final WindowManagerService mService;
     final Context mContext;
@@ -67,8 +67,24 @@
         final int NAT = mService.mAppTokens.size();
         for (i=0; i<NAT; i++) {
             final AppWindowToken appToken = mService.mAppTokens.get(i);
+            final boolean wasAnimating = appToken.animation != null;
             if (appToken.stepAnimationLocked(mCurrentTime, mInnerDw, mInnerDh)) {
                 mAnimating = true;
+            } else if (wasAnimating) {
+                // stopped animating, do one more pass through the layout
+                mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
+            }
+        }
+        
+        final int NEAT = mService.mExitingAppTokens.size();
+        for (i=0; i<NEAT; i++) {
+            final AppWindowToken appToken = mService.mExitingAppTokens.get(i);
+            final boolean wasAnimating = appToken.animation != null;
+            if (appToken.stepAnimationLocked(mCurrentTime, mInnerDw, mInnerDh)) {
+                mAnimating = true;
+            } else if (wasAnimating) {
+                // stopped animating, do one more pass through the layout
+                mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
             }
         }
 
@@ -517,6 +533,7 @@
     }
 
     void animate() {
+        mPendingLayoutChanges = 0;
         mCurrentTime = SystemClock.uptimeMillis();
 
         // Update animations of all applications, including those