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

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

Fixes ActivityLifecycleTests flakiness

The Launcher Task has a empty child TaskFragment, which makes the
Launcher delayed to be paused and sometimes making lifecycle test
failed.

The direct child resumed activity should be paused immediately if
it shouldn't be stayed in the RESUMED state.

Bug: 329953510
Test: ActivityLifecycleTests
Test: TaskTests

Change-Id: I1a3331fd17f683896e39cc10b6e0f27fe76def0a
parent db65f732
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1274,7 +1274,8 @@ class Task extends TaskFragment {
        if (!isLeafTaskFragment()) {
            final ActivityRecord top = topRunningActivity();
            final ActivityRecord resumedActivity = getResumedActivity();
            if (resumedActivity != null && top.getTaskFragment() != this) {
            if (resumedActivity != null
                    && (top.getTaskFragment() != this || !canBeResumed(resuming))) {
                // Pausing the resumed activity because it is occluded by other task fragment.
                if (startPausing(false /* uiSleeping*/, resuming, reason)) {
                    someActivityPaused[0]++;
+15 −0
Original line number Diff line number Diff line
@@ -1928,6 +1928,21 @@ public class TaskTests extends WindowTestsBase {
        assertEquals(2, finishCount[0]);
    }

    @Test
    public void testPauseActivityWhenHasEmptyLeafTaskFragment() {
        // Creating a task that has a RESUMED activity and an empty TaskFragment.
        final Task task = new TaskBuilder(mSupervisor).setCreateActivity(true).build();
        final ActivityRecord activity = task.getTopMostActivity();
        new TaskFragmentBuilder(mAtm).setParentTask(task).build();
        activity.setState(ActivityRecord.State.RESUMED, "test");

        // Ensure the activity is paused if cannot be resumed.
        doReturn(false).when(task).canBeResumed(any());
        mSupervisor.mUserLeaving = true;
        task.pauseActivityIfNeeded(null /* resuming */, "test");
        verify(task).startPausing(eq(true) /* userLeaving */, anyBoolean(), any(), any());
    }

    private Task getTestTask() {
        return new TaskBuilder(mSupervisor).setCreateActivity(true).build();
    }