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

Commit 5dc3ec51 authored by Louis Chang's avatar Louis Chang
Browse files

Fixes app crash when starts activity with FLAG_ACTIVITY_REORDER_TO_FRONT

Application was crashed while starting an embedded Activity with
FLAG_ACTIVITY_REORDER_TO_FRONT, because the embedded Activity was
not the direct child of the Task.

In this CL, the embedded activity is now moved to the top-most
position of the Task and dismissed from being embedded in order
to honer FLAG_ACTIVITY_REORDER_TO_FRONT.

Bug: 255701223
Test: locally verified with app
Test: atest TaskTests
Change-Id: I491139e5e1d712993f1fef9aebbd75e9ccfc539e
parent 6cc66e45
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -82,6 +82,12 @@ public final class TaskFragmentInfo implements Parcelable {
     */
    private final boolean mIsTaskFragmentClearedForPip;

    /**
     * Whether the last running activity of the TaskFragment was removed because it was reordered to
     * front of the Task.
     */
    private final boolean mIsClearedForReorderActivityToFront;

    /**
     * The maximum {@link ActivityInfo.WindowLayout#minWidth} and
     * {@link ActivityInfo.WindowLayout#minHeight} aggregated from the TaskFragment's child
@@ -96,7 +102,7 @@ public final class TaskFragmentInfo implements Parcelable {
            @NonNull Configuration configuration, int runningActivityCount,
            boolean isVisible, @NonNull List<IBinder> activities, @NonNull Point positionInParent,
            boolean isTaskClearedForReuse, boolean isTaskFragmentClearedForPip,
            @NonNull Point minimumDimensions) {
            boolean isClearedForReorderActivityToFront, @NonNull Point minimumDimensions) {
        mFragmentToken = requireNonNull(fragmentToken);
        mToken = requireNonNull(token);
        mConfiguration.setTo(configuration);
@@ -106,6 +112,7 @@ public final class TaskFragmentInfo implements Parcelable {
        mPositionInParent.set(positionInParent);
        mIsTaskClearedForReuse = isTaskClearedForReuse;
        mIsTaskFragmentClearedForPip = isTaskFragmentClearedForPip;
        mIsClearedForReorderActivityToFront = isClearedForReorderActivityToFront;
        mMinimumDimensions.set(minimumDimensions);
    }

@@ -160,6 +167,11 @@ public final class TaskFragmentInfo implements Parcelable {
        return mIsTaskFragmentClearedForPip;
    }

    /** @hide */
    public boolean isClearedForReorderActivityToFront() {
        return mIsClearedForReorderActivityToFront;
    }

    @WindowingMode
    public int getWindowingMode() {
        return mConfiguration.windowConfiguration.getWindowingMode();
@@ -207,6 +219,7 @@ public final class TaskFragmentInfo implements Parcelable {
                && mPositionInParent.equals(that.mPositionInParent)
                && mIsTaskClearedForReuse == that.mIsTaskClearedForReuse
                && mIsTaskFragmentClearedForPip == that.mIsTaskFragmentClearedForPip
                && mIsClearedForReorderActivityToFront == that.mIsClearedForReorderActivityToFront
                && mMinimumDimensions.equals(that.mMinimumDimensions);
    }

@@ -220,6 +233,7 @@ public final class TaskFragmentInfo implements Parcelable {
        mPositionInParent.readFromParcel(in);
        mIsTaskClearedForReuse = in.readBoolean();
        mIsTaskFragmentClearedForPip = in.readBoolean();
        mIsClearedForReorderActivityToFront = in.readBoolean();
        mMinimumDimensions.readFromParcel(in);
    }

@@ -235,6 +249,7 @@ public final class TaskFragmentInfo implements Parcelable {
        mPositionInParent.writeToParcel(dest, flags);
        dest.writeBoolean(mIsTaskClearedForReuse);
        dest.writeBoolean(mIsTaskFragmentClearedForPip);
        dest.writeBoolean(mIsClearedForReorderActivityToFront);
        mMinimumDimensions.writeToParcel(dest, flags);
    }

@@ -262,8 +277,9 @@ public final class TaskFragmentInfo implements Parcelable {
                + " activities=" + mActivities
                + " positionInParent=" + mPositionInParent
                + " isTaskClearedForReuse=" + mIsTaskClearedForReuse
                + " isTaskFragmentClearedForPip" + mIsTaskFragmentClearedForPip
                + " minimumDimensions" + mMinimumDimensions
                + " isTaskFragmentClearedForPip=" + mIsTaskFragmentClearedForPip
                + " mIsClearedForReorderActivityToFront=" + mIsClearedForReorderActivityToFront
                + " minimumDimensions=" + mMinimumDimensions
                + "}";
    }

+4 −0
Original line number Diff line number Diff line
@@ -389,6 +389,10 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
                // launching activity in the Task.
                mTransactionManager.getCurrentTransactionRecord().setOriginType(TRANSIT_CLOSE);
                mPresenter.cleanupContainer(wct, container, false /* shouldFinishDependent */);
            } else if (taskFragmentInfo.isClearedForReorderActivityToFront()) {
                // Do not finish the dependents if this TaskFragment was cleared to reorder
                // the launching Activity to front of the Task.
                mPresenter.cleanupContainer(wct, container, false /* shouldFinishDependent */);
            } else if (!container.isWaitingActivityAppear()) {
                // Do not finish the container before the expected activity appear until
                // timeout.
+1 −0
Original line number Diff line number Diff line
@@ -169,6 +169,7 @@ public class EmbeddingTestUtils {
                new Point(),
                false /* isTaskClearedForReuse */,
                false /* isTaskFragmentClearedForPip */,
                false /* isClearedForReorderActivityToFront */,
                new Point());
    }

+1 −1
Original line number Diff line number Diff line
@@ -144,6 +144,6 @@ public class JetpackTaskFragmentOrganizerTest {
                mock(WindowContainerToken.class), new Configuration(), 0 /* runningActivityCount */,
                false /* isVisible */, new ArrayList<>(), new Point(),
                false /* isTaskClearedForReuse */, false /* isTaskFragmentClearedForPip */,
                new Point());
                false /* isClearedForReorderActivityToFront */, new Point());
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -2394,7 +2394,7 @@ class ActivityStarter {
                            mStartActivity.mUserId);
            if (act != null) {
                final Task task = act.getTask();
                boolean actuallyMoved = task.moveActivityToFrontLocked(act);
                boolean actuallyMoved = task.moveActivityToFront(act);
                if (actuallyMoved) {
                    // Only record if the activity actually moved.
                    mMovedToTopActivity = act;
Loading