Remove AppWindowToken lists.

No longer necessary.

Change-Id: I0d2b96f69152fb93b6ba56f02ce9693ff1370cbc
diff --git a/services/java/com/android/server/wm/DisplayContent.java b/services/java/com/android/server/wm/DisplayContent.java
index 0b6c514d..b48a004 100644
--- a/services/java/com/android/server/wm/DisplayContent.java
+++ b/services/java/com/android/server/wm/DisplayContent.java
@@ -16,8 +16,6 @@
 
 package com.android.server.wm;
 
-import android.os.Debug;
-import android.util.Slog;
 import android.util.SparseArray;
 import android.view.Display;
 import android.view.DisplayInfo;
@@ -38,7 +36,7 @@
  * WindowManagerService.mWindowMap.
  */
 class DisplayContent {
-    private final static String TAG = "DisplayContent";
+//    private final static String TAG = "DisplayContent";
 
     /** Unique identifier of this stack. */
     private final int mDisplayId;
@@ -73,20 +71,6 @@
     final boolean isDefaultDisplay;
 
     /**
-     * List controlling the ordering of windows in different applications which must
-     * be kept in sync with ActivityManager.
-     */
-    final AppTokenList mAppTokens = new AppTokenList();
-
-    /**
-     * AppWindowTokens in the Z order they were in at the start of an animation. Between
-     * animations this list is maintained in the exact order of mAppTokens. If tokens
-     * are added to mAppTokens during an animation an attempt is made to insert them at the same
-     * logical location in this list. Note that this list is always in sync with mWindows.
-     */
-    AppTokenList mAnimatingAppTokens = new AppTokenList();
-
-    /**
      * Window tokens that are in the process of exiting, but still
      * on screen for animations.
      */
@@ -140,18 +124,6 @@
      * @param wtoken The token to insert.
      */
     void addAppToken(final int addPos, final AppWindowToken wtoken) {
-        mAppTokens.add(addPos, wtoken);
-
-        if (addPos == 0 || addPos == mAnimatingAppTokens.size()) {
-            // It was inserted into the beginning or end of mAppTokens. Honor that.
-            mAnimatingAppTokens.add(addPos, wtoken);
-        } else {
-            // Find the item immediately above the mAppTokens insertion point and put the token
-            // immediately below that one in mAnimatingAppTokens.
-            final AppWindowToken aboveAnchor = mAppTokens.get(addPos + 1);
-            mAnimatingAppTokens.add(mAnimatingAppTokens.indexOf(aboveAnchor), wtoken);
-        }
-
         TaskList task = mTaskIdToTaskList.get(wtoken.groupId);
         if (task == null) {
             task = new TaskList(wtoken, this);
@@ -163,8 +135,6 @@
     }
 
     void removeAppToken(final AppWindowToken wtoken) {
-        mAppTokens.remove(wtoken);
-        mAnimatingAppTokens.remove(wtoken);
         final int taskId = wtoken.groupId;
         final TaskList task = mTaskIdToTaskList.get(taskId);
         if (task != null) {
@@ -177,14 +147,6 @@
         }
     }
 
-    void refillAnimatingAppTokens() {
-        mAnimatingAppTokens.clear();
-        AppTokenIterator iterator = new AppTokenIterator();
-        while (iterator.hasNext()) {
-            mAnimatingAppTokens.add(iterator.next());
-        }
-    }
-
     void setAppTaskId(AppWindowToken wtoken, int newTaskId) {
         final int taskId = wtoken.groupId;
         TaskList task = mTaskIdToTaskList.get(taskId);
diff --git a/services/java/com/android/server/wm/WindowAnimator.java b/services/java/com/android/server/wm/WindowAnimator.java
index 546bf2f..92ad485 100644
--- a/services/java/com/android/server/wm/WindowAnimator.java
+++ b/services/java/com/android/server/wm/WindowAnimator.java
@@ -25,6 +25,7 @@
 import android.view.WindowManagerPolicy;
 import android.view.animation.Animation;
 
+import com.android.server.wm.DisplayContent.AppTokenIterator;
 import com.android.server.wm.WindowManagerService.DisplayContentsIterator;
 import com.android.server.wm.WindowManagerService.LayoutFields;
 
@@ -174,10 +175,9 @@
     private void updateAppWindowsLocked(int displayId) {
         int i;
         final DisplayContent displayContent = mService.getDisplayContentLocked(displayId);
-        final AppTokenList appTokens = displayContent.mAnimatingAppTokens;
-        final int NAT = appTokens.size();
-        for (i=0; i<NAT; i++) {
-            final AppWindowAnimator appAnimator = appTokens.get(i).mAppAnimator;
+        AppTokenIterator iterator = displayContent.new AppTokenIterator();
+        while (iterator.hasNext()) {
+            final AppWindowAnimator appAnimator = iterator.next().mAppAnimator;
             final boolean wasAnimating = appAnimator.animation != null
                     && appAnimator.animation != AppWindowAnimator.sDummyAnimation;
             if (appAnimator.stepAnimationLocked(mCurrentTime)) {
@@ -458,11 +458,10 @@
     private void testTokenMayBeDrawnLocked(int displayId) {
         // See if any windows have been drawn, so they (and others
         // associated with them) can now be shown.
-        final AppTokenList appTokens =
-                mService.getDisplayContentLocked(displayId).mAnimatingAppTokens;
-        final int NT = appTokens.size();
-        for (int i=0; i<NT; i++) {
-            AppWindowToken wtoken = appTokens.get(i);
+        AppTokenIterator iterator = mService.getDisplayContentLocked(displayId).new
+                AppTokenIterator();
+        while (iterator.hasNext()) {
+            AppWindowToken wtoken = iterator.next();
             AppWindowAnimator appAnimator = wtoken.mAppAnimator;
             final boolean allDrawn = wtoken.allDrawn;
             if (allDrawn != appAnimator.allDrawn) {
diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java
index 397b363..7d2574d 100644
--- a/services/java/com/android/server/wm/WindowManagerService.java
+++ b/services/java/com/android/server/wm/WindowManagerService.java
@@ -888,7 +888,6 @@
         final WindowList windows = win.getWindowList();
         final int N = windows.size();
         final WindowState attached = win.mAttachedWindow;
-        int i;
         WindowList tokenWindowList = getTokenWindowsOnDisplay(token, displayContent);
         if (attached == null) {
             int tokenWindowsPos = 0;
@@ -938,13 +937,12 @@
                         + client.asBinder() + " (token=" + token + ")");
                     // Figure out where the window should go, based on the
                     // order of applications.
-                    AppTokenList animatingAppTokens = displayContent.mAnimatingAppTokens;
-                    final int NA = animatingAppTokens.size();
                     WindowState pos = null;
-                    for (i=NA-1; i>=0; i--) {
-                        AppWindowToken t = animatingAppTokens.get(i);
+                    AppTokenIterator iterator =
+                            displayContent.new AppTokenIterator(true /*reverse*/);
+                    while (iterator.hasNext()) {
+                        AppWindowToken t = iterator.next();
                         if (t == token) {
-                            i--;
                             break;
                         }
 
@@ -977,15 +975,14 @@
                     } else {
                         // Continue looking down until we find the first
                         // token that has windows on this display.
-                        while (i >= 0) {
-                            AppWindowToken t = animatingAppTokens.get(i);
+                        while (iterator.hasNext()) {
+                            AppWindowToken t = iterator.next();
                             tokenWindowList = getTokenWindowsOnDisplay(t, displayContent);
                             final int NW = tokenWindowList.size();
                             if (NW > 0) {
                                 pos = tokenWindowList.get(NW-1);
                                 break;
                             }
-                            i--;
                         }
                         if (pos != null) {
                             // Move in front of any windows attached to this
@@ -1004,7 +1001,8 @@
                         } else {
                             // Just search for the start of this layer.
                             final int myLayer = win.mBaseLayer;
-                            for (i=0; i<N; i++) {
+                            int i;
+                            for (i = 0; i < N; i++) {
                                 WindowState w = windows.get(i);
                                 if (w.mBaseLayer > myLayer) {
                                     break;
@@ -1022,7 +1020,8 @@
             } else {
                 // Figure out where window should go, based on layer.
                 final int myLayer = win.mBaseLayer;
-                for (i=N-1; i>=0; i--) {
+                int i;
+                for (i = N - 1; i >= 0; i--) {
                     if (windows.get(i).mBaseLayer <= myLayer) {
                         break;
                     }
@@ -1047,7 +1046,8 @@
             final int sublayer = win.mSubLayer;
             int largestSublayer = Integer.MIN_VALUE;
             WindowState windowWithLargestSublayer = null;
-            for (i=0; i<NA; i++) {
+            int i;
+            for (i = 0; i < NA; i++) {
                 WindowState w = tokenWindowList.get(i);
                 final int wSublayer = w.mSubLayer;
                 if (wSublayer >= largestSublayer) {
@@ -4369,18 +4369,6 @@
         }
     }
 
-    void dumpAnimatingAppTokensLocked() {
-        DisplayContentsIterator iterator = new DisplayContentsIterator();
-        while (iterator.hasNext()) {
-            DisplayContent displayContent = iterator.next();
-            Slog.v(TAG, "  Display " + displayContent.getDisplayId());
-            AppTokenList appTokens = displayContent.mAnimatingAppTokens;
-            for (int i=appTokens.size()-1; i>=0; i--) {
-                Slog.v(TAG, "  #" + i + ": " + appTokens.get(i).token);
-            }
-        }
-    }
-
     void dumpWindowsLocked() {
         int i = 0;
         final AllWindowsIterator iterator = new AllWindowsIterator(REVERSE_ITERATOR);
@@ -4550,7 +4538,6 @@
                 }
                 displayContent.mTaskLists.add(taskList);
 
-                displayContent.refillAnimatingAppTokens();
                 moveTaskWindowsLocked(taskId);
             }
         } finally {
@@ -4579,7 +4566,6 @@
                 }
                 displayContent.mTaskLists.add(0, taskList);
 
-                displayContent.refillAnimatingAppTokens();
                 moveTaskWindowsLocked(taskId);
             }
         } finally {
@@ -6829,7 +6815,6 @@
                         if (mAppTransition.isTransitionSet()) {
                             if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** APP TRANSITION TIMEOUT");
                             mAppTransition.setTimeout();
-                            getDefaultDisplayContentLocked().refillAnimatingAppTokens();
                             performLayoutAndPlaceSurfacesLocked();
                         }
                     }
@@ -7338,10 +7323,9 @@
         }
 
         // And add in the still active app tokens in Z order.
-        AppTokenList animatingAppTokens = displayContent.mAnimatingAppTokens;
-        NT = animatingAppTokens.size();
-        for (int j=0; j<NT; j++) {
-            i = reAddAppWindowsLocked(displayContent, i, animatingAppTokens.get(j));
+        AppTokenIterator iterator = displayContent.new AppTokenIterator();
+        while (iterator.hasNext()) {
+            i = reAddAppWindowsLocked(displayContent, i, iterator.next());
         }
 
         i -= lastBelow;
@@ -7361,7 +7345,7 @@
                 }
             }
             Slog.w(TAG, "Current app token list:");
-            dumpAnimatingAppTokensLocked();
+            dumpAppTokensLocked();
             Slog.w(TAG, "Final window list:");
             dumpWindowsLocked();
         }
@@ -8008,11 +7992,10 @@
         mAppTransition.setIdle();
         // Restore window app tokens to the ActivityManager views
         final DisplayContent displayContent = getDefaultDisplayContentLocked();
-        final AppTokenList animatingAppTokens = displayContent.mAnimatingAppTokens;
-        for (int i = animatingAppTokens.size() - 1; i >= 0; i--) {
-            animatingAppTokens.get(i).sendingToBottom = false;
+        AppTokenIterator iterator = displayContent.new AppTokenIterator();
+        while (iterator.hasNext()) {
+            iterator.next().sendingToBottom = false;
         }
-        displayContent.refillAnimatingAppTokens();
         rebuildAppWindowListLocked();
 
         changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
@@ -8169,10 +8152,9 @@
     private void updateAllDrawnLocked(DisplayContent displayContent) {
         // See if any windows have been drawn, so they (and others
         // associated with them) can now be shown.
-        final AppTokenList appTokens = displayContent.mAnimatingAppTokens;
-        final int NT = appTokens.size();
-        for (int i=0; i<NT; i++) {
-            AppWindowToken wtoken = appTokens.get(i);
+        AppTokenIterator iterator = displayContent.new AppTokenIterator();
+        while (iterator.hasNext()) {
+            AppWindowToken wtoken = iterator.next();
             if (!wtoken.allDrawn) {
                 int numInteresting = wtoken.numInterestingWindows;
                 if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
@@ -9533,23 +9515,6 @@
                 }
             }
         }
-        final AppTokenList animatingAppTokens =
-                getDefaultDisplayContentLocked().mAnimatingAppTokens;
-        if (mAppTransition.isRunning() && animatingAppTokens.size() > 0) {
-            pw.println();
-            pw.println("  Application tokens during animation:");
-            for (int i=animatingAppTokens.size()-1; i>=0; i--) {
-                WindowToken token = animatingAppTokens.get(i);
-                pw.print("  App moving to bottom #"); pw.print(i);
-                        pw.print(' '); pw.print(token);
-                if (dumpAll) {
-                    pw.println(':');
-                    token.dump(pw, "    ");
-                } else {
-                    pw.println();
-                }
-            }
-        }
         if (mOpeningApps.size() > 0 || mClosingApps.size() > 0) {
             pw.println();
             if (mOpeningApps.size() > 0) {