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

Commit 3d1b6a60 authored by Jorge Gil's avatar Jorge Gil
Browse files

Do not crash when root appears without matching request

It's possible that a display becomes inelegible for desktop while a desk
root task (or minimization root) was being requested, and that the root
created is reparented to another display when this happens. In such
cases, the task may appear (in ShellTaskOrg) for the first time under
the new display instead of the one that originally requested.

With this change we no longer crash SystemUI and log an error instead.

Flag: com.android.window.flags.enable_multiple_desktops_backend
Fix: 439173763
Test: atest WMShellUnitTests
Change-Id: I7846a447cfa78e1f653ba49a3cd24a51bfa3c617
parent 6b8b441a
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -497,6 +497,13 @@ class RootTaskDesksOrganizer(
        }

        val appearingInDisplayId = taskInfo.displayId
        logV(
            "Task #%d appeared in display #%d, deskRootRequests=%s minimizationRootRequests=%s",
            taskInfo.taskId,
            appearingInDisplayId,
            createDeskRootRequests,
            createDeskMinimizationRootRequests,
        )
        // Check if there's any pending desk creation requests under this display.
        val deskRequest =
            createDeskRootRequests.firstOrNull { it.displayId == appearingInDisplayId }
@@ -532,7 +539,15 @@ class RootTaskDesksOrganizer(
        }
        // Check if there's any pending minimization container creation requests under this display.
        val deskMinimizationRootRequest =
            createDeskMinimizationRootRequests.first { it.displayId == appearingInDisplayId }
            createDeskMinimizationRootRequests.firstOrNull { it.displayId == appearingInDisplayId }
        if (deskMinimizationRootRequest == null) {
            logE(
                "Did not find a matching desk minimization root request for task#%d in display#%d",
                taskInfo.taskId,
                taskInfo.displayId,
            )
            return
        }
        val deskId = deskMinimizationRootRequest.deskId
        logV("Minimization container for desk #$deskId appeared with id=${taskInfo.taskId}")
        val deskMinimizationRoot = DeskMinimizationRoot(deskId, taskInfo, leash)
+0 −9
Original line number Diff line number Diff line
@@ -295,15 +295,6 @@ class RootTaskDesksOrganizerTest : ShellTestCase() {
            )
    }

    @Test
    fun testOnTaskAppeared_withoutRequest_throws() = runTest {
        val freeformRoot = createFreeformTask().apply { parentTaskId = -1 }

        assertThrows(Exception::class.java) {
            organizer.onTaskAppeared(freeformRoot, SurfaceControl())
        }
    }

    @Test
    fun testOnTaskAppeared_duplicateRoot_throws() = runTest {
        val desk = createDeskSuspending()