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

Commit 84f72306 authored by Jorge Gil's avatar Jorge Gil
Browse files

Allow closing tasks even if not inside a desk

Freeform tasks may get created along with an app header without being
part of a desk. While this is always a bug in launch logic, if we happen
to get into this state we should allow the task to be closed using the X
button instead of throwing an illegal state exception.

Flag: EXEMPT bugfix
Fix: 442865973
Test: atest DesktopTasksControllerTest
Change-Id: Ie62261ae54c6e785f2fda5d3bf19936d0d990cd9
parent c0bbfb05
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -1606,13 +1606,14 @@ class DesktopTasksController(
        wct: WindowContainerTransaction,
        displayId: Int,
        taskInfo: RunningTaskInfo,
    ): ((IBinder) -> Unit) {
    ): ((IBinder) -> Unit)? {
        val taskId = taskInfo.taskId
        val userId = taskInfo.userId
        val repository = userRepositories.getProfile(userId)
        val deskId = repository.getDeskIdForTask(taskInfo.taskId)
        if (deskId == null && DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
            error("Did not find desk for task: $taskId")
            logW("onDesktopWindowClose: desk not found for task: $taskId")
            return null
        }
        snapEventHandler.removeTaskIfTiled(displayId, taskId)
        val shouldExitDesktop =
+1 −1
Original line number Diff line number Diff line
@@ -1265,7 +1265,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
                        decoration.getTaskInfo().displayId, decoration.getTaskInfo());
        final IBinder transition = mTaskOperations.closeTask(
                decoration.getTaskInfo().token, wct);
        if (transition != null) {
        if (transition != null && runOnTransitionStart != null) {
            runOnTransitionStart.invoke(transition);
        }
    }
+16 −3
Original line number Diff line number Diff line
@@ -4672,6 +4672,19 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        wct.assertWithoutPendingIntent(launchHomeIntent(DEFAULT_DISPLAY))
    }
    @Test
    @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
    fun onDesktopWindowClose_notInDesk_returnsNullOnTransitStart() {
        val task = setUpFreeformTask(deskId = DEFAULT_DESK_ID)
        val wct = WindowContainerTransaction()
        taskRepository.removeDesk(DEFAULT_DESK_ID)
        val runOnTransitStart =
            controller.onDesktopWindowClose(wct, displayId = DEFAULT_DISPLAY, task)
        assertThat(runOnTransitStart).isNull()
    }
    @Test
    fun tilingBroken_onTaskMinimised() {
        val task = setUpFreeformTask()
@@ -4770,7 +4783,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        val transition = Binder()
        val runOnTransitStart =
            controller.onDesktopWindowClose(wct, displayId = DEFAULT_DISPLAY, task)
        runOnTransitStart(transition)
        runOnTransitStart?.invoke(transition)
        verify(desksTransitionsObserver)
            .addPendingTransition(
@@ -4798,7 +4811,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        val transition = Binder()
        val runOnTransitStart =
            controller.onDesktopWindowClose(wct, displayId = DEFAULT_DISPLAY, task)
        runOnTransitStart(transition)
        runOnTransitStart?.invoke(transition)
        verify(desksTransitionsObserver)
            .addPendingTransition(
@@ -12833,7 +12846,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        const val MAX_TASK_LIMIT = 6
        private const val TASKBAR_FRAME_HEIGHT = 200
        private const val FLOAT_TOLERANCE = 0.005f
        private const val DEFAULT_DESK_ID = 100
        private const val DEFAULT_DESK_ID = 0
        // For testing disconnecting a display containing a desk.
        private const val DISCONNECTED_DESK_ID = 200
        private val TASK_BOUNDS = Rect(100, 100, 300, 300)