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

Commit cec97c3c authored by Orhan Uysal's avatar Orhan Uysal
Browse files

Remove vanished tasks from repo

When a task vanishes we might mark them as minimized. If that task is
being launched in a different windowing mode, we should remove it from
the repository.

Bug: 369975365
Test: atest DesktopTasksTransitionObserverTest
Flag: com.android.window.flags.enable_desktop_windowing_back_navigation
Change-Id: I252c090e7b690f87223c000840fc41d64f4fb239
parent 82a6c7a9
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.window.flags.DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_WALLPAPER_
import com.android.internal.protolog.ProtoLog
import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE
import com.android.wm.shell.shared.TransitionUtil
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus
import com.android.wm.shell.sysui.ShellInit
import com.android.wm.shell.transition.Transitions
@@ -67,9 +68,29 @@ class DesktopTasksTransitionObserver(
    ) {
        // TODO: b/332682201 Update repository state
        updateWallpaperToken(info)

        if (DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION.isTrue()) {
            handleBackNavigation(info)
            removeTaskIfNeeded(info)
        }
    }

    private fun removeTaskIfNeeded(info: TransitionInfo) {
        // Since we are no longer removing all the tasks [onTaskVanished], we need to remove them by
        // checking the transitions.
        if (!TransitionUtil.isOpeningType(info.type)) return
        // Remove a task from the repository if the app is launched outside of desktop.
        for (change in info.changes) {
            val taskInfo = change.taskInfo
            if (taskInfo == null || taskInfo.taskId == -1) continue

            if (desktopModeTaskRepository.isActiveTask(taskInfo.taskId)
                && taskInfo.windowingMode != WINDOWING_MODE_FREEFORM
            ) {
                desktopModeTaskRepository.removeFreeformTask(
                    taskInfo.displayId,
                    taskInfo.taskId
                )
            }
        }
    }

+37 −2
Original line number Diff line number Diff line
@@ -18,11 +18,13 @@ package com.android.wm.shell.desktopmode

import android.app.ActivityManager.RunningTaskInfo
import android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM
import android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.platform.test.annotations.EnableFlags
import android.view.Display.DEFAULT_DISPLAY
import android.view.WindowManager.TRANSIT_OPEN
import android.view.WindowManager.TRANSIT_TO_BACK
import android.window.IWindowContainerToken
import android.window.TransitionInfo
@@ -110,6 +112,24 @@ class DesktopTasksTransitionObserverTest {
        verify(taskRepository, never()).minimizeTask(task.displayId, task.taskId)
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION)
    fun removeTasks_onTaskFullscreenLaunch_taskRemovedFromRepo() {
        val task = createTaskInfo(1, WINDOWING_MODE_FULLSCREEN)
        whenever(taskRepository.getVisibleTaskCount(any())).thenReturn(1)
        whenever(taskRepository.isActiveTask(task.taskId)).thenReturn(true)

        transitionObserver.onTransitionReady(
            transition = mock(),
            info = createOpenTransition(task),
            startTransaction = mock(),
            finishTransaction = mock(),
        )

        verify(taskRepository, never()).minimizeTask(task.displayId, task.taskId)
        verify(taskRepository).removeFreeformTask(task.displayId, task.taskId)
    }

    private fun createBackNavigationTransition(
        task: RunningTaskInfo?
    ): TransitionInfo {
@@ -125,11 +145,26 @@ class DesktopTasksTransitionObserverTest {
        }
    }

    private fun createTaskInfo(id: Int) =
    private fun createOpenTransition(
        task: RunningTaskInfo?
    ): TransitionInfo {
        return TransitionInfo(TRANSIT_OPEN, 0 /* flags */).apply {
            addChange(
                Change(mock(), mock()).apply {
                    mode = TRANSIT_OPEN
                    parent = null
                    taskInfo = task
                    flags = flags
                }
            )
        }
    }

    private fun createTaskInfo(id: Int, windowingMode: Int = WINDOWING_MODE_FREEFORM) =
        RunningTaskInfo().apply {
            taskId = id
            displayId = DEFAULT_DISPLAY
            configuration.windowConfiguration.windowingMode = WINDOWING_MODE_FREEFORM
            configuration.windowConfiguration.windowingMode = windowingMode
            token = WindowContainerToken(Mockito.mock(IWindowContainerToken::class.java))
            baseIntent = Intent().apply {
                component = ComponentName("package", "component.name")