Loading services/core/java/com/android/server/SensitiveContentProtectionManagerService.java +37 −21 Original line number Diff line number Diff line Loading @@ -316,11 +316,16 @@ public final class SensitiveContentProtectionManagerService extends SystemServic rankingMap = null; } if (rankingMap == null) { Log.w(TAG, "Ranking map not initialized."); return; } updateAppsThatShouldBlockScreenCapture(rankingMap); } @GuardedBy("mSensitiveContentProtectionLock") private void updateAppsThatShouldBlockScreenCapture(RankingMap rankingMap) { private void updateAppsThatShouldBlockScreenCapture(@NonNull RankingMap rankingMap) { StatusBarNotification[] notifications; try { notifications = mNotificationListener.getActiveNotifications(); Loading @@ -337,15 +342,15 @@ public final class SensitiveContentProtectionManagerService extends SystemServic } } private ArraySet<PackageInfo> getSensitivePackagesFromNotifications( @NonNull StatusBarNotification[] notifications, RankingMap rankingMap) { private static @NonNull ArraySet<PackageInfo> getSensitivePackagesFromNotifications( @NonNull StatusBarNotification[] notifications, @NonNull RankingMap rankingMap) { ArraySet<PackageInfo> sensitivePackages = new ArraySet<>(); if (rankingMap == null) { Log.w(TAG, "Ranking map not initialized."); return sensitivePackages; for (StatusBarNotification sbn : notifications) { if (sbn == null) { Log.w(TAG, "Unable to parse null notification"); continue; } for (StatusBarNotification sbn : notifications) { PackageInfo info = getSensitivePackageFromNotification(sbn, rankingMap); if (info != null) { sensitivePackages.add(info); Loading @@ -354,22 +359,18 @@ public final class SensitiveContentProtectionManagerService extends SystemServic return sensitivePackages; } private PackageInfo getSensitivePackageFromNotification( StatusBarNotification sbn, RankingMap rankingMap) { if (sbn == null) { Log.w(TAG, "Unable to protect null notification"); return null; private static @Nullable PackageInfo getSensitivePackageFromNotification( @NonNull StatusBarNotification sbn, @NonNull RankingMap rankingMap) { if (notificationHasSensitiveContent(sbn, rankingMap)) { return new PackageInfo(sbn.getPackageName(), sbn.getUid()); } if (rankingMap == null) { Log.w(TAG, "Ranking map not initialized."); return null; } private static boolean notificationHasSensitiveContent( @NonNull StatusBarNotification sbn, @NonNull RankingMap rankingMap) { NotificationListenerService.Ranking ranking = rankingMap.getRawRankingObject(sbn.getKey()); if (ranking != null && ranking.hasSensitiveContent()) { return new PackageInfo(sbn.getPackageName(), sbn.getUid()); } return null; return ranking != null && ranking.hasSensitiveContent(); } @VisibleForTesting Loading Loading @@ -397,6 +398,16 @@ public final class SensitiveContentProtectionManagerService extends SystemServic Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "SensitiveContentProtectionManagerService.onNotificationPosted"); try { if (sbn == null) { Log.w(TAG, "Unable to parse null notification"); return; } if (rankingMap == null) { Log.w(TAG, "Ranking map not initialized."); return; } synchronized (mSensitiveContentProtectionLock) { if (!mProjectionActive) { return; Loading @@ -421,6 +432,11 @@ public final class SensitiveContentProtectionManagerService extends SystemServic Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "SensitiveContentProtectionManagerService.onNotificationRankingUpdate"); try { if (rankingMap == null) { Log.w(TAG, "Ranking map not initialized."); return; } synchronized (mSensitiveContentProtectionLock) { if (mProjectionActive) { updateAppsThatShouldBlockScreenCapture(rankingMap); Loading services/tests/mockingservicestests/src/com/android/server/SensitiveContentProtectionManagerServiceNotificationTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -282,6 +282,14 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { .getActiveNotifications(); } private void setupNullNotifications() { // Setup Notification Values StatusBarNotification[] mNotifications = new StatusBarNotification[] { null, null}; doReturn(mNotifications) .when(mSensitiveContentProtectionManagerService.mNotificationListener) .getActiveNotifications(); } private MediaProjectionInfo createMediaProjectionInfo() { return new MediaProjectionInfo(SCREEN_RECORDER_PACKAGE, Process.myUserHandle(), null); } Loading Loading @@ -501,6 +509,17 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { verifyZeroInteractions(mWindowManager); } @Test public void nlsOnListenerConnected_nullNotifications_noBlockedPackages() { setupNullNotifications(); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener.onListenerConnected(); verifyZeroInteractions(mWindowManager); } @Test public void nlsOnListenerConnected_nullRankingMap_noBlockedPackages() { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 Loading Loading
services/core/java/com/android/server/SensitiveContentProtectionManagerService.java +37 −21 Original line number Diff line number Diff line Loading @@ -316,11 +316,16 @@ public final class SensitiveContentProtectionManagerService extends SystemServic rankingMap = null; } if (rankingMap == null) { Log.w(TAG, "Ranking map not initialized."); return; } updateAppsThatShouldBlockScreenCapture(rankingMap); } @GuardedBy("mSensitiveContentProtectionLock") private void updateAppsThatShouldBlockScreenCapture(RankingMap rankingMap) { private void updateAppsThatShouldBlockScreenCapture(@NonNull RankingMap rankingMap) { StatusBarNotification[] notifications; try { notifications = mNotificationListener.getActiveNotifications(); Loading @@ -337,15 +342,15 @@ public final class SensitiveContentProtectionManagerService extends SystemServic } } private ArraySet<PackageInfo> getSensitivePackagesFromNotifications( @NonNull StatusBarNotification[] notifications, RankingMap rankingMap) { private static @NonNull ArraySet<PackageInfo> getSensitivePackagesFromNotifications( @NonNull StatusBarNotification[] notifications, @NonNull RankingMap rankingMap) { ArraySet<PackageInfo> sensitivePackages = new ArraySet<>(); if (rankingMap == null) { Log.w(TAG, "Ranking map not initialized."); return sensitivePackages; for (StatusBarNotification sbn : notifications) { if (sbn == null) { Log.w(TAG, "Unable to parse null notification"); continue; } for (StatusBarNotification sbn : notifications) { PackageInfo info = getSensitivePackageFromNotification(sbn, rankingMap); if (info != null) { sensitivePackages.add(info); Loading @@ -354,22 +359,18 @@ public final class SensitiveContentProtectionManagerService extends SystemServic return sensitivePackages; } private PackageInfo getSensitivePackageFromNotification( StatusBarNotification sbn, RankingMap rankingMap) { if (sbn == null) { Log.w(TAG, "Unable to protect null notification"); return null; private static @Nullable PackageInfo getSensitivePackageFromNotification( @NonNull StatusBarNotification sbn, @NonNull RankingMap rankingMap) { if (notificationHasSensitiveContent(sbn, rankingMap)) { return new PackageInfo(sbn.getPackageName(), sbn.getUid()); } if (rankingMap == null) { Log.w(TAG, "Ranking map not initialized."); return null; } private static boolean notificationHasSensitiveContent( @NonNull StatusBarNotification sbn, @NonNull RankingMap rankingMap) { NotificationListenerService.Ranking ranking = rankingMap.getRawRankingObject(sbn.getKey()); if (ranking != null && ranking.hasSensitiveContent()) { return new PackageInfo(sbn.getPackageName(), sbn.getUid()); } return null; return ranking != null && ranking.hasSensitiveContent(); } @VisibleForTesting Loading Loading @@ -397,6 +398,16 @@ public final class SensitiveContentProtectionManagerService extends SystemServic Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "SensitiveContentProtectionManagerService.onNotificationPosted"); try { if (sbn == null) { Log.w(TAG, "Unable to parse null notification"); return; } if (rankingMap == null) { Log.w(TAG, "Ranking map not initialized."); return; } synchronized (mSensitiveContentProtectionLock) { if (!mProjectionActive) { return; Loading @@ -421,6 +432,11 @@ public final class SensitiveContentProtectionManagerService extends SystemServic Trace.traceBegin(Trace.TRACE_TAG_SYSTEM_SERVER, "SensitiveContentProtectionManagerService.onNotificationRankingUpdate"); try { if (rankingMap == null) { Log.w(TAG, "Ranking map not initialized."); return; } synchronized (mSensitiveContentProtectionLock) { if (mProjectionActive) { updateAppsThatShouldBlockScreenCapture(rankingMap); Loading
services/tests/mockingservicestests/src/com/android/server/SensitiveContentProtectionManagerServiceNotificationTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -282,6 +282,14 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { .getActiveNotifications(); } private void setupNullNotifications() { // Setup Notification Values StatusBarNotification[] mNotifications = new StatusBarNotification[] { null, null}; doReturn(mNotifications) .when(mSensitiveContentProtectionManagerService.mNotificationListener) .getActiveNotifications(); } private MediaProjectionInfo createMediaProjectionInfo() { return new MediaProjectionInfo(SCREEN_RECORDER_PACKAGE, Process.myUserHandle(), null); } Loading Loading @@ -501,6 +509,17 @@ public class SensitiveContentProtectionManagerServiceNotificationTest { verifyZeroInteractions(mWindowManager); } @Test public void nlsOnListenerConnected_nullNotifications_noBlockedPackages() { setupNullNotifications(); mMediaProjectionCallbackCaptor.getValue().onStart(createMediaProjectionInfo()); Mockito.reset(mWindowManager); mSensitiveContentProtectionManagerService.mNotificationListener.onListenerConnected(); verifyZeroInteractions(mWindowManager); } @Test public void nlsOnListenerConnected_nullRankingMap_noBlockedPackages() { // Sets up mNotification1 & mRankingMap to be a sensitive notification, and mNotification2 Loading