Loading packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotExecutor.kt +3 −2 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ import android.view.WindowManager.TAKE_SCREENSHOT_PROVIDED_IMAGE import com.android.app.tracing.coroutines.launch import com.android.internal.logging.UiEventLogger import com.android.internal.util.ScreenshotRequest import com.android.systemui.Flags.screenshotShelfUi2 import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.display.data.repository.DisplayRepository Loading Loading @@ -123,8 +124,8 @@ constructor( private suspend fun getDisplaysToScreenshot(requestType: Int): List<Display> { val allDisplays = displays.first() return if (requestType == TAKE_SCREENSHOT_PROVIDED_IMAGE) { // If this is a provided image, let's show the UI on the default display only. return if (requestType == TAKE_SCREENSHOT_PROVIDED_IMAGE || screenshotShelfUi2()) { // If this is a provided image or using the shelf UI, just screenshot th default display allDisplays.filter { it.displayId == Display.DEFAULT_DISPLAY } } else { allDisplays.filter { it.type in ALLOWED_DISPLAY_TYPES } Loading packages/SystemUI/tests/src/com/android/systemui/screenshot/TakeScreenshotExecutorTest.kt +46 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,8 @@ package com.android.systemui.screenshot import android.content.ComponentName import android.graphics.Bitmap import android.net.Uri import android.platform.test.annotations.DisableFlags import android.platform.test.annotations.EnableFlags import android.testing.AndroidTestingRunner import android.view.Display import android.view.Display.TYPE_EXTERNAL Loading @@ -15,6 +17,7 @@ import android.view.WindowManager.TAKE_SCREENSHOT_PROVIDED_IMAGE import androidx.test.filters.SmallTest import com.android.internal.logging.testing.UiEventLoggerFake import com.android.internal.util.ScreenshotRequest import com.android.systemui.Flags import com.android.systemui.SysuiTestCase import com.android.systemui.display.data.repository.FakeDisplayRepository import com.android.systemui.display.data.repository.display Loading Loading @@ -77,6 +80,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_severalDisplays_callsControllerForEachOne() = testScope.runTest { val internalDisplay = display(TYPE_INTERNAL, id = 0) Loading Loading @@ -108,6 +112,32 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @EnableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_severalDisplaysShelfUi_justCallsOne() = testScope.runTest { val internalDisplay = display(TYPE_INTERNAL, id = 0) val externalDisplay = display(TYPE_EXTERNAL, id = 1) setDisplays(internalDisplay, externalDisplay) val onSaved = { _: Uri? -> } screenshotExecutor.executeScreenshots(createScreenshotRequest(), onSaved, callback) verify(controllerFactory).create(eq(internalDisplay), any()) val capturer = ArgumentCaptor<ScreenshotData>() verify(controller0).handleScreenshot(capturer.capture(), any(), any()) assertThat(capturer.value.displayId).isEqualTo(0) assertThat(eventLogger.numLogs()).isEqualTo(1) assertThat(eventLogger.get(0).eventId) .isEqualTo(ScreenshotEvent.SCREENSHOT_REQUESTED_KEY_OTHER.id) assertThat(eventLogger.get(0).packageName).isEqualTo(topComponent.packageName) screenshotExecutor.onDestroy() } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_providedImageType_callsOnlyDefaultDisplayController() = testScope.runTest { val internalDisplay = display(TYPE_INTERNAL, id = 0) Loading Loading @@ -139,6 +169,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_onlyVirtualDisplays_noInteractionsWithControllers() = testScope.runTest { setDisplays(display(TYPE_VIRTUAL, id = 0), display(TYPE_VIRTUAL, id = 1)) Loading @@ -150,6 +181,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_allowedTypes_allCaptured() = testScope.runTest { whenever(controllerFactory.create(any(), any())).thenReturn(controller0) Loading @@ -168,6 +200,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_reportsOnFinishedOnlyWhenBothFinished() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading @@ -193,6 +226,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_oneFinishesOtherFails_reportFailsOnlyAtTheEnd() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading Loading @@ -220,6 +254,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_allDisplaysFail_reportsFail() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading Loading @@ -247,6 +282,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun onDestroy_propagatedToControllers() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading @@ -259,6 +295,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun removeWindows_propagatedToControllers() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading @@ -273,6 +310,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun onCloseSystemDialogsReceived_propagatedToControllers() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading @@ -287,6 +325,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun onCloseSystemDialogsReceived_someControllerHavePendingTransitions() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading @@ -303,6 +342,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_controllerCalledWithRequestProcessorReturnValue() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0)) Loading @@ -324,6 +364,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_errorFromProcessor_logsScreenshotRequested() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading @@ -341,6 +382,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_errorFromProcessor_logsUiError() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading @@ -358,6 +400,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_errorFromProcessorOnDefaultDisplay_showsErrorNotification() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading @@ -384,6 +427,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_errorFromScreenshotController_reportsRequested() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading @@ -404,6 +448,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_errorFromScreenshotController_reportsError() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading @@ -424,6 +469,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_errorFromScreenshotController_showsErrorNotification() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading Loading
packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotExecutor.kt +3 −2 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ import android.view.WindowManager.TAKE_SCREENSHOT_PROVIDED_IMAGE import com.android.app.tracing.coroutines.launch import com.android.internal.logging.UiEventLogger import com.android.internal.util.ScreenshotRequest import com.android.systemui.Flags.screenshotShelfUi2 import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.display.data.repository.DisplayRepository Loading Loading @@ -123,8 +124,8 @@ constructor( private suspend fun getDisplaysToScreenshot(requestType: Int): List<Display> { val allDisplays = displays.first() return if (requestType == TAKE_SCREENSHOT_PROVIDED_IMAGE) { // If this is a provided image, let's show the UI on the default display only. return if (requestType == TAKE_SCREENSHOT_PROVIDED_IMAGE || screenshotShelfUi2()) { // If this is a provided image or using the shelf UI, just screenshot th default display allDisplays.filter { it.displayId == Display.DEFAULT_DISPLAY } } else { allDisplays.filter { it.type in ALLOWED_DISPLAY_TYPES } Loading
packages/SystemUI/tests/src/com/android/systemui/screenshot/TakeScreenshotExecutorTest.kt +46 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,8 @@ package com.android.systemui.screenshot import android.content.ComponentName import android.graphics.Bitmap import android.net.Uri import android.platform.test.annotations.DisableFlags import android.platform.test.annotations.EnableFlags import android.testing.AndroidTestingRunner import android.view.Display import android.view.Display.TYPE_EXTERNAL Loading @@ -15,6 +17,7 @@ import android.view.WindowManager.TAKE_SCREENSHOT_PROVIDED_IMAGE import androidx.test.filters.SmallTest import com.android.internal.logging.testing.UiEventLoggerFake import com.android.internal.util.ScreenshotRequest import com.android.systemui.Flags import com.android.systemui.SysuiTestCase import com.android.systemui.display.data.repository.FakeDisplayRepository import com.android.systemui.display.data.repository.display Loading Loading @@ -77,6 +80,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_severalDisplays_callsControllerForEachOne() = testScope.runTest { val internalDisplay = display(TYPE_INTERNAL, id = 0) Loading Loading @@ -108,6 +112,32 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @EnableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_severalDisplaysShelfUi_justCallsOne() = testScope.runTest { val internalDisplay = display(TYPE_INTERNAL, id = 0) val externalDisplay = display(TYPE_EXTERNAL, id = 1) setDisplays(internalDisplay, externalDisplay) val onSaved = { _: Uri? -> } screenshotExecutor.executeScreenshots(createScreenshotRequest(), onSaved, callback) verify(controllerFactory).create(eq(internalDisplay), any()) val capturer = ArgumentCaptor<ScreenshotData>() verify(controller0).handleScreenshot(capturer.capture(), any(), any()) assertThat(capturer.value.displayId).isEqualTo(0) assertThat(eventLogger.numLogs()).isEqualTo(1) assertThat(eventLogger.get(0).eventId) .isEqualTo(ScreenshotEvent.SCREENSHOT_REQUESTED_KEY_OTHER.id) assertThat(eventLogger.get(0).packageName).isEqualTo(topComponent.packageName) screenshotExecutor.onDestroy() } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_providedImageType_callsOnlyDefaultDisplayController() = testScope.runTest { val internalDisplay = display(TYPE_INTERNAL, id = 0) Loading Loading @@ -139,6 +169,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_onlyVirtualDisplays_noInteractionsWithControllers() = testScope.runTest { setDisplays(display(TYPE_VIRTUAL, id = 0), display(TYPE_VIRTUAL, id = 1)) Loading @@ -150,6 +181,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_allowedTypes_allCaptured() = testScope.runTest { whenever(controllerFactory.create(any(), any())).thenReturn(controller0) Loading @@ -168,6 +200,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_reportsOnFinishedOnlyWhenBothFinished() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading @@ -193,6 +226,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_oneFinishesOtherFails_reportFailsOnlyAtTheEnd() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading Loading @@ -220,6 +254,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_allDisplaysFail_reportsFail() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading Loading @@ -247,6 +282,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun onDestroy_propagatedToControllers() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading @@ -259,6 +295,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun removeWindows_propagatedToControllers() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading @@ -273,6 +310,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun onCloseSystemDialogsReceived_propagatedToControllers() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading @@ -287,6 +325,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun onCloseSystemDialogsReceived_someControllerHavePendingTransitions() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading @@ -303,6 +342,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_controllerCalledWithRequestProcessorReturnValue() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0)) Loading @@ -324,6 +364,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_errorFromProcessor_logsScreenshotRequested() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading @@ -341,6 +382,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_errorFromProcessor_logsUiError() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading @@ -358,6 +400,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_errorFromProcessorOnDefaultDisplay_showsErrorNotification() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading @@ -384,6 +427,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_errorFromScreenshotController_reportsRequested() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading @@ -404,6 +448,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_errorFromScreenshotController_reportsError() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading @@ -424,6 +469,7 @@ class TakeScreenshotExecutorTest : SysuiTestCase() { } @Test @DisableFlags(Flags.FLAG_SCREENSHOT_SHELF_UI2) fun executeScreenshots_errorFromScreenshotController_showsErrorNotification() = testScope.runTest { setDisplays(display(TYPE_INTERNAL, id = 0), display(TYPE_EXTERNAL, id = 1)) Loading