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

Commit 92424f8a authored by Kazuki Takise's avatar Kazuki Takise
Browse files

Implement attachChildSurfaceToTask() in RootTaskDesksOrganizer

Now that DW tasks are orgnized by the desk organizer, we need to
implement attachChildSurfaceToTask() in RootTaskDesksOrganizer so
CompatUI can add dialogs etc to DW tasks. (Most of the app-compat
features are disabled in DW, but the new restart handle menu is
an exception.)

attachChildSurfaceToTask() needs a task's leash provided by
onTaskAppeared(), so we need to maintain leaf leashes in the
organizer as all other organizers do.

Flag: com.android.window.flags.enable_multiple_desktops_backend
Bug: 416126996
Test: Manual. "Optimize View" no longer crashes.
Change-Id: Ic766c1a51551a315a38e475524e090e455618623
parent 0318370c
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ class RootTaskDesksOrganizer(
    @VisibleForTesting
    val deskMinimizationRootsByDeskId: MutableMap<Int, DeskMinimizationRoot> = mutableMapOf()
    private val removeDeskRootRequests = mutableSetOf<Int>()
    private val childLeashes = SparseArray<SurfaceControl>()
    private var onTaskInfoChangedListener: ((RunningTaskInfo) -> Unit)? = null

    init {
@@ -439,12 +440,17 @@ class RootTaskDesksOrganizer(
        updateLaunchAdjacentController()
    }

    override fun attachChildSurfaceToTask(taskId: Int, b: SurfaceControl.Builder) {
        childLeashes.get(taskId)?.let { b.setParent(it) }
    }

    private fun handleTaskAppeared(taskInfo: RunningTaskInfo, leash: SurfaceControl) {
        // Check whether this task is appearing inside a desk.
        if (taskInfo.parentTaskId in deskRootsByDeskId) {
            val deskId = taskInfo.parentTaskId
            val taskId = taskInfo.taskId
            logV("Task #$taskId appeared in desk #$deskId")
            childLeashes.put(taskId, leash)
            addChildToDesk(taskId = taskId, deskId = deskId)
            return
        }
@@ -455,6 +461,7 @@ class RootTaskDesksOrganizer(
            val deskId = minimizationRoot.deskId
            val taskId = taskInfo.taskId
            logV("Task #$taskId was minimized in desk #$deskId ")
            childLeashes.put(taskId, leash)
            addChildToMinimizationRoot(taskId = taskId, deskId = deskId)
            return
        }
@@ -567,6 +574,7 @@ class RootTaskDesksOrganizer(
        deskRootsByDeskId.forEach { deskId, deskRoot ->
            if (deskRoot.children.remove(taskInfo.taskId)) {
                logV("Task #${taskInfo.taskId} vanished from desk #$deskId")
                childLeashes.remove(taskInfo.taskId)
                return
            }
        }
@@ -575,6 +583,7 @@ class RootTaskDesksOrganizer(
            val taskId = taskInfo.taskId
            if (root.children.remove(taskId)) {
                logV("Task #$taskId vanished from minimization root of desk #${root.deskId}")
                childLeashes.remove(taskInfo.taskId)
                return
            }
        }