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

Commit a71cfd64 authored by Louis Chang's avatar Louis Chang Committed by Android (Google) Code Review
Browse files

Merge "Fixes ActivityLifecycleTests flakiness" into main

parents 652f276d c244307e
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
@@ -1945,6 +1945,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();
    }