Loading packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotData.kt +16 −11 Original line number Diff line number Diff line Loading @@ -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 ?: "" Loading @@ -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, ) } Loading packages/SystemUI/tests/src/com/android/systemui/screenshot/DefaultScreenshotActionsProviderTest.kt +1 −7 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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() Loading packages/SystemUI/tests/src/com/android/systemui/screenshot/MessageContainerControllerTest.kt +3 −5 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -61,7 +61,7 @@ class MessageContainerControllerTest : SysuiTestCase() { workProfileMessageController, profileMessageController, screenshotDetectionController, TestScope(UnconfinedTestDispatcher()) TestScope(UnconfinedTestDispatcher()), ) screenshotView = ConstraintLayout(mContext) workProfileData = WorkProfileMessageController.WorkProfileFirstRunData(appName, icon) Loading @@ -83,8 +83,6 @@ class MessageContainerControllerTest : SysuiTestCase() { container.addView(detectionNoticeView) messageContainer.setView(screenshotView) screenshotData.userHandle = userHandle } @Test Loading @@ -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) Loading packages/SystemUI/tests/src/com/android/systemui/screenshot/ScreenshotDetectionControllerTest.kt +27 −23 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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()) Loading @@ -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" Loading @@ -95,7 +95,7 @@ class ScreenshotDetectionControllerTest { whenever( packageManager.getActivityInfo( eq(component), any(PackageManager.ComponentInfoFlags::class.java) any(PackageManager.ComponentInfoFlags::class.java), ) ) .thenReturn(activityInfo) Loading @@ -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") Loading @@ -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) Loading @@ -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() Loading @@ -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" Loading @@ -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)) Loading Loading
packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotData.kt +16 −11 Original line number Diff line number Diff line Loading @@ -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 ?: "" Loading @@ -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, ) } Loading
packages/SystemUI/tests/src/com/android/systemui/screenshot/DefaultScreenshotActionsProviderTest.kt +1 −7 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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() Loading
packages/SystemUI/tests/src/com/android/systemui/screenshot/MessageContainerControllerTest.kt +3 −5 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -61,7 +61,7 @@ class MessageContainerControllerTest : SysuiTestCase() { workProfileMessageController, profileMessageController, screenshotDetectionController, TestScope(UnconfinedTestDispatcher()) TestScope(UnconfinedTestDispatcher()), ) screenshotView = ConstraintLayout(mContext) workProfileData = WorkProfileMessageController.WorkProfileFirstRunData(appName, icon) Loading @@ -83,8 +83,6 @@ class MessageContainerControllerTest : SysuiTestCase() { container.addView(detectionNoticeView) messageContainer.setView(screenshotView) screenshotData.userHandle = userHandle } @Test Loading @@ -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) Loading
packages/SystemUI/tests/src/com/android/systemui/screenshot/ScreenshotDetectionControllerTest.kt +27 −23 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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()) Loading @@ -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" Loading @@ -95,7 +95,7 @@ class ScreenshotDetectionControllerTest { whenever( packageManager.getActivityInfo( eq(component), any(PackageManager.ComponentInfoFlags::class.java) any(PackageManager.ComponentInfoFlags::class.java), ) ) .thenReturn(activityInfo) Loading @@ -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") Loading @@ -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) Loading @@ -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() Loading @@ -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" Loading @@ -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)) Loading