Move handleCompleteDeferredRemoval to animator thread

The method may remove window hierarchy element in random
timing (usually depends on animation). If the caller
indirectly calls to performSurfacePlacement inside a loop
that also removes element, the loop may encounter index
out of bound exception. It is hard for the caller to aware
how to iterate window containers safely.

Because performSurfacePlacement always calls WindowAnimator
scheduleAnimationLocked, the movement of invocation should
not miss the original cases for deferred removal.

It also reduces unnecessary invocations up to 50% because
animator won't execute multiple times if it is scheduled,
while performSurfacePlacement calls each time. And the
partial cost may be moved out from binder thread.

Bug: 173270358
Test: CtsWindowManagerDeviceTestCases
Change-Id: If9a45403e7bbedb2073f8e6f6e90934af0c4c29e
This commit is contained in:
Riddle Hsu
2020-11-19 19:28:38 +08:00
parent edf2036691
commit 275aba2deb
3 changed files with 4 additions and 4 deletions

View File

@@ -994,9 +994,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
}
}
// Remove all deferred displays stacks, tasks, and activities.
handleCompleteDeferredRemoval();
forAllDisplays(dc -> {
dc.getInputMonitor().updateInputWindowsLw(true /*force*/);
dc.updateSystemGestureExclusion();

View File

@@ -143,6 +143,9 @@ public class WindowAnimator {
ProtoLog.i(WM_SHOW_TRANSACTIONS, ">>> OPEN TRANSACTION animate");
mService.openSurfaceTransaction();
try {
// Remove all deferred displays, tasks, and activities.
mService.mRoot.handleCompleteDeferredRemoval();
final AccessibilityController accessibilityController =
mService.mAccessibilityController;
final int numDisplays = mDisplayContentsAnimators.size();

View File

@@ -1060,7 +1060,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
// descendant. E.g. if a display is pending to be removed because it contains an
// activity with {@link ActivityRecord#mIsExiting} is true, the display may be
// removed when completing the removal of the last activity from
// {@link ActivityRecord#checkCompleteDeferredRemoval}.
// {@link ActivityRecord#handleCompleteDeferredRemoval}.
return false;
}
}