Removed WindowManagerService.getWindowListLocked()

3rd step in trying to make the WindowList private to DisplayContent.
The method was another an indirect way to the the window list
from the display content.

Test: Manual testing and existing tests pass.
Change-Id: Ifb0548a91b5bc64461e14f63256b61b8fa5e2e0c
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 2288d1e..9a638a2 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -292,6 +292,7 @@
 import static android.provider.Settings.Global.WAIT_FOR_DEBUGGER;
 import static android.provider.Settings.System.FONT_SCALE;
 import static android.util.TypedValue.COMPLEX_UNIT_DIP;
+import static android.view.Display.DEFAULT_DISPLAY;
 import static com.android.internal.util.XmlUtils.readBooleanAttribute;
 import static com.android.internal.util.XmlUtils.readIntAttribute;
 import static com.android.internal.util.XmlUtils.readLongAttribute;
@@ -7681,7 +7682,7 @@
                 mDefaultPinnedStackScreenEdgeInsetsDp.getHeight(), dm);
         try {
             final Rect insets = new Rect();
-            final DisplayInfo info = mWindowManager.getDefaultDisplayInfoLocked();
+            final DisplayInfo info = mStackSupervisor.getDisplayInfo(DEFAULT_DISPLAY);
             mWindowManager.getStableInsets(insets);
 
             // Calculate the insets from the system decorations and apply the gravity
@@ -9899,7 +9900,7 @@
             if (stack != null && stack.mActivityContainer.isAttachedLocked()) {
                 return stack.mActivityContainer.getDisplayId();
             }
-            return Display.DEFAULT_DISPLAY;
+            return DEFAULT_DISPLAY;
         }
     }
 
diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
index 63a4e86..a111230 100644
--- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java
+++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
@@ -3393,6 +3393,10 @@
         mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_CHANGED, displayId, 0));
     }
 
