Loading libs/WindowManager/Shell/tests/e2e/utils/src/com/android/wm/shell/SimulatedConnectedDisplayTestRule.kt +17 −13 Original line number Diff line number Diff line Loading @@ -41,7 +41,6 @@ import org.junit.runners.model.Statement class SimulatedConnectedDisplayTestRule : TestRule { private val context = InstrumentationRegistry.getInstrumentation().targetContext private val uiAutomation = InstrumentationRegistry.getInstrumentation().uiAutomation private val displayManager = context.getSystemService(DisplayManager::class.java) private val addedDisplays = mutableListOf<Int>() Loading Loading @@ -102,7 +101,8 @@ class SimulatedConnectedDisplayTestRule : TestRule { // Add the overlay displays Settings.Global.putString( InstrumentationRegistry.getInstrumentation().context.contentResolver, Settings.Global.OVERLAY_DISPLAY_DEVICES, displaySettings Settings.Global.OVERLAY_DISPLAY_DEVICES, displaySettings ) withTimeoutOrNull(TIMEOUT) { displayAddedFlow.take(displays.size).collect { displayId -> Loading @@ -125,10 +125,6 @@ class SimulatedConnectedDisplayTestRule : TestRule { } private fun cleanupTestDisplays() = runBlocking { if (addedDisplays.isEmpty()) { return@runBlocking } val displayRemovedFlow: Flow<Int> = callbackFlow { val listener = object : DisplayListener { override fun onDisplayAdded(displayId: Int) {} Loading @@ -146,16 +142,24 @@ class SimulatedConnectedDisplayTestRule : TestRule { } } // Remove overlay displays // Remove overlay displays. We'll execute this regardless of addedDisplays just to // ensure all overlay displays are removed before and after the test. // Note: If we want to restore the original overlay display added before this test (and its // topology), it will be complicated as re-adding overlay display would lead to different // displayId and topology could not be restored easily. Settings.Global.putString( InstrumentationRegistry.getInstrumentation().context.contentResolver, Settings.Global.OVERLAY_DISPLAY_DEVICES, null) Settings.Global.OVERLAY_DISPLAY_DEVICES, null ) if (!addedDisplays.isEmpty()) { withTimeoutOrNull(TIMEOUT) { displayRemovedFlow.take(addedDisplays.size).collect { displayId -> addedDisplays.remove(displayId) } } ?: error("Timed out waiting for displays to be removed.") } ?: error("Timed out waiting for displays to be removed: $addedDisplays") } } private companion object { Loading Loading
libs/WindowManager/Shell/tests/e2e/utils/src/com/android/wm/shell/SimulatedConnectedDisplayTestRule.kt +17 −13 Original line number Diff line number Diff line Loading @@ -41,7 +41,6 @@ import org.junit.runners.model.Statement class SimulatedConnectedDisplayTestRule : TestRule { private val context = InstrumentationRegistry.getInstrumentation().targetContext private val uiAutomation = InstrumentationRegistry.getInstrumentation().uiAutomation private val displayManager = context.getSystemService(DisplayManager::class.java) private val addedDisplays = mutableListOf<Int>() Loading Loading @@ -102,7 +101,8 @@ class SimulatedConnectedDisplayTestRule : TestRule { // Add the overlay displays Settings.Global.putString( InstrumentationRegistry.getInstrumentation().context.contentResolver, Settings.Global.OVERLAY_DISPLAY_DEVICES, displaySettings Settings.Global.OVERLAY_DISPLAY_DEVICES, displaySettings ) withTimeoutOrNull(TIMEOUT) { displayAddedFlow.take(displays.size).collect { displayId -> Loading @@ -125,10 +125,6 @@ class SimulatedConnectedDisplayTestRule : TestRule { } private fun cleanupTestDisplays() = runBlocking { if (addedDisplays.isEmpty()) { return@runBlocking } val displayRemovedFlow: Flow<Int> = callbackFlow { val listener = object : DisplayListener { override fun onDisplayAdded(displayId: Int) {} Loading @@ -146,16 +142,24 @@ class SimulatedConnectedDisplayTestRule : TestRule { } } // Remove overlay displays // Remove overlay displays. We'll execute this regardless of addedDisplays just to // ensure all overlay displays are removed before and after the test. // Note: If we want to restore the original overlay display added before this test (and its // topology), it will be complicated as re-adding overlay display would lead to different // displayId and topology could not be restored easily. Settings.Global.putString( InstrumentationRegistry.getInstrumentation().context.contentResolver, Settings.Global.OVERLAY_DISPLAY_DEVICES, null) Settings.Global.OVERLAY_DISPLAY_DEVICES, null ) if (!addedDisplays.isEmpty()) { withTimeoutOrNull(TIMEOUT) { displayRemovedFlow.take(addedDisplays.size).collect { displayId -> addedDisplays.remove(displayId) } } ?: error("Timed out waiting for displays to be removed.") } ?: error("Timed out waiting for displays to be removed: $addedDisplays") } } private companion object { Loading