Eliminate wallpaper exposure during transition.

Make sure that the wallpaper target exists and is visible before
exposing the wallpaper.

Fixes bug 6570335.

Change-Id: I1dddfe26683e84fd813e7bee884ba2bd4bb85272
diff --git a/services/java/com/android/server/wm/WindowAnimator.java b/services/java/com/android/server/wm/WindowAnimator.java
index d6954a5..d25a960 100644
--- a/services/java/com/android/server/wm/WindowAnimator.java
+++ b/services/java/com/android/server/wm/WindowAnimator.java
@@ -489,7 +489,11 @@
 
             final int N = mWinAnimators.size();
             for (int i = 0; i < N; i++) {
-                mWinAnimators.get(i).prepareSurfaceLocked(true);
+                final WindowStateAnimator winAnimator = mWinAnimators.get(i);
+                if (winAnimator.mWin.mIsWallpaper && mService.mWallpaperTarget == null) {
+                    continue;
+                }
+                winAnimator.prepareSurfaceLocked(true);
             }
 
             if (mDimParams != null) {
diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java
index 9257028..5f63934 100755
--- a/services/java/com/android/server/wm/WindowManagerService.java
+++ b/services/java/com/android/server/wm/WindowManagerService.java
@@ -8553,7 +8553,7 @@
                     handleNotObscuredLocked(w, currentTime, innerDw, innerDh);
                 }
 
-                if (obscuredChanged && mWallpaperTarget == w) {
+                if (obscuredChanged && (mWallpaperTarget == w) && w.isVisibleLw()) {
                     // This is the wallpaper target and its obscured state
                     // changed... make sure the current wallaper's visibility
                     // has been updated accordingly.
diff --git a/services/java/com/android/server/wm/WindowStateAnimator.java b/services/java/com/android/server/wm/WindowStateAnimator.java
index affe5d4..485f4a7 100644
--- a/services/java/com/android/server/wm/WindowStateAnimator.java
+++ b/services/java/com/android/server/wm/WindowStateAnimator.java
@@ -381,6 +381,7 @@
         }
         if (mService.mWallpaperTarget == mWin && mService.mLowerWallpaperTarget == null) {
             mAnimator.hideWallpapersLocked();
+            mAnimator.mPendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
         }
     }
 
@@ -1105,8 +1106,8 @@
                 try {
                     mSurfaceAlpha = mShownAlpha;
                     mSurface.setAlpha(mShownAlpha);
-                    mSurfaceLayer = w.mWinAnimator.mAnimLayer;
-                    mSurface.setLayer(w.mWinAnimator.mAnimLayer);
+                    mSurfaceLayer = mAnimLayer;
+                    mSurface.setLayer(mAnimLayer);
                     mSurface.setMatrix(
                         mDsDx*w.mHScale, mDtDx*w.mVScale,
                         mDsDy*w.mHScale, mDtDy*w.mVScale);