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

Commit 0cc0152b authored by Matt Casey's avatar Matt Casey Committed by Android Build Coastguard Worker
Browse files

Propagate task ID for all screenshots when available.

Bug: 352818794
Test: atest PolicyRequestProcessorTest
Flag: EXEMPT simple bugfix
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:04c70296eae4659ae8d8ef024a74ea3f943e47d1)
Merged-In: I0cde8c8f7363254793a088ed37d72463b778fe6d
Change-Id: I0cde8c8f7363254793a088ed37d72463b778fe6d
parent 0b951d2e
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -99,7 +99,7 @@ class PolicyRequestProcessor(
                        original,
                        updates.component,
                        updates.owner,
                        type.displayId
                        type.displayId,
                    )
            }
        return updated
@@ -120,6 +120,7 @@ class PolicyRequestProcessor(
        return replaceWithScreenshot(
            original = original,
            componentName = topMainRootTask?.topActivity ?: defaultComponent,
            taskId = topMainRootTask?.taskId,
            owner = defaultOwner,
            displayId = original.displayId
        )
@@ -144,11 +145,12 @@ class PolicyRequestProcessor(
        )
    }

    suspend fun replaceWithScreenshot(
    private suspend fun replaceWithScreenshot(
        original: ScreenshotData,
        componentName: ComponentName?,
        owner: UserHandle?,
        displayId: Int,
        taskId: Int? = null,
    ): ScreenshotData {
        Log.i(TAG, "Capturing screenshot: $componentName / $owner")
        val screenshot = captureDisplay(displayId)
@@ -157,7 +159,8 @@ class PolicyRequestProcessor(
            bitmap = screenshot,
            userHandle = owner,
            topComponent = componentName,
            screenBounds = Rect(0, 0, screenshot?.width ?: 0, screenshot?.height ?: 0)
            screenBounds = Rect(0, 0, screenshot?.width ?: 0, screenshot?.height ?: 0),
            taskId = taskId ?: -1,
        )
    }

+28 −14
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.UserHandle
import android.view.Display.DEFAULT_DISPLAY
import android.view.WindowManager.ScreenshotSource.SCREENSHOT_KEY_CHORD
import android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.systemui.screenshot.ImageCapture
import com.android.systemui.screenshot.ScreenshotData
import com.android.systemui.screenshot.data.model.DisplayContentScenarios.ActivityNames.FILES
@@ -37,8 +38,10 @@ import org.junit.Test

class PolicyRequestProcessorTest {

    val imageCapture = object : ImageCapture {
    val imageCapture =
        object : ImageCapture {
            override fun captureDisplay(displayId: Int, crop: Rect?) = null

            override suspend fun captureTask(taskId: Int) = null
        }

@@ -46,11 +49,12 @@ class PolicyRequestProcessorTest {
    @Test
    fun testProcess_defaultOwner_whenNoPolicyApplied() {
        val fullScreenWork = DisplayContentRepository {
            singleFullScreen(TaskSpec(taskId = 1001, name = FILES, userId = WORK))
            singleFullScreen(TaskSpec(taskId = TASK_ID, name = FILES, userId = WORK))
        }

        val request =
            ScreenshotData(TAKE_SCREENSHOT_FULLSCREEN,
            ScreenshotData(
                TAKE_SCREENSHOT_FULLSCREEN,
                SCREENSHOT_KEY_CHORD,
                null,
                topComponent = null,
@@ -58,24 +62,34 @@ class PolicyRequestProcessorTest {
                taskId = -1,
                insets = Insets.NONE,
                bitmap = null,
                displayId = DEFAULT_DISPLAY)
                displayId = DEFAULT_DISPLAY
            )

        /* Create a policy request processor with no capture policies */
        val requestProcessor =
            PolicyRequestProcessor(Dispatchers.Unconfined,
            PolicyRequestProcessor(
                Dispatchers.Unconfined,
                imageCapture,
                policies = emptyList(),
                defaultOwner = UserHandle.of(PERSONAL),
                defaultComponent = ComponentName("default", "Component"),
                displayTasks = fullScreenWork)
                displayTasks = fullScreenWork
            )

        val result = runBlocking { requestProcessor.process(request) }

        assertWithMessage(
            "With no policy, the screenshot should be assigned to the default user"
        ).that(result.userHandle).isEqualTo(UserHandle.of(PERSONAL))
        assertWithMessage("With no policy, the screenshot should be assigned to the default user")
            .that(result.userHandle)
            .isEqualTo(UserHandle.of(PERSONAL))

        assertWithMessage("The topComponent of the screenshot").that(result.topComponent)
        assertWithMessage("The topComponent of the screenshot")
            .that(result.topComponent)
            .isEqualTo(ComponentName.unflattenFromString(FILES))

        assertWithMessage("Task ID").that(result.taskId).isEqualTo(TASK_ID)
    }

    companion object {
        const val TASK_ID = 1001
    }
}
 No newline at end of file