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

Commit b2585195 authored by Gustav Sennton's avatar Gustav Sennton
Browse files

Keep transparent fullscreen task when that's the one being launched

Before this CL, when running a transition that launches a new task in a
desk, we would close the current top transparent fullscreen task in that
desk. With this CL, we don't close the top transparent fullscreen task
if that's the task that is being opened / moved to front in that desk.

Bug: 440096166
Flag: EXEMPT small bug fix
Test: DesktopTasksControllerTest, and manual
Change-Id: Icaaa63eacf740ef2760a0f31de16b900f91e60b5
parent 46104d0b
Loading
Loading
Loading
Loading
+48 −21
Original line number Diff line number Diff line
@@ -1024,9 +1024,8 @@ class DesktopTasksController(
        val excludedTasks =
            getFocusedNonDesktopTasks(DEFAULT_DISPLAY, userId).map { task -> task.taskId }
        // Preserve focus state on reconnect, regardless if focused task is restored or not.
        val globallyFocusedTask = shellTaskOrganizer.getRunningTaskInfo(
            focusTransitionObserver.globallyFocusedTaskId
        )
        val globallyFocusedTask =
            shellTaskOrganizer.getRunningTaskInfo(focusTransitionObserver.globallyFocusedTaskId)
        mainScope.launch {
            preservedTaskIdsByDeskId.forEach { (preservedDeskId, preservedTaskIds) ->
                val newDeskId =
@@ -2197,8 +2196,6 @@ class DesktopTasksController(
                    launchingNewIntent = launchingTaskId == null,
                )
            }
        val closingTopTransparentTaskId =
            deskId?.let { repository.getTopTransparentFullscreenTaskData(it)?.taskId }
        val exitImmersiveResult =
            desktopImmersiveController.exitImmersiveIfApplicable(
                wct = launchTransaction,
@@ -2239,8 +2236,14 @@ class DesktopTasksController(
            }
        }
        // Remove top transparent fullscreen task if needed.
        val closingTopTransparentTaskId =
            deskId?.let {
            closeTopTransparentFullscreenTask(wct = launchTransaction, deskId = it, userId = userId)
                closeTopTransparentFullscreenTask(
                    wct = launchTransaction,
                    deskId = it,
                    launchingTaskId = launchingTaskId,
                    userId = userId,
                )
            }
        val t =
            if (remoteTransition == null) {
@@ -4065,8 +4068,12 @@ class DesktopTasksController(
            // flag
            val taskIdToMinimize = addAndGetMinimizeChanges(targetDeskId, wct, task.taskId)
            val closingTopTransparentTaskId =
                repository.getTopTransparentFullscreenTaskData(targetDeskId)?.taskId
            closeTopTransparentFullscreenTask(wct, targetDeskId, userId)
                closeTopTransparentFullscreenTask(
                    wct,
                    targetDeskId,
                    launchingTaskId = task.taskId,
                    userId,
                )
            addPendingAppLaunchTransition(
                transition,
                task.taskId,
@@ -4142,8 +4149,12 @@ class DesktopTasksController(
                            addPendingTaskLimitTransition(transition, deskId, task.taskId)
                            // Remove top transparent fullscreen task if needed.
                            val closingTopTransparentTaskId =
                                repository.getTopTransparentFullscreenTaskData(deskId)?.taskId
                            closeTopTransparentFullscreenTask(wct, deskId, userId)
                                closeTopTransparentFullscreenTask(
                                    wct,
                                    deskId,
                                    launchingTaskId = task.taskId,
                                    userId,
                                )
                            // Also track the pending launching task.
                            addPendingAppLaunchTransition(
                                transition,
@@ -4861,8 +4872,12 @@ class DesktopTasksController(
                if (newTask != null && addPendingLaunchTransition) {
                    // Remove top transparent fullscreen task if needed.
                    val closingTopTransparentTaskId =
                        repository.getTopTransparentFullscreenTaskData(deskId)?.taskId
                    closeTopTransparentFullscreenTask(wct, deskId, userId)
                        closeTopTransparentFullscreenTask(
                            wct,
                            deskId,
                            launchingTaskId = newTask.taskId,
                            userId,
                        )
                    addPendingAppLaunchTransition(
                        transition,
                        newTask.taskId,
@@ -4946,18 +4961,30 @@ class DesktopTasksController(
        }
    }

    // returns the id of the task that was closed (if any)
    private fun closeTopTransparentFullscreenTask(
        wct: WindowContainerTransaction,
        deskId: Int,
        launchingTaskId: Int?,
        userId: Int,
    ) {
        if (!DesktopExperienceFlags.FORCE_CLOSE_TOP_TRANSPARENT_FULLSCREEN_TASK.isTrue) return
    ): Int? {
        if (!DesktopExperienceFlags.FORCE_CLOSE_TOP_TRANSPARENT_FULLSCREEN_TASK.isTrue) return null
        val repository = userRepositories.getProfile(userId)
        val data = repository.getTopTransparentFullscreenTaskData(deskId)
        if (data != null) {
        val data = repository.getTopTransparentFullscreenTaskData(deskId) ?: return null

        if (launchingTaskId != null && data.taskId == launchingTaskId) {
            logD(
                "closeTopTransparentFullscreenTask: task relaunching as freeform, not closing" +
                    ", taskId=%d, deskId=%d",
                data.taskId,
                deskId,
            )
            repository.clearTopTransparentFullscreenTaskData(deskId)
            return null
        }
        logD("closeTopTransparentFullscreenTask: taskId=%d, deskId=%d", data.taskId, deskId)
        wct.removeTask(data.token)
        }
        return data.taskId
    }

    /** Activates the desk at the given index if it exists. */
+16 −1
Original line number Diff line number Diff line
@@ -6613,6 +6613,20 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
            )
    }
    @Test
    @EnableFlags(Flags.FLAG_FORCE_CLOSE_TOP_TRANSPARENT_FULLSCREEN_TASK)
    fun handleRequest_newTaskLaunch_sameAsTopTransparentFullscreenTask_clearsTopTransparent() {
        val transition = Binder()
        val topTransparentTask = setUpFullscreenTask(displayId = DEFAULT_DISPLAY)
        taskRepository.setTopTransparentFullscreenTaskData(DEFAULT_DISPLAY, topTransparentTask)
        val task =
            setUpFreeformTask(displayId = DEFAULT_DISPLAY, taskId = topTransparentTask.taskId)
        controller.handleRequest(transition, createTransition(task))
        assertThat(taskRepository.getTopTransparentFullscreenTaskData(DEFAULT_DISPLAY)).isNull()
    }
    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODALS_POLICY)
    fun handleRequest_desktopNotShowing_topTransparentFullscreenTask_returnNull() {
@@ -12401,8 +12415,9 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        active: Boolean = true,
        background: Boolean = false,
        deskId: Int? = null,
        taskId: Int? = null,
    ): RunningTaskInfo {
        val task = createFreeformTask(displayId, bounds, taskRepository.userId)
        val task = createFreeformTask(displayId, bounds, taskRepository.userId, taskId)
        val activityInfo = ActivityInfo()
        activityInfo.applicationInfo = ApplicationInfo()
        task.topActivityInfo = activityInfo
+2 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ object DesktopTestHelpers {
        displayId: Int = DEFAULT_DISPLAY,
        bounds: Rect? = null,
        userId: Int = ActivityManager.getCurrentUser(),
        taskId: Int? = null,
    ): RunningTaskInfo =
        TestRunningTaskInfoBuilder()
            .setDisplayId(displayId)
@@ -50,6 +51,7 @@ object DesktopTestHelpers {
            .setWindowingMode(WINDOWING_MODE_FREEFORM)
            .setLastActiveTime(100)
            .setUserId(userId)
            .apply { taskId?.let { setTaskId(it) } }
            .apply { bounds?.let { setBounds(it) } }
            .build()