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

Commit 5fee177f authored by Orhan Uysal's avatar Orhan Uysal
Browse files

Remove the desk task fully if it's closing.

Currently we don't handle the closing tasks from core initiated
transitions due to the fact that some of them might have been triggered
by back nav. When the logic here catches closing tasks, we already know
that they are not being handled by back navigation. So also start a
transition to explicitly remove them, which prevents the tasks from
showing up on Overview.

Fix: 410912498
Test: atest DesktopTasksTransitionObserverTest
Flag: com.android.window.flags.enable_desktop_close_task_animation_in_dtc_bugfix

Change-Id: I865ae7ad39e894e2a43e3872169760a1c3d766a6
parent d06d32bc
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ class DesktopTasksTransitionObserver(
    data class CloseWallpaperTransition(val transition: IBinder, val displayId: Int)

    private var transitionToCloseWallpaper: CloseWallpaperTransition? = null
    private var closingTransitionToTransitionInfo = HashMap<IBinder, TransitionInfo>()
    private var currentProfileId: Int

    init {
@@ -94,6 +95,7 @@ class DesktopTasksTransitionObserver(
            desktopMixedTransitionHandler.addPendingMixedTransition(
                DesktopMixedTransitionHandler.PendingMixedTransition.Close(transition)
            )
            closingTransitionToTransitionInfo.put(transition, info)
        }
        removeWallpaperOnLastTaskClosingIfNeeded(transition, info)
    }
@@ -175,6 +177,35 @@ class DesktopTasksTransitionObserver(
                }
            transitionToCloseWallpaper = null
        }

        // If a task is closing and is not handled by back navigation logic, remove it here with a
        // follow up transition fully so it doesn't show up on recents.
        //
        // The reason that this is done here and not on [DesktopTasksController#handleRequest] is
        // because for closing tasks we first need to check whether it's because of back navigation
        // so that we can minimize it if needed.
        val info = closingTransitionToTransitionInfo.remove(transition) ?: return
        removeClosingTask(info)
    }

    /** Finds the closing task in the change and removes it full by a [TRANSIT_CLOSE] transition. */
    private fun removeClosingTask(info: TransitionInfo) {
        val task =
            info.changes
                .find { change -> change.mode == TRANSIT_CLOSE && change.taskInfo != null }
                ?.taskInfo ?: return

        transitions.startTransition(
            TRANSIT_CLOSE,
            WindowContainerTransaction().removeTask(task.token),
            null,
        )

        ProtoLog.d(
            WM_SHELL_DESKTOP_MODE,
            "DesktopTasksTransitionObserver: removing closing task=%d fully",
            task.taskId,
        )
    }

    private fun updateWallpaperToken(info: TransitionInfo) {
+29 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.window.TransitionInfo
import android.window.TransitionInfo.Change
import android.window.WindowContainerToken
import android.window.WindowContainerTransaction
import android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_REMOVE_TASK
import android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_REORDER
import com.android.window.flags.Flags
import com.android.wm.shell.MockToken
@@ -275,6 +276,27 @@ class DesktopTasksTransitionObserverTest : ShellTestCase() {
            )
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_CLOSE_TASK_ANIMATION_IN_DTC_BUGFIX)
    fun closingTask_startsTransitionToRemoveFully() {
        val mockTransition = Mockito.mock(IBinder::class.java)
        val freeformTask = createTaskInfo(1)
        whenever(taskRepository.isAnyDeskActive(any())).thenReturn(true)
        whenever(mixedHandler.hasTransition(mockTransition)).thenReturn(false)

        transitionObserver.onTransitionReady(
            transition = mockTransition,
            info = createCloseTransition(freeformTask),
            startTransaction = mock(),
            finishTransaction = mock(),
        )
        transitionObserver.onTransitionFinished(transition = mockTransition, aborted = false)

        val wct = getLatestWct(type = TRANSIT_CLOSE)
        assertThat(wct.hierarchyOps).hasSize(1)
        wct.assertRemoveAt(index = 0, freeformTask.token)
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_CLOSE_TASK_ANIMATION_IN_DTC_BUGFIX)
    fun onTransitionReady_handlerHasTransition_notAddPendingMixedTransition() {
@@ -396,6 +418,13 @@ class DesktopTasksTransitionObserverTest : ShellTestCase() {
        return arg.value
    }

    private fun WindowContainerTransaction.assertRemoveAt(index: Int, token: WindowContainerToken) {
        assertIndexInBounds(index)
        val op = hierarchyOps[index]
        assertThat(op.type).isEqualTo(HIERARCHY_OP_TYPE_REMOVE_TASK)
        assertThat(op.container).isEqualTo(token.asBinder())
    }

    private fun WindowContainerTransaction.assertReorderAt(
        index: Int,
        token: WindowContainerToken,