Loading packages/SystemUI/src/com/android/systemui/screencapture/record/largescreen/domain/interactor/ScreenshotInteractor.kt +4 −4 Original line number Diff line number Diff line Loading @@ -34,13 +34,13 @@ import kotlinx.coroutines.withContext class ScreenshotInteractor @Inject constructor( @Background private val backgroundContext: CoroutineContext, @Background private val backgroundHandler: Handler, private val imageCapture: ImageCapture, private val screenshotHelper: ScreenshotHelper, @Background private val backgroundContext: CoroutineContext, @Background private val backgroundHandler: Handler, private val userRepository: UserRepository, ) { suspend fun requestFullscreenScreenshot(displayId: Int) { suspend fun takeFullscreenScreenshot(displayId: Int) { val request = ScreenshotRequest.Builder( WindowManager.TAKE_SCREENSHOT_FULLSCREEN, Loading @@ -52,7 +52,7 @@ constructor( takeScreenshot(request) } suspend fun requestPartialScreenshot(regionBounds: Rect, displayId: Int) { suspend fun takePartialScreenshot(regionBounds: Rect, displayId: Int) { val bitmap = withContext(backgroundContext) { requireNotNull(imageCapture.captureDisplay(displayId, regionBounds)) Loading packages/SystemUI/src/com/android/systemui/screencapture/record/largescreen/ui/viewmodel/PreCaptureViewModel.kt +13 −14 Original line number Diff line number Diff line Loading @@ -32,7 +32,6 @@ import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.launch Loading Loading @@ -127,32 +126,32 @@ constructor( private fun takeScreenshot() { when (captureRegionSource.value) { ScreenCaptureRegion.FULLSCREEN -> beginFullscreenScreenshot() ScreenCaptureRegion.PARTIAL -> beginPartialScreenshot() ScreenCaptureRegion.FULLSCREEN -> takeFullscreenScreenshot() ScreenCaptureRegion.PARTIAL -> takePartialScreenshot() ScreenCaptureRegion.APP_WINDOW -> {} } } private fun beginFullscreenScreenshot() { // Hide the UI to avoid the parent window closing animation. private fun takeFullscreenScreenshot() { // Finishing the activity is not guaranteed to complete before the screenshot is taken. // Since the pre-capture UI should not be included in the screenshot, hide the UI first. hideUi() backgroundScope.launch { screenshotInteractor.requestFullscreenScreenshot(displayId) } closeUi() backgroundScope.launch { screenshotInteractor.takeFullscreenScreenshot(displayId) } } private fun beginPartialScreenshot() { private fun takePartialScreenshot() { val regionBoxRect = requireNotNull(regionBoxSource.value) // Hide the UI to avoid the parent window closing animation. // Finishing the activity is not guaranteed to complete before the screenshot is taken. // Since the pre-capture UI should not be included in the screenshot, hide the UI first. hideUi() closeUi() backgroundScope.launch { // Temporary fix to allow enough time for the pre-capture UI to dismiss. // TODO(b/435225255) Implement a more reliable way to ensure the UI is hidden prior to // taking the screenshot. delay(100) screenshotInteractor.requestPartialScreenshot(regionBoxRect, displayId) screenshotInteractor.takePartialScreenshot(regionBoxRect, displayId) } closeUi() } /** Loading packages/SystemUI/tests/src/com/android/systemui/screencapture/record/largescreen/domain/interactor/ScreenshotInteractorTest.kt +4 −4 Original line number Diff line number Diff line Loading @@ -61,10 +61,10 @@ class ScreenshotInteractorTest : SysuiTestCase() { } @Test fun requestFullscreenScreenshot_callsScreenshotHelper_withCorrectRequest() { fun takeFullscreenScreenshot_callsScreenshotHelper_withCorrectRequest() { testScope.runTest { val displayId = 3 interactor.requestFullscreenScreenshot(displayId) interactor.takeFullscreenScreenshot(displayId) val screenshotRequestCaptor = argumentCaptor<ScreenshotRequest>() verify(kosmos.mockScreenshotHelper, times(1)) Loading @@ -79,7 +79,7 @@ class ScreenshotInteractorTest : SysuiTestCase() { } @Test fun requestPartialScreenshot_callsScreenshotHelper_withCorrectRequest() { fun takePartialScreenshot_callsScreenshotHelper_withCorrectRequest() { testScope.runTest { val bounds = Rect(0, 0, 100, 100) val displayId = 3 Loading @@ -91,7 +91,7 @@ class ScreenshotInteractorTest : SysuiTestCase() { kosmos.fakeUserRepository.setUserInfos(listOf(mainUser, secondaryUser)) kosmos.fakeUserRepository.setSelectedUserInfo(secondaryUser) interactor.requestPartialScreenshot(bounds, displayId) interactor.takePartialScreenshot(bounds, displayId) val screenshotRequestCaptor = argumentCaptor<ScreenshotRequest>() verify(kosmos.mockImageCapture, times(1)).captureDisplay(any(), eq(bounds)) Loading Loading
packages/SystemUI/src/com/android/systemui/screencapture/record/largescreen/domain/interactor/ScreenshotInteractor.kt +4 −4 Original line number Diff line number Diff line Loading @@ -34,13 +34,13 @@ import kotlinx.coroutines.withContext class ScreenshotInteractor @Inject constructor( @Background private val backgroundContext: CoroutineContext, @Background private val backgroundHandler: Handler, private val imageCapture: ImageCapture, private val screenshotHelper: ScreenshotHelper, @Background private val backgroundContext: CoroutineContext, @Background private val backgroundHandler: Handler, private val userRepository: UserRepository, ) { suspend fun requestFullscreenScreenshot(displayId: Int) { suspend fun takeFullscreenScreenshot(displayId: Int) { val request = ScreenshotRequest.Builder( WindowManager.TAKE_SCREENSHOT_FULLSCREEN, Loading @@ -52,7 +52,7 @@ constructor( takeScreenshot(request) } suspend fun requestPartialScreenshot(regionBounds: Rect, displayId: Int) { suspend fun takePartialScreenshot(regionBounds: Rect, displayId: Int) { val bitmap = withContext(backgroundContext) { requireNotNull(imageCapture.captureDisplay(displayId, regionBounds)) Loading
packages/SystemUI/src/com/android/systemui/screencapture/record/largescreen/ui/viewmodel/PreCaptureViewModel.kt +13 −14 Original line number Diff line number Diff line Loading @@ -32,7 +32,6 @@ import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.launch Loading Loading @@ -127,32 +126,32 @@ constructor( private fun takeScreenshot() { when (captureRegionSource.value) { ScreenCaptureRegion.FULLSCREEN -> beginFullscreenScreenshot() ScreenCaptureRegion.PARTIAL -> beginPartialScreenshot() ScreenCaptureRegion.FULLSCREEN -> takeFullscreenScreenshot() ScreenCaptureRegion.PARTIAL -> takePartialScreenshot() ScreenCaptureRegion.APP_WINDOW -> {} } } private fun beginFullscreenScreenshot() { // Hide the UI to avoid the parent window closing animation. private fun takeFullscreenScreenshot() { // Finishing the activity is not guaranteed to complete before the screenshot is taken. // Since the pre-capture UI should not be included in the screenshot, hide the UI first. hideUi() backgroundScope.launch { screenshotInteractor.requestFullscreenScreenshot(displayId) } closeUi() backgroundScope.launch { screenshotInteractor.takeFullscreenScreenshot(displayId) } } private fun beginPartialScreenshot() { private fun takePartialScreenshot() { val regionBoxRect = requireNotNull(regionBoxSource.value) // Hide the UI to avoid the parent window closing animation. // Finishing the activity is not guaranteed to complete before the screenshot is taken. // Since the pre-capture UI should not be included in the screenshot, hide the UI first. hideUi() closeUi() backgroundScope.launch { // Temporary fix to allow enough time for the pre-capture UI to dismiss. // TODO(b/435225255) Implement a more reliable way to ensure the UI is hidden prior to // taking the screenshot. delay(100) screenshotInteractor.requestPartialScreenshot(regionBoxRect, displayId) screenshotInteractor.takePartialScreenshot(regionBoxRect, displayId) } closeUi() } /** Loading
packages/SystemUI/tests/src/com/android/systemui/screencapture/record/largescreen/domain/interactor/ScreenshotInteractorTest.kt +4 −4 Original line number Diff line number Diff line Loading @@ -61,10 +61,10 @@ class ScreenshotInteractorTest : SysuiTestCase() { } @Test fun requestFullscreenScreenshot_callsScreenshotHelper_withCorrectRequest() { fun takeFullscreenScreenshot_callsScreenshotHelper_withCorrectRequest() { testScope.runTest { val displayId = 3 interactor.requestFullscreenScreenshot(displayId) interactor.takeFullscreenScreenshot(displayId) val screenshotRequestCaptor = argumentCaptor<ScreenshotRequest>() verify(kosmos.mockScreenshotHelper, times(1)) Loading @@ -79,7 +79,7 @@ class ScreenshotInteractorTest : SysuiTestCase() { } @Test fun requestPartialScreenshot_callsScreenshotHelper_withCorrectRequest() { fun takePartialScreenshot_callsScreenshotHelper_withCorrectRequest() { testScope.runTest { val bounds = Rect(0, 0, 100, 100) val displayId = 3 Loading @@ -91,7 +91,7 @@ class ScreenshotInteractorTest : SysuiTestCase() { kosmos.fakeUserRepository.setUserInfos(listOf(mainUser, secondaryUser)) kosmos.fakeUserRepository.setSelectedUserInfo(secondaryUser) interactor.requestPartialScreenshot(bounds, displayId) interactor.takePartialScreenshot(bounds, displayId) val screenshotRequestCaptor = argumentCaptor<ScreenshotRequest>() verify(kosmos.mockImageCapture, times(1)).captureDisplay(any(), eq(bounds)) Loading