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

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

Merge "Initialize enabledDisplays with the correct displays" into main

parents 1d2e58bb caf6457b
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -160,7 +160,10 @@ constructor(
                    .stateIn(
                        bgApplicationScope,
                        SharingStarted.WhileSubscribed(),
                        emptySet(),
                        // This is necessary because there might be multiple displays, and we could
                        // have missed events for those added before this process or flow started.
                        // Note it causes a binder call from the main thread (it's traced).
                        getDisplays().map { display -> display.displayId }.toSet(),
                    )
            } else {
                oldEnabledDisplays.map { enabledDisplaysSet ->
@@ -186,8 +189,12 @@ constructor(
                .stateIn(
                    bgApplicationScope,
                    started = SharingStarted.WhileSubscribed(),
                    initialValue = setOf(defaultDisplay)
                )
                    // This triggers a single binder call on the UI thread per process. The
                    // alternative would be to use sharedFlows, but they are prohibited due to
                    // performance concerns.
                    // Ultimately, this is a trade-off between a one-time UI thread binder call and
                    // the constant overhead of sharedFlows.
                    initialValue = getDisplays())
        } else {
            oldEnabledDisplays
        }
+13 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.FlowValue
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.coroutines.collectValues
import com.android.systemui.util.mockito.kotlinArgumentCaptor
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.whenever
@@ -456,8 +457,20 @@ class DisplayRepositoryTest : SysuiTestCase() {
            assertThat(value?.ids()).containsExactly(DEFAULT_DISPLAY)
        }

    @Test
    fun displayFlow_emitsCorrectDisplaysAtFirst() =
        testScope.runTest {
            setDisplays(0, 1, 2)

            val values: List<Set<Display>> by collectValues(displayRepository.displays)

            assertThat(values.toIdSets()).containsExactly(setOf(0, 1, 2))
        }

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

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

    // Wrapper to capture the displayListener.
    private fun TestScope.latestDisplayFlowValue(): FlowValue<Set<Display>?> {
        val flowValue = collectLastValue(displayRepository.displays)