Merge "Replace mPendingRemove with hierarchy deferred removal"

This commit is contained in:
TreeHugger Robot
2022-02-09 03:12:19 +00:00
committed by Android (Google) Code Review
4 changed files with 27 additions and 60 deletions

View File

@@ -981,29 +981,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
mWmService.checkDrawnWindowsLocked();
}
final int N = mWmService.mPendingRemove.size();
if (N > 0) {
if (mWmService.mPendingRemoveTmp.length < N) {
mWmService.mPendingRemoveTmp = new WindowState[N + 10];
}
mWmService.mPendingRemove.toArray(mWmService.mPendingRemoveTmp);
mWmService.mPendingRemove.clear();
ArrayList<DisplayContent> displayList = new ArrayList();
for (i = 0; i < N; i++) {
final WindowState w = mWmService.mPendingRemoveTmp[i];
w.removeImmediately();
final DisplayContent displayContent = w.getDisplayContent();
if (displayContent != null && !displayList.contains(displayContent)) {
displayList.add(displayContent);
}
}
for (int j = displayList.size() - 1; j >= 0; --j) {
final DisplayContent dc = displayList.get(j);
dc.assignWindowLayers(true /*setLayoutNeeded*/);
}
}
forAllDisplays(dc -> {
dc.getInputMonitor().updateInputWindowsLw(true /*force*/);
dc.updateSystemGestureExclusion();

View File

@@ -224,7 +224,6 @@ import android.util.DisplayMetrics;
import android.util.EventLog;
import android.util.MergedConfiguration;
import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.util.TimeUtils;
import android.util.TypedValue;
@@ -583,20 +582,6 @@ public class WindowManagerService extends IWindowManager.Stub
*/
final ArrayList<WindowState> mResizingWindows = new ArrayList<>();
/**
* Windows whose animations have ended and now must be removed.
*/
final ArrayList<WindowState> mPendingRemove = new ArrayList<>();
/**
* Used when processing mPendingRemove to avoid working on the original array.
*/
WindowState[] mPendingRemoveTmp = new WindowState[20];
// TODO: use WindowProcessController once go/wm-unified is done.
/** Mapping of process pids to configurations */
final SparseArray<Configuration> mProcessConfigurations = new SparseArray<>();
/**
* Mapping of displayId to {@link DisplayImePolicy}.
* Note that this can be accessed without holding the lock.
@@ -2039,7 +2024,6 @@ public class WindowManagerService extends IWindowManager.Stub
dc.mWinRemovedSinceNullFocus.add(win);
}
mEmbeddedWindowController.onWindowRemoved(win);
mPendingRemove.remove(win);
mResizingWindows.remove(win);
updateNonSystemOverlayWindowsVisibilityIfNeeded(win, false /* surfaceShown */);
mWindowsChanged = true;
@@ -6411,23 +6395,6 @@ public class WindowManagerService extends IWindowManager.Stub
}
}
}
if (mPendingRemove.size() > 0) {
pw.println();
pw.println(" Remove pending for:");
for (int i=mPendingRemove.size()-1; i>=0; i--) {
WindowState w = mPendingRemove.get(i);
if (windows == null || windows.contains(w)) {
pw.print(" Remove #"); pw.print(i); pw.print(' ');
pw.print(w);
if (dumpAll) {
pw.println(":");
w.dump(pw, " ", true);
} else {
pw.println();
}
}
}
}
if (mForceRemoves != null && mForceRemoves.size() > 0) {
pw.println();
pw.println(" Windows force removing:");

View File

@@ -4910,15 +4910,20 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
if (hasSurface) {
mWmService.mDestroySurface.add(this);
}
if (mRemoveOnExit) {
mWmService.mPendingRemove.add(this);
mRemoveOnExit = false;
}
}
mAnimatingExit = false;
getDisplayContent().mWallpaperController.hideWallpapers(this);
}
@Override
boolean handleCompleteDeferredRemoval() {
if (mRemoveOnExit && !isSelfAnimating(0 /* flags */, EXIT_ANIMATING_TYPES)) {
mRemoveOnExit = false;
removeImmediately();
}
return super.handleCompleteDeferredRemoval();
}
boolean clearAnimatingFlags() {
boolean didSomething = false;
// We don't want to clear it out for windows that get replaced, because the

View File

@@ -870,6 +870,24 @@ public class WindowContainerTests extends WindowTestsBase {
final DisplayContent displayContent = createNewDisplay();
// Do not reparent activity to default display when removing the display.
doReturn(true).when(displayContent).shouldDestroyContentOnRemove();
// An animating window with mRemoveOnExit can be removed by handleCompleteDeferredRemoval
// once it no longer animates.
final WindowState exitingWindow = createWindow(null, TYPE_APPLICATION_OVERLAY,
displayContent, "exiting window");
exitingWindow.startAnimation(exitingWindow.getPendingTransaction(),
mock(AnimationAdapter.class), false /* hidden */,
SurfaceAnimator.ANIMATION_TYPE_WINDOW_ANIMATION);
exitingWindow.mRemoveOnExit = true;
exitingWindow.handleCompleteDeferredRemoval();
// The animation has not finished so the window is not removed.
assertTrue(exitingWindow.isAnimating());
assertTrue(exitingWindow.isAttached());
exitingWindow.cancelAnimation();
// The window is removed because the animation is gone.
exitingWindow.handleCompleteDeferredRemoval();
assertFalse(exitingWindow.isAttached());
final ActivityRecord r = new TaskBuilder(mSupervisor).setCreateActivity(true)
.setDisplay(displayContent).build().getTopMostActivity();
// Add a window and make the activity animating so the removal of activity is deferred.