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

Commit 17d3ab35 authored by Gustav Sennton's avatar Gustav Sennton Committed by Android (Google) Code Review
Browse files

Merge "Keep transparent fullscreen task when that's the one being launched" into main

parents 55d0ea08 b2585195
Loading
Loading
Loading
Loading
+45 −17
Original line number Diff line number Diff line
@@ -2197,8 +2197,6 @@ class DesktopTasksController(
                    launchingNewIntent = launchingTaskId == null,
                )
            }
        val closingTopTransparentTaskId =
            deskId?.let { repository.getTopTransparentFullscreenTaskData(it)?.taskId }
        val exitImmersiveResult =
            desktopImmersiveController.exitImmersiveIfApplicable(
                wct = launchTransaction,
@@ -2239,8 +2237,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) {
@@ -4070,8 +4074,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,
@@ -4147,8 +4155,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,
@@ -4868,8 +4880,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,
@@ -4954,18 +4970,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
@@ -6624,6 +6624,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() {
@@ -12417,8 +12431,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()