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

Commit e2f665b7 authored by Matt Casey's avatar Matt Casey Committed by Android (Google) Code Review
Browse files

Merge "Convert a bunch of ScreenshotData's unmodified vars to vals." into main

parents 4df27d7d f8c8f758
Loading
Loading
Loading
Loading
+16 −11
Original line number Diff line number Diff line
@@ -15,17 +15,17 @@ import com.android.internal.util.ScreenshotRequest

/** [ScreenshotData] represents the current state of a single screenshot being acquired. */
data class ScreenshotData(
    @ScreenshotType var type: Int,
    @ScreenshotSource var source: Int,
    @ScreenshotType val type: Int,
    @ScreenshotSource val source: Int,
    /** UserHandle for the owner of the app being screenshotted, if known. */
    var userHandle: UserHandle?,
    val userHandle: UserHandle?,
    /** ComponentName of the top-most app in the screenshot. */
    var topComponent: ComponentName?,
    val topComponent: ComponentName?,
    var screenBounds: Rect?,
    var taskId: Int,
    val taskId: Int,
    var insets: Insets,
    var bitmap: Bitmap?,
    var displayId: Int,
    val displayId: Int,
) {
    val packageNameString
        get() = topComponent?.packageName ?: ""
@@ -50,16 +50,21 @@ data class ScreenshotData(
            )

        @VisibleForTesting
        fun forTesting() =
        fun forTesting(
            userHandle: UserHandle? = null,
            source: Int = ScreenshotSource.SCREENSHOT_KEY_CHORD,
            topComponent: ComponentName? = null,
            bitmap: Bitmap? = null,
        ) =
            ScreenshotData(
                type = WindowManager.TAKE_SCREENSHOT_FULLSCREEN,
                source = ScreenshotSource.SCREENSHOT_KEY_CHORD,
                userHandle = null,
                topComponent = null,
                source = source,
                userHandle = userHandle,
                topComponent = topComponent,
                screenBounds = null,
                taskId = 0,
                insets = Insets.NONE,
                bitmap = null,
                bitmap = bitmap,
                displayId = Display.DEFAULT_DISPLAY,
            )
    }
