Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 45974dd3 authored by Jiaming Liu's avatar Jiaming Liu
Browse files

Fix placeholder launch with AvoidMoveToFront flag

Placeholder could be dismissed and immediately relaunched if an activity
matches a split rule with clear-top flag but ends up launched in a new
task. In this case, the current task would be incorrectly placed on top
of the new task. Always setting the AvoidMoveToFront flag can prevent
this issue, and no animation issue is found in contrast to the previous
comment.

Bug: 374213115
Test: atest WMJetpackUnitTests:SplitControllerTest
Flag: EXEMPT bugfix
Change-Id: Ib34b30ff06903a26410eea8521ef51bc17156f0d
parent d95b534a
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -2314,15 +2314,12 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
    @GuardedBy("mLock")
    @Nullable
    Bundle getPlaceholderOptions(@NonNull Activity primaryActivity, boolean isOnCreated) {
        // Setting avoid move to front will also skip the animation. We only want to do that when
        // the Task is currently in background.
        // Check if the primary is resumed or if this is called when the primary is onCreated
        // (not resumed yet).
        if (isOnCreated || primaryActivity.isResumed()) {
            // Only set trigger type if the launch happens in foreground.
            mTransactionManager.getCurrentTransactionRecord()
                    .setOriginType(TASK_FRAGMENT_TRANSIT_OPEN);
            return null;
        }
        final ActivityOptions options = ActivityOptions.makeBasic();
        options.setAvoidMoveToFront();
+24 −18
Original line number Diff line number Diff line
@@ -166,6 +166,8 @@ public class SplitControllerTest {
    private List<SplitInfo> mSplitInfos;
    private TransactionManager mTransactionManager;
    private ActivityThread mCurrentActivityThread;
    private final ArgumentCaptor<Bundle> mBundleArgumentCaptor =
            ArgumentCaptor.forClass(Bundle.class);

    @Before
    public void setUp() {
@@ -685,9 +687,13 @@ public class SplitControllerTest {
                false /* isOnReparent */);

        assertTrue(result);
        verify(mSplitPresenter).startActivityToSide(mTransaction, mActivity, PLACEHOLDER_INTENT,
                mSplitController.getPlaceholderOptions(mActivity, true /* isOnCreated */),
                placeholderRule, SPLIT_ATTRIBUTES, true /* isPlaceholder */);
        verify(mSplitPresenter).startActivityToSide(eq(mTransaction), eq(mActivity),
                eq(PLACEHOLDER_INTENT), mBundleArgumentCaptor.capture(),
                eq(placeholderRule), eq(SPLIT_ATTRIBUTES), eq(true) /* isPlaceholder */);

        final ActivityOptions activityOptions =
                new ActivityOptions(mBundleArgumentCaptor.getValue());
        assertTrue(activityOptions.getAvoidMoveToFront());
    }

    @Test
@@ -720,9 +726,13 @@ public class SplitControllerTest {
                false /* isOnReparent */);

        assertTrue(result);
        verify(mSplitPresenter).startActivityToSide(mTransaction, mActivity, PLACEHOLDER_INTENT,
                mSplitController.getPlaceholderOptions(mActivity, true /* isOnCreated */),
                placeholderRule, SPLIT_ATTRIBUTES, true /* isPlaceholder */);
        verify(mSplitPresenter).startActivityToSide(eq(mTransaction), eq(mActivity),
                eq(PLACEHOLDER_INTENT), mBundleArgumentCaptor.capture(),
                eq(placeholderRule), eq(SPLIT_ATTRIBUTES), eq(true) /* isPlaceholder */);

        final ActivityOptions activityOptions =
                new ActivityOptions(mBundleArgumentCaptor.getValue());
        assertTrue(activityOptions.getAvoidMoveToFront());
    }

    @Test
@@ -755,9 +765,13 @@ public class SplitControllerTest {
                false /* isOnReparent */);

        assertTrue(result);
        verify(mSplitPresenter).startActivityToSide(mTransaction, mActivity, PLACEHOLDER_INTENT,
                mSplitController.getPlaceholderOptions(mActivity, true /* isOnCreated */),
                placeholderRule, SPLIT_ATTRIBUTES, true /* isPlaceholder */);
        verify(mSplitPresenter).startActivityToSide(eq(mTransaction), eq(mActivity),
                eq(PLACEHOLDER_INTENT), mBundleArgumentCaptor.capture(),
                eq(placeholderRule), eq(SPLIT_ATTRIBUTES), eq(true) /* isPlaceholder */);

        final ActivityOptions activityOptions =
                new ActivityOptions(mBundleArgumentCaptor.getValue());
        assertTrue(activityOptions.getAvoidMoveToFront());
    }

    @Test
@@ -1065,16 +1079,8 @@ public class SplitControllerTest {
    public void testGetPlaceholderOptions() {
        // Setup to make sure a transaction record is started.
        mTransactionManager.startNewTransaction();
        doReturn(true).when(mActivity).isResumed();

        assertNull(mSplitController.getPlaceholderOptions(mActivity, false /* isOnCreated */));

        doReturn(false).when(mActivity).isResumed();

        assertNull(mSplitController.getPlaceholderOptions(mActivity, true /* isOnCreated */));

        // Launch placeholder without moving the Task to front if the Task is now in background (not
        // resumed or onCreated).
        // Launch placeholder without moving the Task to front
        final Bundle options = mSplitController.getPlaceholderOptions(mActivity,
                false /* isOnCreated */);