@@ -2795,40 +2795,99 @@ public void testHasCompanionDevice_noService() {
27952795 assertFalse (mService .hasCompanionDevice (mListener ));
27962796 }
27972797
2798+ @ Test
2799+ public void testSnoozeRunnable_tooManySnoozed_singleNotification () {
2800+ final NotificationRecord notification = generateNotificationRecord (
2801+ mTestNotificationChannel , 1 , null , true );
2802+ mService .addNotification (notification );
2803+
2804+ when (mSnoozeHelper .canSnooze (anyInt ())).thenReturn (true );
2805+ when (mSnoozeHelper .canSnooze (1 )).thenReturn (false );
2806+
2807+ NotificationManagerService .SnoozeNotificationRunnable snoozeNotificationRunnable =
2808+ mService .new SnoozeNotificationRunnable (
2809+ notification .getKey (), 100 , null );
2810+ snoozeNotificationRunnable .run ();
2811+
2812+ verify (mSnoozeHelper , never ()).snooze (any (NotificationRecord .class ), anyLong ());
2813+ assertEquals (1 , mService .getNotificationRecordCount ());
2814+ }
2815+
2816+ @ Test
2817+ public void testSnoozeRunnable_tooManySnoozed_singleGroupChildNotification () {
2818+ final NotificationRecord notification = generateNotificationRecord (
2819+ mTestNotificationChannel , 1 , "group" , true );
2820+ final NotificationRecord notificationChild = generateNotificationRecord (
2821+ mTestNotificationChannel , 1 , "group" , false );
2822+ mService .addNotification (notification );
2823+ mService .addNotification (notificationChild );
2824+
2825+ when (mSnoozeHelper .canSnooze (anyInt ())).thenReturn (true );
2826+ when (mSnoozeHelper .canSnooze (2 )).thenReturn (false );
2827+
2828+ NotificationManagerService .SnoozeNotificationRunnable snoozeNotificationRunnable =
2829+ mService .new SnoozeNotificationRunnable (
2830+ notificationChild .getKey (), 100 , null );
2831+ snoozeNotificationRunnable .run ();
2832+
2833+ verify (mSnoozeHelper , never ()).snooze (any (NotificationRecord .class ), anyLong ());
2834+ assertEquals (2 , mService .getNotificationRecordCount ());
2835+ }
2836+
2837+ @ Test
2838+ public void testSnoozeRunnable_tooManySnoozed_summaryNotification () {
2839+ final NotificationRecord notification = generateNotificationRecord (
2840+ mTestNotificationChannel , 1 , "group" , true );
2841+ final NotificationRecord notificationChild = generateNotificationRecord (
2842+ mTestNotificationChannel , 12 , "group" , false );
2843+ final NotificationRecord notificationChild2 = generateNotificationRecord (
2844+ mTestNotificationChannel , 13 , "group" , false );
2845+ mService .addNotification (notification );
2846+ mService .addNotification (notificationChild );
2847+ mService .addNotification (notificationChild2 );
2848+
2849+ when (mSnoozeHelper .canSnooze (anyInt ())).thenReturn (true );
2850+ when (mSnoozeHelper .canSnooze (3 )).thenReturn (false );
2851+
2852+ NotificationManagerService .SnoozeNotificationRunnable snoozeNotificationRunnable =
2853+ mService .new SnoozeNotificationRunnable (
2854+ notification .getKey (), 100 , null );
2855+ snoozeNotificationRunnable .run ();
2856+
2857+ verify (mSnoozeHelper , never ()).snooze (any (NotificationRecord .class ), anyLong ());
2858+ assertEquals (3 , mService .getNotificationRecordCount ());
2859+ }
2860+
27982861 @ Test
27992862 public void testSnoozeRunnable_reSnoozeASingleSnoozedNotification () throws Exception {
28002863 final NotificationRecord notification = generateNotificationRecord (
28012864 mTestNotificationChannel , 1 , null , true );
28022865 mService .addNotification (notification );
28032866 when (mSnoozeHelper .getNotification (any ())).thenReturn (notification );
2867+ when (mSnoozeHelper .canSnooze (anyInt ())).thenReturn (true );
28042868
28052869 NotificationManagerService .SnoozeNotificationRunnable snoozeNotificationRunnable =
28062870 mService .new SnoozeNotificationRunnable (
28072871 notification .getKey (), 100 , null );
28082872 snoozeNotificationRunnable .run ();
2809- NotificationManagerService .SnoozeNotificationRunnable snoozeNotificationRunnable2 =
2810- mService .new SnoozeNotificationRunnable (
2811- notification .getKey (), 100 , null );
28122873 snoozeNotificationRunnable .run ();
28132874
28142875 // snooze twice
28152876 verify (mSnoozeHelper , times (2 )).snooze (any (NotificationRecord .class ), anyLong ());
28162877 }
28172878
28182879 @ Test
2819- public void testSnoozeRunnable_reSnoozeASnoozedNotificationWithGroupKey () throws Exception {
2880+ public void testSnoozeRunnable_reSnoozeASnoozedNotificationWithGroupKey () {
28202881 final NotificationRecord notification = generateNotificationRecord (
28212882 mTestNotificationChannel , 1 , "group" , true );
28222883 mService .addNotification (notification );
28232884 when (mSnoozeHelper .getNotification (any ())).thenReturn (notification );
2885+ when (mSnoozeHelper .canSnooze (anyInt ())).thenReturn (true );
28242886
28252887 NotificationManagerService .SnoozeNotificationRunnable snoozeNotificationRunnable =
28262888 mService .new SnoozeNotificationRunnable (
28272889 notification .getKey (), 100 , null );
28282890 snoozeNotificationRunnable .run ();
2829- NotificationManagerService .SnoozeNotificationRunnable snoozeNotificationRunnable2 =
2830- mService .new SnoozeNotificationRunnable (
2831- notification .getKey (), 100 , null );
28322891 snoozeNotificationRunnable .run ();
28332892
28342893 // snooze twice
@@ -2846,6 +2905,7 @@ public void testSnoozeRunnable_reSnoozeMultipleNotificationsWithGroupKey() throw
28462905 when (mSnoozeHelper .getNotification (any ())).thenReturn (notification );
28472906 when (mSnoozeHelper .getNotifications (
28482907 anyString (), anyString (), anyInt ())).thenReturn (new ArrayList <>());
2908+ when (mSnoozeHelper .canSnooze (anyInt ())).thenReturn (true );
28492909
28502910 NotificationManagerService .SnoozeNotificationRunnable snoozeNotificationRunnable =
28512911 mService .new SnoozeNotificationRunnable (
@@ -2855,8 +2915,8 @@ mService.new SnoozeNotificationRunnable(
28552915 .thenReturn (new ArrayList <>(Arrays .asList (notification , notification2 )));
28562916 NotificationManagerService .SnoozeNotificationRunnable snoozeNotificationRunnable2 =
28572917 mService .new SnoozeNotificationRunnable (
2858- notification .getKey (), 100 , null );
2859- snoozeNotificationRunnable .run ();
2918+ notification2 .getKey (), 100 , null );
2919+ snoozeNotificationRunnable2 .run ();
28602920
28612921 // snooze twice
28622922 verify (mSnoozeHelper , times (4 )).snooze (any (NotificationRecord .class ), anyLong ());
@@ -2870,6 +2930,7 @@ public void testSnoozeRunnable_snoozeNonGrouped() throws Exception {
28702930 mTestNotificationChannel , 2 , "group" , false );
28712931 mService .addNotification (grouped );
28722932 mService .addNotification (nonGrouped );
2933+ when (mSnoozeHelper .canSnooze (anyInt ())).thenReturn (true );
28732934
28742935 NotificationManagerService .SnoozeNotificationRunnable snoozeNotificationRunnable =
28752936 mService .new SnoozeNotificationRunnable (
@@ -2899,6 +2960,7 @@ public void testSnoozeRunnable_snoozeSummary_withChildren() throws Exception {
28992960 mService .addNotification (parent );
29002961 mService .addNotification (child );
29012962 mService .addNotification (child2 );
2963+ when (mSnoozeHelper .canSnooze (anyInt ())).thenReturn (true );
29022964
29032965 NotificationManagerService .SnoozeNotificationRunnable snoozeNotificationRunnable =
29042966 mService .new SnoozeNotificationRunnable (
@@ -2920,6 +2982,7 @@ public void testSnoozeRunnable_snoozeGroupChild_fellowChildren() throws Exceptio
29202982 mService .addNotification (parent );
29212983 mService .addNotification (child );
29222984 mService .addNotification (child2 );
2985+ when (mSnoozeHelper .canSnooze (anyInt ())).thenReturn (true );
29232986
29242987 NotificationManagerService .SnoozeNotificationRunnable snoozeNotificationRunnable =
29252988 mService .new SnoozeNotificationRunnable (
@@ -2945,6 +3008,7 @@ public void testSnoozeRunnable_snoozeGroupChild_onlyChildOfSummary() throws Exce
29453008 mTestNotificationChannel , 2 , "group" , false );
29463009 mService .addNotification (parent );
29473010 mService .addNotification (child );
3011+ when (mSnoozeHelper .canSnooze (anyInt ())).thenReturn (true );
29483012
29493013 NotificationManagerService .SnoozeNotificationRunnable snoozeNotificationRunnable =
29503014 mService .new SnoozeNotificationRunnable (
@@ -2972,6 +3036,7 @@ public void testSnoozeRunnable_snoozeGroupChild_noOthersInGroup() throws Excepti
29723036 final NotificationRecord child = generateNotificationRecord (
29733037 mTestNotificationChannel , 2 , "group" , false );
29743038 mService .addNotification (child );
3039+ when (mSnoozeHelper .canSnooze (anyInt ())).thenReturn (true );
29753040
29763041 NotificationManagerService .SnoozeNotificationRunnable snoozeNotificationRunnable =
29773042 mService .new SnoozeNotificationRunnable (
0 commit comments