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

Commit 2f6f24c4 authored by Orhan Uysal's avatar Orhan Uysal Committed by Android (Google) Code Review
Browse files

Merge "Update peristent repository on visiblity change" into main

parents c19a039f 49b04a23
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -294,6 +294,9 @@ class DesktopRepository (
                taskId, isVisible, displayId)
            logD("VisibleTaskCount has changed from %d to %d", prevCount, newCount)
            notifyVisibleTaskListeners(displayId, newCount)
            if (Flags.enableDesktopWindowingPersistence()) {
                updatePersistentRepository(displayId)
            }
        }
    }

+21 −3
Original line number Diff line number Diff line
@@ -50,7 +50,9 @@ class DesktopPersistentRepository(
        DataStoreFactory.create(
            serializer = DesktopPersistentRepositoriesSerializer,
            produceFile = { context.dataStoreFile(DESKTOP_REPOSITORIES_DATASTORE_FILE) },
            scope = bgCoroutineScope))
            scope = bgCoroutineScope,
        ),
    )

    /** Provides `dataStore.data` flow and handles exceptions thrown during collection */
    private val dataStoreFlow: Flow<DesktopPersistentRepositories> =
@@ -116,7 +118,11 @@ class DesktopPersistentRepository(
                val desktop =
                    getDesktop(currentRepository, desktopId)
                        .toBuilder()
                        .updateTaskStates(visibleTasks, minimizedTasks)
                        .updateTaskStates(
                            visibleTasks,
                            minimizedTasks,
                            freeformTasksInZOrder,
                        )
                        .updateZOrder(freeformTasksInZOrder)

                desktopPersistentRepositories
@@ -169,9 +175,21 @@ class DesktopPersistentRepository(

        private fun Desktop.Builder.updateTaskStates(
            visibleTasks: ArraySet<Int>,
            minimizedTasks: ArraySet<Int>
            minimizedTasks: ArraySet<Int>,
            freeformTasksInZOrder: ArrayList<Int>,
        ): Desktop.Builder {
            clearTasksByTaskId()

            // Handle the case where tasks are not marked as visible but are meant to be visible
            // after reboot. E.g. User moves out of desktop when there are multiple tasks are
            // visible, they will be marked as not visible afterwards. This ensures that they are
            // still persisted as visible.
            // TODO - b/350476823: Remove this logic once repository holds expanded tasks
            if (freeformTasksInZOrder.size > visibleTasks.size + minimizedTasks.size &&
                visibleTasks.isEmpty()
            ) {
                visibleTasks.addAll(freeformTasksInZOrder.filterNot { it in minimizedTasks })
            }
            putAllTasksByTaskId(
                visibleTasks.associateWith {
                    createDesktopTask(it, state = DesktopTaskState.VISIBLE)
+29 −1
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import org.mockito.Mockito.inOrder
import org.mockito.Mockito.spy
import org.mockito.kotlin.any
import org.mockito.kotlin.never
import org.mockito.kotlin.times
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever

@@ -226,6 +227,33 @@ class DesktopRepositoryTest : ShellTestCase() {
        assertThat(repo.isOnlyVisibleNonClosingTask(99)).isFalse()
    }

    @Test
    @EnableFlags(FLAG_ENABLE_DESKTOP_WINDOWING_PERSISTENCE)
    fun updateTaskVisibility_multipleTasks_persistsVisibleTasks() =
        runTest(StandardTestDispatcher()) {
            repo.updateTask(DEFAULT_DISPLAY, taskId = 1, isVisible = true)
            repo.updateTask(DEFAULT_DISPLAY, taskId = 2, isVisible = true)

            inOrder(persistentRepository).run {
                verify(persistentRepository)
                    .addOrUpdateDesktop(
                        DEFAULT_USER_ID,
                        DEFAULT_DESKTOP_ID,
                        visibleTasks = ArraySet(arrayOf(1)),
                        minimizedTasks = ArraySet(),
                        freeformTasksInZOrder = arrayListOf()
                    )
                verify(persistentRepository)
                    .addOrUpdateDesktop(
                        DEFAULT_USER_ID,
                        DEFAULT_DESKTOP_ID,
                        visibleTasks = ArraySet(arrayOf(1, 2)),
                        minimizedTasks = ArraySet(),
                        freeformTasksInZOrder = arrayListOf()
                    )
            }
        }

    @Test
    fun isOnlyVisibleNonClosingTask_singleVisibleClosingTask() {
        repo.updateTask(DEFAULT_DISPLAY, taskId = 1, isVisible = true)
@@ -614,7 +642,7 @@ class DesktopRepositoryTest : ShellTestCase() {
                        minimizedTasks = ArraySet(),
                        freeformTasksInZOrder = arrayListOf(7, 6, 5)
                    )
                verify(persistentRepository)
                verify(persistentRepository, times(2))
                    .addOrUpdateDesktop(
                        DEFAULT_USER_ID,
                        DEFAULT_DESKTOP_ID,