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

Commit 848a35cc authored by Graciela Wissen Putri's avatar Graciela Wissen Putri
Browse files

Remove task regardless of displayId

Using taskInfo.displayId to removeTask if task is launching in different
display will result in no task being removed. TaskId should be unique so
if conditions require task to be removed, repository should remove task
regardless of where it was first launched.

Flag: EXEMPT bug fix
Test: atest WMShellUnitTests
Fix: 415284139
Change-Id: I4d246611b37a63a095710f1f27d2d8ed506dfb01
parent 906bc5ea
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ class DesktopBackNavTransitionObserver(
            val desktopRepository = desktopUserRepositories.getProfile(taskInfo.userId)
            if (desktopRepository.isExitingDesktopTask(change)) {
                logD("removeTaskIfNeeded taskId=%d", taskInfo.taskId)
                desktopRepository.removeTask(taskInfo.displayId, taskInfo.taskId)
                desktopRepository.removeTask(taskInfo.taskId)
            }
        }
    }
+3 −7
Original line number Diff line number Diff line
@@ -929,14 +929,10 @@ class DesktopRepository(
     *
     * TODO: b/389960283 - consider using [removeTaskFromDesk] instead.
     */
    fun removeTask(displayId: Int, taskId: Int) {
    fun removeTask(taskId: Int) {
        logD("Removes freeform task: taskId=%d", taskId)
        if (displayId == INVALID_DISPLAY) {
        // Removes the original display id of the task.
        getDisplayIdForTask(taskId)?.let { removeTaskFromDisplay(it, taskId) }
        } else {
            removeTaskFromDisplay(displayId, taskId)
        }
    }

    /** Removes given task from a valid [displayId] and updates the repository state. */
+10 −10
Original line number Diff line number Diff line
@@ -33,18 +33,18 @@ class DesktopTaskChangeListener(

    override fun onTaskOpening(taskInfo: RunningTaskInfo) {
        logD("onTaskOpening for taskId=%d, displayId=%d", taskInfo.taskId, taskInfo.displayId)
        val desktopRepository: DesktopRepository =
            desktopUserRepositories.getProfile(taskInfo.userId)
        if (!isFreeformTask(taskInfo) && desktopRepository.isActiveTask(taskInfo.taskId)) {
            desktopRepository.removeTask(taskInfo.taskId)
            return
        }
        if (
            !desktopState.isDesktopModeSupportedOnDisplay(taskInfo.displayId) &&
                DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue
        ) {
            return
        }
        val desktopRepository: DesktopRepository =
            desktopUserRepositories.getProfile(taskInfo.userId)
        if (!isFreeformTask(taskInfo) && desktopRepository.isActiveTask(taskInfo.taskId)) {
            desktopRepository.removeTask(taskInfo.displayId, taskInfo.taskId)
            return
        }
        if (isFreeformTask(taskInfo) && !desktopRepository.isActiveTask(taskInfo.taskId)) {
            desktopRepository.addTask(taskInfo.displayId, taskInfo.taskId, taskInfo.isVisible)
        }
@@ -70,7 +70,7 @@ class DesktopTaskChangeListener(
        // fullscreen,
        // remove the task from the desktop repository since it is no longer a freeform task.
        if (!isFreeformTask(taskInfo) && desktopRepository.isActiveTask(taskInfo.taskId)) {
            desktopRepository.removeTask(taskInfo.displayId, taskInfo.taskId)
            desktopRepository.removeTask(taskInfo.taskId)
        } else if (isFreeformTask(taskInfo)) {
            // If the task is already active in the repository, then moves task to the front,
            // else adds the task.
@@ -105,7 +105,7 @@ class DesktopTaskChangeListener(
        // When the task change is from a task in the desktop repository which is now fullscreen,
        // remove the task from the desktop repository since it is no longer a freeform task.
        if (!isFreeformTask(taskInfo) && desktopRepository.isActiveTask(taskInfo.taskId)) {
            desktopRepository.removeTask(taskInfo.displayId, taskInfo.taskId)
            desktopRepository.removeTask(taskInfo.taskId)
        }
        if (isFreeformTask(taskInfo)) {
            // If the task is already active in the repository, then it only moves the task to the
@@ -150,11 +150,11 @@ class DesktopTaskChangeListener(
            if (isMinimized) {
                desktopRepository.updateTask(taskInfo.displayId, taskInfo.taskId, isVisible = false)
            } else {
                desktopRepository.removeTask(taskInfo.displayId, taskInfo.taskId)
                desktopRepository.removeTask(taskInfo.taskId)
            }
        } else {
            desktopRepository.removeClosingTask(taskInfo.taskId)
            desktopRepository.removeTask(taskInfo.displayId, taskInfo.taskId)
            desktopRepository.removeTask(taskInfo.taskId)
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -139,7 +139,7 @@ public class FreeformTaskListener implements ShellTaskOrganizer.TaskListener,
                // triggered on a task and the task is closing. It will be marked as minimized in
                // [DesktopTasksTransitionObserver] before it gets here.
                repository.removeClosingTask(taskInfo.taskId);
                repository.removeTask(taskInfo.displayId, taskInfo.taskId);
                repository.removeTask(taskInfo.taskId);
            }
        }
        // TODO: b/367268649 - This listener shouldn't need to call the transition observer directly
+1 −2
Original line number Diff line number Diff line
@@ -322,8 +322,7 @@ public class RecentTasksController implements TaskStackListenerCallback,
    @Override
    public void onRecentTaskRemovedForAddTask(int taskId) {
        mDesktopUserRepositories.ifPresent(
                desktopUserRepositories -> desktopUserRepositories.getCurrent().removeTask(
                        INVALID_DISPLAY, taskId));
                desktopUserRepositories -> desktopUserRepositories.getCurrent().removeTask(taskId));
    }

    public void onTaskAdded(RunningTaskInfo taskInfo) {
Loading