Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8de73bd5 authored by Matt Casey's avatar Matt Casey Committed by Android (Google) Code Review
Browse files

Merge "Instantiate a new ScreenshotController if consecutive request are for...

Merge "Instantiate a new ScreenshotController if consecutive request are for different displays" into main
parents 7647de67 ed59788e
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
@@ -640,6 +640,48 @@ class TakeScreenshotExecutorTest : SysuiTestCase() {
            screenshotExecutor.onDestroy()
        }

    @Test
    @EnableFlags(Flags.FLAG_SCREENSHOT_MULTIDISPLAY_FOCUS_CHANGE)
    fun executeScreenshots_consecutiveRequestsOnDifferentDisplays() =
        testScope.runTest {
            val secondaryDisplay = display(TYPE_EXTERNAL, id = 1)
            var focusedDisplay = Display.DEFAULT_DISPLAY
            setDisplays(display(TYPE_INTERNAL, id = Display.DEFAULT_DISPLAY), secondaryDisplay)
            screenshotProxy.stub {
                onBlocking { getFocusedDisplay() }.thenAnswer { focusedDisplay }
            }

            val secondaryController = mock<ScreenshotController>()
            whenever(controllerFactory.create(eq(secondaryDisplay))).thenReturn(secondaryController)

            screenshotExecutor.executeScreenshots(
                createScreenshotRequest(
                    source = WindowManager.ScreenshotSource.SCREENSHOT_KEY_OTHER
                ),
                { _: Uri? -> },
                callback,
            )

            verify(controller).handleScreenshot(any(), any(), any())
            verify(secondaryController, never()).handleScreenshot(any(), any(), any())

            // Now input focus moves to secondary display.
            focusedDisplay = secondaryDisplay.displayId
            screenshotExecutor.executeScreenshots(
                createScreenshotRequest(
                    source = WindowManager.ScreenshotSource.SCREENSHOT_KEY_OTHER
                ),
                { _: Uri? -> },
                callback,
            )

            // Destroy the old controller, send screenshot to the secondary display one.
            verify(controller).onDestroy()
            verify(secondaryController).handleScreenshot(any(), any(), any())

            screenshotExecutor.onDestroy()
        }

    private suspend fun TestScope.setDisplays(vararg displays: Display) {
        fakeDisplayRepository.emit(displays.toSet())
        runCurrent()
+2 −0
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import android.view.Display
interface InteractiveScreenshotHandler : ScreenshotHandler {
    fun isPendingSharedTransition(): Boolean

    fun getDisplay(): Display

    fun requestDismissal(event: ScreenshotEvent)

    fun removeWindow()
+3 −0
Original line number Diff line number Diff line
@@ -300,8 +300,11 @@ internal constructor(
        screenshotSoundController.releaseScreenshotSoundAsync()
        releaseContext()
        bgExecutor.shutdown()
        screenshotHandler.cancelTimeout()
    }

    override fun getDisplay() = display

    /** Release the constructed window context. */
    private fun releaseContext() {
        broadcastDispatcher.unregisterReceiver(copyBroadcastReceiver)
+10 −0
Original line number Diff line number Diff line
@@ -274,6 +274,16 @@ constructor(
    }

    private fun getScreenshotController(display: Display): InteractiveScreenshotHandler {

        if (
            SCREENSHOT_MULTIDISPLAY_FOCUS_CHANGE.isTrue &&
                screenshotController?.getDisplay() != display
        ) {
            // New request is from a different display, throw out the old UI so we can instantiate a
            // new one.
            screenshotController?.onDestroy()
            screenshotController = null
        }
        val controller = screenshotController ?: interactiveScreenshotHandlerFactory.create(display)
        screenshotController = controller
        return controller