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

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

Merge "Fix race from DisplayRepository.getDisplay" into main

parents 48e59be7 414d6e28
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -638,6 +638,20 @@ class DisplayRepositoryTest : SysuiTestCase() {
        verify(commandQueue, times(1)).removeCallback(any())
    }

    @Test
    fun getDisplay_slowMappingToDisplay_returnsRegardless() =
        testScope.runTest {
            val displayIds by collectLastValue(displayRepository.displayIds)
            val displays by latestDisplayFlowValue()

            sendOnDisplayAdded(1, TYPE_EXTERNAL)

            assertThat(displayIds).contains(1)
            assertThat(displays!!.ids()).contains(1)
            assertThat(displayRepository.getCachedDisplay(1)).isNotNull()
            assertThat(displayRepository.getDisplay(1)).isNotNull()
        }

    private fun Iterable<Display>.ids(): List<Int> = map { it.displayId }

    private fun Iterable<Set<Display>>.toIdSets(): List<Set<Int>> = map { it.ids().toSet() }
+1 −1
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ abstract class PerDisplayStoreImpl<T>(
     *   displays.
     */
    override fun forDisplay(displayId: Int): T? {
        if (displayRepository.getDisplay(displayId)  == null) {
        if (!displayRepository.containsDisplay(displayId)) {
            Log.e(TAG, "<${instanceClass.simpleName}>: Display with id $displayId doesn't exist.")
            return null
        }
+4 −0
Original line number Diff line number Diff line
@@ -116,6 +116,10 @@ class FakeDisplayRepository @Inject constructor() : DisplayRepository {
    override val defaultDisplayOff: Flow<Boolean>
        get() = _defaultDisplayOff.asStateFlow()

    override fun getDisplay(displayId: Int): Display? {
        return displays.value.find { it.displayId == displayId }
    }

    override val displayAdditionEvent: Flow<Display?>
        get() = displayAdditionEventFlow