Window manager: cancel animations before losing references to them.

For possible future changes to android.view.animation.Animation to tie
into StrictMode's animation annotations on violations.

Change-Id: I3a23fa9bd5edb0500586bb0e341f83f998b28ae7
diff --git a/services/java/com/android/server/WindowManagerService.java b/services/java/com/android/server/WindowManagerService.java
index 1be74d3..c74a27c 100644
--- a/services/java/com/android/server/WindowManagerService.java
+++ b/services/java/com/android/server/WindowManagerService.java
@@ -2736,7 +2736,10 @@
                 displayed = !win.isVisibleLw();
                 if (win.mExiting) {
                     win.mExiting = false;
-                    win.mAnimation = null;
+                    if (win.mAnimation != null) {
+                        win.mAnimation.cancel();
+                        win.mAnimation = null;
+                    }
                 }
                 if (win.mDestroying) {
                     win.mDestroying = false;
@@ -6903,6 +6906,7 @@
             if (mAnimation != null) {
                 mAnimating = true;
                 mLocalAnimating = false;
+                mAnimation.cancel();
                 mAnimation = null;
             }
         }
@@ -7174,6 +7178,7 @@
                         // starting window, so there is no need for it to also
                         // be doing its own stuff.
                         if (mAnimation != null) {
+                            mAnimation.cancel();
                             mAnimation = null;
                             // Make sure we clean up the animation.
                             mAnimating = true;
@@ -7219,7 +7224,11 @@
                     if (DEBUG_ANIM) Slog.v(
                         TAG, "Finished animation in " + this +
                         " @ " + currentTime);
-                    mAnimation = null;
+
+                    if (mAnimation != null) {
+                        mAnimation.cancel();
+                        mAnimation = null;
+                    }
                     //WindowManagerService.this.dump();
                 }
                 mHasLocalTransformation = false;
@@ -7248,6 +7257,7 @@
                 // clear it and make sure we run the cleanup code.
                 mAnimating = true;
                 mLocalAnimating = true;
+                mAnimation.cancel();
                 mAnimation = null;
             }
 
@@ -7262,7 +7272,10 @@
 
             mAnimating = false;
             mLocalAnimating = false;
-            mAnimation = null;
+            if (mAnimation != null) {
+                mAnimation.cancel();
+                mAnimation = null;
+            }
             mAnimLayer = mLayer;
             if (mIsImWindow) {
                 mAnimLayer += mInputMethodAnimLayerAdjustment;