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

Commit 04c70296 authored by Matt Casey's avatar Matt Casey
Browse files

Propagate task ID for all screenshots when available.

Bug: 352818794
Test: atest PolicyRequestProcessorTest
Flag: EXEMPT simple bugfix
Change-Id: I0cde8c8f7363254793a088ed37d72463b778fe6d
parent 3f83d163
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 −15
Original line number Diff line number Diff line
@@ -16,13 +16,13 @@
package com.android.systemui.screenshot.policy

import android.content.ComponentName
import androidx.test.ext.junit.runners.AndroidJUnit4
import android.graphics.Insets
import android.graphics.Rect
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
@@ -40,8 +40,10 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
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
        }

@@ -49,11 +51,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,
@@ -61,24 +64,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
    }
}