Clean up use of DisplayContent from WindowState.

Follow up to ag/1483993 where WindowTokens can now only be on one display.
Clean-up some existing code that dealt with having WindowTokens on
multiple displays.

Test: Existing tests pass.
Change-Id: Ie908eda37bc44097dea773b0fc163d35cc9baf35
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index f1df94f..ee7c6d2 100644
--- a/services/core/java/com/android/server/wm/AppWindowToken.java
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -270,7 +270,7 @@
                 final WindowState window = findMainWindow();
                 //TODO (multidisplay): Magnification is supported only for the default display.
                 if (window != null && accessibilityController != null
-                        && window.getDisplayId() == DEFAULT_DISPLAY) {
+                        && getDisplayContent().getDisplayId() == DEFAULT_DISPLAY) {
                     accessibilityController.onAppWindowTransitionLocked(window, transit);
                 }
                 changed = true;
@@ -418,22 +418,15 @@
      * surfaces that's eligible, if the app is already stopped.
      */
     private void destroySurfaces(boolean cleanupOnResume) {
-        final ArrayList<DisplayContent> displayList = new ArrayList();
+        boolean destroyedSomething = false;
         for (int i = mChildren.size() - 1; i >= 0; i--) {
             final WindowState win = mChildren.get(i);
-            final boolean destroyed = win.destroySurface(cleanupOnResume, mAppStopped);
-
-            if (destroyed) {
-                final DisplayContent displayContent = win.getDisplayContent();
-                if (displayContent != null && !displayList.contains(displayContent)) {
-                    displayList.add(displayContent);
-                }
-            }
+            destroyedSomething |= win.destroySurface(cleanupOnResume, mAppStopped);
         }
-        for (int i = 0; i < displayList.size(); i++) {
-            final DisplayContent displayContent = displayList.get(i);
-            mService.mLayersController.assignLayersLocked(displayContent.getWindowList());
-            displayContent.setLayoutNeeded();
+        if (destroyedSomething) {
+            final DisplayContent dc = getDisplayContent();
+            mService.mLayersController.assignLayersLocked(dc.getWindowList());
+            dc.setLayoutNeeded();
         }
     }
 
@@ -700,7 +693,7 @@
         }
     }
 
-    boolean waitingForReplacement() {
+    private boolean waitingForReplacement() {
         for (int i = mChildren.size() - 1; i >= 0; i--) {
             final WindowState candidate = mChildren.get(i);
             if (candidate.waitingForReplacement()) {
@@ -816,17 +809,12 @@
         }
     }
 
-    void setAppLayoutChanges(int changes, String reason, int displayId) {
-        final WindowAnimator windowAnimator = mAppAnimator.mAnimator;
-        for (int i = mChildren.size() - 1; i >= 0; i--) {
-            // Child windows will be on the same display as their parents.
-            if (displayId == (mChildren.get(i)).getDisplayId()) {
-                windowAnimator.setPendingLayoutChanges(displayId, changes);
-                if (DEBUG_LAYOUT_REPEATS) {
-                    mService.mWindowPlacerLocked.debugLayoutRepeats(
-                            reason, windowAnimator.getPendingLayoutChanges(displayId));
-                }
-                break;
+    void setAppLayoutChanges(int changes, String reason) {
+        if (!mChildren.isEmpty()) {
+            final DisplayContent dc = getDisplayContent();
+            dc.pendingLayoutChanges |= changes;
+            if (DEBUG_LAYOUT_REPEATS) {
+                mService.mWindowPlacerLocked.debugLayoutRepeats(reason, dc.pendingLayoutChanges);
             }
         }
     }
@@ -931,7 +919,7 @@
 
             if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) Slog.v(TAG_WM,
                     "Removing starting window: " + tStartingWindow);
-            tStartingWindow.getWindowList().remove(tStartingWindow);
+            getDisplayContent().getWindowList().remove(tStartingWindow);
             mService.mWindowsChanged = true;
             if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
                     "Removing starting " + tStartingWindow + " from " + fromToken);
@@ -1028,7 +1016,7 @@
     }
 
     @Override
-    void checkAppWindowsReadyToShow(int displayId) {
+    void checkAppWindowsReadyToShow() {
         if (allDrawn == mAppAnimator.allDrawn) {
             return;
         }
@@ -1047,9 +1035,9 @@
                     + " numInteresting=" + mNumInterestingWindows + " numDrawn=" + mNumDrawnWindows);
             // This will set mOrientationChangeComplete and cause a pass through layout.
             setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER,
-                    "checkAppWindowsReadyToShow: freezingScreen", displayId);
+                    "checkAppWindowsReadyToShow: freezingScreen");
         } else {
-            setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow", displayId);
+            setAppLayoutChanges(FINISH_LAYOUT_REDO_ANIM, "checkAppWindowsReadyToShow");
 
             // We can now show all of the drawn windows!
             if (!mService.mOpeningApps.contains(this)) {
@@ -1170,16 +1158,15 @@
     }
 
     @Override
-    void stepAppWindowsAnimation(long currentTime, int displayId) {
+    void stepAppWindowsAnimation(long currentTime) {
         mAppAnimator.wasAnimating = mAppAnimator.animating;
-        if (mAppAnimator.stepAnimationLocked(currentTime, displayId)) {
+        if (mAppAnimator.stepAnimationLocked(currentTime)) {
             mAppAnimator.animating = true;
             mService.mAnimator.setAnimating(true);
             mService.mAnimator.mAppWindowAnimating = true;
         } else if (mAppAnimator.wasAnimating) {
             // stopped animating, do one more pass through the layout
-            setAppLayoutChanges(
-                    FINISH_LAYOUT_REDO_WALLPAPER, "appToken " + this + " done", displayId);
+            setAppLayoutChanges(FINISH_LAYOUT_REDO_WALLPAPER, "appToken " + this + " done");
             if (DEBUG_ANIM) Slog.v(TAG, "updateWindowsApps...: done animating " + this);
         }
     }