summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Nicolo' Mazzucato <nicomazz@google.com> 2023-09-05 20:55:33 +0000
committer Nicolo' Mazzucato <nicomazz@google.com> 2023-09-05 20:56:24 +0000
commitd0bb2106d0f2007f41f8517e4d0347100ae09894 (patch)
treec7b5ce2dc1e4a583bf74c4cf31be65c27a4907dd
parent3081c06484fb34917c41d1debbbc6cd6340ef6b5 (diff)
Consider only external displays as pending
This prevents foldable devices from seeing internal displays as pending, otherwise the enable dialog would be shown on felix as well after boot. Bug: 299154872 Test: DisplayRepositoryTest Change-Id: Ica21700a68fedc225ac8e4629071308425bde0f1
-rw-r--r--packages/SystemUI/src/com/android/systemui/display/data/repository/DisplayRepository.kt21
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayRepositoryTest.kt26
2 files changed, 41 insertions, 6 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/display/data/repository/DisplayRepository.kt b/packages/SystemUI/src/com/android/systemui/display/data/repository/DisplayRepository.kt
index f68078a8a340..739932a0bd29 100644
--- a/packages/SystemUI/src/com/android/systemui/display/data/repository/DisplayRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/display/data/repository/DisplayRepository.kt
@@ -174,24 +174,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")
diff --git a/packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayRepositoryTest.kt
index 4bd380e927c7..3a0883b3a575 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayRepositoryTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/display/data/repository/DisplayRepositoryTest.kt
@@ -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.
@@ -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)
}