diff options
| author | 2021-03-01 17:52:09 -0800 | |
|---|---|---|
| committer | 2021-03-01 17:52:09 -0800 | |
| commit | 93b493a2f9a133bb4b5989a0d16f9adcd2fe11e3 (patch) | |
| tree | e636f25051dcff4160d43f1e4324ece88cdc8fec | |
| parent | 057fc812a94b4ffd242af09ecb019108af42051f (diff) | |
Move insets freeze to visibleRequested change
Instead of doing freeze/unfreeze exclusively for legacy
transitions, just freeze the insets whenever an activity goes
invisible; then clear it whenever the the activity is visible.
This is compatible with shell transitions as well.
Bug: 179270750
Test: updated/added WindowContainerTests
Change-Id: Iae5025beaed7d70a4623b446a1bb73574d420663
6 files changed, 35 insertions, 19 deletions
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index f40f4a98964a..6c14a698aa1e 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -4447,6 +4447,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A return; } mVisibleRequested = visible; + setInsetsFrozen(!visible); if (app != null) { mTaskSupervisor.onProcessActivityStateChanged(app, false /* forceBatch */); } diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index eff4ea6536bd..3bb0b8406f19 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -4105,13 +4105,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp */ void onWindowAnimationFinished(@NonNull WindowContainer wc, int type) { if (type == ANIMATION_TYPE_APP_TRANSITION || type == ANIMATION_TYPE_RECENTS) { - // Unfreeze the insets state of the frozen target when the animation finished if exists. - final Task task = wc.asTask(); - if (task != null) { - task.forAllWindows(w -> { - w.clearFrozenInsetsState(); - }, true /* traverseTopToBottom */); - } removeImeSurfaceImmediately(); } } diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java index dd4ee877c05b..000889a16d4c 100644 --- a/services/core/java/com/android/server/wm/WindowContainer.java +++ b/services/core/java/com/android/server/wm/WindowContainer.java @@ -2684,14 +2684,6 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer< @Nullable ArrayList<WindowContainer> sources) { final Task task = asTask(); if (task != null && !enter && !task.isHomeOrRecentsRootTask()) { - if (AppTransition.isClosingTransitOld(transit)) { - // Freezes the insets state when the window is in app exiting transition, to - // ensure the exiting window won't receive unexpected insets changes from the - // next window. - task.forAllWindows(w -> { - w.freezeInsetsState(); - }, true /* traverseTopToBottom */); - } mDisplayContent.showImeScreenshot(); } final Pair<AnimationAdapter, AnimationAdapter> adapters = getAnimationAdapter(lp, diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 1fc7041c0fe2..e6c560208109 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -797,7 +797,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP * {@link InsetsStateController#notifyInsetsChanged}. */ boolean isReadyToDispatchInsetsState() { - return isVisible() && mFrozenInsetsState == null; + return isVisibleRequested() && mFrozenInsetsState == null; } void seamlesslyRotateIfAllowed(Transaction transaction, @Rotation int oldRotation, diff --git a/services/core/java/com/android/server/wm/WindowToken.java b/services/core/java/com/android/server/wm/WindowToken.java index e87ee918e0f0..066cc1e105ab 100644 --- a/services/core/java/com/android/server/wm/WindowToken.java +++ b/services/core/java/com/android/server/wm/WindowToken.java @@ -736,4 +736,13 @@ class WindowToken extends WindowContainer<WindowState> { boolean isFromClient() { return mFromClientToken; } + + /** @see WindowState#freezeInsetsState() */ + void setInsetsFrozen(boolean freeze) { + if (freeze) { + forAllWindows(WindowState::freezeInsetsState, true /* traverseTopToBottom */); + } else { + forAllWindows(WindowState::clearFrozenInsetsState, true /* traverseTopToBottom */); + } + } } diff --git a/services/tests/wmtests/src/com/android/server/wm/WindowContainerTests.java b/services/tests/wmtests/src/com/android/server/wm/WindowContainerTests.java index 99c96bd0de1b..bbb885eb0dd0 100644 --- a/services/tests/wmtests/src/com/android/server/wm/WindowContainerTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/WindowContainerTests.java @@ -984,6 +984,22 @@ public class WindowContainerTests extends WindowTestsBase { } @Test + public void testFreezeInsets() { + final Task stack = createTaskStackOnDisplay(mDisplayContent); + final ActivityRecord activity = createActivityRecord(mDisplayContent, stack); + final WindowState win = createWindow(null, TYPE_BASE_APPLICATION, activity, "win"); + + // Set visibility to false, verify the main window of the task will be set the frozen + // insets state immediately. + activity.setVisibility(false); + assertNotNull(win.getFrozenInsetsState()); + + // Now make it visible again, verify that the insets are immediately unfrozen. + activity.setVisibility(true); + assertNull(win.getFrozenInsetsState()); + } + + @Test public void testFreezeInsetsStateWhenAppTransition() { final Task stack = createTaskStackOnDisplay(mDisplayContent); final Task task = createTaskInStack(stack, 0 /* userId */); @@ -996,15 +1012,20 @@ public class WindowContainerTests extends WindowTestsBase { sources.add(activity); // Simulate the task applying the exit transition, verify the main window of the task - // will be set the frozen insets state. + // will be set the frozen insets state before the animation starts + activity.setVisibility(false); task.applyAnimation(null, TRANSIT_OLD_TASK_CLOSE, false /* enter */, false /* isVoiceInteraction */, sources); verify(win).freezeInsetsState(); - // Simulate the task transition finished, verify the frozen insets state of the window - // will be reset. + // Simulate the task transition finished. + activity.commitVisibility(false, false); task.onAnimationFinished(ANIMATION_TYPE_APP_TRANSITION, task.mSurfaceAnimator.getAnimation()); + + // Now make it visible again, verify that the insets are immediately unfrozen even before + // transition starts. + activity.setVisibility(true); verify(win).clearFrozenInsetsState(); } |