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

Commit 41145db2 authored by Miranda Kephart's avatar Miranda Kephart Committed by Android (Google) Code Review
Browse files

Merge "Use DisplayManager to retrieve displays to screenshot" into main

parents ad1bb9e2 372f27ee
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ package com.android.systemui.screenshot

import android.content.ComponentName
import android.graphics.Bitmap
import android.hardware.display.DisplayManager
import android.net.Uri
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
@@ -54,6 +55,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() {
    private val controllerFactory = mock<InteractiveScreenshotHandler.Factory>()
    private val callback = mock<TakeScreenshotService.RequestCallback>()
    private val notificationControllerFactory = mock<ScreenshotNotificationsController.Factory>()
    private val displayManager = mock<DisplayManager>()

    private val fakeDisplayRepository = FakeDisplayRepository()
    private val requestProcessor = FakeRequestProcessor()
@@ -72,6 +74,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() {
        TakeScreenshotExecutorImpl(
            controllerFactory,
            fakeDisplayRepository,
            displayManager,
            testScope,
            requestProcessor,
            eventLogger,
@@ -728,6 +731,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() {

    private suspend fun TestScope.setDisplays(vararg displays: Display) {
        fakeDisplayRepository.emit(displays.toSet())
        displays.forEach { whenever(displayManager.getDisplay(it.displayId)).thenReturn(it) }
        runCurrent()
    }

+7 −5
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.screenshot

import android.hardware.display.DisplayManager
import android.net.Uri
import android.os.Trace
import android.util.Log
@@ -83,6 +84,7 @@ class TakeScreenshotExecutorImpl
constructor(
    private val interactiveScreenshotHandlerFactory: InteractiveScreenshotHandler.Factory,
    private val displayRepository: DisplayRepository,
    private val displayManager: DisplayManager,
    @Application private val mainScope: CoroutineScope,
    private val screenshotRequestProcessor: ScreenshotRequestProcessor,
    private val uiEventLogger: UiEventLogger,
@@ -213,23 +215,23 @@ constructor(
            // was shown, if available.
            ScreenshotSource.SCREENSHOT_OVERVIEW,
            ScreenshotSource.SCREENSHOT_SCREEN_CAPTURE_UI ->
                displayRepository.getDisplay(screenshotRequest.displayId)
                    ?: displayRepository.getDisplay(Display.DEFAULT_DISPLAY)
                displayManager.getDisplay(screenshotRequest.displayId)
                    ?: displayManager.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
            // display
            ScreenshotSource.SCREENSHOT_KEY_CHORD,
            ScreenshotSource.SCREENSHOT_VENDOR_GESTURE ->
                displayRepository.getDisplay(Display.DEFAULT_DISPLAY)
                displayManager.getDisplay(Display.DEFAULT_DISPLAY)
                    ?: error("Can't find default display")

            // All other invocations use the focused display
            else -> {
                val focusedDisplay = getFocusedDisplay()
                Log.i(TAG, "Focused display ID is $focusedDisplay")
                displayRepository.getDisplay(focusedDisplay)
                    ?: displayRepository.getDisplay(Display.DEFAULT_DISPLAY)
                displayManager.getDisplay(focusedDisplay)
                    ?: displayManager.getDisplay(Display.DEFAULT_DISPLAY)
                    ?: error("Can't find default display")
            }
        }