blob: f6328149b076d60d149a6452ec4cbb6a039b460b [file] [log] [blame]
Julia Reynoldsf8c53672017-10-04 16:09:29 -04001/**
2 * Copyright (C) 2017 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
17package android.ext.services.notification;
18
19import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
20import static android.app.NotificationManager.IMPORTANCE_LOW;
21import static android.app.NotificationManager.IMPORTANCE_MIN;
22
23import static org.mockito.ArgumentMatchers.any;
Julia Reynolds6a63d1b2018-08-14 16:59:33 -040024import static org.mockito.ArgumentMatchers.anyInt;
25import static org.mockito.ArgumentMatchers.anyString;
Julia Reynoldsf8c53672017-10-04 16:09:29 -040026import static org.mockito.Mockito.mock;
27import static org.mockito.Mockito.never;
28import static org.mockito.Mockito.times;
29import static org.mockito.Mockito.verify;
30import static org.mockito.Mockito.when;
31
Rohan Shah0350dab2018-05-04 13:42:18 -070032import android.app.Application;
Julia Reynoldsf8c53672017-10-04 16:09:29 -040033import android.app.INotificationManager;
34import android.app.Notification;
35import android.app.NotificationChannel;
36import android.content.Intent;
Julia Reynolds6a63d1b2018-08-14 16:59:33 -040037import android.content.pm.ApplicationInfo;
38import android.content.pm.IPackageManager;
39import android.os.Build;
Julia Reynoldsf8c53672017-10-04 16:09:29 -040040import android.os.UserHandle;
41import android.service.notification.Adjustment;
42import android.service.notification.NotificationListenerService;
43import android.service.notification.NotificationListenerService.Ranking;
44import android.service.notification.NotificationListenerService.RankingMap;
45import android.service.notification.NotificationStats;
46import android.service.notification.StatusBarNotification;
47import android.support.test.InstrumentationRegistry;
48import android.test.ServiceTestCase;
49import android.testing.TestableContext;
Julia Reynolds3d5b3c72017-11-07 09:04:58 -050050import android.util.AtomicFile;
Julia Reynolds3d5b3c72017-11-07 09:04:58 -050051
52import com.android.internal.util.FastXmlSerializer;
Julia Reynoldsf8c53672017-10-04 16:09:29 -040053
54import org.junit.Before;
55import org.junit.Rule;
56import org.junit.Test;
57import org.mockito.ArgumentCaptor;
58import org.mockito.Mock;
59import org.mockito.MockitoAnnotations;
Julia Reynolds3d5b3c72017-11-07 09:04:58 -050060import org.xmlpull.v1.XmlSerializer;
61
62import java.io.BufferedInputStream;
63import java.io.BufferedOutputStream;
64import java.io.ByteArrayInputStream;
65import java.io.ByteArrayOutputStream;
66import java.io.FileOutputStream;
Beverly067a7392018-10-17 15:35:57 -040067import java.util.ArrayList;
Julia Reynoldsf8c53672017-10-04 16:09:29 -040068
69public class AssistantTest extends ServiceTestCase<Assistant> {
70
71 private static final String PKG1 = "pkg1";
72 private static final int UID1 = 1;
73 private static final NotificationChannel P1C1 =
74 new NotificationChannel("one", "", IMPORTANCE_LOW);
75 private static final NotificationChannel P1C2 =
76 new NotificationChannel("p1c2", "", IMPORTANCE_DEFAULT);
77 private static final NotificationChannel P1C3 =
78 new NotificationChannel("p1c3", "", IMPORTANCE_MIN);
79 private static final String PKG2 = "pkg2";
80
81 private static final int UID2 = 2;
82 private static final NotificationChannel P2C1 =
83 new NotificationChannel("one", "", IMPORTANCE_LOW);
84
85 @Mock INotificationManager mNoMan;
Rohan Shah0350dab2018-05-04 13:42:18 -070086 @Mock AtomicFile mFile;
Milo Sredkov22b8d9e2018-11-27 15:52:10 +000087 @Mock IPackageManager mPackageManager;
Nadia Benbernou1ee91a32019-01-28 11:26:46 -050088 @Mock SmsHelper mSmsHelper;
Julia Reynoldsf8c53672017-10-04 16:09:29 -040089
90 Assistant mAssistant;
Rohan Shah0350dab2018-05-04 13:42:18 -070091 Application mApplication;
Julia Reynoldsf8c53672017-10-04 16:09:29 -040092
93 @Rule
94 public final TestableContext mContext =
95 new TestableContext(InstrumentationRegistry.getContext(), null);
96
97 public AssistantTest() {
98 super(Assistant.class);
99 }
100
101 @Before
102 public void setUp() throws Exception {
103 MockitoAnnotations.initMocks(this);
104
105 Intent startIntent =
106 new Intent("android.service.notification.NotificationAssistantService");
107 startIntent.setPackage("android.ext.services");
Rohan Shah0350dab2018-05-04 13:42:18 -0700108
Rohan Shah0350dab2018-05-04 13:42:18 -0700109 mApplication = (Application) InstrumentationRegistry.getInstrumentation().
110 getTargetContext().getApplicationContext();
111 // Force the test to use the correct application instead of trying to use a mock application
112 setApplication(mApplication);
Milo Sredkov22b8d9e2018-11-27 15:52:10 +0000113
114 setupService();
Julia Reynoldsf8c53672017-10-04 16:09:29 -0400115 mAssistant = getService();
Milo Sredkov22b8d9e2018-11-27 15:52:10 +0000116
117 // Override the AssistantSettings factory.
118 mAssistant.mSettingsFactory = AssistantSettings::createForTesting;
119
120 bindService(startIntent);
121
122 mAssistant.mSettings.mDismissToViewRatioLimit = 0.8f;
123 mAssistant.mSettings.mStreakLimit = 2;
124 mAssistant.mSettings.mNewInterruptionModel = true;
Julia Reynoldsf8c53672017-10-04 16:09:29 -0400125 mAssistant.setNoMan(mNoMan);
Julia Reynolds3d5b3c72017-11-07 09:04:58 -0500126 mAssistant.setFile(mFile);
Julia Reynolds6a63d1b2018-08-14 16:59:33 -0400127 mAssistant.setPackageManager(mPackageManager);
Milo Sredkov22b8d9e2018-11-27 15:52:10 +0000128
Julia Reynolds6a63d1b2018-08-14 16:59:33 -0400129 ApplicationInfo info = mock(ApplicationInfo.class);
130 when(mPackageManager.getApplicationInfo(anyString(), anyInt(), anyInt()))
131 .thenReturn(info);
132 info.targetSdkVersion = Build.VERSION_CODES.P;
Julia Reynolds3d5b3c72017-11-07 09:04:58 -0500133 when(mFile.startWrite()).thenReturn(mock(FileOutputStream.class));
Julia Reynoldsf8c53672017-10-04 16:09:29 -0400134 }
135
136 private StatusBarNotification generateSbn(String pkg, int uid, NotificationChannel channel,
137 String tag, String groupKey) {
138 Notification n = new Notification.Builder(mContext, channel.getId())
139 .setContentTitle("foo")
140 .setGroup(groupKey)
141 .build();
142
143 StatusBarNotification sbn = new StatusBarNotification(pkg, pkg, 0, tag, uid, uid, n,
144 UserHandle.SYSTEM, null, 0);
145
146 return sbn;
147 }
148
149 private Ranking generateRanking(StatusBarNotification sbn, NotificationChannel channel) {
150 Ranking mockRanking = mock(Ranking.class);
151 when(mockRanking.getChannel()).thenReturn(channel);
152 when(mockRanking.getImportance()).thenReturn(channel.getImportance());
153 when(mockRanking.getKey()).thenReturn(sbn.getKey());
154 when(mockRanking.getOverrideGroupKey()).thenReturn(null);
155 return mockRanking;
156 }
157
158 private void almostBlockChannel(String pkg, int uid, NotificationChannel channel) {
Rohan Shah0350dab2018-05-04 13:42:18 -0700159 for (int i = 0; i < ChannelImpressions.DEFAULT_STREAK_LIMIT; i++) {
Julia Reynoldsf8c53672017-10-04 16:09:29 -0400160 dismissBadNotification(pkg, uid, channel, String.valueOf(i));
161 }
162 }
163
164 private void dismissBadNotification(String pkg, int uid, NotificationChannel channel,
165 String tag) {
166 StatusBarNotification sbn = generateSbn(pkg, uid, channel, tag, null);
167 mAssistant.setFakeRanking(generateRanking(sbn, channel));
168 mAssistant.onNotificationPosted(sbn, mock(RankingMap.class));
169 mAssistant.setFakeRanking(mock(Ranking.class));
170 NotificationStats stats = new NotificationStats();
171 stats.setDismissalSurface(NotificationStats.DISMISSAL_SHADE);
172 stats.setSeen();
173 mAssistant.onNotificationRemoved(
174 sbn, mock(RankingMap.class), stats, NotificationListenerService.REASON_CANCEL);
175 }
176
177 @Test
178 public void testNoAdjustmentForInitialPost() throws Exception {
179 StatusBarNotification sbn = generateSbn(PKG1, UID1, P1C1, null, null);
180
181 mAssistant.setFakeRanking(generateRanking(sbn, P1C1));
182 mAssistant.onNotificationPosted(sbn, mock(RankingMap.class));
183
184 verify(mNoMan, never()).applyAdjustmentFromAssistant(any(), any());
185 }
186
187 @Test
188 public void testTriggerAdjustment() throws Exception {
189 almostBlockChannel(PKG1, UID1, P1C1);
190 dismissBadNotification(PKG1, UID1, P1C1, "trigger!");
191
192 StatusBarNotification sbn = generateSbn(PKG1, UID1, P1C1, "new one!", null);
193 mAssistant.setFakeRanking(generateRanking(sbn, P1C1));
194 mAssistant.onNotificationPosted(sbn, mock(RankingMap.class));
195
196 ArgumentCaptor<Adjustment> captor = ArgumentCaptor.forClass(Adjustment.class);
197 verify(mNoMan, times(1)).applyAdjustmentFromAssistant(any(), captor.capture());
198 assertEquals(sbn.getKey(), captor.getValue().getKey());
199 assertEquals(Ranking.USER_SENTIMENT_NEGATIVE,
200 captor.getValue().getSignals().getInt(Adjustment.KEY_USER_SENTIMENT));
201 }
202
203 @Test
204 public void testMinCannotTriggerAdjustment() throws Exception {
205 almostBlockChannel(PKG1, UID1, P1C3);
206 dismissBadNotification(PKG1, UID1, P1C3, "trigger!");
207
208 StatusBarNotification sbn = generateSbn(PKG1, UID1, P1C3, "new one!", null);
209 mAssistant.setFakeRanking(generateRanking(sbn, P1C3));
210 mAssistant.onNotificationPosted(sbn, mock(RankingMap.class));
211
212 verify(mNoMan, never()).applyAdjustmentFromAssistant(any(), any());
213 }
214
215 @Test
Julia Reynolds3d5b3c72017-11-07 09:04:58 -0500216 public void testGroupChildCanTriggerAdjustment() throws Exception {
Julia Reynoldsf8c53672017-10-04 16:09:29 -0400217 almostBlockChannel(PKG1, UID1, P1C1);
218
219 StatusBarNotification sbn = generateSbn(PKG1, UID1, P1C1, "no", "I HAVE A GROUP");
Julia Reynolds3d5b3c72017-11-07 09:04:58 -0500220 mAssistant.setFakeRanking(generateRanking(sbn, P1C1));
Julia Reynoldsf8c53672017-10-04 16:09:29 -0400221 NotificationStats stats = new NotificationStats();
222 stats.setDismissalSurface(NotificationStats.DISMISSAL_SHADE);
223 stats.setSeen();
Julia Reynolds3d5b3c72017-11-07 09:04:58 -0500224 mAssistant.onNotificationPosted(sbn, mock(RankingMap.class));
Julia Reynoldsf8c53672017-10-04 16:09:29 -0400225 mAssistant.onNotificationRemoved(
226 sbn, mock(RankingMap.class), stats, NotificationListenerService.REASON_CANCEL);
227
Julia Reynolds3d5b3c72017-11-07 09:04:58 -0500228 sbn = generateSbn(PKG1, UID1, P1C1, "new one!", "group");
229 mAssistant.onNotificationPosted(sbn, mock(RankingMap.class));
230
231 ArgumentCaptor<Adjustment> captor = ArgumentCaptor.forClass(Adjustment.class);
232 verify(mNoMan, times(1)).applyAdjustmentFromAssistant(any(), captor.capture());
233 assertEquals(sbn.getKey(), captor.getValue().getKey());
234 assertEquals(Ranking.USER_SENTIMENT_NEGATIVE,
235 captor.getValue().getSignals().getInt(Adjustment.KEY_USER_SENTIMENT));
236 }
237
238 @Test
239 public void testGroupSummaryCannotTriggerAdjustment() throws Exception {
240 almostBlockChannel(PKG1, UID1, P1C1);
241
242 StatusBarNotification sbn = generateSbn(PKG1, UID1, P1C1, "no", "I HAVE A GROUP");
243 sbn.getNotification().flags |= Notification.FLAG_GROUP_SUMMARY;
244 mAssistant.setFakeRanking(generateRanking(sbn, P1C1));
245 NotificationStats stats = new NotificationStats();
246 stats.setDismissalSurface(NotificationStats.DISMISSAL_SHADE);
247 stats.setSeen();
248 mAssistant.onNotificationPosted(sbn, mock(RankingMap.class));
249 mAssistant.onNotificationRemoved(
250 sbn, mock(RankingMap.class), stats, NotificationListenerService.REASON_CANCEL);
251
252 sbn = generateSbn(PKG1, UID1, P1C1, "new one!", "group");
Julia Reynoldsf8c53672017-10-04 16:09:29 -0400253 mAssistant.onNotificationPosted(sbn, mock(RankingMap.class));
254
255 verify(mNoMan, never()).applyAdjustmentFromAssistant(any(), any());
256 }
257
258 @Test
259 public void testAodCannotTriggerAdjustment() throws Exception {
260 almostBlockChannel(PKG1, UID1, P1C1);
261
262 StatusBarNotification sbn = generateSbn(PKG1, UID1, P1C1, "no", null);
Julia Reynolds3d5b3c72017-11-07 09:04:58 -0500263 mAssistant.setFakeRanking(generateRanking(sbn, P1C1));
Julia Reynoldsf8c53672017-10-04 16:09:29 -0400264 NotificationStats stats = new NotificationStats();
265 stats.setDismissalSurface(NotificationStats.DISMISSAL_AOD);
266 stats.setSeen();
Julia Reynolds3d5b3c72017-11-07 09:04:58 -0500267 mAssistant.onNotificationPosted(sbn, mock(RankingMap.class));
Julia Reynoldsf8c53672017-10-04 16:09:29 -0400268 mAssistant.onNotificationRemoved(
269 sbn, mock(RankingMap.class), stats, NotificationListenerService.REASON_CANCEL);
270
271 sbn = generateSbn(PKG1, UID1, P1C1, "new one!", null);
272 mAssistant.onNotificationPosted(sbn, mock(RankingMap.class));
273
274 verify(mNoMan, never()).applyAdjustmentFromAssistant(any(), any());
275 }
276
277 @Test
278 public void testInteractedCannotTriggerAdjustment() throws Exception {
279 almostBlockChannel(PKG1, UID1, P1C1);
Julia Reynoldsf8c53672017-10-04 16:09:29 -0400280 StatusBarNotification sbn = generateSbn(PKG1, UID1, P1C1, "no", null);
Julia Reynolds3d5b3c72017-11-07 09:04:58 -0500281 mAssistant.setFakeRanking(generateRanking(sbn, P1C1));
Julia Reynoldsf8c53672017-10-04 16:09:29 -0400282 NotificationStats stats = new NotificationStats();
283 stats.setDismissalSurface(NotificationStats.DISMISSAL_SHADE);
284 stats.setSeen();
285 stats.setExpanded();
Julia Reynolds3d5b3c72017-11-07 09:04:58 -0500286 mAssistant.onNotificationPosted(sbn, mock(RankingMap.class));
Julia Reynoldsf8c53672017-10-04 16:09:29 -0400287 mAssistant.onNotificationRemoved(
288 sbn, mock(RankingMap.class), stats, NotificationListenerService.REASON_CANCEL);
289
290 sbn = generateSbn(PKG1, UID1, P1C1, "new one!", null);
291 mAssistant.onNotificationPosted(sbn, mock(RankingMap.class));
292
293 verify(mNoMan, never()).applyAdjustmentFromAssistant(any(), any());
294 }
295
296 @Test
297 public void testAppDismissedCannotTriggerAdjustment() throws Exception {
298 almostBlockChannel(PKG1, UID1, P1C1);
299
300 StatusBarNotification sbn = generateSbn(PKG1, UID1, P1C1, "no", null);
Julia Reynolds3d5b3c72017-11-07 09:04:58 -0500301 mAssistant.setFakeRanking(generateRanking(sbn, P1C1));
Julia Reynoldsf8c53672017-10-04 16:09:29 -0400302 NotificationStats stats = new NotificationStats();
303 stats.setDismissalSurface(NotificationStats.DISMISSAL_SHADE);
304 stats.setSeen();
Julia Reynolds3d5b3c72017-11-07 09:04:58 -0500305 mAssistant.onNotificationPosted(sbn, mock(RankingMap.class));
Julia Reynoldsf8c53672017-10-04 16:09:29 -0400306 mAssistant.onNotificationRemoved(
307 sbn, mock(RankingMap.class), stats, NotificationListenerService.REASON_APP_CANCEL);
308
309 sbn = generateSbn(PKG1, UID1, P1C1, "new one!", null);
310 mAssistant.onNotificationPosted(sbn, mock(RankingMap.class));
311
312 verify(mNoMan, never()).applyAdjustmentFromAssistant(any(), any());
313 }
314
315 @Test
316 public void testAppSeparation() throws Exception {
317 almostBlockChannel(PKG1, UID1, P1C1);
318 dismissBadNotification(PKG1, UID1, P1C1, "trigger!");
319
320 StatusBarNotification sbn = generateSbn(PKG2, UID2, P2C1, "new app!", null);
321 mAssistant.setFakeRanking(generateRanking(sbn, P2C1));
322 mAssistant.onNotificationPosted(sbn, mock(RankingMap.class));
323
324 verify(mNoMan, never()).applyAdjustmentFromAssistant(any(), any());
325 }
326
327 @Test
328 public void testChannelSeparation() throws Exception {
329 almostBlockChannel(PKG1, UID1, P1C1);
330 dismissBadNotification(PKG1, UID1, P1C1, "trigger!");
331
332 StatusBarNotification sbn = generateSbn(PKG1, UID1, P1C2, "new app!", null);
333 mAssistant.setFakeRanking(generateRanking(sbn, P1C2));
334 mAssistant.onNotificationPosted(sbn, mock(RankingMap.class));
335
336 verify(mNoMan, never()).applyAdjustmentFromAssistant(any(), any());
337 }
Julia Reynolds3d5b3c72017-11-07 09:04:58 -0500338
339 @Test
340 public void testReadXml() throws Exception {
341 String key1 = mAssistant.getKey("pkg1", 1, "channel1");
342 int streak1 = 2;
343 int views1 = 5;
344 int dismiss1 = 9;
345
346 int streak1a = 3;
347 int views1a = 10;
348 int dismiss1a = 99;
349 String key1a = mAssistant.getKey("pkg1", 1, "channel1a");
350
351 int streak2 = 7;
352 int views2 = 77;
353 int dismiss2 = 777;
354 String key2 = mAssistant.getKey("pkg2", 2, "channel2");
355
Julia Reynoldsef934fd2018-02-01 14:39:17 -0500356 String xml = "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>"
357 + "<assistant version=\"1\">\n"
Julia Reynolds3d5b3c72017-11-07 09:04:58 -0500358 + "<impression-set key=\"" + key1 + "\" "
359 + "dismisses=\"" + dismiss1 + "\" views=\"" + views1
360 + "\" streak=\"" + streak1 + "\"/>\n"
361 + "<impression-set key=\"" + key1a + "\" "
362 + "dismisses=\"" + dismiss1a + "\" views=\"" + views1a
363 + "\" streak=\"" + streak1a + "\"/>\n"
364 + "<impression-set key=\"" + key2 + "\" "
365 + "dismisses=\"" + dismiss2 + "\" views=\"" + views2
366 + "\" streak=\"" + streak2 + "\"/>\n"
367 + "</assistant>\n";
368 mAssistant.readXml(new BufferedInputStream(new ByteArrayInputStream(xml.getBytes())));
369
370 ChannelImpressions c1 = mAssistant.getImpressions(key1);
371 assertEquals(2, c1.getStreak());
372 assertEquals(5, c1.getViews());
373 assertEquals(9, c1.getDismissals());
374
375 ChannelImpressions c1a = mAssistant.getImpressions(key1a);
376 assertEquals(3, c1a.getStreak());
377 assertEquals(10, c1a.getViews());
378 assertEquals(99, c1a.getDismissals());
379
380 ChannelImpressions c2 = mAssistant.getImpressions(key2);
381 assertEquals(7, c2.getStreak());
382 assertEquals(77, c2.getViews());
383 assertEquals(777, c2.getDismissals());
384 }
385
386 @Test
387 public void testRoundTripXml() throws Exception {
388 String key1 = mAssistant.getKey("pkg1", 1, "channel1");
Rohan Shah0350dab2018-05-04 13:42:18 -0700389 ChannelImpressions ci1 = new ChannelImpressions();
Julia Reynolds3d5b3c72017-11-07 09:04:58 -0500390 String key2 = mAssistant.getKey("pkg1", 1, "channel2");
391 ChannelImpressions ci2 = new ChannelImpressions();
392 for (int i = 0; i < 3; i++) {
393 ci2.incrementViews();
394 ci2.incrementDismissals();
395 }
396 ChannelImpressions ci3 = new ChannelImpressions();
397 String key3 = mAssistant.getKey("pkg3", 3, "channel2");
398 for (int i = 0; i < 9; i++) {
399 ci3.incrementViews();
400 if (i % 3 == 0) {
401 ci3.incrementDismissals();
402 }
403 }
404
405 mAssistant.insertImpressions(key1, ci1);
406 mAssistant.insertImpressions(key2, ci2);
407 mAssistant.insertImpressions(key3, ci3);
408
Julia Reynolds3d5b3c72017-11-07 09:04:58 -0500409 XmlSerializer serializer = new FastXmlSerializer();
410 ByteArrayOutputStream baos = new ByteArrayOutputStream();
411 serializer.setOutput(new BufferedOutputStream(baos), "utf-8");
412 mAssistant.writeXml(serializer);
413
414 Assistant assistant = new Assistant();
Milo Sredkov22b8d9e2018-11-27 15:52:10 +0000415 // onCreate is not invoked, so settings won't be initialised, unless we do it here.
416 assistant.mSettings = mAssistant.mSettings;
Julia Reynolds3d5b3c72017-11-07 09:04:58 -0500417 assistant.readXml(new BufferedInputStream(new ByteArrayInputStream(baos.toByteArray())));
418
419 assertEquals(ci1, assistant.getImpressions(key1));
420 assertEquals(ci2, assistant.getImpressions(key2));
421 assertEquals(ci3, assistant.getImpressions(key3));
422 }
423
Rohan Shah0350dab2018-05-04 13:42:18 -0700424 @Test
425 public void testSettingsProviderUpdate() {
Rohan Shah0350dab2018-05-04 13:42:18 -0700426 // Set up channels
427 String key = mAssistant.getKey("pkg1", 1, "channel1");
428 ChannelImpressions ci = new ChannelImpressions();
429 for (int i = 0; i < 3; i++) {
430 ci.incrementViews();
431 if (i % 2 == 0) {
432 ci.incrementDismissals();
433 }
434 }
435
436 mAssistant.insertImpressions(key, ci);
437
438 // With default values, the blocking helper shouldn't be triggered.
439 assertEquals(false, ci.shouldTriggerBlock());
440
441 // Update settings values.
Milo Sredkov22b8d9e2018-11-27 15:52:10 +0000442 mAssistant.mSettings.mDismissToViewRatioLimit = 0f;
443 mAssistant.mSettings.mStreakLimit = 0;
Rohan Shah0350dab2018-05-04 13:42:18 -0700444
445 // Notify for the settings values we updated.
Milo Sredkov22b8d9e2018-11-27 15:52:10 +0000446 mAssistant.mSettings.mOnUpdateRunnable.run();
Rohan Shah0350dab2018-05-04 13:42:18 -0700447
448 // With the new threshold, the blocking helper should be triggered.
449 assertEquals(true, ci.shouldTriggerBlock());
450 }
Julia Reynolds6a63d1b2018-08-14 16:59:33 -0400451
452 @Test
453 public void testTrimLiveNotifications() {
454 StatusBarNotification sbn = generateSbn(PKG1, UID1, P1C1, "no", null);
455 mAssistant.setFakeRanking(generateRanking(sbn, P1C1));
456
457 mAssistant.onNotificationPosted(sbn, mock(RankingMap.class));
458
459 assertTrue(mAssistant.mLiveNotifications.containsKey(sbn.getKey()));
460
461 mAssistant.onNotificationRemoved(
462 sbn, mock(RankingMap.class), new NotificationStats(), 0);
463
464 assertFalse(mAssistant.mLiveNotifications.containsKey(sbn.getKey()));
465 }
Beverly067a7392018-10-17 15:35:57 -0400466
467 @Test
468 public void testAssistantNeverIncreasesImportanceWhenSuggestingSilent() throws Exception {
469 StatusBarNotification sbn = generateSbn(PKG1, UID1, P1C3, "min notif!", null);
470 Adjustment adjust = mAssistant.createEnqueuedNotificationAdjustment(new NotificationEntry(
Nadia Benbernou1ee91a32019-01-28 11:26:46 -0500471 mPackageManager, sbn, P1C3, mSmsHelper), new ArrayList<>(), new ArrayList<>());
Beverly067a7392018-10-17 15:35:57 -0400472 assertEquals(IMPORTANCE_MIN, adjust.getSignals().getInt(Adjustment.KEY_IMPORTANCE));
473 }
Julia Reynoldsf8c53672017-10-04 16:09:29 -0400474}