Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package com.android.server.notification; |
| 17 | |
| 18 | import org.junit.Before; |
| 19 | import org.junit.Test; |
| 20 | import org.junit.runner.RunWith; |
Julia Reynolds | 5098977 | 2017-02-23 14:32:16 -0500 | [diff] [blame] | 21 | import org.mockito.ArgumentCaptor; |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 22 | import org.mockito.Mock; |
| 23 | import org.mockito.MockitoAnnotations; |
| 24 | |
| 25 | import android.app.AlarmManager; |
| 26 | import android.app.Notification; |
| 27 | import android.app.NotificationChannel; |
Julia Reynolds | 8576991 | 2016-10-25 09:08:57 -0400 | [diff] [blame] | 28 | import android.app.NotificationManager; |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 29 | import android.app.PendingIntent; |
Julia Reynolds | 5098977 | 2017-02-23 14:32:16 -0500 | [diff] [blame] | 30 | import android.os.SystemClock; |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 31 | import android.os.UserHandle; |
| 32 | import android.service.notification.StatusBarNotification; |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 33 | import android.support.test.runner.AndroidJUnit4; |
| 34 | import android.test.suitebuilder.annotation.SmallTest; |
Julia Reynolds | a78cdff | 2017-04-26 10:19:25 -0400 | [diff] [blame] | 35 | import android.util.Slog; |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 36 | |
Julia Reynolds | cf63ff1 | 2017-01-24 13:55:48 -0500 | [diff] [blame] | 37 | import static junit.framework.Assert.assertEquals; |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 38 | import static junit.framework.Assert.assertFalse; |
| 39 | import static junit.framework.Assert.assertTrue; |
| 40 | import static org.mockito.Matchers.any; |
| 41 | import static org.mockito.Matchers.anyInt; |
Julia Reynolds | b6c1f99 | 2016-11-22 09:26:46 -0500 | [diff] [blame] | 42 | import static org.mockito.Matchers.anyLong; |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 43 | import static org.mockito.Matchers.eq; |
| 44 | import static org.mockito.Mockito.never; |
| 45 | import static org.mockito.Mockito.times; |
| 46 | import static org.mockito.Mockito.verify; |
Julia Reynolds | cf63ff1 | 2017-01-24 13:55:48 -0500 | [diff] [blame] | 47 | import static org.mockito.Mockito.when; |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 48 | |
| 49 | |
| 50 | @SmallTest |
| 51 | @RunWith(AndroidJUnit4.class) |
Chris Wren | 89aa226 | 2017-05-05 18:05:56 -0400 | [diff] [blame] | 52 | public class SnoozeHelperTest extends NotificationTestCase { |
Geoffrey Pitsch | af759c5 | 2017-02-15 09:35:38 -0500 | [diff] [blame] | 53 | private static final String TEST_CHANNEL_ID = "test_channel_id"; |
| 54 | |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 55 | @Mock SnoozeHelper.Callback mCallback; |
| 56 | @Mock AlarmManager mAm; |
| 57 | @Mock ManagedServices.UserProfiles mUserProfiles; |
| 58 | |
| 59 | private SnoozeHelper mSnoozeHelper; |
| 60 | |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 61 | @Before |
| 62 | public void setUp() { |
| 63 | MockitoAnnotations.initMocks(this); |
| 64 | |
| 65 | mSnoozeHelper = new SnoozeHelper(getContext(), mCallback, mUserProfiles); |
| 66 | mSnoozeHelper.setAlarmManager(mAm); |
| 67 | } |
| 68 | |
| 69 | @Test |
Julia Reynolds | b6c1f99 | 2016-11-22 09:26:46 -0500 | [diff] [blame] | 70 | public void testSnoozeForTime() throws Exception { |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 71 | NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); |
Julia Reynolds | 7967230 | 2017-01-12 08:30:16 -0500 | [diff] [blame] | 72 | mSnoozeHelper.snooze(r, 1000); |
Julia Reynolds | 5098977 | 2017-02-23 14:32:16 -0500 | [diff] [blame] | 73 | ArgumentCaptor<Long> captor = ArgumentCaptor.forClass(Long.class); |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 74 | verify(mAm, times(1)).setExactAndAllowWhileIdle( |
Julia Reynolds | 5098977 | 2017-02-23 14:32:16 -0500 | [diff] [blame] | 75 | anyInt(), captor.capture(), any(PendingIntent.class)); |
| 76 | long actualSnoozedUntilDuration = captor.getValue() - SystemClock.elapsedRealtime(); |
Julia Reynolds | 4024b66 | 2017-03-01 09:33:41 -0500 | [diff] [blame] | 77 | assertTrue(Math.abs(actualSnoozedUntilDuration - 1000) < 25); |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 78 | assertTrue(mSnoozeHelper.isSnoozed( |
| 79 | UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey())); |
| 80 | } |
| 81 | |
| 82 | @Test |
Julia Reynolds | b6c1f99 | 2016-11-22 09:26:46 -0500 | [diff] [blame] | 83 | public void testSnooze() throws Exception { |
| 84 | NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); |
Julia Reynolds | 7967230 | 2017-01-12 08:30:16 -0500 | [diff] [blame] | 85 | mSnoozeHelper.snooze(r); |
Julia Reynolds | b6c1f99 | 2016-11-22 09:26:46 -0500 | [diff] [blame] | 86 | verify(mAm, never()).setExactAndAllowWhileIdle( |
| 87 | anyInt(), anyLong(), any(PendingIntent.class)); |
| 88 | assertTrue(mSnoozeHelper.isSnoozed( |
| 89 | UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey())); |
| 90 | } |
| 91 | |
| 92 | @Test |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 93 | public void testCancelByApp() throws Exception { |
| 94 | NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); |
| 95 | NotificationRecord r2 = getNotificationRecord("pkg", 2, "two", UserHandle.SYSTEM); |
Julia Reynolds | 7967230 | 2017-01-12 08:30:16 -0500 | [diff] [blame] | 96 | mSnoozeHelper.snooze(r, 1000); |
| 97 | mSnoozeHelper.snooze(r2 , 1000); |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 98 | assertTrue(mSnoozeHelper.isSnoozed( |
| 99 | UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey())); |
| 100 | assertTrue(mSnoozeHelper.isSnoozed( |
| 101 | UserHandle.USER_SYSTEM, r2.sbn.getPackageName(), r2.getKey())); |
| 102 | |
| 103 | mSnoozeHelper.cancel(UserHandle.USER_SYSTEM, r.sbn.getPackageName(), "one", 1); |
Julia Reynolds | a8b766f | 2017-03-07 16:30:21 -0500 | [diff] [blame] | 104 | // 2 = one for each snooze, above, zero for the cancel. |
| 105 | verify(mAm, times(2)).cancel(any(PendingIntent.class)); |
| 106 | assertTrue(mSnoozeHelper.isSnoozed( |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 107 | UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey())); |
| 108 | assertTrue(mSnoozeHelper.isSnoozed( |
| 109 | UserHandle.USER_SYSTEM, r2.sbn.getPackageName(), r2.getKey())); |
| 110 | } |
| 111 | |
| 112 | @Test |
| 113 | public void testCancelAllForUser() throws Exception { |
| 114 | NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); |
| 115 | NotificationRecord r2 = getNotificationRecord("pkg", 2, "two", UserHandle.SYSTEM); |
| 116 | NotificationRecord r3 = getNotificationRecord("pkg", 3, "three", UserHandle.ALL); |
Julia Reynolds | 7967230 | 2017-01-12 08:30:16 -0500 | [diff] [blame] | 117 | mSnoozeHelper.snooze(r, 1000); |
| 118 | mSnoozeHelper.snooze(r2, 1000); |
| 119 | mSnoozeHelper.snooze(r3, 1000); |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 120 | assertTrue(mSnoozeHelper.isSnoozed( |
| 121 | UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey())); |
| 122 | assertTrue(mSnoozeHelper.isSnoozed( |
| 123 | UserHandle.USER_SYSTEM, r2.sbn.getPackageName(), r2.getKey())); |
| 124 | assertTrue(mSnoozeHelper.isSnoozed( |
| 125 | UserHandle.USER_ALL, r3.sbn.getPackageName(), r3.getKey())); |
| 126 | |
| 127 | mSnoozeHelper.cancel(UserHandle.USER_SYSTEM, false); |
Julia Reynolds | a8b766f | 2017-03-07 16:30:21 -0500 | [diff] [blame] | 128 | // 3 = once for each snooze above (3), only. |
| 129 | verify(mAm, times(3)).cancel(any(PendingIntent.class)); |
| 130 | assertTrue(mSnoozeHelper.isSnoozed( |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 131 | UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey())); |
Julia Reynolds | a8b766f | 2017-03-07 16:30:21 -0500 | [diff] [blame] | 132 | assertTrue(mSnoozeHelper.isSnoozed( |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 133 | UserHandle.USER_SYSTEM, r2.sbn.getPackageName(), r2.getKey())); |
| 134 | assertTrue(mSnoozeHelper.isSnoozed( |
| 135 | UserHandle.USER_ALL, r3.sbn.getPackageName(), r3.getKey())); |
| 136 | } |
| 137 | |
| 138 | @Test |
| 139 | public void testCancelAllByApp() throws Exception { |
| 140 | NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); |
| 141 | NotificationRecord r2 = getNotificationRecord("pkg", 2, "two", UserHandle.SYSTEM); |
| 142 | NotificationRecord r3 = getNotificationRecord("pkg2", 3, "three", UserHandle.SYSTEM); |
Julia Reynolds | 7967230 | 2017-01-12 08:30:16 -0500 | [diff] [blame] | 143 | mSnoozeHelper.snooze(r, 1000); |
| 144 | mSnoozeHelper.snooze(r2, 1000); |
| 145 | mSnoozeHelper.snooze(r3, 1000); |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 146 | assertTrue(mSnoozeHelper.isSnoozed( |
| 147 | UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey())); |
| 148 | assertTrue(mSnoozeHelper.isSnoozed( |
| 149 | UserHandle.USER_SYSTEM, r2.sbn.getPackageName(), r2.getKey())); |
| 150 | assertTrue(mSnoozeHelper.isSnoozed( |
| 151 | UserHandle.USER_SYSTEM, r3.sbn.getPackageName(), r3.getKey())); |
| 152 | |
| 153 | mSnoozeHelper.cancel(UserHandle.USER_SYSTEM, "pkg2"); |
Julia Reynolds | a8b766f | 2017-03-07 16:30:21 -0500 | [diff] [blame] | 154 | // 3 = once for each snooze above (3), only. |
| 155 | verify(mAm, times(3)).cancel(any(PendingIntent.class)); |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 156 | assertTrue(mSnoozeHelper.isSnoozed( |
| 157 | UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey())); |
| 158 | assertTrue(mSnoozeHelper.isSnoozed( |
| 159 | UserHandle.USER_SYSTEM, r2.sbn.getPackageName(), r2.getKey())); |
Julia Reynolds | a8b766f | 2017-03-07 16:30:21 -0500 | [diff] [blame] | 160 | assertTrue(mSnoozeHelper.isSnoozed( |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 161 | UserHandle.USER_SYSTEM, r3.sbn.getPackageName(), r3.getKey())); |
| 162 | } |
| 163 | |
| 164 | @Test |
Julia Reynolds | a8b766f | 2017-03-07 16:30:21 -0500 | [diff] [blame] | 165 | public void testCancelDoesNotUnsnooze() throws Exception { |
| 166 | NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); |
| 167 | mSnoozeHelper.snooze(r, 1000); |
| 168 | assertTrue(mSnoozeHelper.isSnoozed( |
| 169 | UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey())); |
| 170 | |
| 171 | mSnoozeHelper.cancel(UserHandle.USER_SYSTEM, r.sbn.getPackageName(), "one", 1); |
| 172 | |
| 173 | assertTrue(mSnoozeHelper.isSnoozed( |
| 174 | UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey())); |
| 175 | } |
| 176 | |
| 177 | @Test |
| 178 | public void testCancelDoesNotRepost() throws Exception { |
| 179 | NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); |
| 180 | NotificationRecord r2 = getNotificationRecord("pkg", 2, "two", UserHandle.SYSTEM); |
| 181 | mSnoozeHelper.snooze(r, 1000); |
| 182 | mSnoozeHelper.snooze(r2 , 1000); |
| 183 | assertTrue(mSnoozeHelper.isSnoozed( |
| 184 | UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey())); |
| 185 | assertTrue(mSnoozeHelper.isSnoozed( |
| 186 | UserHandle.USER_SYSTEM, r2.sbn.getPackageName(), r2.getKey())); |
| 187 | |
| 188 | mSnoozeHelper.cancel(UserHandle.USER_SYSTEM, r.sbn.getPackageName(), "one", 1); |
| 189 | |
| 190 | mSnoozeHelper.repost(r.getKey(), UserHandle.USER_SYSTEM); |
| 191 | verify(mCallback, never()).repost(UserHandle.USER_SYSTEM, r); |
| 192 | } |
| 193 | |
| 194 | @Test |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 195 | public void testRepost() throws Exception { |
| 196 | NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); |
Julia Reynolds | 7967230 | 2017-01-12 08:30:16 -0500 | [diff] [blame] | 197 | mSnoozeHelper.snooze(r, 1000); |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 198 | NotificationRecord r2 = getNotificationRecord("pkg", 2, "one", UserHandle.ALL); |
Julia Reynolds | 7967230 | 2017-01-12 08:30:16 -0500 | [diff] [blame] | 199 | mSnoozeHelper.snooze(r2, 1000); |
Julia Reynolds | b6c1f99 | 2016-11-22 09:26:46 -0500 | [diff] [blame] | 200 | mSnoozeHelper.repost(r.getKey(), UserHandle.USER_SYSTEM); |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 201 | verify(mCallback, times(1)).repost(UserHandle.USER_SYSTEM, r); |
| 202 | } |
| 203 | |
| 204 | @Test |
Julia Reynolds | 7967230 | 2017-01-12 08:30:16 -0500 | [diff] [blame] | 205 | public void testRepost_noUser() throws Exception { |
| 206 | NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); |
| 207 | mSnoozeHelper.snooze(r, 1000); |
| 208 | NotificationRecord r2 = getNotificationRecord("pkg", 2, "one", UserHandle.ALL); |
| 209 | mSnoozeHelper.snooze(r2, 1000); |
| 210 | mSnoozeHelper.repost(r.getKey()); |
| 211 | verify(mCallback, times(1)).repost(UserHandle.USER_SYSTEM, r); |
| 212 | } |
| 213 | |
| 214 | @Test |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 215 | public void testUpdate() throws Exception { |
| 216 | NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); |
Julia Reynolds | 7967230 | 2017-01-12 08:30:16 -0500 | [diff] [blame] | 217 | mSnoozeHelper.snooze(r , 1000); |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 218 | r.getNotification().category = "NEW CATEGORY"; |
| 219 | |
| 220 | mSnoozeHelper.update(UserHandle.USER_SYSTEM, r); |
| 221 | verify(mCallback, never()).repost(anyInt(), any(NotificationRecord.class)); |
| 222 | |
Julia Reynolds | b6c1f99 | 2016-11-22 09:26:46 -0500 | [diff] [blame] | 223 | mSnoozeHelper.repost(r.getKey(), UserHandle.USER_SYSTEM); |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 224 | verify(mCallback, times(1)).repost(UserHandle.USER_SYSTEM, r); |
| 225 | } |
| 226 | |
Julia Reynolds | cf63ff1 | 2017-01-24 13:55:48 -0500 | [diff] [blame] | 227 | @Test |
| 228 | public void testGetSnoozedByUser() throws Exception { |
| 229 | NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); |
| 230 | NotificationRecord r2 = getNotificationRecord("pkg", 2, "two", UserHandle.SYSTEM); |
| 231 | NotificationRecord r3 = getNotificationRecord("pkg2", 3, "three", UserHandle.SYSTEM); |
| 232 | NotificationRecord r4 = getNotificationRecord("pkg2", 3, "three", UserHandle.CURRENT); |
| 233 | mSnoozeHelper.snooze(r, 1000); |
| 234 | mSnoozeHelper.snooze(r2, 1000); |
| 235 | mSnoozeHelper.snooze(r3, 1000); |
| 236 | mSnoozeHelper.snooze(r4, 1000); |
| 237 | when(mUserProfiles.getCurrentProfileIds()).thenReturn( |
| 238 | new int[] {UserHandle.USER_SYSTEM}); |
| 239 | assertEquals(3, mSnoozeHelper.getSnoozed().size()); |
| 240 | when(mUserProfiles.getCurrentProfileIds()).thenReturn( |
| 241 | new int[] {UserHandle.USER_CURRENT}); |
| 242 | assertEquals(1, mSnoozeHelper.getSnoozed().size()); |
| 243 | } |
| 244 | |
| 245 | @Test |
| 246 | public void testGetSnoozedByUser_managedProfiles() throws Exception { |
| 247 | when(mUserProfiles.getCurrentProfileIds()).thenReturn( |
| 248 | new int[] {UserHandle.USER_SYSTEM, UserHandle.USER_CURRENT}); |
| 249 | NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); |
| 250 | NotificationRecord r2 = getNotificationRecord("pkg", 2, "two", UserHandle.SYSTEM); |
| 251 | NotificationRecord r3 = getNotificationRecord("pkg2", 3, "three", UserHandle.SYSTEM); |
| 252 | NotificationRecord r4 = getNotificationRecord("pkg2", 3, "three", UserHandle.CURRENT); |
| 253 | mSnoozeHelper.snooze(r, 1000); |
| 254 | mSnoozeHelper.snooze(r2, 1000); |
| 255 | mSnoozeHelper.snooze(r3, 1000); |
| 256 | mSnoozeHelper.snooze(r4, 1000); |
| 257 | assertEquals(4, mSnoozeHelper.getSnoozed().size()); |
| 258 | } |
| 259 | |
Julia Reynolds | a78cdff | 2017-04-26 10:19:25 -0400 | [diff] [blame] | 260 | @Test |
| 261 | public void repostGroupSummary_onlyFellowGroupChildren() throws Exception { |
| 262 | NotificationRecord r = getNotificationRecord( |
| 263 | "pkg", 1, "one", UserHandle.SYSTEM, "group1", false); |
| 264 | NotificationRecord r2 = getNotificationRecord( |
| 265 | "pkg", 2, "two", UserHandle.SYSTEM, "group1", false); |
| 266 | mSnoozeHelper.snooze(r, 1000); |
| 267 | mSnoozeHelper.snooze(r2, 1000); |
| 268 | mSnoozeHelper.repostGroupSummary("pkg", UserHandle.USER_SYSTEM, "group1"); |
| 269 | |
| 270 | verify(mCallback, never()).repost(UserHandle.USER_SYSTEM, r); |
| 271 | } |
| 272 | |
| 273 | @Test |
| 274 | public void repostGroupSummary_repostsSummary() throws Exception { |
| 275 | when(mUserProfiles.getCurrentProfileIds()).thenReturn( |
| 276 | new int[] {UserHandle.USER_SYSTEM}); |
| 277 | NotificationRecord r = getNotificationRecord( |
| 278 | "pkg", 1, "one", UserHandle.SYSTEM, "group1", true); |
| 279 | NotificationRecord r2 = getNotificationRecord( |
| 280 | "pkg", 2, "two", UserHandle.SYSTEM, "group1", false); |
| 281 | mSnoozeHelper.snooze(r, 1000); |
| 282 | mSnoozeHelper.snooze(r2, 1000); |
| 283 | assertEquals(2, mSnoozeHelper.getSnoozed().size()); |
| 284 | assertEquals(2, mSnoozeHelper.getSnoozed(UserHandle.USER_SYSTEM, "pkg").size()); |
| 285 | |
| 286 | mSnoozeHelper.repostGroupSummary("pkg", UserHandle.USER_SYSTEM, r.getGroupKey()); |
| 287 | |
| 288 | verify(mCallback, times(1)).repost(UserHandle.USER_SYSTEM, r); |
| 289 | verify(mCallback, never()).repost(UserHandle.USER_SYSTEM, r2); |
| 290 | |
| 291 | assertEquals(1, mSnoozeHelper.getSnoozed().size()); |
| 292 | assertEquals(1, mSnoozeHelper.getSnoozed(UserHandle.USER_SYSTEM, "pkg").size()); |
| 293 | } |
| 294 | |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 295 | private NotificationRecord getNotificationRecord(String pkg, int id, String tag, |
Julia Reynolds | a78cdff | 2017-04-26 10:19:25 -0400 | [diff] [blame] | 296 | UserHandle user, String groupKey, boolean groupSummary) { |
Geoffrey Pitsch | af759c5 | 2017-02-15 09:35:38 -0500 | [diff] [blame] | 297 | Notification n = new Notification.Builder(getContext(), TEST_CHANNEL_ID) |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 298 | .setContentTitle("A") |
| 299 | .setGroup("G") |
| 300 | .setSortKey("A") |
| 301 | .setWhen(1205) |
Julia Reynolds | a78cdff | 2017-04-26 10:19:25 -0400 | [diff] [blame] | 302 | .setGroup(groupKey) |
| 303 | .setGroupSummary(groupSummary) |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 304 | .build(); |
Geoffrey Pitsch | af759c5 | 2017-02-15 09:35:38 -0500 | [diff] [blame] | 305 | final NotificationChannel notificationChannel = new NotificationChannel( |
| 306 | TEST_CHANNEL_ID, "name", NotificationManager.IMPORTANCE_LOW); |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 307 | return new NotificationRecord(getContext(), new StatusBarNotification( |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 308 | pkg, pkg, id, tag, 0, 0, n, user, null, |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 309 | System.currentTimeMillis()), notificationChannel); |
Julia Reynolds | 423b9fc | 2016-11-09 09:51:08 -0500 | [diff] [blame] | 310 | } |
Julia Reynolds | a78cdff | 2017-04-26 10:19:25 -0400 | [diff] [blame] | 311 | |
| 312 | private NotificationRecord getNotificationRecord(String pkg, int id, String tag, |
| 313 | UserHandle user) { |
| 314 | return getNotificationRecord(pkg, id, tag, user, null, false); |
| 315 | } |
Julia Reynolds | 72f1cbb | 2016-09-19 14:57:31 -0400 | [diff] [blame] | 316 | } |