Loading services/core/java/com/android/server/notification/NotificationManagerService.java +4 −3 Original line number Diff line number Diff line Loading @@ -1051,7 +1051,8 @@ public class NotificationManagerService extends SystemService { @VisibleForTesting void init(Looper looper, IPackageManager packageManager, PackageManager packageManagerClient, LightsManager lightsManager, NotificationListeners notificationListeners, ICompanionDeviceManager companionManager, SnoozeHelper snoozeHelper) { ICompanionDeviceManager companionManager, SnoozeHelper snoozeHelper, NotificationUsageStats usageStats) { Resources resources = getContext().getResources(); mMaxPackageEnqueueRate = Settings.Global.getFloat(getContext().getContentResolver(), Settings.Global.MAX_NOTIFICATION_ENQUEUE_RATE, Loading @@ -1074,7 +1075,7 @@ public class NotificationManagerService extends SystemService { } catch (Resources.NotFoundException e) { extractorNames = new String[0]; } mUsageStats = new NotificationUsageStats(getContext()); mUsageStats = usageStats; mRankingHandler = new RankingHandlerWorker(mRankingThread.getLooper()); mRankingHelper = new RankingHelper(getContext(), getContext().getPackageManager(), Loading Loading @@ -1243,7 +1244,7 @@ public class NotificationManagerService extends SystemService { init(Looper.myLooper(), AppGlobals.getPackageManager(), getContext().getPackageManager(), getLocalService(LightsManager.class), new NotificationListeners(), null, snoozeHelper); null, snoozeHelper, new NotificationUsageStats(getContext())); publishBinderService(Context.NOTIFICATION_SERVICE, mService); publishLocalService(NotificationManagerInternal.class, mInternalService); } Loading services/tests/notification/src/com/android/server/notification/NotificationManagerServiceTest.java +9 −10 Original line number Diff line number Diff line Loading @@ -91,6 +91,8 @@ public class NotificationManagerServiceTest extends NotificationTestCase { private TestableLooper mTestableLooper; @Mock private RankingHelper mRankingHelper; @Mock private NotificationUsageStats mUsageStats; private NotificationChannel mTestNotificationChannel = new NotificationChannel( TEST_CHANNEL_ID, TEST_CHANNEL_ID, NotificationManager.IMPORTANCE_DEFAULT); @Mock Loading Loading @@ -147,7 +149,7 @@ public class NotificationManagerServiceTest extends NotificationTestCase { when(mNotificationListeners.checkServiceTokenLocked(any())).thenReturn(mListener); mNotificationManagerService.init(mTestableLooper.getLooper(), mPackageManager, mPackageManagerClient, mockLightsManager, mNotificationListeners, mCompanionMgr, mSnoozeHelper); mSnoozeHelper, mUsageStats); // Tests call directly into the Binder. mBinderService = mNotificationManagerService.getBinderService(); Loading Loading @@ -261,40 +263,37 @@ public class NotificationManagerServiceTest extends NotificationTestCase { @Test public void testBlockedNotifications_suspended() throws Exception { NotificationUsageStats usageStats = mock(NotificationUsageStats.class); when(mPackageManager.isPackageSuspendedForUser(anyString(), anyInt())).thenReturn(true); NotificationChannel channel = new NotificationChannel("id", "name", NotificationManager.IMPORTANCE_HIGH); NotificationRecord r = generateNotificationRecord(channel); assertTrue(mNotificationManagerService.isBlocked(r, usageStats)); verify(usageStats, times(1)).registerSuspendedByAdmin(eq(r)); assertTrue(mNotificationManagerService.isBlocked(r, mUsageStats)); verify(mUsageStats, times(1)).registerSuspendedByAdmin(eq(r)); } @Test public void testBlockedNotifications_blockedChannel() throws Exception { NotificationUsageStats usageStats = mock(NotificationUsageStats.class); when(mPackageManager.isPackageSuspendedForUser(anyString(), anyInt())).thenReturn(false); NotificationChannel channel = new NotificationChannel("id", "name", NotificationManager.IMPORTANCE_HIGH); channel.setImportance(NotificationManager.IMPORTANCE_NONE); NotificationRecord r = generateNotificationRecord(channel); assertTrue(mNotificationManagerService.isBlocked(r, usageStats)); verify(usageStats, times(1)).registerBlocked(eq(r)); assertTrue(mNotificationManagerService.isBlocked(r, mUsageStats)); verify(mUsageStats, times(1)).registerBlocked(eq(r)); } @Test public void testBlockedNotifications_blockedApp() throws Exception { NotificationUsageStats usageStats = mock(NotificationUsageStats.class); when(mPackageManager.isPackageSuspendedForUser(anyString(), anyInt())).thenReturn(false); NotificationChannel channel = new NotificationChannel("id", "name", NotificationManager.IMPORTANCE_HIGH); NotificationRecord r = generateNotificationRecord(channel); r.setUserImportance(NotificationManager.IMPORTANCE_NONE); assertTrue(mNotificationManagerService.isBlocked(r, usageStats)); verify(usageStats, times(1)).registerBlocked(eq(r)); assertTrue(mNotificationManagerService.isBlocked(r, mUsageStats)); verify(mUsageStats, times(1)).registerBlocked(eq(r)); } @Test Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +4 −3 Original line number Diff line number Diff line Loading @@ -1051,7 +1051,8 @@ public class NotificationManagerService extends SystemService { @VisibleForTesting void init(Looper looper, IPackageManager packageManager, PackageManager packageManagerClient, LightsManager lightsManager, NotificationListeners notificationListeners, ICompanionDeviceManager companionManager, SnoozeHelper snoozeHelper) { ICompanionDeviceManager companionManager, SnoozeHelper snoozeHelper, NotificationUsageStats usageStats) { Resources resources = getContext().getResources(); mMaxPackageEnqueueRate = Settings.Global.getFloat(getContext().getContentResolver(), Settings.Global.MAX_NOTIFICATION_ENQUEUE_RATE, Loading @@ -1074,7 +1075,7 @@ public class NotificationManagerService extends SystemService { } catch (Resources.NotFoundException e) { extractorNames = new String[0]; } mUsageStats = new NotificationUsageStats(getContext()); mUsageStats = usageStats; mRankingHandler = new RankingHandlerWorker(mRankingThread.getLooper()); mRankingHelper = new RankingHelper(getContext(), getContext().getPackageManager(), Loading Loading @@ -1243,7 +1244,7 @@ public class NotificationManagerService extends SystemService { init(Looper.myLooper(), AppGlobals.getPackageManager(), getContext().getPackageManager(), getLocalService(LightsManager.class), new NotificationListeners(), null, snoozeHelper); null, snoozeHelper, new NotificationUsageStats(getContext())); publishBinderService(Context.NOTIFICATION_SERVICE, mService); publishLocalService(NotificationManagerInternal.class, mInternalService); } Loading
services/tests/notification/src/com/android/server/notification/NotificationManagerServiceTest.java +9 −10 Original line number Diff line number Diff line Loading @@ -91,6 +91,8 @@ public class NotificationManagerServiceTest extends NotificationTestCase { private TestableLooper mTestableLooper; @Mock private RankingHelper mRankingHelper; @Mock private NotificationUsageStats mUsageStats; private NotificationChannel mTestNotificationChannel = new NotificationChannel( TEST_CHANNEL_ID, TEST_CHANNEL_ID, NotificationManager.IMPORTANCE_DEFAULT); @Mock Loading Loading @@ -147,7 +149,7 @@ public class NotificationManagerServiceTest extends NotificationTestCase { when(mNotificationListeners.checkServiceTokenLocked(any())).thenReturn(mListener); mNotificationManagerService.init(mTestableLooper.getLooper(), mPackageManager, mPackageManagerClient, mockLightsManager, mNotificationListeners, mCompanionMgr, mSnoozeHelper); mSnoozeHelper, mUsageStats); // Tests call directly into the Binder. mBinderService = mNotificationManagerService.getBinderService(); Loading Loading @@ -261,40 +263,37 @@ public class NotificationManagerServiceTest extends NotificationTestCase { @Test public void testBlockedNotifications_suspended() throws Exception { NotificationUsageStats usageStats = mock(NotificationUsageStats.class); when(mPackageManager.isPackageSuspendedForUser(anyString(), anyInt())).thenReturn(true); NotificationChannel channel = new NotificationChannel("id", "name", NotificationManager.IMPORTANCE_HIGH); NotificationRecord r = generateNotificationRecord(channel); assertTrue(mNotificationManagerService.isBlocked(r, usageStats)); verify(usageStats, times(1)).registerSuspendedByAdmin(eq(r)); assertTrue(mNotificationManagerService.isBlocked(r, mUsageStats)); verify(mUsageStats, times(1)).registerSuspendedByAdmin(eq(r)); } @Test public void testBlockedNotifications_blockedChannel() throws Exception { NotificationUsageStats usageStats = mock(NotificationUsageStats.class); when(mPackageManager.isPackageSuspendedForUser(anyString(), anyInt())).thenReturn(false); NotificationChannel channel = new NotificationChannel("id", "name", NotificationManager.IMPORTANCE_HIGH); channel.setImportance(NotificationManager.IMPORTANCE_NONE); NotificationRecord r = generateNotificationRecord(channel); assertTrue(mNotificationManagerService.isBlocked(r, usageStats)); verify(usageStats, times(1)).registerBlocked(eq(r)); assertTrue(mNotificationManagerService.isBlocked(r, mUsageStats)); verify(mUsageStats, times(1)).registerBlocked(eq(r)); } @Test public void testBlockedNotifications_blockedApp() throws Exception { NotificationUsageStats usageStats = mock(NotificationUsageStats.class); when(mPackageManager.isPackageSuspendedForUser(anyString(), anyInt())).thenReturn(false); NotificationChannel channel = new NotificationChannel("id", "name", NotificationManager.IMPORTANCE_HIGH); NotificationRecord r = generateNotificationRecord(channel); r.setUserImportance(NotificationManager.IMPORTANCE_NONE); assertTrue(mNotificationManagerService.isBlocked(r, usageStats)); verify(usageStats, times(1)).registerBlocked(eq(r)); assertTrue(mNotificationManagerService.isBlocked(r, mUsageStats)); verify(mUsageStats, times(1)).registerBlocked(eq(r)); } @Test Loading