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

Commit 2b9a6d7c authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Ensure to resume home if there is no other activity

On default display, there will always have home stack,
but home activity may not have been started yet. In that
case if we want to resume home, the home stack should
still move to front.

Fix: 118862669
Test: atest ActivityStackTests#testAdjustFocusedStackToHomeWhenNoActivity
Change-Id: I3c744f6d3adeb151eac864d88d2b195e05d2332f
parent bd873544
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -1323,14 +1323,17 @@ class ActivityDisplay extends ConfigurationContainer<ActivityStack>
        }
    }

    /** Returns true if the focus activity was adjusted to the home stack top activity. */
    boolean moveHomeActivityToTop(String reason) {
    /**
     * Moves the focusable home activity to top. If there is no such activity, the home stack will
     * still move to top.
     */
    void moveHomeActivityToTop(String reason) {
        final ActivityRecord top = getHomeActivity();
        if (top == null) {
            return false;
            moveHomeStackToFront(reason);
            return;
        }
        top.moveFocusableActivityToTop(reason);
        return true;
    }

    @Nullable
+17 −0
Original line number Diff line number Diff line
@@ -929,6 +929,23 @@ public class ActivityStackTests extends ActivityTestsBase {
        assertThat(mStack.getAllTasks()).isEmpty();
    }

    @Test
    public void testAdjustFocusedStackToHomeWhenNoActivity() {
        final ActivityRecord topActivity = new ActivityBuilder(mService).setTask(mTask).build();
        mStack.moveToFront("testAdjustFocusedStack");

        final ActivityStack homeStask = mDefaultDisplay.getHomeStack();
        final TaskRecord homeTask = homeStask.topTask();
        // Simulate that home activity has not been started or is force-stopped.
        homeStask.removeTask(homeTask, "testAdjustFocusedStack", REMOVE_TASK_MODE_DESTROYING);

        // Finish the only activity.
        mStack.finishActivityLocked(topActivity, 0 /* resultCode */, null /* resultData */,
                "testAdjustFocusedStack", false /* oomAdj */);
        // Although home stack is empty, it should still be the focused stack.
        assertEquals(homeStask, mDefaultDisplay.getFocusedStack());
    }

    @Test
    public void testWontFinishHomeStackImmediately() {
        final ActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay,