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

Commit 4db46a16 authored by Jorge Gil's avatar Jorge Gil
Browse files

Desks: Only deactivate pre-recents desk

Ensures that the only desk that is deactivated on a
!returnToApp recents finish is the desk that was active when we first
entered Overview. This is because desk->desk transitions from Overview
are also !returnToApp, and by the time this finishing function is called
the new desk is now the "active" one, which would result in deactivating
the desk that the user intended to activate.

With this change, the active desk is saved when recents first starts, so
that only that one is deactivated on finishing if !returnToApp (e.g.
going Home or to a non-desktop tile)

Flag: com.android.window.flags.enable_multiple_desktops_backend
Bug: 409848289
Bug: 409639676
Test: switch desks from overview - verify activation change is
successful

Change-Id: I227b03856784796d475a9d4de003c40c1993f766
parent 82654ed9
Loading
Loading
Loading
Loading
+24 −7
Original line number Diff line number Diff line
@@ -383,6 +383,9 @@ class DesktopTasksController(
    /** Returns whether the given display has an active desk. */
    fun isAnyDeskActive(displayId: Int): Boolean = taskRepository.isAnyDeskActive(displayId)

    /** Returns the id of the active desk in [displayId]. */
    fun getActiveDeskId(displayId: Int): Int? = taskRepository.getActiveDeskId(displayId)

    /**
     * Moves focused task to desktop mode for given [displayId].
     *
@@ -474,20 +477,34 @@ class DesktopTasksController(
        transition: IBinder,
        finishWct: WindowContainerTransaction,
        returnToApp: Boolean,
        activeDeskIdOnRecentsStart: Int?,
    ) {
        if (!DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) return
        logV("onRecentsInDesktopAnimationFinishing returnToApp=%b", returnToApp)
        if (returnToApp) return
        // Home/Recents only exists in the default display.
        val activeDesk = taskRepository.getActiveDeskId(DEFAULT_DISPLAY) ?: return
        // Not going back to the active desk, deactivate it.
        logV(
            "onRecentsInDesktopAnimationFinishing returnToApp=%b activeDeskIdOnRecentsStart=%d",
            returnToApp,
            activeDeskIdOnRecentsStart,
        )
        if (returnToApp) {
            // Returning to the same desk, nothing to do.
            return
        }
        if (
            activeDeskIdOnRecentsStart == null ||
                !taskRepository.isDeskActive(activeDeskIdOnRecentsStart)
        ) {
            // No desk was active or it is already inactive.
            return
        }
        // At this point the recents transition is either finishing to home, to another non-desktop
        // task or to a different desk than the one that was active when recents started. For all
        // of those the desk that was active needs to be deactivated.
        val runOnTransitStart =
            performDesktopExitCleanUp(
                wct = finishWct,
                deskId = activeDesk,
                deskId = activeDeskIdOnRecentsStart,
                displayId = DEFAULT_DISPLAY,
                willExitDesktop = true,
                shouldEndUpAtHome = true,
                // No need to clean up the wallpaper / home when coming from a recents transition.
                skipWallpaperAndHomeOrdering = true,
            )
+11 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.wm.shell.transition;

import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_UNOCCLUDING;

import static com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_POSITION_UNDEFINED;
@@ -42,6 +43,13 @@ class RecentsMixedTransition extends DefaultMixedHandler.MixedTransition {
    private final RecentsTransitionHandler mRecentsHandler;
    private final DesktopTasksController mDesktopTasksController;

    /**
     * The id of the desk that was active when the transition started. Only set when {@link #mType}
     * is {@link DefaultMixedHandler.MixedTransition#TYPE_RECENTS_DURING_DESKTOP}.
     */
    @Nullable
    private final Integer mActiveDeskIdOnStart;

    RecentsMixedTransition(int type, IBinder transition, Transitions player,
            MixedTransitionHandler mixedHandler, PipTransitionController pipHandler,
            StageCoordinator splitHandler, KeyguardTransitionHandler keyguardHandler,
@@ -51,6 +59,8 @@ class RecentsMixedTransition extends DefaultMixedHandler.MixedTransition {
        mRecentsHandler = recentsHandler;
        mDesktopTasksController = desktopTasksController;
        mLeftoversHandler = mRecentsHandler;
        mActiveDeskIdOnStart = mType == TYPE_RECENTS_DURING_DESKTOP
                ? mDesktopTasksController.getActiveDeskId(DEFAULT_DISPLAY) : null;
    }

    @Override
@@ -204,7 +214,7 @@ class RecentsMixedTransition extends DefaultMixedHandler.MixedTransition {
    void onAnimateRecentsDuringDesktopFinishing(boolean returnToApp,
            @NonNull WindowContainerTransaction finishWct) {
        mDesktopTasksController.onRecentsInDesktopAnimationFinishing(mTransition, finishWct,
                returnToApp);
                returnToApp, mActiveDeskIdOnStart);
    }

    @Override
+9 −4
Original line number Diff line number Diff line
@@ -8748,6 +8748,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
            transition = transition,
            finishWct = finishWct,
            returnToApp = true,
            activeDeskIdOnRecentsStart = deskId,
        )

        verify(desksOrganizer, never()).deactivateDesk(finishWct, deskId)
@@ -8759,7 +8760,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
    fun onRecentsInDesktopAnimationFinishing_noActiveDesk_noDeskDeactivation() {
    fun onRecentsInDesktopAnimationFinishing_deskNoLongerActive_noDeskDeactivation() {
        val deskId = 0
        taskRepository.setDeskInactive(deskId)

@@ -8769,6 +8770,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
            transition = transition,
            finishWct = finishWct,
            returnToApp = false,
            activeDeskIdOnRecentsStart = deskId,
        )

        verify(desksOrganizer, never()).deactivateDesk(finishWct, deskId)
@@ -8780,7 +8782,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
    fun onRecentsInDesktopAnimationFinishing_activeDesk_notReturningToDesk_deactivatesDesk() {
    fun onRecentsInDesktopAnimationFinishing_deskStillActive_notReturningToDesk_deactivatesDesk() {
        val deskId = 0
        taskRepository.setActiveDesk(DEFAULT_DISPLAY, deskId)

@@ -8790,6 +8792,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
            transition = transition,
            finishWct = finishWct,
            returnToApp = false,
            activeDeskIdOnRecentsStart = deskId,
        )

        verify(desksOrganizer).deactivateDesk(finishWct, deskId)
@@ -8799,7 +8802,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
    fun onRecentsInDesktopAnimationFinishing_activeDesk_notReturningToDesk_notifiesDesktopExit() {
    fun onRecentsInDesktopAnimationFinishing_deskStillActive_notReturningToDesk_notifiesDesktopExit() {
        val deskId = 0
        taskRepository.setActiveDesk(DEFAULT_DISPLAY, deskId)

@@ -8809,6 +8812,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
            transition = transition,
            finishWct = finishWct,
            returnToApp = false,
            activeDeskIdOnRecentsStart = deskId,
        )

        verify(desktopModeEnterExitTransitionListener)
@@ -8817,7 +8821,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
    fun onRecentsInDesktopAnimationFinishing_activeDesk_notReturningToDesk_doesNotBringUpWallpaperOrHome() {
    fun onRecentsInDesktopAnimationFinishing_deskStillActive_notReturningToDesk_doesNotBringUpWallpaperOrHome() {
        val deskId = 0
        taskRepository.setActiveDesk(DEFAULT_DISPLAY, deskId)

@@ -8827,6 +8831,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
            transition = transition,
            finishWct = finishWct,
            returnToApp = false,
            activeDeskIdOnRecentsStart = deskId,
        )

        finishWct.assertWithoutHop { hop ->