@@ -887,6 +887,12 @@ private int findIdxBasedOnAppTokens(WindowState win) {
887887 return -1 ;
888888 }
889889
890+ /**
891+ * Return the list of Windows from the passed token on the given Display.
892+ * @param token The token with all the windows.
893+ * @param displayContent The display we are interested in.
894+ * @return List of windows from token that are on displayContent.
895+ */
890896 WindowList getTokenWindowsOnDisplay (WindowToken token , DisplayContent displayContent ) {
891897 final WindowList windowList = new WindowList ();
892898 final int count = token .windows .size ();
@@ -928,7 +934,7 @@ private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
928934 WindowState lastWindow = tokenWindowList .get (index );
929935 if (atoken != null && lastWindow == atoken .startingWindow ) {
930936 placeWindowBefore (lastWindow , win );
931- tokenWindowsPos = token .windows .indexOf (lastWindow ) - 1 ;
937+ tokenWindowsPos = token .windows .indexOf (lastWindow );
932938 } else {
933939 int newIdx = findIdxBasedOnAppTokens (win );
934940 //there is a window above this one associated with the same
@@ -937,10 +943,15 @@ private void addWindowToListInOrderLocked(WindowState win, boolean addToToken) {
937943 //windows associated with this token.
938944 if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE ) {
939945 Slog .v (TAG , "Adding window " + win + " at "
940- + (newIdx +1 ) + " of " + N );
946+ + (newIdx + 1 ) + " of " + N );
947+ }
948+ windows .add (newIdx + 1 , win );
949+ if (newIdx < 0 ) {
950+ // No window from token found on win's display.
951+ tokenWindowsPos = 0 ;
952+ } else {
953+ tokenWindowsPos = token .windows .indexOf (windows .get (newIdx )) + 1 ;
941954 }
942- windows .add (newIdx +1 , win );
943- tokenWindowsPos = token .windows .indexOf (windows .get (newIdx )) + 1 ;
944955 mWindowsChanged = true ;
945956 }
946957 }
0 commit comments