OSDN Git Service

Ensure to resume home if there is no other activity
authorRiddle Hsu <riddlehsu@google.com>
Wed, 24 Apr 2019 15:55:11 +0000 (23:55 +0800)
committerRiddle Hsu <riddlehsu@google.com>
Thu, 25 Apr 2019 07:58:45 +0000 (07:58 +0000)
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

services/core/java/com/android/server/wm/ActivityDisplay.java
services/tests/wmtests/src/com/android/server/wm/ActivityStackTests.java

index 9d6efb4..637ad03 100644 (file)
@@ -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
index 1e00b30..757267e 100644 (file)
@@ -930,6 +930,23 @@ public class ActivityStackTests extends ActivityTestsBase {
     }
 
     @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 */);