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

Commit 138ef93c authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Move display to bottom only when no next focusable stack

If a display contains several focusable stacks, the display should
not lose focus when one of stacks moves to bottom.

Bug: 118488048
Test: atest ActivityStackTests#testMoveStackToBackIncludingParent
Change-Id: Idafde99b7b5cc88686ad957bd878d975867db3e7
parent 8c12dcd1
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -820,8 +820,13 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
    }

    void positionChildWindowContainerAtBottom(TaskRecord child) {
        // If there are other focusable stacks on the display, the z-order of the display should not
        // be changed just because a task was placed at the bottom. E.g. if it is moving the topmost
        // task to bottom, the next focusable stack on the same display should be focused.
        final ActivityStack nextFocusableStack = getDisplay().getNextFocusableStack(
                child.getStack(), true /* ignoreCurrent */);
        mWindowContainerController.positionChildAtBottom(child.getWindowContainerController(),
                true /* includingParents */);
                nextFocusableStack == null /* includingParents */);
    }

    /**
@@ -1132,8 +1137,6 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai

        getDisplay().positionChildAtBottom(this, reason);
        if (task != null) {
            // TODO(b/111541062): We probably don't want to change display z-order to bottom just
            // because one of its stacks moved to bottom.
            insertTaskAtBottom(task);
        }
    }
@@ -2912,7 +2915,6 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
    }

    private void insertTaskAtBottom(TaskRecord task) {
        // Unlike insertTaskAtPosition, this will also position parents of the windowcontroller.
        mTaskHistory.remove(task);
        final int position = getAdjustedPositionForTask(task, 0, null);
        mTaskHistory.add(position, task);
+21 −1
Original line number Diff line number Diff line
@@ -38,9 +38,9 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@@ -252,6 +252,26 @@ public class ActivityStackTests extends ActivityTestsBase {
        assertNotNull(result.mRecord);
    }

    @Test
    public void testMoveStackToBackIncludingParent() {
        final ActivityDisplay display = addNewActivityDisplayAt(ActivityDisplay.POSITION_TOP);
        final ActivityStack stack1 = createStackForShouldBeVisibleTest(display,
                WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */);
        final ActivityStack stack2 = createStackForShouldBeVisibleTest(display,
                WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_STANDARD, true /* onTop */);

        // Do not move display to back because there is still another stack.
        stack2.moveToBack("testMoveStackToBackIncludingParent", stack2.topTask());
        verify(stack2.getWindowContainerController()).positionChildAtBottom(any(),
                eq(false) /* includingParents */);

        // Also move display to back because there is only one stack left.
        display.removeChild(stack1);
        stack2.moveToBack("testMoveStackToBackIncludingParent", stack2.topTask());
        verify(stack2.getWindowContainerController()).positionChildAtBottom(any(),
                eq(true) /* includingParents */);
    }

    @Test
    public void testShouldBeVisible_Fullscreen() throws Exception {
        final TestActivityStack homeStack = createStackForShouldBeVisibleTest(mDefaultDisplay,