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

Commit 655f4939 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Desks: Allow obtaining non-existent desk instance in single-desk setups" into main

parents c78131d5 3df0d8dc
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -72,6 +72,11 @@ class DesktopDisplayEventHandler(
            return
        }
        logV("Creating new desk in new display#$displayId")
        // TODO: b/362720497 - when SystemUI crashes with a freeform task open for any reason, the
        //  task is recreated and received in [FreeformTaskListener] before this display callback
        //  is invoked, which results in the repository trying to add the task to a desk before the
        //  desk has been recreated here, which may result in a crash-loop if the repository is
        //  checking that the desk exists before adding a task to it. See b/391984373.
        desktopTasksController.createDesk(displayId)
    }

+4 −1
Original line number Diff line number Diff line
@@ -926,7 +926,10 @@ class DesktopRepository(
        }

        override fun getDesk(deskId: Int): Desk =
            checkNotNull(deskByDisplayId[deskId]) { "Expected desk $deskId to exist" }
            // TODO: b/362720497 - consider enforcing that the desk has been created before trying
            //  to use it. As of now, there are cases where a task may be created faster than a
            //  desk is, so just create it here if needed. See b/391984373.
            deskByDisplayId.getOrCreate(deskId)

        override fun getActiveDesk(displayId: Int): Desk {
            // TODO: 389787966 - consider migrating to an "active" state instead of checking the
+9 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.wm.shell.desktopmode

import android.graphics.Rect
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.FlagsParameterization
import android.platform.test.flag.junit.SetFlagsRule
@@ -1159,6 +1160,14 @@ class DesktopRepositoryTest(flags: FlagsParameterization) : ShellTestCase() {
        assertThat(repo.shouldDesktopBeActiveForPip(DEFAULT_DESKTOP_ID)).isFalse()
    }

    @Test
    @DisableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
    fun addTask_deskDoesNotExists_createsDesk() {
        repo.addTask(displayId = 999, taskId = 6, isVisible = true)

        assertThat(repo.getActiveTaskIdsInDesk(999)).contains(6)
    }

    class TestListener : DesktopRepository.ActiveTasksListener {
        var activeChangesOnDefaultDisplay = 0
        var activeChangesOnSecondaryDisplay = 0