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/WindowAnimator.java b/services/java/com/android/server/wm/WindowAnimator.java
index d25a960..b5cf2013 100644
--- a/services/java/com/android/server/wm/WindowAnimator.java
+++ b/services/java/com/android/server/wm/WindowAnimator.java
@@ -85,12 +85,19 @@
         mPolicy = policy;
     }
 
-    void hideWallpapersLocked() {
-        for (final WindowToken token : mService.mWallpaperTokens) {
-            for (final WindowState wallpaper : token.windows) {
-                wallpaper.mWinAnimator.hide();
+    void hideWallpapersLocked(final WindowState w) {
+        if ((mService.mWallpaperTarget == w && mService.mLowerWallpaperTarget == null)
+                || mService.mWallpaperTarget == null) {
+            for (final WindowToken token : mService.mWallpaperTokens) {
+                for (final WindowState wallpaper : token.windows) {
+                    final WindowStateAnimator winAnimator = wallpaper.mWinAnimator;
+                    if (!winAnimator.mLastHidden) {
+                        winAnimator.hide();
+                        mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
+                    }
+                }
+                token.hidden = true;
             }
-            token.hidden = true;
         }
     }
 
@@ -491,6 +498,10 @@
             for (int i = 0; i < N; i++) {
                 final WindowStateAnimator winAnimator = mWinAnimators.get(i);
                 if (winAnimator.mWin.mIsWallpaper && mService.mWallpaperTarget == null) {
+                    if (!winAnimator.mWin.mWallpaperVisible && !winAnimator.mLastHidden) {
+                        // Wallpaper is no longer visible and there is no wp target => hide it.
+                        winAnimator.hide();
+                    }
                     continue;
                 }
                 winAnimator.prepareSurfaceLocked(true);