From e00f086e494c303f39a1f1f594a1b0f629db9d0f Mon Sep 17 00:00:00 2001 From: wilsonshih Date: Wed, 8 Sep 2021 15:44:05 +0800 Subject: [PATCH] Prevent execute app transition too early when performClearTask The app transition could be executed in finishIfPossible if one of the non-top activity in the task is visible but not resumed, which lead the wrong transition type, normally there should wait for for next resumed activity be added to opening apps. Use destroyIfPossible to prevent unnecessary transition. Bug: 192309923 Test: verify the transition type after SUW call finishAndRemoveTask. Test: atest AppTransitionControllerTest TaskStackChangedListenerTest Change-Id: I5c336bc5a8fc52684f5e15d8ff973d0960aa1250 --- services/core/java/com/android/server/wm/Task.java | 12 +++++++++--- .../server/wm/AppTransitionControllerTest.java | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java index 7bdb1a090c1a6..f32fc46932fef 100644 --- a/services/core/java/com/android/server/wm/Task.java +++ b/services/core/java/com/android/server/wm/Task.java @@ -1596,9 +1596,15 @@ class Task extends TaskFragment { } else { forAllActivities((r) -> { if (r.finishing) return; - // TODO: figure-out how to avoid object creation due to capture of reason variable. - r.finishIfPossible(Activity.RESULT_CANCELED, - null /* resultData */, null /* resultGrants */, reason, false /* oomAdj */); + // Prevent the transition from being executed too early if the top activity is + // resumed but the mVisibleRequested of any other activity is true, the transition + // should wait until next activity resumed. + if (r.isState(RESUMED) || (r.isVisible() + && !mDisplayContent.mAppTransition.containsTransitRequest(TRANSIT_CLOSE))) { + r.finishIfPossible(reason, false /* oomAdj */); + } else { + r.destroyIfPossible(reason); + } }); } } diff --git a/services/tests/wmtests/src/com/android/server/wm/AppTransitionControllerTest.java b/services/tests/wmtests/src/com/android/server/wm/AppTransitionControllerTest.java index 53bae4156d6bf..0d0cec7f5dce1 100644 --- a/services/tests/wmtests/src/com/android/server/wm/AppTransitionControllerTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/AppTransitionControllerTest.java @@ -102,6 +102,20 @@ public class AppTransitionControllerTest extends WindowTestsBase { mDisplayContent.mChangingContainers, null, null, false)); } + @Test + public void testClearTaskSkipAppExecuteTransition() { + final ActivityRecord behind = createActivityRecord(mDisplayContent, + WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD); + final Task task = behind.getTask(); + final ActivityRecord top = createActivityRecord(task); + top.setState(ActivityRecord.State.RESUMED, "test"); + behind.setState(ActivityRecord.State.STARTED, "test"); + behind.mVisibleRequested = true; + + task.performClearTask("test"); + assertFalse(mDisplayContent.mAppTransition.isReady()); + } + @Test public void testTranslucentOpen() { final ActivityRecord behind = createActivityRecord(mDisplayContent,