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

Commit a194c10a authored by Louis Chang's avatar Louis Chang
Browse files

Prevents recursively moving activity to a new expanded container

When an activity should be expanded, the activity is moved to a
new expanded TaskFragmentContainer and the same container was
splitted with the SplitPinContainer in the same WCT. However,
the activity may be relaunched afterward when updating the
TaskFragment bound (or could also due to insets changes). In
that case, the activity will be resolved to move to a new
expanded TaskFragmentContainer again while Activity#onCreate
is called. So, TaskFragments are created (and removed) repeatedly
for the expanded Activity.

This issue is not reproducible if the activity can handle the
configuration change.

Do nothing if the expanded activity is already in a standalone
container and split with another pinned container.

Bug: 355595391
Test: verified locally with sample app
Flag: EXEMPT bugfix
Change-Id: I8d92788287d72e1a58d1ad383c25585ea7fc4a19
parent b4eca62f
Loading
Loading
Loading
Loading
+17 −6
Original line number Diff line number Diff line
@@ -1333,14 +1333,25 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
        if (shouldContainerBeExpanded(container)) {
            // Make sure that the existing container is expanded.
            mPresenter.expandTaskFragment(wct, container);
        } else {
            return;
        }

        final SplitContainer splitContainer = getActiveSplitForContainer(container);
        if (splitContainer instanceof SplitPinContainer
                && !container.isPinned() && container.getRunningActivityCount() == 1) {
            // This is already the expected state when the pinned container is shown with an
            // expanded activity in a standalone container on the side. Moving the activity into
            // another new expanded container again is not necessary and could result in
            // recursively creating new TaskFragmentContainers if the activity somehow relaunched.
            return;
        }

        // Put activity into a new expanded container.
        final TaskFragmentContainer newContainer =
                new TaskFragmentContainer.Builder(this, getTaskId(activity), activity)
                        .setPendingAppearedActivity(activity).build();
        mPresenter.expandActivity(wct, newContainer.getTaskFragmentToken(), activity);
    }
    }

    /**
     * Whether the given new launched activity is in a split with a rule matched.