Loading packages/SystemUI/src/com/android/systemui/display/data/repository/DisplayRepository.kt +10 −8 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filterIsInstance import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map Loading Loading @@ -137,6 +138,7 @@ constructor( override val displayAdditionEvent: Flow<Display?> = allDisplayEvents.filterIsInstance<DisplayEvent.Added>().map { getDisplay(it.displayId) } // TODO: b/345472038 - Delete after the flag is ramped up. private val oldEnabledDisplays: Flow<Set<Display>> = allDisplayEvents .map { getDisplays() } Loading Loading @@ -167,6 +169,9 @@ constructor( } .debugLog("enabledDisplayIds") private val defaultDisplay by lazy { getDisplay(Display.DEFAULT_DISPLAY) ?: error("Unable to get default display.") } /** * Represents displays that went though the [DisplayListener.onDisplayAdded] callback. * Loading @@ -181,11 +186,7 @@ constructor( .stateIn( bgApplicationScope, started = SharingStarted.WhileSubscribed(), initialValue = setOf( getDisplay(Display.DEFAULT_DISPLAY) ?: error("Unable to get default display.") ) initialValue = setOf(defaultDisplay) ) } else { oldEnabledDisplays Loading Loading @@ -344,9 +345,10 @@ constructor( .debugLog("pendingDisplay") override val defaultDisplayOff: Flow<Boolean> = displays .map { displays -> displays.firstOrNull { it.displayId == Display.DEFAULT_DISPLAY } } .map { it?.state == Display.STATE_OFF } displayChangeEvent .filter { it == Display.DEFAULT_DISPLAY } .map { defaultDisplay.state == Display.STATE_OFF } .distinctUntilChanged() private fun <T> Flow<T>.debugLog(flowName: String): Flow<T> { return if (DEBUG) { Loading packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayRepositoryTest.kt +10 −12 Original line number Diff line number Diff line Loading @@ -59,12 +59,14 @@ class DisplayRepositoryTest : SysuiTestCase() { private val testHandler = FakeHandler(Looper.getMainLooper()) private val testScope = TestScope(UnconfinedTestDispatcher()) private val defaultDisplay = display(type = TYPE_INTERNAL, id = DEFAULT_DISPLAY, state = Display.STATE_ON) private lateinit var displayRepository: DisplayRepositoryImpl @Before fun setup() { setDisplays(DEFAULT_DISPLAY) setDisplays(listOf(defaultDisplay)) setAllDisplaysIncludingDisabled(DEFAULT_DISPLAY) displayRepository = DisplayRepositoryImpl( Loading Loading @@ -434,19 +436,12 @@ class DisplayRepositoryTest : SysuiTestCase() { fun defaultDisplayOff_changes() = testScope.runTest { val defaultDisplayOff by latestDefaultDisplayOffFlowValue() setDisplays( listOf( display(type = TYPE_INTERNAL, id = DEFAULT_DISPLAY, state = Display.STATE_OFF) ) ) whenever(defaultDisplay.state).thenReturn(Display.STATE_OFF) displayListener.value.onDisplayChanged(DEFAULT_DISPLAY) assertThat(defaultDisplayOff).isTrue() setDisplays( listOf( display(type = TYPE_INTERNAL, id = DEFAULT_DISPLAY, state = Display.STATE_ON) ) ) whenever(defaultDisplay.state).thenReturn(Display.STATE_ON) displayListener.value.onDisplayChanged(DEFAULT_DISPLAY) assertThat(defaultDisplayOff).isFalse() } Loading Loading @@ -545,7 +540,10 @@ class DisplayRepositoryTest : SysuiTestCase() { } private fun setAllDisplaysIncludingDisabled(vararg ids: Int) { val displays = ids.map { display(type = TYPE_EXTERNAL, id = it) }.toTypedArray() val displays = (ids.toSet() - DEFAULT_DISPLAY) // Default display always added. .map { display(type = TYPE_EXTERNAL, id = it) } .toTypedArray() + defaultDisplay whenever( displayManager.getDisplays( eq(DisplayManager.DISPLAY_CATEGORY_ALL_INCLUDING_DISABLED) Loading Loading
packages/SystemUI/src/com/android/systemui/display/data/repository/DisplayRepository.kt +10 −8 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filterIsInstance import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map Loading Loading @@ -137,6 +138,7 @@ constructor( override val displayAdditionEvent: Flow<Display?> = allDisplayEvents.filterIsInstance<DisplayEvent.Added>().map { getDisplay(it.displayId) } // TODO: b/345472038 - Delete after the flag is ramped up. private val oldEnabledDisplays: Flow<Set<Display>> = allDisplayEvents .map { getDisplays() } Loading Loading @@ -167,6 +169,9 @@ constructor( } .debugLog("enabledDisplayIds") private val defaultDisplay by lazy { getDisplay(Display.DEFAULT_DISPLAY) ?: error("Unable to get default display.") } /** * Represents displays that went though the [DisplayListener.onDisplayAdded] callback. * Loading @@ -181,11 +186,7 @@ constructor( .stateIn( bgApplicationScope, started = SharingStarted.WhileSubscribed(), initialValue = setOf( getDisplay(Display.DEFAULT_DISPLAY) ?: error("Unable to get default display.") ) initialValue = setOf(defaultDisplay) ) } else { oldEnabledDisplays Loading Loading @@ -344,9 +345,10 @@ constructor( .debugLog("pendingDisplay") override val defaultDisplayOff: Flow<Boolean> = displays .map { displays -> displays.firstOrNull { it.displayId == Display.DEFAULT_DISPLAY } } .map { it?.state == Display.STATE_OFF } displayChangeEvent .filter { it == Display.DEFAULT_DISPLAY } .map { defaultDisplay.state == Display.STATE_OFF } .distinctUntilChanged() private fun <T> Flow<T>.debugLog(flowName: String): Flow<T> { return if (DEBUG) { Loading
packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayRepositoryTest.kt +10 −12 Original line number Diff line number Diff line Loading @@ -59,12 +59,14 @@ class DisplayRepositoryTest : SysuiTestCase() { private val testHandler = FakeHandler(Looper.getMainLooper()) private val testScope = TestScope(UnconfinedTestDispatcher()) private val defaultDisplay = display(type = TYPE_INTERNAL, id = DEFAULT_DISPLAY, state = Display.STATE_ON) private lateinit var displayRepository: DisplayRepositoryImpl @Before fun setup() { setDisplays(DEFAULT_DISPLAY) setDisplays(listOf(defaultDisplay)) setAllDisplaysIncludingDisabled(DEFAULT_DISPLAY) displayRepository = DisplayRepositoryImpl( Loading Loading @@ -434,19 +436,12 @@ class DisplayRepositoryTest : SysuiTestCase() { fun defaultDisplayOff_changes() = testScope.runTest { val defaultDisplayOff by latestDefaultDisplayOffFlowValue() setDisplays( listOf( display(type = TYPE_INTERNAL, id = DEFAULT_DISPLAY, state = Display.STATE_OFF) ) ) whenever(defaultDisplay.state).thenReturn(Display.STATE_OFF) displayListener.value.onDisplayChanged(DEFAULT_DISPLAY) assertThat(defaultDisplayOff).isTrue() setDisplays( listOf( display(type = TYPE_INTERNAL, id = DEFAULT_DISPLAY, state = Display.STATE_ON) ) ) whenever(defaultDisplay.state).thenReturn(Display.STATE_ON) displayListener.value.onDisplayChanged(DEFAULT_DISPLAY) assertThat(defaultDisplayOff).isFalse() } Loading Loading @@ -545,7 +540,10 @@ class DisplayRepositoryTest : SysuiTestCase() { } private fun setAllDisplaysIncludingDisabled(vararg ids: Int) { val displays = ids.map { display(type = TYPE_EXTERNAL, id = it) }.toTypedArray() val displays = (ids.toSet() - DEFAULT_DISPLAY) // Default display always added. .map { display(type = TYPE_EXTERNAL, id = it) } .toTypedArray() + defaultDisplay whenever( displayManager.getDisplays( eq(DisplayManager.DISPLAY_CATEGORY_ALL_INCLUDING_DISABLED) Loading