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

Commit 4383e8e4 authored by Ats Jenk's avatar Ats Jenk
Browse files

Move home task behind visible task

When switching to desktop mode, move home task behind visible task(s).
This ensures that only the visible task is shown at first on the
desktop.

Bug: 258282673
Test: atest DesktopModeControllerTest
Change-Id: I1d593900789846d8389decaddbaf92eb4a1d6e87
parent fc558746
Loading
Loading
Loading
Loading
+29 −5
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.wm.shell.desktopmode;

import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
@@ -158,15 +159,13 @@ public class DesktopModeController implements RemoteCallable<DesktopModeControll
        WindowContainerTransaction wct = new WindowContainerTransaction();
        // Reset freeform windowing mode that is set per task level so tasks inherit it
        clearFreeformForStandardTasks(runningTasks, wct);
        int targetWindowingMode;
        if (active) {
            targetWindowingMode = WINDOWING_MODE_FREEFORM;
            moveHomeBehindVisibleTasks(runningTasks, wct);
            setDisplayAreaWindowingMode(displayId, WINDOWING_MODE_FREEFORM, wct);
        } else {
            targetWindowingMode = WINDOWING_MODE_FULLSCREEN;
            // Clear any resized bounds
            clearBoundsForStandardTasks(runningTasks, wct);
            setDisplayAreaWindowingMode(displayId, WINDOWING_MODE_FULLSCREEN, wct);
        }
        setDisplayAreaWindowingMode(displayId, targetWindowingMode, wct);
        if (Transitions.ENABLE_SHELL_TRANSITIONS) {
            mTransitions.startTransition(TRANSIT_CHANGE, wct, null);
        } else {
@@ -201,6 +200,31 @@ public class DesktopModeController implements RemoteCallable<DesktopModeControll
        }
    }

    private void moveHomeBehindVisibleTasks(ArrayList<RunningTaskInfo> runningTasks,
            WindowContainerTransaction wct) {
        ProtoLog.v(WM_SHELL_DESKTOP_MODE, "moveHomeBehindVisibleTasks");
        RunningTaskInfo homeTask = null;
        ArrayList<RunningTaskInfo> visibleTasks = new ArrayList<>();
        for (RunningTaskInfo taskInfo : runningTasks) {
            if (taskInfo.getActivityType() == ACTIVITY_TYPE_HOME) {
                homeTask = taskInfo;
            } else if (taskInfo.getActivityType() == ACTIVITY_TYPE_STANDARD
                    && taskInfo.isVisible()) {
                visibleTasks.add(taskInfo);
            }
        }
        if (homeTask == null) {
            ProtoLog.w(WM_SHELL_DESKTOP_MODE, "moveHomeBehindVisibleTasks: home task not found");
        } else {
            ProtoLog.v(WM_SHELL_DESKTOP_MODE, "moveHomeBehindVisibleTasks: visible tasks %d",
                    visibleTasks.size());
            wct.reorder(homeTask.getToken(), true /* onTop */);
            for (RunningTaskInfo task : visibleTasks) {
                wct.reorder(task.getToken(), true /* onTop */);
            }
        }
    }

    private void setDisplayAreaWindowingMode(int displayId,
            @WindowConfiguration.WindowingMode int windowingMode, WindowContainerTransaction wct) {
        DisplayAreaInfo displayAreaInfo = mRootTaskDisplayAreaOrganizer.getDisplayAreaInfo(
+27 −0
Original line number Diff line number Diff line
@@ -205,6 +205,33 @@ public class DesktopModeControllerTest extends ShellTestCase {
                WINDOWING_MODE_UNDEFINED);
    }

    @Test
    public void testDesktopModeEnabled_homeTaskBehindVisibleTask() {
        createMockDisplayArea();
        RunningTaskInfo fullscreenTask1 = createFullscreenTask();
        fullscreenTask1.isVisible = true;
        RunningTaskInfo fullscreenTask2 = createFullscreenTask();
        fullscreenTask2.isVisible = false;
        RunningTaskInfo homeTask = createHomeTask();
        when(mShellTaskOrganizer.getRunningTasks(anyInt())).thenReturn(new ArrayList<>(
                Arrays.asList(fullscreenTask1, fullscreenTask2, homeTask)));

        mController.updateDesktopModeActive(true);
        WindowContainerTransaction wct = getDesktopModeSwitchTransaction();

        // Check that there are hierarchy changes for home task and visible task
        assertThat(wct.getHierarchyOps()).hasSize(2);
        // First show home task
        WindowContainerTransaction.HierarchyOp op1 = wct.getHierarchyOps().get(0);
        assertThat(op1.getType()).isEqualTo(HIERARCHY_OP_TYPE_REORDER);
        assertThat(op1.getContainer()).isEqualTo(homeTask.token.asBinder());

        // Then visible task on top of it
        WindowContainerTransaction.HierarchyOp op2 = wct.getHierarchyOps().get(1);
        assertThat(op2.getType()).isEqualTo(HIERARCHY_OP_TYPE_REORDER);
        assertThat(op2.getContainer()).isEqualTo(fullscreenTask1.token.asBinder());
    }

    @Test
    public void testShowDesktopApps() {
        // Set up two active tasks on desktop