}
}
- /** 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
}
@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,
WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME, true /* onTop */);