diff options
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotExecutor.kt | 6 | ||||
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/screenshot/TakeScreenshotExecutorTest.kt | 61 |
2 files changed, 62 insertions, 5 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotExecutor.kt b/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotExecutor.kt index 38608d0e793a..ab8a9539b7f2 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotExecutor.kt +++ b/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotExecutor.kt @@ -202,10 +202,10 @@ constructor( // Return the single display to be screenshot based upon the request. private suspend fun getDisplayToScreenshot(screenshotRequest: ScreenshotRequest): Display { return when (screenshotRequest.source) { - // TODO(b/367394043): Overview requests should use a display ID provided in - // ScreenshotRequest. ScreenshotSource.SCREENSHOT_OVERVIEW -> - displayRepository.getDisplay(Display.DEFAULT_DISPLAY) + // Show on the display where overview was shown if available. + displayRepository.getDisplay(screenshotRequest.displayId) + ?: displayRepository.getDisplay(Display.DEFAULT_DISPLAY) ?: error("Can't find default display") // Key chord and vendor gesture occur on the device itself, so screenshot the device's diff --git a/packages/SystemUI/tests/src/com/android/systemui/screenshot/TakeScreenshotExecutorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/screenshot/TakeScreenshotExecutorTest.kt index 15705fbfec33..0bea56007a01 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/screenshot/TakeScreenshotExecutorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/screenshot/TakeScreenshotExecutorTest.kt @@ -257,6 +257,58 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test + @EnableFlags(Flags.FLAG_SCREENSHOT_MULTIDISPLAY_FOCUS_CHANGE) + fun executeScreenshots_fromOverview_honorsDisplay() = + testScope.runTest { + val displayId = 1 + setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = displayId)) + val onSaved = { _: Uri? -> } + screenshotExecutor.executeScreenshots( + createScreenshotRequest( + displayId = displayId, + source = WindowManager.ScreenshotSource.SCREENSHOT_OVERVIEW, + ), + onSaved, + callback, + ) + + val dataCaptor = ArgumentCaptor<ScreenshotData>() + + verify(controller).handleScreenshot(dataCaptor.capture(), any(), any()) + + assertThat(dataCaptor.value.displayId).isEqualTo(displayId) + + screenshotExecutor.onDestroy() + } + + @Test + @EnableFlags(Flags.FLAG_SCREENSHOT_MULTIDISPLAY_FOCUS_CHANGE) + fun executeScreenshots_fromOverviewInvalidDisplay_usesDefault() = + testScope.runTest { + setDisplays( + display(TYPE_INTERNAL, id = Display.DEFAULT_DISPLAY), + display(TYPE_EXTERNAL, id = 1), + ) + val onSaved = { _: Uri? -> } + screenshotExecutor.executeScreenshots( + createScreenshotRequest( + displayId = 5, + source = WindowManager.ScreenshotSource.SCREENSHOT_OVERVIEW, + ), + onSaved, + callback, + ) + + val dataCaptor = ArgumentCaptor<ScreenshotData>() + + verify(controller).handleScreenshot(dataCaptor.capture(), any(), any()) + + assertThat(dataCaptor.value.displayId).isEqualTo(Display.DEFAULT_DISPLAY) + + screenshotExecutor.onDestroy() + } + + @Test fun onDestroy_propagatedToControllers() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) @@ -527,9 +579,14 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { runCurrent() } - private fun createScreenshotRequest(type: Int = WindowManager.TAKE_SCREENSHOT_FULLSCREEN) = - ScreenshotRequest.Builder(type, WindowManager.ScreenshotSource.SCREENSHOT_KEY_OTHER) + private fun createScreenshotRequest( + type: Int = WindowManager.TAKE_SCREENSHOT_FULLSCREEN, + source: Int = WindowManager.ScreenshotSource.SCREENSHOT_KEY_OTHER, + displayId: Int = Display.DEFAULT_DISPLAY, + ) = + ScreenshotRequest.Builder(type, source) .setTopComponent(topComponent) + .setDisplayId(displayId) .also { if (type == TAKE_SCREENSHOT_PROVIDED_IMAGE) { it.setBitmap(Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888)) |