Fix Home key causes wrong animation

Wallpaper logic assumed that if mWallpaperTarget was non-null then
any wallpaper animation should be exiting. However, if the existing
wallpaper target was already animating away then mWallpaperTarget
remains non-null until it is completely gone. Pressing Home during
this time was causing the next animation to exit rather than reverse
and enter.

This fix looks to see if the wallpaper target is animating and if it
is to treat it as null for the purpose of determining which direction
the animation should go.

Fixes bug 6407941.

Change-Id: I731267328db0f9972a5aed6f214962f96737dd07
diff --git a/services/java/com/android/server/wm/WindowStateAnimator.java b/services/java/com/android/server/wm/WindowStateAnimator.java
index 9147a10..2e38332 100644
--- a/services/java/com/android/server/wm/WindowStateAnimator.java
+++ b/services/java/com/android/server/wm/WindowStateAnimator.java
@@ -380,8 +380,9 @@
 
     boolean finishDrawingLocked() {
         if (mDrawState == DRAW_PENDING) {
-            if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
-                TAG, "finishDrawingLocked: " + this + " in " + mSurface);
+            if (DEBUG_ANIM || SHOW_TRANSACTIONS || DEBUG_ORIENTATION) Slog.v(
+                TAG, "finishDrawingLocked: mDrawState=COMMIT_DRAW_PENDING " + this + " in "
+                        + mSurface);
             mDrawState = COMMIT_DRAW_PENDING;
             return true;
         }
@@ -393,7 +394,8 @@
         if (mDrawState != COMMIT_DRAW_PENDING) {
             return false;
         }
-        //Slog.i(TAG, "commitFinishDrawingLocked: Draw pending. " + mSurface);
+        if (DEBUG_ANIM)
+            Slog.i(TAG, "commitFinishDrawingLocked: mDrawState=READY_TO_SHOW " + mSurface);
         mDrawState = READY_TO_SHOW;
         final boolean starting = mWin.mAttrs.type == TYPE_APPLICATION_STARTING;
         final AppWindowToken atoken = mWin.mAppToken;
@@ -526,8 +528,8 @@
         if (mSurface == null) {
             mReportDestroySurface = false;
             mSurfacePendingDestroy = false;
-            if (DEBUG_ORIENTATION) Slog.i(TAG,
-                    "createSurface " + this + ": DRAW NOW PENDING");
+            if (DEBUG_ANIM || DEBUG_ORIENTATION) Slog.i(TAG,
+                    "createSurface " + this + ": mDrawState=DRAW_PENDING");
             mDrawState = DRAW_PENDING;
             if (mWin.mAppToken != null) {
                 mWin.mAppToken.allDrawn = false;
@@ -1062,6 +1064,9 @@
                 }
             }
         } else {
+            if (DEBUG_ANIM) {
+                Slog.v(TAG, "prepareSurface: No changes in animation for " + mWin);
+            }
             displayed = true;
         }
 
@@ -1145,6 +1150,7 @@
 
             // Force the show in the next prepareSurfaceLocked() call.
             mLastAlpha = -1;
+            if (DEBUG_ANIM) Slog.v(TAG, "performShowLocked: mDrawState=HAS_DRAWN");
             mDrawState = HAS_DRAWN;
             mService.scheduleAnimationLocked();
 
@@ -1285,7 +1291,7 @@
                     + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
                     + " a=" + a
                     + " mAnimation=" + mAnimation
-                    + " isEntrance=" + isEntrance);
+                    + " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3));
             if (a != null) {
                 if (WindowManagerService.DEBUG_ANIM) {
                     RuntimeException e = null;