+1 −7
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import com.google.common.truth.Truth.assertThat
import java.util.UUID
import kotlin.test.Test
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.runner.RunWith
import org.mockito.Mockito.verifyNoMoreInteractions
import org.mockito.kotlin.any
@@ -47,16 +46,11 @@ class DefaultScreenshotActionsProviderTest : SysuiTestCase() {
    private val uiEventLogger = mock<UiEventLogger>()
    private val actionsCallback = mock<ScreenshotActionsController.ActionsCallback>()

    private val request = ScreenshotData.forTesting()
    private val request = ScreenshotData.forTesting(userHandle = UserHandle.OWNER)
    private val validResult = ScreenshotSavedResult(Uri.EMPTY, Process.myUserHandle(), 0)

    private lateinit var actionsProvider: ScreenshotActionsProvider

    @Before
    fun setUp() {
        request.userHandle = UserHandle.OWNER
    }

    @Test
    fun previewActionAccessed_beforeScreenshotCompleted_doesNothing() {
        actionsProvider = createActionsProvider()
+3 −5
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ class MessageContainerControllerTest : SysuiTestCase() {
    lateinit var screenshotView: ViewGroup

    val userHandle = UserHandle.of(5)
    val screenshotData = ScreenshotData.forTesting()
    val screenshotData = ScreenshotData.forTesting(userHandle = userHandle)

    val appName = "app name"
    lateinit var workProfileData: WorkProfileMessageController.WorkProfileFirstRunData
@@ -61,7 +61,7 @@ class MessageContainerControllerTest : SysuiTestCase() {
                workProfileMessageController,
                profileMessageController,
                screenshotDetectionController,
                TestScope(UnconfinedTestDispatcher())
                TestScope(UnconfinedTestDispatcher()),
            )
        screenshotView = ConstraintLayout(mContext)
        workProfileData = WorkProfileMessageController.WorkProfileFirstRunData(appName, icon)
@@ -83,8 +83,6 @@ class MessageContainerControllerTest : SysuiTestCase() {
        container.addView(detectionNoticeView)

        messageContainer.setView(screenshotView)

        screenshotData.userHandle = userHandle
    }

    @Test
@@ -92,7 +90,7 @@ class MessageContainerControllerTest : SysuiTestCase() {
        val profileData =
            ProfileMessageController.ProfileFirstRunData(
                LabeledIcon(appName, icon),
                ProfileMessageController.FirstRunProfile.PRIVATE
                ProfileMessageController.FirstRunProfile.PRIVATE,
            )
        whenever(profileMessageController.onScreenshotTaken(eq(userHandle))).thenReturn(profileData)
        messageContainer.onScreenshotTaken(screenshotData)
+27 −23
Original line number Diff line number Diff line
@@ -61,8 +61,8 @@ class ScreenshotDetectionControllerTest {

    @Test
    fun testMaybeNotifyOfScreenshot_ignoresOverview() {
        val data = ScreenshotData.forTesting()
        data.source = WindowManager.ScreenshotSource.SCREENSHOT_OVERVIEW
        val data =
            ScreenshotData.forTesting(source = WindowManager.ScreenshotSource.SCREENSHOT_OVERVIEW)

        val list = controller.maybeNotifyOfScreenshot(data)

@@ -72,8 +72,8 @@ class ScreenshotDetectionControllerTest {

    @Test
    fun testMaybeNotifyOfScreenshot_emptySet() {
        val data = ScreenshotData.forTesting()
        data.source = WindowManager.ScreenshotSource.SCREENSHOT_KEY_CHORD
        val data =
            ScreenshotData.forTesting(source = WindowManager.ScreenshotSource.SCREENSHOT_KEY_CHORD)

        whenever(windowManager.notifyScreenshotListeners(eq(Display.DEFAULT_DISPLAY)))
            .thenReturn(listOf())
@@ -85,8 +85,8 @@ class ScreenshotDetectionControllerTest {

    @Test
    fun testMaybeNotifyOfScreenshot_oneApp() {
        val data = ScreenshotData.forTesting()
        data.source = WindowManager.ScreenshotSource.SCREENSHOT_KEY_CHORD
        val data =
            ScreenshotData.forTesting(source = WindowManager.ScreenshotSource.SCREENSHOT_KEY_CHORD)

        val component = ComponentName("package1", "class1")
        val appName = "app name"
@@ -95,7 +95,7 @@ class ScreenshotDetectionControllerTest {
        whenever(
                packageManager.getActivityInfo(
                    eq(component),
                    any(PackageManager.ComponentInfoFlags::class.java)
                    any(PackageManager.ComponentInfoFlags::class.java),
                )
            )
            .thenReturn(activityInfo)
@@ -112,8 +112,8 @@ class ScreenshotDetectionControllerTest {

    @Test
    fun testMaybeNotifyOfScreenshot_multipleApps() {
        val data = ScreenshotData.forTesting()
        data.source = WindowManager.ScreenshotSource.SCREENSHOT_KEY_CHORD
        val data =
            ScreenshotData.forTesting(source = WindowManager.ScreenshotSource.SCREENSHOT_KEY_CHORD)

        val component1 = ComponentName("package1", "class1")
        val component2 = ComponentName("package2", "class2")
@@ -129,21 +129,21 @@ class ScreenshotDetectionControllerTest {
        whenever(
                packageManager.getActivityInfo(
                    eq(component1),
                    any(PackageManager.ComponentInfoFlags::class.java)
                    any(PackageManager.ComponentInfoFlags::class.java),
                )
            )
            .thenReturn(activityInfo1)
        whenever(
                packageManager.getActivityInfo(
                    eq(component2),
                    any(PackageManager.ComponentInfoFlags::class.java)
                    any(PackageManager.ComponentInfoFlags::class.java),
                )
            )
            .thenReturn(activityInfo2)
        whenever(
                packageManager.getActivityInfo(
                    eq(component3),
                    any(PackageManager.ComponentInfoFlags::class.java)
                    any(PackageManager.ComponentInfoFlags::class.java),
                )
            )
            .thenReturn(activityInfo3)
@@ -165,11 +165,13 @@ class ScreenshotDetectionControllerTest {

    private fun includesFlagBits(@PackageManager.ComponentInfoFlagsBits mask: Int) =
        ComponentInfoFlagMatcher(mask, mask)

    private fun excludesFlagBits(@PackageManager.ComponentInfoFlagsBits mask: Int) =
        ComponentInfoFlagMatcher(mask, 0)

    private class ComponentInfoFlagMatcher(
        @PackageManager.ComponentInfoFlagsBits val mask: Int, val value: Int
        @PackageManager.ComponentInfoFlagsBits val mask: Int,
        val value: Int,
    ) : ArgumentMatcher<PackageManager.ComponentInfoFlags> {
        override fun matches(flags: PackageManager.ComponentInfoFlags?): Boolean {
            return flags != null && (mask.toLong() and flags.value) == value.toLong()
@@ -182,8 +184,8 @@ class ScreenshotDetectionControllerTest {

    @Test
    fun testMaybeNotifyOfScreenshot_disabledApp() {
        val data = ScreenshotData.forTesting()
        data.source = WindowManager.ScreenshotSource.SCREENSHOT_KEY_CHORD
        val data =
            ScreenshotData.forTesting(source = WindowManager.ScreenshotSource.SCREENSHOT_KEY_CHORD)

        val component = ComponentName("package1", "class1")
        val appName = "app name"
@@ -192,16 +194,18 @@ class ScreenshotDetectionControllerTest {
        whenever(
                packageManager.getActivityInfo(
                    eq(component),
                argThat(includesFlagBits(MATCH_DISABLED_COMPONENTS or MATCH_ANY_USER))
                    argThat(includesFlagBits(MATCH_DISABLED_COMPONENTS or MATCH_ANY_USER)),
                )
            )
        ).thenReturn(activityInfo)
            .thenReturn(activityInfo)

        whenever(
                packageManager.getActivityInfo(
                    eq(component),
                argThat(excludesFlagBits(MATCH_DISABLED_COMPONENTS))
                    argThat(excludesFlagBits(MATCH_DISABLED_COMPONENTS)),
                )
            )
        ).thenThrow(PackageManager.NameNotFoundException::class.java)
            .thenThrow(PackageManager.NameNotFoundException::class.java)

        whenever(windowManager.notifyScreenshotListeners(eq(Display.DEFAULT_DISPLAY)))
            .thenReturn(listOf(component))