Fix exposing wallpaper on rotations and other.

1. Rotations do not go through standard closing of animations so the
wallpaper was not being hidden when the wallpaper target surface was
destroyed. This fix adds hiding the wallpaper when the wallpaper
target is destroyed.

2. The wallpaper target is nulled when switching from launcher home
screen to launcher all apps. In this case the wallpaper remains
visible but below visible layers. It should be hidden so that when
those layers adjust it is not exposed. (Separate fix for adjusting
wallpaper in this case will come).

Fixes bug 6629464.

Change-Id: I522f97dafc0cdcc0f933a825ec9a29d8f63590b5
diff --git a/services/java/com/android/server/wm/WindowStateAnimator.java b/services/java/com/android/server/wm/WindowStateAnimator.java
index 5908958..d140aca 100644
--- a/services/java/com/android/server/wm/WindowStateAnimator.java
+++ b/services/java/com/android/server/wm/WindowStateAnimator.java
@@ -16,7 +16,6 @@
 import android.graphics.Rect;
 import android.graphics.Region;
 import android.os.Debug;
-import android.os.RemoteException;
 import android.util.Slog;
 import android.view.Surface;
 import android.view.SurfaceSession;
@@ -379,10 +378,7 @@
             mService.mPendingRemove.add(mWin);
             mWin.mRemoveOnExit = false;
         }
-        if (mService.mWallpaperTarget == mWin && mService.mLowerWallpaperTarget == null) {
-            mAnimator.hideWallpapersLocked();
-            mAnimator.mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
-        }
+        mAnimator.hideWallpapersLocked(mWin);
     }
 
     void hide() {
@@ -738,6 +734,7 @@
                     }
                     mSurface.destroy();
                 }
+                mAnimator.hideWallpapersLocked(mWin);
             } catch (RuntimeException e) {
                 Slog.w(TAG, "Exception thrown when destroying Window " + this
                     + " surface " + mSurface + " session " + mSession
@@ -763,6 +760,7 @@
                     WindowManagerService.logSurface(mWin, "DESTROY PENDING", e);
                 }
                 mPendingDestroySurface.destroy();
+                mAnimator.hideWallpapersLocked(mWin);
             }
         } catch (RuntimeException e) {
             Slog.w(TAG, "Exception thrown when destroying Window "
@@ -1067,11 +1065,8 @@
 
         if (w.mAttachedHidden || !w.isReadyForDisplay()) {
             hide();
-            // TODO: Consider moving the following into hide() and out of finishExit() as well.
-            if (mService.mWallpaperTarget == mWin && mService.mLowerWallpaperTarget == null) {
-                mAnimator.hideWallpapersLocked();
-                mAnimator.mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
-            }
+            mAnimator.hideWallpapersLocked(w);
+
             // If we are waiting for this window to handle an
             // orientation change, well, it is hidden, so
             // doesn't really matter.  Note that this does