From 92fc37294c474fd47b4439736c6cf700c4e46a27 Mon Sep 17 00:00:00 2001 From: Wale Ogunwale Date: Fri, 5 Aug 2016 12:19:08 -0700 Subject: [PATCH] Replaced use of AppWindowToken.allAppWindows with WindowToken.windows After ag/1290328 the 2 list now contain the same entries. The only different is allAppWindows is not sorted and windows is. Removing allAppWindows and only having one windows list for a token object reduces confusion in the codebase and also removes a major source of bugs. Bug: 30060889 Change-Id: I6e9a3a4b52cfd686788fe18f4fd6c9b0731f10bd --- .../com/android/server/wm/AppWindowToken.java | 285 +++++++----------- .../com/android/server/wm/InputMonitor.java | 2 +- .../server/wm/WindowManagerService.java | 20 +- .../com/android/server/wm/WindowState.java | 8 +- .../com/android/server/wm/WindowToken.java | 27 +- 5 files changed, 137 insertions(+), 205 deletions(-) diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java index 7004e355179a1..c78e94bff7937 100644 --- a/services/core/java/com/android/server/wm/AppWindowToken.java +++ b/services/core/java/com/android/server/wm/AppWindowToken.java @@ -73,9 +73,6 @@ class AppWindowToken extends WindowToken { // Non-null only for application tokens. final IApplicationToken appToken; - // All of the windows and child windows that are included in this - // application token. Note this list is NOT sorted! - private final WindowList allAppWindows = new WindowList(); @NonNull final AppWindowAnimator mAppAnimator; final boolean voiceInteraction; @@ -163,9 +160,9 @@ class AppWindowToken extends WindowToken { } void sendAppVisibilityToClients() { - final int N = allAppWindows.size(); + final int N = windows.size(); for (int i=0; i= 0; i--) { - final WindowState w = allAppWindows.get(i); + for (int i = windows.size() - 1; i >= 0; i--) { + final WindowState w = windows.get(i); w.setVisibleBeforeClientHidden(); } } @@ -217,9 +214,9 @@ class AppWindowToken extends WindowToken { if (DEBUG_VISIBILITY) Slog.v(TAG, "Update reported visibility: " + this); - final int N = allAppWindows.size(); + final int N = windows.size(); for (int i=0; i= 0 && !delayed; i--) { - if (allAppWindows.get(i).mWinAnimator.isWindowAnimationSet()) { + for (int i = windows.size() - 1; i >= 0 && !delayed; i--) { + if (windows.get(i).mWinAnimator.isWindowAnimationSet()) { delayed = true; } } @@ -434,10 +431,10 @@ class AppWindowToken extends WindowToken { WindowState findMainWindow() { WindowState candidate = null; - int j = allAppWindows.size(); + int j = windows.size(); while (j > 0) { j--; - WindowState win = allAppWindows.get(j); + WindowState win = windows.get(j); if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) { // In cases where there are multiple windows, we prefer the non-exiting window. This @@ -458,9 +455,9 @@ class AppWindowToken extends WindowToken { } boolean isVisible() { - final int N = allAppWindows.size(); + final int N = windows.size(); for (int i=0; i= 0; j--) { - final WindowState w = allAppWindows.get(j); + for (int j = windows.size() - 1; j >= 0; j--) { + final WindowState w = windows.get(j); if (!w.isHiddenFromUserLocked()) { return true; } @@ -501,8 +498,8 @@ class AppWindowToken extends WindowToken { } void clearAnimatingFlags() { - for (int i = allAppWindows.size() - 1; i >= 0; i--) { - final WindowState win = allAppWindows.get(i); + for (int i = windows.size() - 1; i >= 0; i--) { + final WindowState win = windows.get(i); // We don't want to clear it out for windows that get replaced, because the // animation depends on the flag to remove the replaced window. // @@ -540,7 +537,7 @@ class AppWindowToken extends WindowToken { */ private void destroySurfaces(boolean cleanupOnResume) { - final ArrayList allWindows = (ArrayList) allAppWindows.clone(); + final ArrayList allWindows = (ArrayList) windows.clone(); final DisplayContentList displayList = new DisplayContentList(); for (int i = allWindows.size() - 1; i >= 0; i--) { final WindowState win = allWindows.get(i); @@ -620,8 +617,8 @@ class AppWindowToken extends WindowToken { } boolean canRestoreSurfaces() { - for (int i = allAppWindows.size() -1; i >= 0; i--) { - final WindowState w = allAppWindows.get(i); + for (int i = windows.size() -1; i >= 0; i--) { + final WindowState w = windows.get(i); if (w.canRestoreSurface()) { return true; } @@ -630,8 +627,8 @@ class AppWindowToken extends WindowToken { } void clearVisibleBeforeClientHidden() { - for (int i = allAppWindows.size() - 1; i >= 0; i--) { - final WindowState w = allAppWindows.get(i); + for (int i = windows.size() - 1; i >= 0; i--) { + final WindowState w = windows.get(i); w.clearVisibleBeforeClientHidden(); } } @@ -641,8 +638,8 @@ class AppWindowToken extends WindowToken { * animating with saved surface. */ boolean isAnimatingInvisibleWithSavedSurface() { - for (int i = allAppWindows.size() - 1; i >= 0; i--) { - final WindowState w = allAppWindows.get(i); + for (int i = windows.size() - 1; i >= 0; i--) { + final WindowState w = windows.get(i); if (w.isAnimatingInvisibleWithSavedSurface()) { return true; } @@ -655,8 +652,8 @@ class AppWindowToken extends WindowToken { * with a saved surface, and mark them destroying. */ void stopUsingSavedSurfaceLocked() { - for (int i = allAppWindows.size() - 1; i >= 0; i--) { - final WindowState w = allAppWindows.get(i); + for (int i = windows.size() - 1; i >= 0; i--) { + final WindowState w = windows.get(i); if (w.isAnimatingInvisibleWithSavedSurface()) { if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.d(TAG, "stopUsingSavedSurfaceLocked: " + w); @@ -670,8 +667,8 @@ class AppWindowToken extends WindowToken { } void markSavedSurfaceExiting() { - for (int i = allAppWindows.size() - 1; i >= 0; i--) { - final WindowState w = allAppWindows.get(i); + for (int i = windows.size() - 1; i >= 0; i--) { + final WindowState w = windows.get(i); if (w.isAnimatingInvisibleWithSavedSurface()) { w.mAnimatingExit = true; w.mWinAnimator.mAnimating = true; @@ -687,8 +684,8 @@ class AppWindowToken extends WindowToken { // Check if we have enough drawn windows to mark allDrawn= true. int numInteresting = 0; int numDrawn = 0; - for (int i = allAppWindows.size() - 1; i >= 0; i--) { - WindowState w = allAppWindows.get(i); + for (int i = windows.size() - 1; i >= 0; i--) { + WindowState w = windows.get(i); if (w != startingWindow && !w.mAppDied && w.wasVisibleBeforeClientHidden() && (!mAppAnimator.freezingScreen || !w.mAppFreezing)) { numInteresting++; @@ -715,8 +712,8 @@ class AppWindowToken extends WindowToken { } void destroySavedSurfaces() { - for (int i = allAppWindows.size() - 1; i >= 0; i--) { - WindowState win = allAppWindows.get(i); + for (int i = windows.size() - 1; i >= 0; i--) { + WindowState win = windows.get(i); win.destroySavedSurface(); } } @@ -727,41 +724,20 @@ class AppWindowToken extends WindowToken { allDrawnExcludingSaved = false; } - @Override - void removeAllWindows() { - for (int winNdx = allAppWindows.size() - 1; winNdx >= 0; - // removeWindowLocked at bottom of loop may remove multiple entries from - // allAppWindows if the window to be removed has child windows. It also may - // not remove any windows from allAppWindows at all if win is exiting and - // currently animating away. This ensures that winNdx is monotonically decreasing - // and never beyond allAppWindows bounds. - winNdx = Math.min(winNdx - 1, allAppWindows.size() - 1)) { - WindowState win = allAppWindows.get(winNdx); - if (DEBUG_WINDOW_MOVEMENT) { - Slog.w(TAG, "removeAllWindows: removing win=" + win); - } - - mService.removeWindowLocked(win); - } - allAppWindows.clear(); - windows.clear(); - } - @Override void removeWindow(WindowState win) { super.removeWindow(win); - allAppWindows.remove(win); - + // TODO: Something smells about the code below...Is there a better way? if (startingWindow == win) { if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Notify removed startingWindow " + win); mService.scheduleRemoveStartingWindowLocked(this); - } else if (allAppWindows.size() == 0 && startingData != null) { + } else if (windows.size() == 0 && startingData != null) { // If this is the last window and we had requested a starting transition window, // well there is no point now. if (DEBUG_STARTING_WINDOW) Slog.v(TAG_WM, "Nulling last startingWindow"); startingData = null; - } else if (allAppWindows.size() == 1 && startingView != null) { + } else if (windows.size() == 1 && startingView != null) { // If this is the last window except for a starting transition window, // we need to get rid of the starting transition. mService.scheduleRemoveStartingWindowLocked(this); @@ -769,28 +745,27 @@ class AppWindowToken extends WindowToken { } void removeAllDeadWindows() { - for (int winNdx = allAppWindows.size() - 1; winNdx >= 0; - // removeWindowLocked at bottom of loop may remove multiple entries from - // allAppWindows if the window to be removed has child windows. It also may - // not remove any windows from allAppWindows at all if win is exiting and + for (int winNdx = windows.size() - 1; winNdx >= 0; + // WindowState#removeIfPossible() at bottom of loop may remove multiple entries from + // windows if the window to be removed has child windows. It also may + // not remove any windows from windows at all if win is exiting and // currently animating away. This ensures that winNdx is monotonically decreasing - // and never beyond allAppWindows bounds. - winNdx = Math.min(winNdx - 1, allAppWindows.size() - 1)) { - WindowState win = allAppWindows.get(winNdx); + // and never beyond windows bounds. + winNdx = Math.min(winNdx - 1, windows.size() - 1)) { + WindowState win = windows.get(winNdx); if (win.mAppDied) { - if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) { - Slog.w(TAG, "removeAllDeadWindows: " + win); - } + if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.w(TAG, + "removeAllDeadWindows: " + win); // Set mDestroying, we don't want any animation or delayed removal here. win.mDestroying = true; - mService.removeWindowLocked(win); + win.removeIfPossible(); } } } boolean hasWindowsAlive() { - for (int i = allAppWindows.size() - 1; i >= 0; i--) { - if (!allAppWindows.get(i).mAppDied) { + for (int i = windows.size() - 1; i >= 0; i--) { + if (!windows.get(i).mAppDied) { return true; } } @@ -801,8 +776,8 @@ class AppWindowToken extends WindowToken { if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this + " with replacing windows."); - for (int i = allAppWindows.size() - 1; i >= 0; i--) { - final WindowState w = allAppWindows.get(i); + for (int i = windows.size() - 1; i >= 0; i--) { + final WindowState w = windows.get(i); w.setReplacing(animate); } if (animate) { @@ -818,8 +793,8 @@ class AppWindowToken extends WindowToken { void setReplacingChildren() { if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Marking app token " + this + " with replacing child windows."); - for (int i = allAppWindows.size() - 1; i >= 0; i--) { - final WindowState w = allAppWindows.get(i); + for (int i = windows.size() - 1; i >= 0; i--) { + final WindowState w = windows.get(i); if (w.shouldBeReplacedWithChildren()) { w.setReplacing(false /* animate */); } @@ -830,15 +805,15 @@ class AppWindowToken extends WindowToken { if (DEBUG_ADD_REMOVE) Slog.d(TAG_WM, "Resetting app token " + this + " of replacing window marks."); - for (int i = allAppWindows.size() - 1; i >= 0; i--) { - final WindowState w = allAppWindows.get(i); + for (int i = windows.size() - 1; i >= 0; i--) { + final WindowState w = windows.get(i); w.resetReplacing(); } } void requestUpdateWallpaperIfNeeded() { - for (int i = allAppWindows.size() - 1; i >= 0; i--) { - final WindowState w = allAppWindows.get(i); + for (int i = windows.size() - 1; i >= 0; i--) { + final WindowState w = windows.get(i); w.requestUpdateWallpaperIfNeeded(); } } @@ -873,28 +848,26 @@ class AppWindowToken extends WindowToken { mPendingRelaunchCount = 0; } + @Override void addWindow(WindowState w) { - if (allAppWindows.contains(w)) { - return; - } + super.addWindow(w); + + for (int i = windows.size() - 1; i >= 0; i--) { + final WindowState candidate = windows.get(i); + if (candidate.mWillReplaceWindow && candidate.mReplacingWindow == null + && candidate.getWindowTag().toString().equals(w.getWindowTag().toString())) { - for (int i = allAppWindows.size() - 1; i >= 0; i--) { - WindowState candidate = allAppWindows.get(i); - if (candidate.mWillReplaceWindow && candidate.mReplacingWindow == null && - candidate.getWindowTag().toString().equals(w.getWindowTag().toString())) { candidate.mReplacingWindow = w; w.mSkipEnterAnimationForSeamlessReplacement = !candidate.mAnimateReplacingWindow; - // if we got a replacement window, reset the timeout to give drawing more time mService.scheduleReplacingWindowTimeouts(this); } } - allAppWindows.add(w); } boolean waitingForReplacement() { - for (int i = allAppWindows.size() -1; i >= 0; i--) { - WindowState candidate = allAppWindows.get(i); + for (int i = windows.size() - 1; i >= 0; i--) { + WindowState candidate = windows.get(i); if (candidate.mWillReplaceWindow) { return true; } @@ -903,15 +876,14 @@ class AppWindowToken extends WindowToken { } void clearTimedoutReplacesLocked() { - for (int i = allAppWindows.size() - 1; i >= 0; - // removeWindowLocked at bottom of loop may remove multiple entries from - // allAppWindows if the window to be removed has child windows. It also may - // not remove any windows from allAppWindows at all if win is exiting and - // currently animating away. This ensures that winNdx is monotonically decreasing - // and never beyond allAppWindows bounds. - i = Math.min(i - 1, allAppWindows.size() - 1)) { - WindowState candidate = allAppWindows.get(i); - if (candidate.mWillReplaceWindow == false) { + for (int i = windows.size() - 1; i >= 0; + // WindowState#remove() at bottom of loop may remove multiple entries from windows if + // the window to be removed has child windows. It also may not remove any windows from + // windows at all if win is exiting and currently animating away. This ensures that + // winNdx is monotonically decreasing and never beyond windows bounds. + i = Math.min(i - 1, windows.size() - 1)) { + final WindowState candidate = windows.get(i); + if (!candidate.mWillReplaceWindow) { continue; } candidate.mWillReplaceWindow = false; @@ -919,7 +891,7 @@ class AppWindowToken extends WindowToken { candidate.mReplacingWindow.mSkipEnterAnimationForSeamlessReplacement = false; } // Since the window already timed out, remove it immediately now. - // Use WindowState#remove() instead of removeWindowLocked(), as the latter + // Use WindowState#remove() instead of WindowState#removeIfPossible(), as the latter // delays removal on certain conditions, which will leave the stale window in the // stack and marked mWillReplaceWindow=false, so the window will never be removed. candidate.remove(); @@ -962,8 +934,8 @@ class AppWindowToken extends WindowToken { if (!mFrozenMergedConfig.isEmpty()) { mFrozenMergedConfig.remove(); } - for (int i = allAppWindows.size() - 1; i >= 0; i--) { - final WindowState win = allAppWindows.get(i); + for (int i = windows.size() - 1; i >= 0; i--) { + final WindowState win = windows.get(i); if (!win.mHasSurface) { continue; } @@ -1007,49 +979,14 @@ class AppWindowToken extends WindowToken { } void resetJustMovedInStack() { - for (int i = allAppWindows.size() - 1; i >= 0; i--) { - allAppWindows.get(i).resetJustMovedInStack(); + for (int i = windows.size() - 1; i >= 0; i--) { + windows.get(i).resetJustMovedInStack(); } } - @Override - int adjustAnimLayer(int adj) { - int highestAnimLayer = super.adjustAnimLayer(adj); - - final int windowCount = allAppWindows.size(); - - for (int i = 0; i < windowCount; i++) { - final WindowState w = allAppWindows.get(i); - w.adjustAnimLayer(adj); - - final int animLayer = w.mWinAnimator.mAnimLayer; - if (DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": " + animLayer); - if (animLayer > highestAnimLayer) { - highestAnimLayer = animLayer; - } - if (w == mService.mInputMethodTarget && !mService.mInputMethodTargetWaitingAnim) { - mService.mLayersController.setInputMethodAnimLayerAdjustment(adj); - } - } - - return highestAnimLayer; - } - - @Override - int getHighestAnimLayer() { - int layer = super.getHighestAnimLayer(); - for (int j = 0; j < allAppWindows.size(); j++) { - final WindowState win = allAppWindows.get(j); - if (win.mWinAnimator.mAnimLayer > layer) { - layer = win.mWinAnimator.mAnimLayer; - } - } - return layer; - } - void setWaitingForDrawnIfResizingChanged() { - for (int i = allAppWindows.size() - 1; i >= 0; --i) { - final WindowState win = allAppWindows.get(i); + for (int i = windows.size() - 1; i >= 0; --i) { + final WindowState win = windows.get(i); if (win.isDragResizeChanged()) { mService.mWaitingForDrawn.add(win); } @@ -1062,8 +999,8 @@ class AppWindowToken extends WindowToken { // destroy all saved surfaces here. destroySavedSurfaces(); - for (int winNdx = allAppWindows.size() - 1; winNdx >= 0; --winNdx) { - final WindowState win = allAppWindows.get(winNdx); + for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { + final WindowState win = windows.get(winNdx); if (win.mHasSurface && !resizingWindows.contains(win)) { if (DEBUG_RESIZE) Slog.d(TAG, "resizeWindows: Resizing " + win); resizingWindows.add(win); @@ -1092,33 +1029,33 @@ class AppWindowToken extends WindowToken { } void moveWindows() { - for (int winNdx = allAppWindows.size() - 1; winNdx >= 0; --winNdx) { - final WindowState win = allAppWindows.get(winNdx); + for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { + final WindowState win = windows.get(winNdx); if (DEBUG_RESIZE) Slog.d(TAG, "moveWindows: Moving " + win); win.mMovedByResize = true; } } void notifyMovedInStack() { - for (int winNdx = allAppWindows.size() - 1; winNdx >= 0; --winNdx) { - final WindowState win = allAppWindows.get(winNdx); + for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { + final WindowState win = windows.get(winNdx); win.notifyMovedInStack(); } } void resetDragResizingChangeReported() { - for (int winNdx = allAppWindows.size() - 1; winNdx >= 0; --winNdx) { - final WindowState win = allAppWindows.get(winNdx); + for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { + final WindowState win = windows.get(winNdx); win.resetDragResizingChangeReported(); } } void detachDisplay() { boolean doAnotherLayoutPass = false; - for (int winNdx = allAppWindows.size() - 1; winNdx >= 0; --winNdx) { + for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { // We are in the middle of changing the state of displays/stacks/tasks. We need // to finish that, before we let layout interfere with it. - mService.removeWindowLocked(allAppWindows.get(winNdx)); + windows.get(winNdx).removeIfPossible(); doAnotherLayoutPass = true; } if (doAnotherLayoutPass) { @@ -1127,8 +1064,8 @@ class AppWindowToken extends WindowToken { } void forceWindowsScaleableInTransaction(boolean force) { - for (int winNdx = allAppWindows.size() - 1; winNdx >= 0; --winNdx) { - final WindowStateAnimator winAnimator = allAppWindows.get(winNdx).mWinAnimator; + for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { + final WindowStateAnimator winAnimator = windows.get(winNdx).mWinAnimator; if (winAnimator == null || !winAnimator.hasSurface()) { continue; } @@ -1137,8 +1074,8 @@ class AppWindowToken extends WindowToken { } boolean isAnimating() { - for (int winNdx = allAppWindows.size() - 1; winNdx >= 0; --winNdx) { - final WindowStateAnimator winAnimator = allAppWindows.get(winNdx).mWinAnimator; + for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) { + final WindowStateAnimator winAnimator = windows.get(winNdx).mWinAnimator; if (winAnimator.isAnimationSet() || winAnimator.mWin.mAnimatingExit) { return true; } @@ -1148,8 +1085,8 @@ class AppWindowToken extends WindowToken { void setAppLayoutChanges(int changes, String reason, int displayId) { final WindowAnimator windowAnimator = mAppAnimator.mAnimator; - for (int i = allAppWindows.size() - 1; i >= 0; i--) { - if (displayId == allAppWindows.get(i).getDisplayId()) { + for (int i = windows.size() - 1; i >= 0; i--) { + if (displayId == windows.get(i).getDisplayId()) { windowAnimator.setPendingLayoutChanges(displayId, changes); if (DEBUG_LAYOUT_REPEATS) { mService.mWindowPlacerLocked.debugLayoutRepeats( @@ -1161,8 +1098,8 @@ class AppWindowToken extends WindowToken { } void removeReplacedWindowIfNeeded(WindowState replacement) { - for (int i = allAppWindows.size() - 1; i >= 0; i--) { - final WindowState win = allAppWindows.get(i); + for (int i = windows.size() - 1; i >= 0; i--) { + final WindowState win = windows.get(i); if (win.mWillReplaceWindow && win.mReplacingWindow == replacement && replacement.hasDrawnLw()) { replacement.mSkipEnterAnimationForSeamlessReplacement = false; @@ -1185,9 +1122,9 @@ class AppWindowToken extends WindowToken { mService.mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 2000); } } - final int count = allAppWindows.size(); + final int count = windows.size(); for (int i = 0; i < count; i++) { - final WindowState w = allAppWindows.get(i); + final WindowState w = windows.get(i); w.mAppFreezing = true; } } @@ -1198,10 +1135,10 @@ class AppWindowToken extends WindowToken { return; } if (DEBUG_ORIENTATION) Slog.v(TAG_WM, "Clear freezing of " + this + " force=" + force); - final int count = allAppWindows.size(); + final int count = windows.size(); boolean unfrozeWindows = false; for (int i = 0; i < count; i++) { - final WindowState w = allAppWindows.get(i); + final WindowState w = windows.get(i); if (w.mAppFreezing) { w.mAppFreezing = false; if (w.mHasSurface && !w.mOrientationChanging @@ -1269,8 +1206,7 @@ class AppWindowToken extends WindowToken { if (DEBUG_ADD_REMOVE) Slog.v(TAG_WM, "Removing starting " + tStartingWindow + " from " + fromToken); fromToken.removeWindow(tStartingWindow); - fromToken.allAppWindows.remove(tStartingWindow); - addWindowToList(tStartingWindow); + addWindow(tStartingWindow); // Propagate other interesting state between the tokens. If the old token is displayed, // we should immediately force the new one to be displayed. If it is animating, we need @@ -1330,25 +1266,19 @@ class AppWindowToken extends WindowToken { } int getWindowsCount() { - return allAppWindows.size(); + return windows.size(); } void setAllAppWinAnimators() { final ArrayList allAppWinAnimators = mAppAnimator.mAllAppWinAnimators; allAppWinAnimators.clear(); - final int windowsCount = allAppWindows.size(); + final int windowsCount = windows.size(); for (int j = 0; j < windowsCount; j++) { - allAppWinAnimators.add(allAppWindows.get(j).mWinAnimator); + allAppWinAnimators.add(windows.get(j).mWinAnimator); } } - /** Returns true if the app token windows list is empty. */ - @Override - boolean isEmpty() { - return allAppWindows.isEmpty(); - } - @Override AppWindowToken asAppWindowToken() { // I am an app window token! @@ -1361,9 +1291,6 @@ class AppWindowToken extends WindowToken { if (appToken != null) { pw.print(prefix); pw.print("app=true voiceInteraction="); pw.println(voiceInteraction); } - if (allAppWindows.size() > 0) { - pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows); - } pw.print(prefix); pw.print("task="); pw.println(mTask); pw.print(prefix); pw.print(" appFullscreen="); pw.print(appFullscreen); pw.print(" requestedOrientation="); pw.println(requestedOrientation); diff --git a/services/core/java/com/android/server/wm/InputMonitor.java b/services/core/java/com/android/server/wm/InputMonitor.java index 00781c53a17b1..b9c55a5762515 100644 --- a/services/core/java/com/android/server/wm/InputMonitor.java +++ b/services/core/java/com/android/server/wm/InputMonitor.java @@ -87,7 +87,7 @@ final class InputMonitor implements InputManagerService.WindowManagerCallbacks { WindowState windowState = (WindowState) inputWindowHandle.windowState; if (windowState != null) { Slog.i(TAG_WM, "WINDOW DIED " + windowState); - mService.removeWindowLocked(windowState); + windowState.removeIfPossible(); } } } diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index f41693aa9b131..be68b92c5977d 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -1269,12 +1269,12 @@ public class WindowManagerService extends IWindowManager.Stub moveInputMethodDialogsLocked(pos + 1); return; } - win.mToken.addWindowToList(win); + win.mToken.addWindow(win); moveInputMethodDialogsLocked(pos); } private void reAddWindowToListInOrderLocked(WindowState win) { - win.mToken.addWindowToList(win); + win.mToken.addWindow(win); // This is a hack to get all of the child windows added as well at the right position. Child // windows should be rare and this case should be rare, so it shouldn't be that big a deal. WindowList windows = win.getWindowList(); @@ -1283,7 +1283,7 @@ public class WindowManagerService extends IWindowManager.Stub if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG_WM, "ReAdd removing from " + wpos + ": " + win); windows.remove(wpos); mWindowsChanged = true; - win.reAddWindowLocked(wpos); + win.reAddWindow(wpos); } } @@ -1325,7 +1325,7 @@ public class WindowManagerService extends IWindowManager.Stub if (DEBUG_INPUT_METHOD) Slog.v(TAG_WM, "Adding " + N + " dialogs at pos=" + pos); for (int i=0; i= 0; --winNdx) { + for (int winNdx = windows.size() - 1; winNdx >= 0; + // WindowState#removeIfPossible() at bottom of loop may remove multiple entries from + // allAppWindows if the window to be removed has child windows. It also may not + // remove any windows from allAppWindows at all if win is exiting and currently + // animating away. This ensures that winNdx is monotonically decreasing and never + // beyond allAppWindows bounds. + winNdx = Math.min(winNdx - 1, windows.size() - 1)) { WindowState win = windows.get(winNdx); if (DEBUG_WINDOW_MOVEMENT) Slog.w(TAG_WM, "removeAllWindows: removing win=" + win); - win.mService.removeWindowLocked(win); + win.removeIfPossible(); } windows.clear(); } @@ -157,6 +164,9 @@ class WindowToken { if (animLayer > highestAnimLayer) { highestAnimLayer = animLayer; } + if (w == mService.mInputMethodTarget && !mService.mInputMethodTargetWaitingAnim) { + mService.mLayersController.setInputMethodAnimLayerAdjustment(adj); + } } return highestAnimLayer; } @@ -258,8 +268,7 @@ class WindowToken { } } - // TODO: Rename to addWindow when conflict with AppWindowToken is resolved. The call below. - void addWindowToList(final WindowState win) { + void addWindow(final WindowState win) { if (DEBUG_FOCUS) Slog.d(TAG_WM, "addWindow: win=" + win + " Callers=" + Debug.getCallers(5)); if (!win.isChildWindow()) { @@ -276,11 +285,6 @@ class WindowToken { } else { addChildWindow(win); } - - final AppWindowToken appToken = win.mAppToken; - if (appToken != null) { - appToken.addWindow(win); - } } private int addAppWindow(final WindowState win) { @@ -452,7 +456,7 @@ class WindowToken { for (int i = 0; i < count; i++) { final WindowState win = windows.get(i); if (win.isChildWindow()) { - // The WindowState.reAddWindowLocked below already takes care of re-adding the + // The WindowState.reAddWindow below already takes care of re-adding the // child windows for any parent window in this token. This is a side effect of // ensuring child windows are in the same WindowToken as their parent window. // @@ -464,7 +468,7 @@ class WindowToken { final DisplayContent winDisplayContent = win.getDisplayContent(); if (winDisplayContent == displayContent || winDisplayContent == null) { win.mDisplayContent = displayContent; - index = win.reAddWindowLocked(index); + index = win.reAddWindow(index); } } return index; @@ -496,6 +500,7 @@ class WindowToken { return null; } + @CallSuper void removeWindow(WindowState win) { windows.remove(win); }