From 27142d6215046ff914764a733e23df341a36e161 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Fri, 2 Jun 2023 00:37:40 +0800 Subject: [PATCH] Do not notify transition finish for a initializing activity Because startActivity always collects the launch activity to transition participants, it may contain some records that are not actual handled by transition. For example, when launching activity under dream, because dream activity has top z-order, the launching activity will use mLaunchTaskBehind to be visible. The z-order: Top TaskD DreamActivity TaskX B <-INITIALIZING A (Trampoline which launches B) There might be a no-op transition triggered by A. If the transition clears B's mLaunchTaskBehind, then after A is paused B won't continue to resume. Fix: 279647026 Test: TransitionTests#testIntermediateVisibility Change-Id: Id0615c2bc6cbea1adb94e866db85567cdf514326 --- .../core/java/com/android/server/wm/Transition.java | 6 +++++- .../src/com/android/server/wm/TransitionTests.java | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/wm/Transition.java b/services/core/java/com/android/server/wm/Transition.java index b938b9e4ec51e..0d1de3ff6b2e2 100644 --- a/services/core/java/com/android/server/wm/Transition.java +++ b/services/core/java/com/android/server/wm/Transition.java @@ -1191,7 +1191,11 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener { // processed all the participants first (in particular, we want to trigger pip-enter first) for (int i = 0; i < mParticipants.size(); ++i) { final ActivityRecord ar = mParticipants.valueAt(i).asActivityRecord(); - if (ar != null) { + // If the activity was just inserted to an invisible task, it will keep INITIALIZING + // state. Then no need to notify the callback to avoid clearing some states + // unexpectedly, e.g. launch-task-behind. + if (ar != null && (ar.isVisibleRequested() + || !ar.isState(ActivityRecord.State.INITIALIZING))) { mController.dispatchLegacyAppTransitionFinished(ar); } } diff --git a/services/tests/wmtests/src/com/android/server/wm/TransitionTests.java b/services/tests/wmtests/src/com/android/server/wm/TransitionTests.java index b59f027fec83b..11267268a6fa9 100644 --- a/services/tests/wmtests/src/com/android/server/wm/TransitionTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/TransitionTests.java @@ -1346,6 +1346,16 @@ public class TransitionTests extends WindowTestsBase { activity1.setVisible(false); abortTransition.abort(); assertTrue(activity1.isVisible()); + + // The mLaunchTaskBehind flag of an invisible initializing activity should not be cleared. + final Transition noChangeTransition = controller.createTransition(TRANSIT_OPEN); + noChangeTransition.collect(activity1); + activity1.setVisibleRequested(false); + activity1.setState(ActivityRecord.State.INITIALIZING, "test"); + activity1.mLaunchTaskBehind = true; + mWm.mSyncEngine.abort(noChangeTransition.getSyncId()); + noChangeTransition.finishTransition(); + assertTrue(activity1.mLaunchTaskBehind); } @Test