+    DisplayInfo getDisplayInfo(int displayId) {
+        return mActivityDisplays.get(displayId).mDisplayInfo;
+    }
+
     private void handleDisplayAdded(int displayId) {
         boolean newDisplay;
         synchronized (mService) {
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index e6f281d..fab0b29 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -36,6 +36,7 @@
 import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
 import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
 import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
+import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
 import static android.view.WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
 import static android.view.WindowManager.LayoutParams.NEEDS_MENU_UNSET;
 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
@@ -43,22 +44,40 @@
 import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
 import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
 import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
+import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
+import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
+import static android.view.WindowManagerPolicy.KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS;
+import static android.view.WindowManagerPolicy.KEYGUARD_GOING_AWAY_FLAG_TO_SHADE;
+import static android.view.WindowManagerPolicy.KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER;
+import static com.android.server.wm.WindowAnimator.KEYGUARD_ANIMATING_OUT;
+import static com.android.server.wm.WindowAnimator.KEYGUARD_ANIM_TIMEOUT_MS;
+import static com.android.server.wm.WindowAnimator.KEYGUARD_NOT_SHOWN;
+import static com.android.server.wm.WindowAnimator.KEYGUARD_SHOWN;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT_METHOD;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_KEYGUARD;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYERS;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_MOVEMENT;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
 import static com.android.server.wm.WindowManagerDebugConfig.SHOW_STACK_CRAWLS;
+import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
 import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
 import static com.android.server.wm.WindowManagerService.H.WINDOW_HIDE_TIMEOUT;
 import static com.android.server.wm.WindowManagerService.dipToPixel;
 import static com.android.server.wm.WindowManagerService.localLOGV;
 import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
+import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
+import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM;
+import static com.android.server.wm.WindowSurfacePlacer.SET_FORCE_HIDING_CHANGED;
+import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
 
 import android.annotation.NonNull;
 import android.app.ActivityManager.StackId;
@@ -79,6 +98,8 @@
 import android.view.IWindow;
 import android.view.WindowManager;
 import android.view.WindowManagerPolicy;
+import android.view.animation.AlphaAnimation;
+import android.view.animation.Animation;
 
 import com.android.internal.util.FastPrintWriter;
 
@@ -100,6 +121,7 @@
  * WindowManagerService.mWindowMap.
  */
 class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> {
+    private static final String TAG = TAG_WITH_CLASS_NAME ? "DisplayContent" : TAG_WM;
 
     /** Unique identifier of this stack. */
     private final int mDisplayId;
@@ -1797,6 +1819,14 @@
         }
     }
 
+    void dumpWindowAnimators(PrintWriter pw, String subPrefix) {
+        final int count = mWindows.size();
+        for (int j = 0; j < count; j++) {
+            final WindowStateAnimator wAnim = mWindows.get(j).mWinAnimator;
+            pw.println(subPrefix + "Window #" + j + ": " + wAnim);
+        }
+    }
+
     void enableSurfaceTrace(FileDescriptor fd) {
         for (int i = mWindows.size() - 1; i >= 0; i--) {
             final WindowState win = mWindows.get(i);
@@ -1811,6 +1841,365 @@
         }
     }
 
+    void updateWindowsForAnimator(WindowAnimator animator) {
+        final WindowManagerPolicy policy = animator.mPolicy;
+        final int keyguardGoingAwayFlags = animator.mKeyguardGoingAwayFlags;
+        final boolean keyguardGoingAwayToShade =
+                (keyguardGoingAwayFlags & KEYGUARD_GOING_AWAY_FLAG_TO_SHADE) != 0;
+        final boolean keyguardGoingAwayNoAnimation =
+                (keyguardGoingAwayFlags & KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS) != 0;
+        final boolean keyguardGoingAwayWithWallpaper =
+                (keyguardGoingAwayFlags & KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER) != 0;
+
+        if (animator.mKeyguardGoingAway) {
+            for (int i = mWindows.size() - 1; i >= 0; i--) {
+                WindowState win = mWindows.get(i);
+                if (!policy.isKeyguardHostWindow(win.mAttrs)) {
+                    continue;
+                }
+                final WindowStateAnimator winAnimator = win.mWinAnimator;
+                if (policy.isKeyguardShowingAndNotOccluded()) {
+                    if (!winAnimator.mAnimating) {
+                        if (DEBUG_KEYGUARD) Slog.d(TAG,
+                                "updateWindowsForAnimator: creating delay animation");
+
+                        // Create a new animation to delay until keyguard is gone on its own.
+                        winAnimator.mAnimation = new AlphaAnimation(1.0f, 1.0f);
+                        winAnimator.mAnimation.setDuration(KEYGUARD_ANIM_TIMEOUT_MS);
+                        winAnimator.mAnimationIsEntrance = false;
+                        winAnimator.mAnimationStartTime = -1;
+                        winAnimator.mKeyguardGoingAwayAnimation = true;
+                        winAnimator.mKeyguardGoingAwayWithWallpaper
+                                = keyguardGoingAwayWithWallpaper;
+                    }
+                } else {
+                    if (DEBUG_KEYGUARD) Slog.d(TAG,
+                            "updateWindowsForAnimator: StatusBar is no longer keyguard");
+                    animator.mKeyguardGoingAway = false;
+                    winAnimator.clearAnimation();
+                }
+                break;
+            }
+        }
+
+        animator.mForceHiding = KEYGUARD_NOT_SHOWN;
+
+        boolean wallpaperInUnForceHiding = false;
+        boolean startingInUnForceHiding = false;
+        ArrayList<WindowStateAnimator> unForceHiding = null;
+        WindowState wallpaper = null;
+        final WallpaperController wallpaperController = mService.mWallpaperControllerLocked;
+        for (int i = mWindows.size() - 1; i >= 0; i--) {
+            WindowState win = mWindows.get(i);
+            WindowStateAnimator winAnimator = win.mWinAnimator;
+            final int flags = win.mAttrs.flags;
+            boolean canBeForceHidden = policy.canBeForceHidden(win, win.mAttrs);
+            boolean shouldBeForceHidden = animator.shouldForceHide(win);
+            if (winAnimator.hasSurface()) {
+                final boolean wasAnimating = winAnimator.mWasAnimating;
+                final boolean nowAnimating = winAnimator.stepAnimationLocked(animator.mCurrentTime);
+                winAnimator.mWasAnimating = nowAnimating;
+                animator.orAnimating(nowAnimating);
+
+                if (DEBUG_WALLPAPER) Slog.v(TAG,
+                        win + ": wasAnimating=" + wasAnimating + ", nowAnimating=" + nowAnimating);
+
+                if (wasAnimating && !winAnimator.mAnimating
+                        && wallpaperController.isWallpaperTarget(win)) {
+                    animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
+                    pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
+                    if (DEBUG_LAYOUT_REPEATS) {
+                        mService.mWindowPlacerLocked.debugLayoutRepeats(
+                                "updateWindowsAndWallpaperLocked 2", pendingLayoutChanges);
+                    }
+                }
+
+                if (policy.isForceHiding(win.mAttrs)) {
+                    if (!wasAnimating && nowAnimating) {
+                        if (DEBUG_KEYGUARD || DEBUG_ANIM || DEBUG_VISIBILITY) Slog.v(TAG,
+                                "Animation started that could impact force hide: " + win);
+                        animator.mBulkUpdateParams |= SET_FORCE_HIDING_CHANGED;
+                        pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
+                        if (DEBUG_LAYOUT_REPEATS) {
+                            mService.mWindowPlacerLocked.debugLayoutRepeats(
+                                    "updateWindowsAndWallpaperLocked 3", pendingLayoutChanges);
+                        }
+                        mService.mFocusMayChange = true;
+                    } else if (animator.mKeyguardGoingAway && !nowAnimating) {
+                        // Timeout!!
+                        Slog.e(TAG, "Timeout waiting for animation to startup");
+                        policy.startKeyguardExitAnimation(0, 0);
+                        animator.mKeyguardGoingAway = false;
+                    }
+                    if (win.isReadyForDisplay()) {
+                        if (nowAnimating && win.mWinAnimator.mKeyguardGoingAwayAnimation) {
+                            animator.mForceHiding = KEYGUARD_ANIMATING_OUT;
+                        } else {
+                            animator.mForceHiding = win.isDrawnLw()
+                                    ? KEYGUARD_SHOWN : KEYGUARD_NOT_SHOWN;
+                        }
+                    }
+                    if (DEBUG_KEYGUARD || DEBUG_VISIBILITY) Slog.v(TAG,
+                            "Force hide " + animator.forceHidingToString()
+                                    + " hasSurface=" + win.mHasSurface
+                                    + " policyVis=" + win.mPolicyVisibility
+                                    + " destroying=" + win.mDestroying
+                                    + " parentHidden=" + win.isParentWindowHidden()
+                                    + " vis=" + win.mViewVisibility
+                                    + " hidden=" + win.mToken.hidden
+                                    + " anim=" + win.mWinAnimator.mAnimation);
+                } else if (canBeForceHidden) {
+                    if (shouldBeForceHidden) {
+                        if (!win.hideLw(false, false)) {
+                            // Was already hidden
+                            continue;
+                        }
+                        if (DEBUG_KEYGUARD || DEBUG_VISIBILITY) Slog.v(TAG,
+                                "Now policy hidden: " + win);
+                    } else {
+                        final Animation postKeyguardExitAnimation =
+                                animator.mPostKeyguardExitAnimation;
+                        boolean applyExistingExitAnimation = postKeyguardExitAnimation != null
+                                && !postKeyguardExitAnimation.hasEnded()
+                                && !winAnimator.mKeyguardGoingAwayAnimation
+                                && win.hasDrawnLw()
+                                && !win.isChildWindow()
+                                && !win.mIsImWindow
+                                && isDefaultDisplay;
+
+                        // If the window is already showing and we don't need to apply an existing
+                        // Keyguard exit animation, skip.
+                        if (!win.showLw(false, false) && !applyExistingExitAnimation) {
+                            continue;
+                        }
+                        final boolean visibleNow = win.isVisibleNow();
+                        if (!visibleNow) {
+                            // Couldn't really show, must showLw() again when win becomes visible.
+                            win.hideLw(false, false);
+                            continue;
+                        }
+                        if (DEBUG_KEYGUARD || DEBUG_VISIBILITY) Slog.v(TAG,
+                                "Now policy shown: " + win);
+                        if ((animator.mBulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0
+                                && !win.isChildWindow()) {
+                            if (unForceHiding == null) {
+                                unForceHiding = new ArrayList<>();
+                            }
+                            unForceHiding.add(winAnimator);
+                            if ((flags & FLAG_SHOW_WALLPAPER) != 0) {
+                                wallpaperInUnForceHiding = true;
+                            }
+                            if (win.mAttrs.type == TYPE_APPLICATION_STARTING) {
+                                startingInUnForceHiding = true;
+                            }
+                        } else if (applyExistingExitAnimation) {
+                            // We're already in the middle of an animation. Use the existing
+                            // animation to bring in this window.
+                            if (DEBUG_KEYGUARD) Slog.v(TAG,
+                                    "Applying existing Keyguard exit animation to new window: win="
+                                            + win);
+
+                            final Animation a = policy.createForceHideEnterAnimation(false,
+                                    keyguardGoingAwayToShade);
+                            winAnimator.setAnimation(a, postKeyguardExitAnimation.getStartTime(),
+                                    STACK_CLIP_BEFORE_ANIM);
+                            winAnimator.mKeyguardGoingAwayAnimation = true;
+                            winAnimator.mKeyguardGoingAwayWithWallpaper
+                                    = keyguardGoingAwayWithWallpaper;
+                        }
+                        final WindowState currentFocus = mService.mCurrentFocus;
+                        if (currentFocus == null || currentFocus.mLayer < win.mLayer) {
+                            // We are showing on top of the current
+                            // focus, so re-evaluate focus to make
+                            // sure it is correct.
+                            if (DEBUG_FOCUS_LIGHT) Slog.v(TAG,
+                                    "updateWindowsForAnimator: setting mFocusMayChange true");
+                            mService.mFocusMayChange = true;
+                        }
+                    }
+                    if ((flags & FLAG_SHOW_WALLPAPER) != 0) {
+                        animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
+                        pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
+                        if (DEBUG_LAYOUT_REPEATS) {
+                            mService.mWindowPlacerLocked.debugLayoutRepeats(
+                                    "updateWindowsAndWallpaperLocked 4", pendingLayoutChanges);
+                        }
+                    }
+                }
+            }
+
+            // If the window doesn't have a surface, the only thing we care about is the correct
+            // policy visibility.
+            else if (canBeForceHidden) {
+                if (shouldBeForceHidden) {
+                    win.hideLw(false, false);
+                } else {
+                    win.showLw(false, false);
+                }
+            }
+
+            final AppWindowToken atoken = win.mAppToken;
+            if (winAnimator.mDrawState == READY_TO_SHOW) {
+                if (atoken == null || atoken.allDrawn) {
+                    if (win.performShowLocked()) {
+                        pendingLayoutChanges |= FINISH_LAYOUT_REDO_ANIM;
+                        if (DEBUG_LAYOUT_REPEATS) {
+                            mService.mWindowPlacerLocked.debugLayoutRepeats(
+                                    "updateWindowsAndWallpaperLocked 5", pendingLayoutChanges);
+                        }
+                    }
+                }
+            }
+            final AppWindowAnimator appAnimator = winAnimator.mAppAnimator;
+            if (appAnimator != null && appAnimator.thumbnail != null) {
+                if (appAnimator.thumbnailTransactionSeq != animator.mAnimTransactionSequence) {
+                    appAnimator.thumbnailTransactionSeq = animator.mAnimTransactionSequence;
+                    appAnimator.thumbnailLayer = 0;
+                }
+                if (appAnimator.thumbnailLayer < winAnimator.mAnimLayer) {
+                    appAnimator.thumbnailLayer = winAnimator.mAnimLayer;
+                }
+            }
+            if (win.mIsWallpaper) {
+                wallpaper = win;
+            }
+        } // end forall windows
+
+        // If we have windows that are being shown due to them no longer being force-hidden, apply
+        // the appropriate animation to them if animations are not disabled.
+        if (unForceHiding != null) {
+            if (!keyguardGoingAwayNoAnimation) {
+                boolean first = true;
+                for (int i=unForceHiding.size()-1; i>=0; i--) {
+                    final WindowStateAnimator winAnimator = unForceHiding.get(i);
+                    final Animation a = policy.createForceHideEnterAnimation(
+                            wallpaperInUnForceHiding && !startingInUnForceHiding,
+                            keyguardGoingAwayToShade);
+                    if (a != null) {
+                        if (DEBUG_KEYGUARD) Slog.v(TAG,
+                                "Starting keyguard exit animation on window " + winAnimator.mWin);
+                        winAnimator.setAnimation(a, STACK_CLIP_BEFORE_ANIM);
+                        winAnimator.mKeyguardGoingAwayAnimation = true;
+                        winAnimator.mKeyguardGoingAwayWithWallpaper
+                                = keyguardGoingAwayWithWallpaper;
+                        if (first) {
+                            animator.mPostKeyguardExitAnimation = a;
+                            animator.mPostKeyguardExitAnimation.setStartTime(animator.mCurrentTime);
+                            first = false;
+                        }
+                    }
+                }
+            } else if (animator.mKeyguardGoingAway) {
+                policy.startKeyguardExitAnimation(animator.mCurrentTime, 0 /* duration */);
+                animator.mKeyguardGoingAway = false;
+            }
+
+
+            // Wallpaper is going away in un-force-hide motion, animate it as well.
+            if (!wallpaperInUnForceHiding && wallpaper != null && !keyguardGoingAwayNoAnimation) {
+                if (DEBUG_KEYGUARD) Slog.d(TAG,
+                        "updateWindowsForAnimator: wallpaper animating away");
+                final Animation a = policy.createForceHideWallpaperExitAnimation(
+                        keyguardGoingAwayToShade);
+                if (a != null) {
+                    wallpaper.mWinAnimator.setAnimation(a);
+                }
+            }
+        }
+
+        if (animator.mPostKeyguardExitAnimation != null) {
+            // We're in the midst of a keyguard exit animation.
+            if (animator.mKeyguardGoingAway) {
+                policy.startKeyguardExitAnimation(animator.mCurrentTime +
+                                animator.mPostKeyguardExitAnimation.getStartOffset(),
+                        animator.mPostKeyguardExitAnimation.getDuration());
+                animator.mKeyguardGoingAway = false;
+            }
+            // mPostKeyguardExitAnimation might either be ended normally, cancelled, or "orphaned",
+            // meaning that the window it was running on was removed. We check for hasEnded() for
+            // ended normally and cancelled case, and check the time for the "orphaned" case.
+            else if (animator.mPostKeyguardExitAnimation.hasEnded()
+                    || animator.mCurrentTime - animator.mPostKeyguardExitAnimation.getStartTime()
+                    > animator.mPostKeyguardExitAnimation.getDuration()) {
+                // Done with the animation, reset.
+                if (DEBUG_KEYGUARD) Slog.v(TAG, "Done with Keyguard exit animations.");
+                animator.mPostKeyguardExitAnimation = null;
+            }
+        }
+
+        final WindowState winShowWhenLocked = (WindowState) policy.getWinShowWhenLockedLw();
+        if (winShowWhenLocked != null) {
+            animator.mLastShowWinWhenLocked = winShowWhenLocked;
+        }
+    }
+
+    void updateWallpaperForAnimator(WindowAnimator animator) {
+        final WindowList windows = mWindows;
+        WindowState detachedWallpaper = null;
+
+        for (int i = windows.size() - 1; i >= 0; i--) {
+            final WindowState win = windows.get(i);
+            final WindowStateAnimator winAnimator = win.mWinAnimator;
+            if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
+                continue;
+            }
+
+            final int flags = win.mAttrs.flags;
+
+            // If this window is animating, make a note that we have an animating window and take
+            // care of a request to run a detached wallpaper animation.
+            if (winAnimator.mAnimating) {
+                if (winAnimator.mAnimation != null) {
+                    if ((flags & FLAG_SHOW_WALLPAPER) != 0
+                            && winAnimator.mAnimation.getDetachWallpaper()) {
+                        detachedWallpaper = win;
+                    }
+                    final int color = winAnimator.mAnimation.getBackgroundColor();
+                    if (color != 0) {
+                        final TaskStack stack = win.getStack();
+                        if (stack != null) {
+                            stack.setAnimationBackground(winAnimator, color);
+                        }
+                    }
+                }
+                animator.setAnimating(true);
+            }
+
+            // If this window's app token is running a detached wallpaper animation, make a note so
+            // we can ensure the wallpaper is displayed behind it.
+            final AppWindowAnimator appAnimator = winAnimator.mAppAnimator;
+            if (appAnimator != null && appAnimator.animation != null
+                    && appAnimator.animating) {
+                if ((flags & FLAG_SHOW_WALLPAPER) != 0
+                        && appAnimator.animation.getDetachWallpaper()) {
+                    detachedWallpaper = win;
+                }
+
+                final int color = appAnimator.animation.getBackgroundColor();
+                if (color != 0) {
+                    final TaskStack stack = win.getStack();
+                    if (stack != null) {
+                        stack.setAnimationBackground(winAnimator, color);
+                    }
+                }
+            }
+        } // end forall windows
+
+        if (animator.mWindowDetachedWallpaper != detachedWallpaper) {
+            if (DEBUG_WALLPAPER) Slog.v(TAG, "Detached wallpaper changed from "
+                    + animator.mWindowDetachedWallpaper + " to " + detachedWallpaper);
+            animator.mWindowDetachedWallpaper = detachedWallpaper;
+            animator.mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
+        }
+    }
+
+    void prepareWindowSurfaces() {
+        final int count = mWindows.size();
+        for (int j = 0; j < count; j++) {
+            mWindows.get(j).mWinAnimator.prepareSurfaceLocked(true);
+        }
+    }
+
     static final class GetWindowOnDisplaySearchResult {
         boolean reachedToken;
         WindowState foundWindow;
diff --git a/services/core/java/com/android/server/wm/WindowAnimator.java b/services/core/java/com/android/server/wm/WindowAnimator.java
index fb6b09a..4c62245 100644
--- a/services/core/java/com/android/server/wm/WindowAnimator.java
+++ b/services/core/java/com/android/server/wm/WindowAnimator.java
@@ -16,28 +16,17 @@
 
 package com.android.server.wm;
 
+import static android.view.Display.DEFAULT_DISPLAY;
 import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
 import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
 import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
 import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR;
-import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
 import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
-import static android.view.WindowManagerPolicy.KEYGUARD_GOING_AWAY_FLAG_TO_SHADE;
-import static android.view.WindowManagerPolicy.KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS;
-import static android.view.WindowManagerPolicy.KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ANIM;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_KEYGUARD;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WINDOW_TRACE;
 import static com.android.server.wm.WindowManagerDebugConfig.SHOW_TRANSACTIONS;
 import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
 import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
-import static com.android.server.wm.WindowStateAnimator.READY_TO_SHOW;
-import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM;
-import static com.android.server.wm.WindowSurfacePlacer.SET_FORCE_HIDING_CHANGED;
 import static com.android.server.wm.WindowSurfacePlacer.SET_ORIENTATION_CHANGE_COMPLETE;
 import static com.android.server.wm.WindowSurfacePlacer.SET_UPDATE_ROTATION;
 import static com.android.server.wm.WindowSurfacePlacer.SET_WALLPAPER_MAY_CHANGE;
@@ -48,14 +37,11 @@
 import android.util.SparseArray;
 import android.util.TimeUtils;
 import android.view.Choreographer;
-import android.view.Display;
 import android.view.SurfaceControl;
 import android.view.WindowManagerPolicy;
-import android.view.animation.AlphaAnimation;
 import android.view.animation.Animation;
 
 import java.io.PrintWriter;
-import java.util.ArrayList;
 
 /**
  * Singleton class that carries out the animations and Surface operations in a separate task
@@ -65,7 +51,7 @@
     private static final String TAG = TAG_WITH_CLASS_NAME ? "WindowAnimator" : TAG_WM;
 
     /** How long to give statusbar to clear the private keyguard flag when animating out */
-    private static final long KEYGUARD_ANIM_TIMEOUT_MS = 1000;
+    static final long KEYGUARD_ANIM_TIMEOUT_MS = 1000;
 
     final WindowManagerService mService;
     final Context mContext;
@@ -85,7 +71,7 @@
 
     /** Skip repeated AppWindowTokens initialization. Note that AppWindowsToken's version of this
      * is a long initialized to Long.MIN_VALUE so that it doesn't match this value on startup. */
-    private int mAnimTransactionSequence;
+    int mAnimTransactionSequence;
 
     /** Window currently running an animation that has requested it be detached
      * from the wallpaper.  This means we need to ensure the wallpaper is
@@ -120,9 +106,9 @@
     private final AppTokenList mTmpExitingAppTokens = new AppTokenList();
 
     /** The window that was previously hiding the Keyguard. */
-    private WindowState mLastShowWinWhenLocked;
+    WindowState mLastShowWinWhenLocked;
 
-    private String forceHidingToString() {
+    String forceHidingToString() {
         switch (mForceHiding) {
             case KEYGUARD_NOT_SHOWN:    return "KEYGUARD_NOT_SHOWN";
             case KEYGUARD_SHOWN:        return "KEYGUARD_SHOWN";
@@ -150,7 +136,7 @@
     void addDisplayLocked(final int displayId) {
         // Create the DisplayContentsAnimator object by retrieving it.
         getDisplayContentsAnimatorLocked(displayId);
-        if (displayId == Display.DEFAULT_DISPLAY) {
+        if (displayId == DEFAULT_DISPLAY) {
             mInitialized = true;
         }
     }
@@ -184,7 +170,7 @@
         return null;
     }
 
-    private boolean shouldForceHide(WindowState win) {
+    boolean shouldForceHide(WindowState win) {
         final WindowState imeTarget = mService.mInputMethodTarget;
         final boolean showImeOverKeyguard = imeTarget != null && imeTarget.isVisibleNow() &&
                 ((imeTarget.getAttrs().flags & FLAG_SHOW_WHEN_LOCKED) != 0
@@ -220,377 +206,10 @@
                 && !mKeyguardAnimatingIn;
         boolean hideDockDivider = win.mAttrs.type == TYPE_DOCK_DIVIDER
                 && win.getDisplayContent().getDockedStackLocked() == null;
-        return keyguardOn && !allowWhenLocked && (win.getDisplayId() == Display.DEFAULT_DISPLAY)
+        return keyguardOn && !allowWhenLocked && (win.getDisplayId() == DEFAULT_DISPLAY)
                 || hideDockDivider;
     }
 
-    private void updateWindowsLocked(final int displayId) {
-        ++mAnimTransactionSequence;
-
-        final WindowList windows = mService.getWindowListLocked(displayId);
-
-        final boolean keyguardGoingAwayToShade =
-                (mKeyguardGoingAwayFlags & KEYGUARD_GOING_AWAY_FLAG_TO_SHADE) != 0;
-        final boolean keyguardGoingAwayNoAnimation =
-                (mKeyguardGoingAwayFlags & KEYGUARD_GOING_AWAY_FLAG_NO_WINDOW_ANIMATIONS) != 0;
-        final boolean keyguardGoingAwayWithWallpaper =
-                (mKeyguardGoingAwayFlags & KEYGUARD_GOING_AWAY_FLAG_WITH_WALLPAPER) != 0;
-
-        if (mKeyguardGoingAway) {
-            for (int i = windows.size() - 1; i >= 0; i--) {
-                WindowState win = windows.get(i);
-                if (!mPolicy.isKeyguardHostWindow(win.mAttrs)) {
-                    continue;
-                }
-                final WindowStateAnimator winAnimator = win.mWinAnimator;
-                if (mPolicy.isKeyguardShowingAndNotOccluded()) {
-                    if (!winAnimator.mAnimating) {
-                        if (DEBUG_KEYGUARD) Slog.d(TAG,
-                                "updateWindowsLocked: creating delay animation");
-
-                        // Create a new animation to delay until keyguard is gone on its own.
-                        winAnimator.mAnimation = new AlphaAnimation(1.0f, 1.0f);
-                        winAnimator.mAnimation.setDuration(KEYGUARD_ANIM_TIMEOUT_MS);
-                        winAnimator.mAnimationIsEntrance = false;
-                        winAnimator.mAnimationStartTime = -1;
-                        winAnimator.mKeyguardGoingAwayAnimation = true;
-                        winAnimator.mKeyguardGoingAwayWithWallpaper
-                                = keyguardGoingAwayWithWallpaper;
-                    }
-                } else {
-                    if (DEBUG_KEYGUARD) Slog.d(TAG,
-                            "updateWindowsLocked: StatusBar is no longer keyguard");
-                    mKeyguardGoingAway = false;
-                    winAnimator.clearAnimation();
-                }
-                break;
-            }
-        }
-
-        mForceHiding = KEYGUARD_NOT_SHOWN;
-
-        boolean wallpaperInUnForceHiding = false;
-        boolean startingInUnForceHiding = false;
-        ArrayList<WindowStateAnimator> unForceHiding = null;
-        WindowState wallpaper = null;
-        final WallpaperController wallpaperController = mService.mWallpaperControllerLocked;
-        for (int i = windows.size() - 1; i >= 0; i--) {
-            WindowState win = windows.get(i);
-            WindowStateAnimator winAnimator = win.mWinAnimator;
-            final int flags = win.mAttrs.flags;
-            boolean canBeForceHidden = mPolicy.canBeForceHidden(win, win.mAttrs);
-            boolean shouldBeForceHidden = shouldForceHide(win);
-            if (winAnimator.hasSurface()) {
-                final boolean wasAnimating = winAnimator.mWasAnimating;
-                final boolean nowAnimating = winAnimator.stepAnimationLocked(mCurrentTime);
-                winAnimator.mWasAnimating = nowAnimating;
-                orAnimating(nowAnimating);
-
-                if (DEBUG_WALLPAPER) {
-                    Slog.v(TAG, win + ": wasAnimating=" + wasAnimating +
-                            ", nowAnimating=" + nowAnimating);
-                }
-
-                if (wasAnimating && !winAnimator.mAnimating
-                        && wallpaperController.isWallpaperTarget(win)) {
-                    mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
-                    setPendingLayoutChanges(Display.DEFAULT_DISPLAY,
-                            WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER);
-                    if (DEBUG_LAYOUT_REPEATS) {
-                        mWindowPlacerLocked.debugLayoutRepeats(
-                                "updateWindowsAndWallpaperLocked 2",
-                                getPendingLayoutChanges(Display.DEFAULT_DISPLAY));
-                    }
-                }
-
-                if (mPolicy.isForceHiding(win.mAttrs)) {
-                    if (!wasAnimating && nowAnimating) {
-                        if (DEBUG_KEYGUARD || DEBUG_ANIM ||
-                                DEBUG_VISIBILITY) Slog.v(TAG,
-                                "Animation started that could impact force hide: " + win);
-                        mBulkUpdateParams |= SET_FORCE_HIDING_CHANGED;
-                        setPendingLayoutChanges(displayId,
-                                WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER);
-                        if (DEBUG_LAYOUT_REPEATS) {
-                            mWindowPlacerLocked.debugLayoutRepeats(
-                                    "updateWindowsAndWallpaperLocked 3",
-                                    getPendingLayoutChanges(displayId));
-                        }
-                        mService.mFocusMayChange = true;
-                    } else if (mKeyguardGoingAway && !nowAnimating) {
-                        // Timeout!!
-                        Slog.e(TAG, "Timeout waiting for animation to startup");
-                        mPolicy.startKeyguardExitAnimation(0, 0);
-                        mKeyguardGoingAway = false;
-                    }
-                    if (win.isReadyForDisplay()) {
-                        if (nowAnimating && win.mWinAnimator.mKeyguardGoingAwayAnimation) {
-                            mForceHiding = KEYGUARD_ANIMATING_OUT;
-                        } else {
-                            mForceHiding = win.isDrawnLw() ? KEYGUARD_SHOWN : KEYGUARD_NOT_SHOWN;
-                        }
-                    }
-                    if (DEBUG_KEYGUARD || DEBUG_VISIBILITY) Slog.v(TAG,
-                            "Force hide " + forceHidingToString()
-                            + " hasSurface=" + win.mHasSurface
-                            + " policyVis=" + win.mPolicyVisibility
-                            + " destroying=" + win.mDestroying
-                            + " parentHidden=" + win.isParentWindowHidden()
-                            + " vis=" + win.mViewVisibility
-                            + " hidden=" + win.mToken.hidden
-                            + " anim=" + win.mWinAnimator.mAnimation);
-                } else if (canBeForceHidden) {
-                    if (shouldBeForceHidden) {
-                        if (!win.hideLw(false, false)) {
-                            // Was already hidden
-                            continue;
-                        }
-                        if (DEBUG_KEYGUARD || DEBUG_VISIBILITY) Slog.v(TAG,
-                                "Now policy hidden: " + win);
-                    } else {
-                        boolean applyExistingExitAnimation = mPostKeyguardExitAnimation != null
-                                && !mPostKeyguardExitAnimation.hasEnded()
-                                && !winAnimator.mKeyguardGoingAwayAnimation
-                                && win.hasDrawnLw()
-                                && !win.isChildWindow()
-                                && !win.mIsImWindow
-                                && displayId == Display.DEFAULT_DISPLAY;
-
-                        // If the window is already showing and we don't need to apply an existing
-                        // Keyguard exit animation, skip.
-                        if (!win.showLw(false, false) && !applyExistingExitAnimation) {
-                            continue;
-                        }
-                        final boolean visibleNow = win.isVisibleNow();
-                        if (!visibleNow) {
-                            // Couldn't really show, must showLw() again when win becomes visible.
-                            win.hideLw(false, false);
-                            continue;
-                        }
-                        if (DEBUG_KEYGUARD || DEBUG_VISIBILITY) Slog.v(TAG,
-                                "Now policy shown: " + win);
-                        if ((mBulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0
-                                && !win.isChildWindow()) {
-                            if (unForceHiding == null) {
-                                unForceHiding = new ArrayList<>();
-                            }
-                            unForceHiding.add(winAnimator);
-                            if ((flags & FLAG_SHOW_WALLPAPER) != 0) {
-                                wallpaperInUnForceHiding = true;
-                            }
-                            if (win.mAttrs.type == TYPE_APPLICATION_STARTING) {
-                                startingInUnForceHiding = true;
-                            }
-                        } else if (applyExistingExitAnimation) {
-                            // We're already in the middle of an animation. Use the existing
-                            // animation to bring in this window.
-                            if (DEBUG_KEYGUARD) Slog.v(TAG,
-                                    "Applying existing Keyguard exit animation to new window: win="
-                                            + win);
-
-                            Animation a = mPolicy.createForceHideEnterAnimation(false,
-                                    keyguardGoingAwayToShade);
-                            winAnimator.setAnimation(a, mPostKeyguardExitAnimation.getStartTime(),
-                                    STACK_CLIP_BEFORE_ANIM);
-                            winAnimator.mKeyguardGoingAwayAnimation = true;
-                            winAnimator.mKeyguardGoingAwayWithWallpaper
-                                    = keyguardGoingAwayWithWallpaper;
-                        }
-                        final WindowState currentFocus = mService.mCurrentFocus;
-                        if (currentFocus == null || currentFocus.mLayer < win.mLayer) {
-                            // We are showing on top of the current
-                            // focus, so re-evaluate focus to make
-                            // sure it is correct.
-                            if (DEBUG_FOCUS_LIGHT) Slog.v(TAG,
-                                    "updateWindowsLocked: setting mFocusMayChange true");
-                            mService.mFocusMayChange = true;
-                        }
-                    }
-                    if ((flags & FLAG_SHOW_WALLPAPER) != 0) {
-                        mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
-                        setPendingLayoutChanges(Display.DEFAULT_DISPLAY,
-                                WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER);
-                        if (DEBUG_LAYOUT_REPEATS) {
-                            mWindowPlacerLocked.debugLayoutRepeats(
-                                    "updateWindowsAndWallpaperLocked 4",
-                                    getPendingLayoutChanges(Display.DEFAULT_DISPLAY));
-                        }
-                    }
-                }
-            }
-
-            // If the window doesn't have a surface, the only thing we care about is the correct
-            // policy visibility.
-            else if (canBeForceHidden) {
-                if (shouldBeForceHidden) {
-                    win.hideLw(false, false);
-                } else {
-                    win.showLw(false, false);
-                }
-            }
-
-            final AppWindowToken atoken = win.mAppToken;
-            if (winAnimator.mDrawState == READY_TO_SHOW) {
-                if (atoken == null || atoken.allDrawn) {
-                    if (win.performShowLocked()) {
-                        setPendingLayoutChanges(displayId,
-                                WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM);
-                        if (DEBUG_LAYOUT_REPEATS) {
-                            mWindowPlacerLocked.debugLayoutRepeats(
-                                    "updateWindowsAndWallpaperLocked 5",
-                                    getPendingLayoutChanges(displayId));
-                        }
-                    }
-                }
-            }
-            final AppWindowAnimator appAnimator = winAnimator.mAppAnimator;
-            if (appAnimator != null && appAnimator.thumbnail != null) {
-                if (appAnimator.thumbnailTransactionSeq != mAnimTransactionSequence) {
-                    appAnimator.thumbnailTransactionSeq = mAnimTransactionSequence;
-                    appAnimator.thumbnailLayer = 0;
-                }
-                if (appAnimator.thumbnailLayer < winAnimator.mAnimLayer) {
-                    appAnimator.thumbnailLayer = winAnimator.mAnimLayer;
-                }
-            }
-            if (win.mIsWallpaper) {
-                wallpaper = win;
-            }
-        } // end forall windows
-
-        // If we have windows that are being show due to them no longer
-        // being force-hidden, apply the appropriate animation to them if animations are not
-        // disabled.
-        if (unForceHiding != null) {
-            if (!keyguardGoingAwayNoAnimation) {
-                boolean first = true;
-                for (int i=unForceHiding.size()-1; i>=0; i--) {
-                    final WindowStateAnimator winAnimator = unForceHiding.get(i);
-                    Animation a = mPolicy.createForceHideEnterAnimation(
-                            wallpaperInUnForceHiding && !startingInUnForceHiding,
-                            keyguardGoingAwayToShade);
-                    if (a != null) {
-                        if (DEBUG_KEYGUARD) Slog.v(TAG,
-                                "Starting keyguard exit animation on window " + winAnimator.mWin);
-                        winAnimator.setAnimation(a, STACK_CLIP_BEFORE_ANIM);
-                        winAnimator.mKeyguardGoingAwayAnimation = true;
-                        winAnimator.mKeyguardGoingAwayWithWallpaper
-                                = keyguardGoingAwayWithWallpaper;
-                        if (first) {
-                            mPostKeyguardExitAnimation = a;
-                            mPostKeyguardExitAnimation.setStartTime(mCurrentTime);
-                            first = false;
-                        }
-                    }
-                }
-            } else if (mKeyguardGoingAway) {
-                mPolicy.startKeyguardExitAnimation(mCurrentTime, 0 /* duration */);
-                mKeyguardGoingAway = false;
-            }
-
-
-            // Wallpaper is going away in un-force-hide motion, animate it as well.
-            if (!wallpaperInUnForceHiding && wallpaper != null && !keyguardGoingAwayNoAnimation) {
-                if (DEBUG_KEYGUARD) Slog.d(TAG, "updateWindowsLocked: wallpaper animating away");
-                Animation a = mPolicy.createForceHideWallpaperExitAnimation(
-                        keyguardGoingAwayToShade);
-                if (a != null) {
-                    wallpaper.mWinAnimator.setAnimation(a);
-                }
-            }
-        }
-
-        if (mPostKeyguardExitAnimation != null) {
-            // We're in the midst of a keyguard exit animation.
-            if (mKeyguardGoingAway) {
-                mPolicy.startKeyguardExitAnimation(mCurrentTime +
-                        mPostKeyguardExitAnimation.getStartOffset(),
-                        mPostKeyguardExitAnimation.getDuration());
-                mKeyguardGoingAway = false;
-            }
-            // mPostKeyguardExitAnimation might either be ended normally, cancelled, or "orphaned",
-            // meaning that the window it was running on was removed. We check for hasEnded() for
-            // ended normally and cancelled case, and check the time for the "orphaned" case.
-            else if (mPostKeyguardExitAnimation.hasEnded()
-                    || mCurrentTime - mPostKeyguardExitAnimation.getStartTime()
-                            > mPostKeyguardExitAnimation.getDuration()) {
-                // Done with the animation, reset.
-                if (DEBUG_KEYGUARD) Slog.v(TAG, "Done with Keyguard exit animations.");
-                mPostKeyguardExitAnimation = null;
-            }
-        }
-
-        final WindowState winShowWhenLocked = (WindowState) mPolicy.getWinShowWhenLockedLw();
-        if (winShowWhenLocked != null) {
-            mLastShowWinWhenLocked = winShowWhenLocked;
-        }
-    }
-
-    private void updateWallpaperLocked(int displayId) {
-        mService.mRoot.getDisplayContentOrCreate(displayId).resetAnimationBackgroundAnimator();
-
-        final WindowList windows = mService.getWindowListLocked(displayId);
-        WindowState detachedWallpaper = null;
-
-        for (int i = windows.size() - 1; i >= 0; i--) {
-            final WindowState win = windows.get(i);
-            WindowStateAnimator winAnimator = win.mWinAnimator;
-            if (winAnimator.mSurfaceController == null || !winAnimator.hasSurface()) {
-                continue;
-            }
-
-            final int flags = win.mAttrs.flags;
-
-            // If this window is animating, make a note that we have
-            // an animating window and take care of a request to run
-            // a detached wallpaper animation.
-            if (winAnimator.mAnimating) {
-                if (winAnimator.mAnimation != null) {
-                    if ((flags & FLAG_SHOW_WALLPAPER) != 0
-                            && winAnimator.mAnimation.getDetachWallpaper()) {
-                        detachedWallpaper = win;
-                    }
-                    final int color = winAnimator.mAnimation.getBackgroundColor();
-                    if (color != 0) {
-                        final TaskStack stack = win.getStack();
-                        if (stack != null) {
-                            stack.setAnimationBackground(winAnimator, color);
-                        }
-                    }
-                }
-                setAnimating(true);
-            }
-
-            // If this window's app token is running a detached wallpaper
-            // animation, make a note so we can ensure the wallpaper is
-            // displayed behind it.
-            final AppWindowAnimator appAnimator = winAnimator.mAppAnimator;
-            if (appAnimator != null && appAnimator.animation != null
-                    && appAnimator.animating) {
-                if ((flags & FLAG_SHOW_WALLPAPER) != 0
-                        && appAnimator.animation.getDetachWallpaper()) {
-                    detachedWallpaper = win;
-                }
-
-                final int color = appAnimator.animation.getBackgroundColor();
-                if (color != 0) {
-                    final TaskStack stack = win.getStack();
-                    if (stack != null) {
-                        stack.setAnimationBackground(winAnimator, color);
-                    }
-                }
-            }
-        } // end forall windows
-
-        if (mWindowDetachedWallpaper != detachedWallpaper) {
-            if (DEBUG_WALLPAPER) Slog.v(TAG,
-                    "Detached wallpaper changed from " + mWindowDetachedWallpaper
-                    + " to " + detachedWallpaper);
-            mWindowDetachedWallpaper = detachedWallpaper;
-            mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
-        }
-    }
-
     /** Locked on mService.mWindowMap. */
     private void animateLocked(long frameTimeNs) {
         if (!mInitialized) {
@@ -606,17 +225,17 @@
             Slog.i(TAG, "!!! animate: entry time=" + mCurrentTime);
         }
 
-        if (SHOW_TRANSACTIONS) Slog.i(
-                TAG, ">>> OPEN TRANSACTION animateLocked");
+        if (SHOW_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION animateLocked");
         mService.openSurfaceTransaction();
         SurfaceControl.setAnimationTransaction();
         try {
+            final AccessibilityController accessibilityController =
+                    mService.mAccessibilityController;
             final int numDisplays = mDisplayContentsAnimators.size();
             for (int i = 0; i < numDisplays; i++) {
                 final int displayId = mDisplayContentsAnimators.keyAt(i);
-                final DisplayContent displayContent = mService.mRoot.getDisplayContentOrCreate(
-                        displayId);
-                displayContent.stepAppWindowsAnimation(mCurrentTime);
+                final DisplayContent dc = mService.mRoot.getDisplayContentOrCreate(displayId);
+                dc.stepAppWindowsAnimation(mCurrentTime);
                 DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.valueAt(i);
 
                 final ScreenRotationAnimation screenRotationAnimation =
@@ -630,11 +249,10 @@
                         displayAnimator.mScreenRotationAnimation = null;
 
                         //TODO (multidisplay): Accessibility supported only for the default display.
-                        if (mService.mAccessibilityController != null
-                                && displayId == Display.DEFAULT_DISPLAY) {
-                            // We just finished rotation animation which means we did not
-                            // anounce the rotation and waited for it to end, announce now.
-                            mService.mAccessibilityController.onRotationChangedLocked(
+                        if (accessibilityController != null && dc.isDefaultDisplay) {
+                            // We just finished rotation animation which means we did not announce
+                            // the rotation and waited for it to end, announce now.
+                            accessibilityController.onRotationChangedLocked(
                                     mService.getDefaultDisplayContentLocked(), mService.mRotation);
                         }
                     }
@@ -642,22 +260,17 @@
 
                 // Update animations of all applications, including those
                 // associated with exiting/removed apps
-                updateWindowsLocked(displayId);
-                updateWallpaperLocked(displayId);
-
-                final WindowList windows = mService.getWindowListLocked(displayId);
-                final int N = windows.size();
-                for (int j = 0; j < N; j++) {
-                    windows.get(j).mWinAnimator.prepareSurfaceLocked(true);
-                }
+                ++mAnimTransactionSequence;
+                dc.updateWindowsForAnimator(this);
+                dc.updateWallpaperForAnimator(this);
+                dc.prepareWindowSurfaces();
             }
 
             for (int i = 0; i < numDisplays; i++) {
                 final int displayId = mDisplayContentsAnimators.keyAt(i);
-                final DisplayContent displayContent = mService.mRoot.getDisplayContentOrCreate(
-                        displayId);
+                final DisplayContent dc = mService.mRoot.getDisplayContentOrCreate(displayId);
 
-                displayContent.checkAppWindowsReadyToShow();
+                dc.checkAppWindowsReadyToShow();
 
                 final ScreenRotationAnimation screenRotationAnimation =
                         mDisplayContentsAnimators.valueAt(i).mScreenRotationAnimation;
@@ -665,11 +278,11 @@
                     screenRotationAnimation.updateSurfacesInTransaction();
                 }
 
-                orAnimating(displayContent.animateDimLayers());
-                orAnimating(displayContent.getDockedDividerController().animate(mCurrentTime));
+                orAnimating(dc.animateDimLayers());
+                orAnimating(dc.getDockedDividerController().animate(mCurrentTime));
                 //TODO (multidisplay): Magnification is supported only for the default display.
-                if (mService.mAccessibilityController != null && displayContent.isDefaultDisplay) {
-                    mService.mAccessibilityController.drawMagnifiedRegionBorderIfNeededLocked();
+                if (accessibilityController != null && dc.isDefaultDisplay) {
+                    accessibilityController.drawMagnifiedRegionBorderIfNeededLocked();
                 }
             }
 
@@ -688,8 +301,7 @@
             Slog.wtf(TAG, "Unhandled exception in Window Manager", e);
         } finally {
             mService.closeSurfaceTransaction();
-            if (SHOW_TRANSACTIONS) Slog.i(
-                    TAG, "<<< CLOSE TRANSACTION animateLocked");
+            if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION animateLocked");
         }
 
         boolean hasPendingLayoutChanges = mService.mRoot.hasPendingLayoutChanges(this);
@@ -726,7 +338,7 @@
             Slog.i(TAG, "!!! animate: exit mAnimating=" + mAnimating
                     + " mBulkUpdateParams=" + Integer.toHexString(mBulkUpdateParams)
                     + " mPendingLayoutChanges(DEFAULT_DISPLAY)="
-                    + Integer.toHexString(getPendingLayoutChanges(Display.DEFAULT_DISPLAY)));
+                    + Integer.toHexString(getPendingLayoutChanges(DEFAULT_DISPLAY)));
         }
     }
 
@@ -758,15 +370,10 @@
             pw.print(prefix); pw.print("DisplayContentsAnimator #");
                     pw.print(mDisplayContentsAnimators.keyAt(i));
                     pw.println(":");
-            DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.valueAt(i);
-            final WindowList windows =
-                    mService.getWindowListLocked(mDisplayContentsAnimators.keyAt(i));
-            final int N = windows.size();
-            for (int j = 0; j < N; j++) {
-                WindowStateAnimator wanim = windows.get(j).mWinAnimator;
-                pw.print(subPrefix); pw.print("Window #"); pw.print(j);
-                        pw.print(": "); pw.println(wanim);
-            }
+            final DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.valueAt(i);
+            final DisplayContent dc =
+                    mService.mRoot.getDisplayContentOrCreate(mDisplayContentsAnimators.keyAt(i));
+            dc.dumpWindowAnimators(pw, subPrefix);
             if (displayAnimator.mScreenRotationAnimation != null) {
                 pw.print(subPrefix); pw.println("mScreenRotationAnimation:");
                 displayAnimator.mScreenRotationAnimation.printTo(subSubPrefix, pw);
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index d632014..aa5f98a 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -172,6 +172,7 @@
 import static android.app.StatusBarManager.DISABLE_MASK;
 import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
 import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
+import static android.view.Display.DEFAULT_DISPLAY;
 import static android.view.WindowManager.DOCKED_INVALID;
 import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
 import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
@@ -1789,7 +1790,7 @@
             if (mAccessibilityController != null) {
                 WindowState window = mWindowMap.get(token);
                 //TODO (multidisplay): Magnification is supported only for the default display.
-                if (window != null && window.getDisplayId() == Display.DEFAULT_DISPLAY) {
+                if (window != null && window.getDisplayId() == DEFAULT_DISPLAY) {
                     mAccessibilityController.onRectangleOnScreenRequestedLocked(rectangle);
                 }
             }
@@ -2160,7 +2161,7 @@
         }
         //TODO (multidisplay): Magnification is supported only for the default
         if (mAccessibilityController != null
-                && win.getDisplayId() == Display.DEFAULT_DISPLAY) {
+                && win.getDisplayId() == DEFAULT_DISPLAY) {
             mAccessibilityController.onWindowTransitionLocked(win, transit);
         }
         return focusMayChange;
@@ -4565,7 +4566,7 @@
         }
         try {
             Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "screenshotWallpaper");
-            return screenshotApplicationsInner(null, Display.DEFAULT_DISPLAY, -1, -1, true, 1f,
+            return screenshotApplicationsInner(null, DEFAULT_DISPLAY, -1, -1, true, 1f,
                     Bitmap.Config.ARGB_8888, true);
         } finally {
             Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
@@ -4587,7 +4588,7 @@
         FgThread.getHandler().post(new Runnable() {
             @Override
             public void run() {
-                Bitmap bm = screenshotApplicationsInner(null, Display.DEFAULT_DISPLAY, -1, -1,
+                Bitmap bm = screenshotApplicationsInner(null, DEFAULT_DISPLAY, -1, -1,
                         true, 1f, Bitmap.Config.ARGB_8888, false);
                 try {
                     receiver.send(bm);
@@ -4859,7 +4860,7 @@
             }
 
             ScreenRotationAnimation screenRotationAnimation =
-                    mAnimator.getScreenRotationAnimationLocked(Display.DEFAULT_DISPLAY);
+                    mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
             final boolean inRotation = screenRotationAnimation != null &&
                     screenRotationAnimation.isAnimating();
             if (DEBUG_SCREENSHOT && inRotation) Slog.v(TAG_WM,
@@ -5044,7 +5045,7 @@
         }
 
         ScreenRotationAnimation screenRotationAnimation =
-                mAnimator.getScreenRotationAnimationLocked(Display.DEFAULT_DISPLAY);
+                mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
         if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
             // Rotation updates cannot be performed while the previous rotation change
             // animation is still in progress.  Skip this update.  We will try updating
@@ -5146,7 +5147,7 @@
             startFreezingDisplayLocked(inTransaction, anim[0], anim[1]);
             // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
             screenRotationAnimation =
-                mAnimator.getScreenRotationAnimationLocked(Display.DEFAULT_DISPLAY);
+                mAnimator.getScreenRotationAnimationLocked(DEFAULT_DISPLAY);
         } else {
             // The screen rotation animation uses a screenshot to freeze the screen
             // while windows resize underneath.
@@ -5232,7 +5233,7 @@
         // Announce rotation only if we will not animate as we already have the
         // windows in final state. Otherwise, we make this call at the rotation end.
         if (screenRotationAnimation == null && mAccessibilityController != null
-                && displayContent.getDisplayId() == Display.DEFAULT_DISPLAY) {
+                && displayContent.getDisplayId() == DEFAULT_DISPLAY) {
             mAccessibilityController.onRotationChangedLocked(getDefaultDisplayContentLocked(),
                     rotation);
         }
@@ -6469,7 +6470,7 @@
                     synchronized(mWindowMap) {
                         // TODO(multidisplay): Accessibility supported only of default desiplay.
                         if (mAccessibilityController != null && getDefaultDisplayContentLocked()
-                                .getDisplayId() == Display.DEFAULT_DISPLAY) {
+                                .getDisplayId() == DEFAULT_DISPLAY) {
                             accessibilityController = mAccessibilityController;
                         }
 
@@ -7236,7 +7237,7 @@
             throw new SecurityException("Must hold permission " +
                     android.Manifest.permission.WRITE_SECURE_SETTINGS);
         }
-        if (displayId != Display.DEFAULT_DISPLAY) {
+        if (displayId != DEFAULT_DISPLAY) {
             throw new IllegalArgumentException("Can only set the default display");
         }
         final long ident = Binder.clearCallingIdentity();
@@ -7271,7 +7272,7 @@
             throw new SecurityException("Must hold permission " +
                     android.Manifest.permission.WRITE_SECURE_SETTINGS);
         }
-        if (displayId != Display.DEFAULT_DISPLAY) {
+        if (displayId != DEFAULT_DISPLAY) {
             throw new IllegalArgumentException("Can only set the default display");
         }
         final long ident = Binder.clearCallingIdentity();
@@ -7354,7 +7355,7 @@
             throw new SecurityException("Must hold permission " +
                     android.Manifest.permission.WRITE_SECURE_SETTINGS);
         }
-        if (displayId != Display.DEFAULT_DISPLAY) {
+        if (displayId != DEFAULT_DISPLAY) {
             throw new IllegalArgumentException("Can only set the default display");
         }
         final long ident = Binder.clearCallingIdentity();
@@ -7403,7 +7404,7 @@
             throw new SecurityException("Must hold permission " +
                     android.Manifest.permission.WRITE_SECURE_SETTINGS);
         }
-        if (displayId != Display.DEFAULT_DISPLAY) {
+        if (displayId != DEFAULT_DISPLAY) {
             throw new IllegalArgumentException("Can only set the default display");
         }
 
@@ -7434,7 +7435,7 @@
             throw new SecurityException("Must hold permission " +
                     android.Manifest.permission.WRITE_SECURE_SETTINGS);
         }
-        if (displayId != Display.DEFAULT_DISPLAY) {
+        if (displayId != DEFAULT_DISPLAY) {
             throw new IllegalArgumentException("Can only set the default display");
         }
 
@@ -8676,7 +8677,7 @@
     }
 
     // TODO: All the display method below should probably be moved into the RootWindowContainer...
-    public void createDisplayContentLocked(final Display display) {
+    private void createDisplayContentLocked(final Display display) {
         if (display == null) {
             throw new IllegalArgumentException("getDisplayContent: display must not be null");
         }
@@ -8684,28 +8685,18 @@
     }
 
     // There is an inherent assumption that this will never return null.
-    public DisplayContent getDefaultDisplayContentLocked() {
-        return mRoot.getDisplayContentOrCreate(Display.DEFAULT_DISPLAY);
+    DisplayContent getDefaultDisplayContentLocked() {
+        return mRoot.getDisplayContentOrCreate(DEFAULT_DISPLAY);
     }
 
-    public WindowList getDefaultWindowListLocked() {
+    WindowList getDefaultWindowListLocked() {
         return getDefaultDisplayContentLocked().getWindowList();
     }
 
-    public DisplayInfo getDefaultDisplayInfoLocked() {
+    private DisplayInfo getDefaultDisplayInfoLocked() {
         return getDefaultDisplayContentLocked().getDisplayInfo();
     }
 
-    /**
-     * Return the list of WindowStates associated on the passed display.
-     * @param displayId The screen to return windows from.
-     * @return The list of WindowStates on the screen, or null if the there is no screen.
-     */
-    WindowList getWindowListLocked(final int displayId) {
-        final DisplayContent displayContent = mRoot.getDisplayContentOrCreate(displayId);
-        return displayContent != null ? displayContent.getWindowList() : null;
-    }
-
     public void onDisplayAdded(int displayId) {
         mH.sendMessage(mH.obtainMessage(H.DO_DISPLAY_ADDED, displayId, 0));
     }