Loading services/tests/mockingservicestests/src/com/android/server/SensitiveContentProtectionManagerServiceNotificationTest.java +69 −57 Original line number Diff line number Diff line Loading @@ -25,7 +25,6 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; Loading @@ -34,6 +33,7 @@ import static org.mockito.Mockito.when; import android.content.pm.PackageManagerInternal; import android.media.projection.MediaProjectionInfo; import android.media.projection.MediaProjectionManager; import android.os.Process; import android.platform.test.annotations.RequiresFlagsEnabled; import android.platform.test.flag.junit.CheckFlagsRule; import android.platform.test.flag.junit.DeviceFlagsValueProvider; Loading Loading @@ -79,7 +79,8 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { private static final String NOTIFICATION_PKG_1 = "com.android.server.notification.one"; private static final String NOTIFICATION_PKG_2 = "com.android.server.notification.two"; private static final String EXEMPTED_SCREEN_RECORDER_PACKAGE = "test.screen.recorder.package"; private static final String SCREEN_RECORDER_PACKAGE = "test.screen.recorder.package"; private static final String EXEMPTED_SCREEN_RECORDER_PACKAGE = "exempt.screen.recorder.package"; private static final int NOTIFICATION_UID_1 = 5; private static final int NOTIFICATION_UID_2 = 6; Loading Loading @@ -281,10 +282,18 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { .getActiveNotifications(); } private MediaProjectionInfo createMediaProjectionInfo() { return new MediaProjectionInfo(SCREEN_RECORDER_PACKAGE, Process.myUserHandle(), null); } private MediaProjectionInfo createExemptMediaProjectionInfo() { return new MediaProjectionInfo( EXEMPTED_SCREEN_RECORDER_PACKAGE, Process.myUserHandle(), null); } @Test public void mediaProjectionOnStart_verifyExemptedRecorderPackage() { MediaProjectionInfo mediaProjectionInfo = mock(MediaProjectionInfo.class); when(mediaProjectionInfo.getPackageName()).thenReturn(EXEMPTED_SCREEN_RECORDER_PACKAGE); MediaProjectionInfo mediaProjectionInfo = createExemptMediaProjectionInfo(); mMediaProjectionCallbackCaptor.getValue().onStart(mediaProjectionInfo); Loading @@ -295,7 +304,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { public void mediaProjectionOnStart_onProjectionStart_setWmBlockedPackages() { ArraySet<PackageInfo> expectedBlockedPackages = setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); verify(mWindowManager).addBlockScreenCaptureForApps(expectedBlockedPackages); } Loading @@ -304,18 +313,18 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { public void mediaProjectionOnStart_noSensitiveNotifications_noBlockedPackages() { setupNoSensitiveNotifications(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test public void mediaProjectionOnStart_noNotifications_noBlockedPackages() { setupNoNotifications(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -323,7 +332,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { ArraySet<PackageInfo> expectedBlockedPackages = setupMultipleSensitiveNotificationsFromSamePackageAndUid(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); verify(mWindowManager).addBlockScreenCaptureForApps(expectedBlockedPackages); } Loading @@ -333,7 +342,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { ArraySet<PackageInfo> expectedBlockedPackages = setupMultipleSensitiveNotificationsFromDifferentPackage(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); verify(mWindowManager).addBlockScreenCaptureForApps(expectedBlockedPackages); } Loading @@ -343,7 +352,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { ArraySet<PackageInfo> expectedBlockedPackages = setupMultipleSensitiveNotificationsFromDifferentUid(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); verify(mWindowManager).addBlockScreenCaptureForApps(expectedBlockedPackages); } Loading @@ -352,7 +361,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { public void mediaProjectionOnStop_onProjectionEnd_clearWmBlockedPackages() { setupSensitiveNotification(); MediaProjectionInfo mediaProjectionInfo = mock(MediaProjectionInfo.class); MediaProjectionInfo mediaProjectionInfo = createMediaProjectionInfo(); mMediaProjectionCallbackCaptor.getValue().onStart(mediaProjectionInfo); Mockito.reset(mWindowManager); Loading @@ -365,7 +374,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { public void mediaProjectionOnStart_afterOnStop_onProjectionStart_setWmBlockedPackages() { ArraySet<PackageInfo> expectedBlockedPackages = setupSensitiveNotification(); MediaProjectionInfo mediaProjectionInfo = mock(MediaProjectionInfo.class); MediaProjectionInfo mediaProjectionInfo = createMediaProjectionInfo(); mMediaProjectionCallbackCaptor.getValue().onStart(mediaProjectionInfo); mMediaProjectionCallbackCaptor.getValue().onStop(mediaProjectionInfo); Mockito.reset(mWindowManager); Loading @@ -381,9 +390,9 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { .when(mSensitiveContentProtectionManagerService.mNotificationListener) .getActiveNotifications(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -392,9 +401,9 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { .when(mSensitiveContentProtectionManagerService.mNotificationListener) .getCurrentRanking(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -403,9 +412,9 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { .when(mSensitiveContentProtectionManagerService.mNotificationListener) .getCurrentRanking(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -416,9 +425,9 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { .when(mSensitiveContentProtectionManagerService.mNotificationListener) .getCurrentRanking(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -426,7 +435,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { mockDisabledViaDevelopOption(); setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); verifyZeroInteractions(mWindowManager); } Loading @@ -447,8 +456,9 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStop(mock(MediaProjectionInfo.class)); MediaProjectionInfo mediaProjectionInfo = createMediaProjectionInfo(); mMediaProjectionCallbackCaptor.getValue().onStart(mediaProjectionInfo); mMediaProjectionCallbackCaptor.getValue().onStop(mediaProjectionInfo); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener.onListenerConnected(); Loading @@ -461,7 +471,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive ArraySet<PackageInfo> expectedBlockedPackages = setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener.onListenerConnected(); Loading @@ -472,23 +482,23 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { @Test public void nlsOnListenerConnected_noSensitiveNotifications_noBlockedPackages() { setupNoSensitiveNotifications(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener.onListenerConnected(); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test public void nlsOnListenerConnected_noNotifications_noBlockedPackages() { setupNoNotifications(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener.onListenerConnected(); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -496,7 +506,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); doReturn(null) .when(mSensitiveContentProtectionManagerService.mNotificationListener) Loading @@ -504,7 +514,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { mSensitiveContentProtectionManagerService.mNotificationListener.onListenerConnected(); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -512,7 +522,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); when(mRankingMap.getRawRankingObject(eq(NOTIFICATION_KEY_1))).thenReturn(null); doReturn(mRankingMap) Loading @@ -521,7 +531,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { mSensitiveContentProtectionManagerService.mNotificationListener.onListenerConnected(); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -530,7 +540,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); mSensitiveContentProtectionManagerService.mNotificationListener.onListenerConnected(); verifyZeroInteractions(mWindowManager); Loading @@ -553,8 +563,9 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStop(mock(MediaProjectionInfo.class)); MediaProjectionInfo mediaProjectionInfo = createMediaProjectionInfo(); mMediaProjectionCallbackCaptor.getValue().onStart(mediaProjectionInfo); mMediaProjectionCallbackCaptor.getValue().onStop(mediaProjectionInfo); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener Loading @@ -568,7 +579,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive ArraySet<PackageInfo> expectedBlockedPackages = setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener Loading @@ -580,25 +591,25 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { @Test public void nlsOnNotificationRankingUpdate_noSensitiveNotifications_noBlockedPackages() { setupNoSensitiveNotifications(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener .onNotificationRankingUpdate(mRankingMap); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test public void nlsOnNotificationRankingUpdate_noNotifications_noBlockedPackages() { setupNoNotifications(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener .onNotificationRankingUpdate(mRankingMap); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -606,13 +617,13 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener .onNotificationRankingUpdate(null); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -620,7 +631,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); when(mRankingMap.getRawRankingObject(eq(NOTIFICATION_KEY_1))).thenReturn(null); doReturn(mRankingMap) Loading @@ -630,7 +641,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { mSensitiveContentProtectionManagerService.mNotificationListener .onNotificationRankingUpdate(mRankingMap); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -638,7 +649,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); doThrow(SecurityException.class) Loading @@ -648,7 +659,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { mSensitiveContentProtectionManagerService.mNotificationListener .onNotificationRankingUpdate(mRankingMap); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -657,7 +668,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); mSensitiveContentProtectionManagerService.mNotificationListener .onNotificationRankingUpdate(mRankingMap); Loading @@ -681,8 +692,9 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStop(mock(MediaProjectionInfo.class)); MediaProjectionInfo mediaProjectionInfo = createMediaProjectionInfo(); mMediaProjectionCallbackCaptor.getValue().onStart(mediaProjectionInfo); mMediaProjectionCallbackCaptor.getValue().onStop(mediaProjectionInfo); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener Loading @@ -696,7 +708,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener Loading @@ -712,7 +724,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener Loading @@ -726,7 +738,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener Loading @@ -740,7 +752,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener Loading @@ -754,7 +766,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); when(mRankingMap.getRawRankingObject(eq(NOTIFICATION_KEY_1))).thenReturn(null); Loading @@ -770,7 +782,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); mSensitiveContentProtectionManagerService.mNotificationListener .onNotificationPosted(mNotification1, mRankingMap); Loading Loading
services/tests/mockingservicestests/src/com/android/server/SensitiveContentProtectionManagerServiceNotificationTest.java +69 −57 Original line number Diff line number Diff line Loading @@ -25,7 +25,6 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; Loading @@ -34,6 +33,7 @@ import static org.mockito.Mockito.when; import android.content.pm.PackageManagerInternal; import android.media.projection.MediaProjectionInfo; import android.media.projection.MediaProjectionManager; import android.os.Process; import android.platform.test.annotations.RequiresFlagsEnabled; import android.platform.test.flag.junit.CheckFlagsRule; import android.platform.test.flag.junit.DeviceFlagsValueProvider; Loading Loading @@ -79,7 +79,8 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { private static final String NOTIFICATION_PKG_1 = "com.android.server.notification.one"; private static final String NOTIFICATION_PKG_2 = "com.android.server.notification.two"; private static final String EXEMPTED_SCREEN_RECORDER_PACKAGE = "test.screen.recorder.package"; private static final String SCREEN_RECORDER_PACKAGE = "test.screen.recorder.package"; private static final String EXEMPTED_SCREEN_RECORDER_PACKAGE = "exempt.screen.recorder.package"; private static final int NOTIFICATION_UID_1 = 5; private static final int NOTIFICATION_UID_2 = 6; Loading Loading @@ -281,10 +282,18 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { .getActiveNotifications(); } private MediaProjectionInfo createMediaProjectionInfo() { return new MediaProjectionInfo(SCREEN_RECORDER_PACKAGE, Process.myUserHandle(), null); } private MediaProjectionInfo createExemptMediaProjectionInfo() { return new MediaProjectionInfo( EXEMPTED_SCREEN_RECORDER_PACKAGE, Process.myUserHandle(), null); } @Test public void mediaProjectionOnStart_verifyExemptedRecorderPackage() { MediaProjectionInfo mediaProjectionInfo = mock(MediaProjectionInfo.class); when(mediaProjectionInfo.getPackageName()).thenReturn(EXEMPTED_SCREEN_RECORDER_PACKAGE); MediaProjectionInfo mediaProjectionInfo = createExemptMediaProjectionInfo(); mMediaProjectionCallbackCaptor.getValue().onStart(mediaProjectionInfo); Loading @@ -295,7 +304,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { public void mediaProjectionOnStart_onProjectionStart_setWmBlockedPackages() { ArraySet<PackageInfo> expectedBlockedPackages = setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); verify(mWindowManager).addBlockScreenCaptureForApps(expectedBlockedPackages); } Loading @@ -304,18 +313,18 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { public void mediaProjectionOnStart_noSensitiveNotifications_noBlockedPackages() { setupNoSensitiveNotifications(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test public void mediaProjectionOnStart_noNotifications_noBlockedPackages() { setupNoNotifications(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -323,7 +332,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { ArraySet<PackageInfo> expectedBlockedPackages = setupMultipleSensitiveNotificationsFromSamePackageAndUid(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); verify(mWindowManager).addBlockScreenCaptureForApps(expectedBlockedPackages); } Loading @@ -333,7 +342,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { ArraySet<PackageInfo> expectedBlockedPackages = setupMultipleSensitiveNotificationsFromDifferentPackage(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); verify(mWindowManager).addBlockScreenCaptureForApps(expectedBlockedPackages); } Loading @@ -343,7 +352,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { ArraySet<PackageInfo> expectedBlockedPackages = setupMultipleSensitiveNotificationsFromDifferentUid(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); verify(mWindowManager).addBlockScreenCaptureForApps(expectedBlockedPackages); } Loading @@ -352,7 +361,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { public void mediaProjectionOnStop_onProjectionEnd_clearWmBlockedPackages() { setupSensitiveNotification(); MediaProjectionInfo mediaProjectionInfo = mock(MediaProjectionInfo.class); MediaProjectionInfo mediaProjectionInfo = createMediaProjectionInfo(); mMediaProjectionCallbackCaptor.getValue().onStart(mediaProjectionInfo); Mockito.reset(mWindowManager); Loading @@ -365,7 +374,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { public void mediaProjectionOnStart_afterOnStop_onProjectionStart_setWmBlockedPackages() { ArraySet<PackageInfo> expectedBlockedPackages = setupSensitiveNotification(); MediaProjectionInfo mediaProjectionInfo = mock(MediaProjectionInfo.class); MediaProjectionInfo mediaProjectionInfo = createMediaProjectionInfo(); mMediaProjectionCallbackCaptor.getValue().onStart(mediaProjectionInfo); mMediaProjectionCallbackCaptor.getValue().onStop(mediaProjectionInfo); Mockito.reset(mWindowManager); Loading @@ -381,9 +390,9 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { .when(mSensitiveContentProtectionManagerService.mNotificationListener) .getActiveNotifications(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -392,9 +401,9 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { .when(mSensitiveContentProtectionManagerService.mNotificationListener) .getCurrentRanking(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -403,9 +412,9 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { .when(mSensitiveContentProtectionManagerService.mNotificationListener) .getCurrentRanking(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -416,9 +425,9 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { .when(mSensitiveContentProtectionManagerService.mNotificationListener) .getCurrentRanking(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -426,7 +435,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { mockDisabledViaDevelopOption(); setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); verifyZeroInteractions(mWindowManager); } Loading @@ -447,8 +456,9 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStop(mock(MediaProjectionInfo.class)); MediaProjectionInfo mediaProjectionInfo = createMediaProjectionInfo(); mMediaProjectionCallbackCaptor.getValue().onStart(mediaProjectionInfo); mMediaProjectionCallbackCaptor.getValue().onStop(mediaProjectionInfo); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener.onListenerConnected(); Loading @@ -461,7 +471,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive ArraySet<PackageInfo> expectedBlockedPackages = setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener.onListenerConnected(); Loading @@ -472,23 +482,23 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { @Test public void nlsOnListenerConnected_noSensitiveNotifications_noBlockedPackages() { setupNoSensitiveNotifications(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener.onListenerConnected(); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test public void nlsOnListenerConnected_noNotifications_noBlockedPackages() { setupNoNotifications(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener.onListenerConnected(); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -496,7 +506,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); doReturn(null) .when(mSensitiveContentProtectionManagerService.mNotificationListener) Loading @@ -504,7 +514,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { mSensitiveContentProtectionManagerService.mNotificationListener.onListenerConnected(); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -512,7 +522,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); when(mRankingMap.getRawRankingObject(eq(NOTIFICATION_KEY_1))).thenReturn(null); doReturn(mRankingMap) Loading @@ -521,7 +531,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { mSensitiveContentProtectionManagerService.mNotificationListener.onListenerConnected(); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -530,7 +540,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); mSensitiveContentProtectionManagerService.mNotificationListener.onListenerConnected(); verifyZeroInteractions(mWindowManager); Loading @@ -553,8 +563,9 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStop(mock(MediaProjectionInfo.class)); MediaProjectionInfo mediaProjectionInfo = createMediaProjectionInfo(); mMediaProjectionCallbackCaptor.getValue().onStart(mediaProjectionInfo); mMediaProjectionCallbackCaptor.getValue().onStop(mediaProjectionInfo); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener Loading @@ -568,7 +579,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive ArraySet<PackageInfo> expectedBlockedPackages = setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener Loading @@ -580,25 +591,25 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { @Test public void nlsOnNotificationRankingUpdate_noSensitiveNotifications_noBlockedPackages() { setupNoSensitiveNotifications(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener .onNotificationRankingUpdate(mRankingMap); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test public void nlsOnNotificationRankingUpdate_noNotifications_noBlockedPackages() { setupNoNotifications(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener .onNotificationRankingUpdate(mRankingMap); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -606,13 +617,13 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener .onNotificationRankingUpdate(null); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -620,7 +631,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); when(mRankingMap.getRawRankingObject(eq(NOTIFICATION_KEY_1))).thenReturn(null); doReturn(mRankingMap) Loading @@ -630,7 +641,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { mSensitiveContentProtectionManagerService.mNotificationListener .onNotificationRankingUpdate(mRankingMap); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -638,7 +649,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); doThrow(SecurityException.class) Loading @@ -648,7 +659,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { mSensitiveContentProtectionManagerService.mNotificationListener .onNotificationRankingUpdate(mRankingMap); verify(mWindowManager).addBlockScreenCaptureForApps(EMPTY_SET); verifyZeroInteractions(mWindowManager); } @Test Loading @@ -657,7 +668,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); mSensitiveContentProtectionManagerService.mNotificationListener .onNotificationRankingUpdate(mRankingMap); Loading @@ -681,8 +692,9 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStop(mock(MediaProjectionInfo.class)); MediaProjectionInfo mediaProjectionInfo = createMediaProjectionInfo(); mMediaProjectionCallbackCaptor.getValue().onStart(mediaProjectionInfo); mMediaProjectionCallbackCaptor.getValue().onStop(mediaProjectionInfo); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener Loading @@ -696,7 +708,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener Loading @@ -712,7 +724,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener Loading @@ -726,7 +738,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener Loading @@ -740,7 +752,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener Loading @@ -754,7 +766,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); when(mRankingMap.getRawRankingObject(eq(NOTIFICATION_KEY_1))).thenReturn(null); Loading @@ -770,7 +782,7 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 // as non-sensitive setupSensitiveNotification(); mMediaProjectionCallbackCaptor.getValue().onStart(mock(MediaProjectionInfo.class)); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); mSensitiveContentProtectionManagerService.mNotificationListener .onNotificationPosted(mNotification1, mRankingMap); Loading