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

Commit 49522a5b authored by Govinda Wasserman's avatar Govinda Wasserman
Browse files

Thumbnail capture AL fix

On AL devices, windows not currently visible cannot have a thumbnail
captured. This change causes thumbnail fetching to fall back to the
latest cached thumbnail in such cases.

Test: atest SystemUITests:com.android.systemui.screencapture
BUG: 39894067
Flag: com.android.systemui.large_screen_sharing
Change-Id: I833d171d4a286d070c08c376d57053c54d37ba45
parent c8db426a
Loading
Loading
Loading
Loading
+29 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ class ScreenCaptureThumbnailRepositoryImplTest : SysuiTestCase() {
        }

    @Test
    fun loadThumbnail_failsToTakeThumbnail_returnsNull() =
    fun loadThumbnail_failsToTakeThumbnail_fallsBackToCachedThumbnail() =
        kosmos.runTest {
            // Arrange
            val thumbnailRepository =
@@ -75,6 +75,33 @@ class ScreenCaptureThumbnailRepositoryImplTest : SysuiTestCase() {
                    activityManager =
                        activityManagerWrapper.stub {
                            on { takeTaskThumbnail(any()) } doReturn ThumbnailData(thumbnail = null)
                            on { getTaskThumbnail(any(), any()) } doReturn
                                ThumbnailData(thumbnail = fakeThumbnail)
                        },
                )

            // Act
            val result = thumbnailRepository.loadThumbnail(123)

            // Assert
            verify(activityManagerWrapper).takeTaskThumbnail(eq(123))
            verify(activityManagerWrapper).getTaskThumbnail(eq(123), eq(false))
            assertThat(result.isSuccess).isTrue()
            assertThat(result.getOrNull()?.sameAs(fakeThumbnail)).isTrue()
        }

    @Test
    fun loadThumbnail_failsToTakeThumbnailAndNoCache_returnsFailure() =
        kosmos.runTest {
            // Arrange
            val thumbnailRepository =
                ScreenCaptureThumbnailRepositoryImpl(
                    bgContext = testDispatcher,
                    activityManager =
                        activityManagerWrapper.stub {
                            on { takeTaskThumbnail(any()) } doReturn ThumbnailData(thumbnail = null)
                            on { getTaskThumbnail(any(), any()) } doReturn
                                ThumbnailData(thumbnail = null)
                        },
                )

@@ -83,6 +110,7 @@ class ScreenCaptureThumbnailRepositoryImplTest : SysuiTestCase() {

            // Assert
            verify(activityManagerWrapper).takeTaskThumbnail(eq(123))
            verify(activityManagerWrapper).getTaskThumbnail(eq(123), eq(false))
            assertThat(result.isFailure).isTrue()
        }
}
+10 −2
Original line number Diff line number Diff line
@@ -30,7 +30,11 @@ interface ScreenCaptureThumbnailRepository {
    suspend fun loadThumbnail(taskId: Int): Result<Bitmap>
}

/** Default implementation of [ScreenCaptureThumbnailRepository]. */
/**
 * Default implementation of [ScreenCaptureThumbnailRepository].
 *
 * Captures new thumbnail on request, falls back to cached thumbnail if capture fails.
 */
@ScreenCaptureUiScope
class ScreenCaptureThumbnailRepositoryImpl
@Inject
@@ -41,7 +45,11 @@ constructor(

    override suspend fun loadThumbnail(taskId: Int): Result<Bitmap> =
        withContext(bgContext) {
            activityManager.takeTaskThumbnail(taskId).thumbnail?.let { Result.success(it) }
            getLatestThumbnail(taskId)?.let { Result.success(it) }
                ?: Result.failure(IllegalStateException("Could not get thumbnail for task $taskId"))
        }

    private fun getLatestThumbnail(taskId: Int): Bitmap? =
        activityManager.takeTaskThumbnail(taskId).thumbnail
            ?: activityManager.getTaskThumbnail(taskId, false).thumbnail
}