Loading packages/SystemUI/src/com/android/systemui/display/data/repository/DisplayRepository.kt +16 −5 Original line number Diff line number Diff line Loading @@ -175,24 +175,35 @@ constructor( initialValue = emptySet() ) private val connectedExternalDisplayIds: Flow<Set<Int>> = connectedDisplayIds .map { connectedDisplayIds -> connectedDisplayIds .filter { id -> displayManager.getDisplay(id)?.type == Display.TYPE_EXTERNAL } .toSet() } .flowOn(backgroundCoroutineDispatcher) .debugLog("connectedExternalDisplayIds") /** * Pending displays are the ones connected, but not enabled and not ignored. A connected display * is ignored after the user makes the decision to use it or not. For now, the initial decision * from the user is final and not reversible. */ private val pendingDisplayIds: Flow<Set<Int>> = combine(enabledDisplayIds, connectedDisplayIds, ignoredDisplayIds) { combine(enabledDisplayIds, connectedExternalDisplayIds, ignoredDisplayIds) { enabledDisplaysIds, connectedDisplayIds, connectedExternalDisplayIds, ignoredDisplayIds -> if (DEBUG) { Log.d( TAG, "combining enabled: $enabledDisplaysIds, " + "connected: $connectedDisplayIds, ignored: $ignoredDisplayIds" "combining enabled=$enabledDisplaysIds, " + "connectedExternalDisplayIds=$connectedExternalDisplayIds, " + "ignored=$ignoredDisplayIds" ) } connectedDisplayIds - enabledDisplaysIds - ignoredDisplayIds connectedExternalDisplayIds - enabledDisplaysIds - ignoredDisplayIds } .debugLog("pendingDisplayIds") Loading packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayRepositoryTest.kt +25 −1 Original line number Diff line number Diff line Loading @@ -350,6 +350,27 @@ class DisplayRepositoryTest : SysuiTestCase() { assertThat(pendingDisplay).isNotNull() } @Test fun onPendingDisplay_internalDisplay_ignored() = testScope.runTest { val pendingDisplay by lastPendingDisplay() sendOnDisplayConnected(1, Display.TYPE_INTERNAL) assertThat(pendingDisplay).isNull() } @Test fun onPendingDisplay_OneInternalAndOneExternalDisplay_internalIgnored() = testScope.runTest { val pendingDisplay by lastPendingDisplay() sendOnDisplayConnected(1, Display.TYPE_EXTERNAL) sendOnDisplayConnected(2, Display.TYPE_INTERNAL) assertThat(pendingDisplay!!.id).isEqualTo(1) } private fun Iterable<Display>.ids(): List<Int> = map { it.displayId } // Wrapper to capture the displayListener. Loading Loading @@ -392,9 +413,12 @@ class DisplayRepositoryTest : SysuiTestCase() { private fun sendOnDisplayDisconnected(id: Int) { connectedDisplayListener.value.onDisplayDisconnected(id) whenever(displayManager.getDisplay(eq(id))).thenReturn(null) } private fun sendOnDisplayConnected(id: Int) { private fun sendOnDisplayConnected(id: Int, displayType: Int = Display.TYPE_EXTERNAL) { val mockDisplay = display(id = id, type = displayType) whenever(displayManager.getDisplay(eq(id))).thenReturn(mockDisplay) connectedDisplayListener.value.onDisplayConnected(id) } Loading Loading
packages/SystemUI/src/com/android/systemui/display/data/repository/DisplayRepository.kt +16 −5 Original line number Diff line number Diff line Loading @@ -175,24 +175,35 @@ constructor( initialValue = emptySet() ) private val connectedExternalDisplayIds: Flow<Set<Int>> = connectedDisplayIds .map { connectedDisplayIds -> connectedDisplayIds .filter { id -> displayManager.getDisplay(id)?.type == Display.TYPE_EXTERNAL } .toSet() } .flowOn(backgroundCoroutineDispatcher) .debugLog("connectedExternalDisplayIds") /** * Pending displays are the ones connected, but not enabled and not ignored. A connected display * is ignored after the user makes the decision to use it or not. For now, the initial decision * from the user is final and not reversible. */ private val pendingDisplayIds: Flow<Set<Int>> = combine(enabledDisplayIds, connectedDisplayIds, ignoredDisplayIds) { combine(enabledDisplayIds, connectedExternalDisplayIds, ignoredDisplayIds) { enabledDisplaysIds, connectedDisplayIds, connectedExternalDisplayIds, ignoredDisplayIds -> if (DEBUG) { Log.d( TAG, "combining enabled: $enabledDisplaysIds, " + "connected: $connectedDisplayIds, ignored: $ignoredDisplayIds" "combining enabled=$enabledDisplaysIds, " + "connectedExternalDisplayIds=$connectedExternalDisplayIds, " + "ignored=$ignoredDisplayIds" ) } connectedDisplayIds - enabledDisplaysIds - ignoredDisplayIds connectedExternalDisplayIds - enabledDisplaysIds - ignoredDisplayIds } .debugLog("pendingDisplayIds") Loading
packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayRepositoryTest.kt +25 −1 Original line number Diff line number Diff line Loading @@ -350,6 +350,27 @@ class DisplayRepositoryTest : SysuiTestCase() { assertThat(pendingDisplay).isNotNull() } @Test fun onPendingDisplay_internalDisplay_ignored() = testScope.runTest { val pendingDisplay by lastPendingDisplay() sendOnDisplayConnected(1, Display.TYPE_INTERNAL) assertThat(pendingDisplay).isNull() } @Test fun onPendingDisplay_OneInternalAndOneExternalDisplay_internalIgnored() = testScope.runTest { val pendingDisplay by lastPendingDisplay() sendOnDisplayConnected(1, Display.TYPE_EXTERNAL) sendOnDisplayConnected(2, Display.TYPE_INTERNAL) assertThat(pendingDisplay!!.id).isEqualTo(1) } private fun Iterable<Display>.ids(): List<Int> = map { it.displayId } // Wrapper to capture the displayListener. Loading Loading @@ -392,9 +413,12 @@ class DisplayRepositoryTest : SysuiTestCase() { private fun sendOnDisplayDisconnected(id: Int) { connectedDisplayListener.value.onDisplayDisconnected(id) whenever(displayManager.getDisplay(eq(id))).thenReturn(null) } private fun sendOnDisplayConnected(id: Int) { private fun sendOnDisplayConnected(id: Int, displayType: Int = Display.TYPE_EXTERNAL) { val mockDisplay = display(id = id, type = displayType) whenever(displayManager.getDisplay(eq(id))).thenReturn(mockDisplay) connectedDisplayListener.value.onDisplayConnected(id) } Loading