blob: 703adf7a047f59846fabf889f965ebf855e06f17 [file] [log] [blame]
Geoffrey Pitschdf44b602017-02-03 13:31:50 -05001/*
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
Rohan Shah20790b82018-07-02 17:21:04 -070014 * limitations under the License
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050015 */
16
Rohan Shah20790b82018-07-02 17:21:04 -070017package com.android.systemui.statusbar.notification.row;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050018
Julia Reynoldsc65656a2018-02-12 09:55:14 -050019import static android.app.NotificationChannel.USER_LOCKED_IMPORTANCE;
Gus Prevas9abc5062018-10-31 16:11:04 -040020import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
Julia Reynolds437cdb12018-01-03 12:27:24 -050021import static android.app.NotificationManager.IMPORTANCE_LOW;
Julia Reynoldse0341482018-03-08 14:42:50 -050022import static android.app.NotificationManager.IMPORTANCE_MIN;
Julia Reynoldsc65656a2018-02-12 09:55:14 -050023import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
Julia Reynoldsf7321592017-05-24 16:09:19 -040024import static android.print.PrintManager.PRINT_SPOOLER_PACKAGE_NAME;
Gus Prevas9abc5062018-10-31 16:11:04 -040025import static android.provider.Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL;
Julia Reynolds437cdb12018-01-03 12:27:24 -050026import static android.view.View.GONE;
27import static android.view.View.VISIBLE;
Julia Reynoldsf7321592017-05-24 16:09:19 -040028
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050029import static junit.framework.Assert.assertEquals;
30import static junit.framework.Assert.assertFalse;
31import static junit.framework.Assert.assertTrue;
Julia Reynolds5a311932017-03-01 16:33:44 -050032
William Brockman75cf66a2018-12-21 13:25:01 -050033import static org.mockito.ArgumentMatchers.argThat;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050034import static org.mockito.Mockito.any;
35import static org.mockito.Mockito.anyBoolean;
36import static org.mockito.Mockito.anyInt;
37import static org.mockito.Mockito.anyString;
Rohan Shahda5dcdd2018-04-27 17:21:50 -070038import static org.mockito.Mockito.doCallRealMethod;
39import static org.mockito.Mockito.doNothing;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050040import static org.mockito.Mockito.eq;
41import static org.mockito.Mockito.mock;
42import static org.mockito.Mockito.never;
Rohan Shahda5dcdd2018-04-27 17:21:50 -070043import static org.mockito.Mockito.spy;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050044import static org.mockito.Mockito.times;
45import static org.mockito.Mockito.verify;
46import static org.mockito.Mockito.when;
47
48import android.app.INotificationManager;
Julia Reynolds3aedded2017-03-31 14:42:09 -040049import android.app.Notification;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050050import android.app.NotificationChannel;
51import android.app.NotificationChannelGroup;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050052import android.content.pm.ApplicationInfo;
53import android.content.pm.PackageInfo;
54import android.content.pm.PackageManager;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050055import android.graphics.drawable.Drawable;
Rohan Shahda5dcdd2018-04-27 17:21:50 -070056import android.os.IBinder;
Julia Reynolds3aedded2017-03-31 14:42:09 -040057import android.os.UserHandle;
Gus Prevas9abc5062018-10-31 16:11:04 -040058import android.provider.Settings;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050059import android.service.notification.StatusBarNotification;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050060import android.test.suitebuilder.annotation.SmallTest;
Jason Monk340b0e52017-03-08 14:57:56 -050061import android.testing.AndroidTestingRunner;
Julia Reynolds437cdb12018-01-03 12:27:24 -050062import android.testing.PollingCheck;
Rohan Shahca0447e2018-03-30 15:18:27 -070063import android.testing.TestableLooper;
Jason Monk340b0e52017-03-08 14:57:56 -050064import android.testing.UiThreadTest;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050065import android.view.LayoutInflater;
66import android.view.View;
67import android.widget.ImageView;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050068import android.widget.TextView;
Jason Monk340b0e52017-03-08 14:57:56 -050069
Rohan Shahda5dcdd2018-04-27 17:21:50 -070070import com.android.internal.logging.MetricsLogger;
Eyal Posenera9cf9c72018-12-18 16:23:54 +020071import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Rohan Shahca0447e2018-03-30 15:18:27 -070072import com.android.systemui.Dependency;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050073import com.android.systemui.R;
74import com.android.systemui.SysuiTestCase;
Ned Burns9512e0c2019-05-30 19:36:04 -040075import com.android.systemui.statusbar.notification.VisualStabilityManager;
Jason Monkba364322017-03-06 11:19:20 -050076
Gus Prevas9abc5062018-10-31 16:11:04 -040077import org.junit.After;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050078import org.junit.Before;
Rohan Shah524cf7b2018-03-15 14:40:02 -070079import org.junit.Rule;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050080import org.junit.Test;
Jason Monk340b0e52017-03-08 14:57:56 -050081import org.junit.runner.RunWith;
Julia Reynolds8ceb5792017-04-11 11:32:44 -040082import org.mockito.ArgumentCaptor;
Rohan Shah524cf7b2018-03-15 14:40:02 -070083import org.mockito.Mock;
84import org.mockito.junit.MockitoJUnit;
85import org.mockito.junit.MockitoRule;
Julia Reynolds3aedded2017-03-31 14:42:09 -040086
Evan Laird47dc4542019-04-24 15:10:52 -040087import java.util.HashSet;
88import java.util.Set;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050089import java.util.concurrent.CountDownLatch;
90
91@SmallTest
Jason Monk340b0e52017-03-08 14:57:56 -050092@RunWith(AndroidTestingRunner.class)
Rohan Shahca0447e2018-03-30 15:18:27 -070093@TestableLooper.RunWithLooper
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050094public class NotificationInfoTest extends SysuiTestCase {
95 private static final String TEST_PACKAGE_NAME = "test_package";
Julia Reynoldsf7321592017-05-24 16:09:19 -040096 private static final String TEST_SYSTEM_PACKAGE_NAME = PRINT_SPOOLER_PACKAGE_NAME;
Geoffrey Pitschd034d292017-05-12 11:59:20 -040097 private static final int TEST_UID = 1;
Rohan Shah63411fc2018-03-28 19:05:52 -070098 private static final int MULTIPLE_CHANNEL_COUNT = 2;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050099 private static final String TEST_CHANNEL = "test_channel";
100 private static final String TEST_CHANNEL_NAME = "TEST CHANNEL NAME";
101
Rohan Shahca0447e2018-03-30 15:18:27 -0700102 private TestableLooper mTestableLooper;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500103 private NotificationInfo mNotificationInfo;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500104 private NotificationChannel mNotificationChannel;
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500105 private NotificationChannel mDefaultNotificationChannel;
Evan Laird47dc4542019-04-24 15:10:52 -0400106 private Set<NotificationChannel> mNotificationChannelSet = new HashSet<>();
107 private Set<NotificationChannel> mDefaultNotificationChannelSet = new HashSet<>();
Julia Reynolds3aedded2017-03-31 14:42:09 -0400108 private StatusBarNotification mSbn;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500109
Will Brockmana399f022019-01-30 10:59:36 -0500110 @Rule
111 public MockitoRule mockito = MockitoJUnit.rule();
112 @Mock
113 private MetricsLogger mMetricsLogger;
114 @Mock
115 private INotificationManager mMockINotificationManager;
116 @Mock
117 private PackageManager mMockPackageManager;
118 @Mock
119 private NotificationBlockingHelperManager mBlockingHelperManager;
Ned Burns9512e0c2019-05-30 19:36:04 -0400120 @Mock
121 private VisualStabilityManager mVisualStabilityManager;
Rohan Shah524cf7b2018-03-15 14:40:02 -0700122
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500123 @Before
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500124 public void setUp() throws Exception {
Rohan Shah524cf7b2018-03-15 14:40:02 -0700125 mDependency.injectTestDependency(
126 NotificationBlockingHelperManager.class,
127 mBlockingHelperManager);
Rohan Shahca0447e2018-03-30 15:18:27 -0700128 mTestableLooper = TestableLooper.get(this);
129 mDependency.injectTestDependency(Dependency.BG_LOOPER, mTestableLooper.getLooper());
Rohan Shahda5dcdd2018-04-27 17:21:50 -0700130 mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500131 // Inflate the layout
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500132 final LayoutInflater layoutInflater = LayoutInflater.from(mContext);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500133 mNotificationInfo = (NotificationInfo) layoutInflater.inflate(R.layout.notification_info,
134 null);
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500135 mNotificationInfo.setGutsParent(mock(NotificationGuts.class));
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500136
137 // PackageManager must return a packageInfo and applicationInfo.
138 final PackageInfo packageInfo = new PackageInfo();
139 packageInfo.packageName = TEST_PACKAGE_NAME;
Julia Reynoldsf7321592017-05-24 16:09:19 -0400140 when(mMockPackageManager.getPackageInfo(eq(TEST_PACKAGE_NAME), anyInt()))
141 .thenReturn(packageInfo);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500142 final ApplicationInfo applicationInfo = new ApplicationInfo();
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400143 applicationInfo.uid = TEST_UID; // non-zero
Julia Reynolds268647a2018-10-25 16:54:27 -0400144 when(mMockPackageManager.getApplicationInfo(eq(TEST_PACKAGE_NAME), anyInt())).thenReturn(
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500145 applicationInfo);
Julia Reynoldsf7321592017-05-24 16:09:19 -0400146 final PackageInfo systemPackageInfo = new PackageInfo();
147 systemPackageInfo.packageName = TEST_SYSTEM_PACKAGE_NAME;
148 when(mMockPackageManager.getPackageInfo(eq(TEST_SYSTEM_PACKAGE_NAME), anyInt()))
149 .thenReturn(systemPackageInfo);
150 when(mMockPackageManager.getPackageInfo(eq("android"), anyInt()))
151 .thenReturn(packageInfo);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500152
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500153 // Package has one channel by default.
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500154 when(mMockINotificationManager.getNumNotificationChannelsForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400155 eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(1);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500156
157 // Some test channels.
158 mNotificationChannel = new NotificationChannel(
Julia Reynolds437cdb12018-01-03 12:27:24 -0500159 TEST_CHANNEL, TEST_CHANNEL_NAME, IMPORTANCE_LOW);
Evan Laird47dc4542019-04-24 15:10:52 -0400160 mNotificationChannelSet.add(mNotificationChannel);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500161 mDefaultNotificationChannel = new NotificationChannel(
162 NotificationChannel.DEFAULT_CHANNEL_ID, TEST_CHANNEL_NAME,
Julia Reynolds437cdb12018-01-03 12:27:24 -0500163 IMPORTANCE_LOW);
Evan Laird47dc4542019-04-24 15:10:52 -0400164 mDefaultNotificationChannelSet.add(mDefaultNotificationChannel);
Julia Reynolds33bef2c2017-09-05 11:07:18 -0400165 mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, TEST_UID, 0,
Julia Reynolds3aedded2017-03-31 14:42:09 -0400166 new Notification(), UserHandle.CURRENT, null, 0);
Gus Prevas9abc5062018-10-31 16:11:04 -0400167
168 Settings.Secure.putInt(mContext.getContentResolver(),
169 NOTIFICATION_NEW_INTERRUPTION_MODEL, 1);
170 }
171
172 @After
173 public void tearDown() {
174 Settings.Secure.putInt(mContext.getContentResolver(),
175 NOTIFICATION_NEW_INTERRUPTION_MODEL, 0);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500176 }
177
Julia Reynolds437cdb12018-01-03 12:27:24 -0500178 // TODO: if tests are taking too long replace this with something that makes the animation
179 // finish instantly.
180 private void waitForUndoButton() {
181 PollingCheck.waitFor(1000,
182 () -> VISIBLE == mNotificationInfo.findViewById(R.id.confirmation).getVisibility());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500183 }
Will Brockmana399f022019-01-30 10:59:36 -0500184
Gus Prevas533836a2018-09-24 17:15:32 -0400185 private void ensureNoUndoButton() {
186 PollingCheck.waitFor(1000,
187 () -> GONE == mNotificationInfo.findViewById(R.id.confirmation).getVisibility()
188 && !mNotificationInfo.isAnimating());
189 }
Will Brockmana399f022019-01-30 10:59:36 -0500190
Julia Reynolds437cdb12018-01-03 12:27:24 -0500191 private void waitForStopButton() {
192 PollingCheck.waitFor(1000,
193 () -> VISIBLE == mNotificationInfo.findViewById(R.id.prompt).getVisibility());
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500194 }
195
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500196 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500197 public void testBindNotification_SetsTextApplicationName() throws Exception {
198 when(mMockPackageManager.getApplicationLabel(any())).thenReturn("App Name");
Ned Burns9512e0c2019-05-30 19:36:04 -0400199 mNotificationInfo.bindNotification(
200 mMockPackageManager,
201 mMockINotificationManager,
202 mVisualStabilityManager,
203 TEST_PACKAGE_NAME,
204 mNotificationChannel,
205 mNotificationChannelSet,
206 mSbn,
207 null,
208 null,
209 null,
210 true,
211 false,
212 IMPORTANCE_DEFAULT,
213 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500214 final TextView textView = mNotificationInfo.findViewById(R.id.pkgname);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500215 assertTrue(textView.getText().toString().contains("App Name"));
Julia Reynoldse0341482018-03-08 14:42:50 -0500216 assertEquals(VISIBLE, mNotificationInfo.findViewById(R.id.header).getVisibility());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500217 }
218
219 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500220 public void testBindNotification_SetsPackageIcon() throws Exception {
221 final Drawable iconDrawable = mock(Drawable.class);
222 when(mMockPackageManager.getApplicationIcon(any(ApplicationInfo.class)))
223 .thenReturn(iconDrawable);
Ned Burns9512e0c2019-05-30 19:36:04 -0400224 mNotificationInfo.bindNotification(
225 mMockPackageManager,
226 mMockINotificationManager,
227 mVisualStabilityManager,
228 TEST_PACKAGE_NAME,
229 mNotificationChannel,
230 mNotificationChannelSet,
231 mSbn,
232 null,
233 null,
234 null,
235 true,
236 false,
237 IMPORTANCE_DEFAULT,
238 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500239 final ImageView iconView = mNotificationInfo.findViewById(R.id.pkgicon);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500240 assertEquals(iconDrawable, iconView.getDrawable());
241 }
242
243 @Test
Julia Reynolds268647a2018-10-25 16:54:27 -0400244 public void testBindNotification_noDelegate() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400245 mNotificationInfo.bindNotification(
246 mMockPackageManager,
247 mMockINotificationManager,
248 mVisualStabilityManager,
249 TEST_PACKAGE_NAME,
250 mNotificationChannel,
251 mNotificationChannelSet,
252 mSbn,
253 null,
254 null,
255 null,
256 true,
257 false,
258 IMPORTANCE_DEFAULT,
259 true);
Julia Reynolds268647a2018-10-25 16:54:27 -0400260 final TextView nameView = mNotificationInfo.findViewById(R.id.delegate_name);
261 assertEquals(GONE, nameView.getVisibility());
262 final TextView dividerView = mNotificationInfo.findViewById(R.id.pkg_divider);
263 assertEquals(GONE, dividerView.getVisibility());
264 }
265
266 @Test
267 public void testBindNotification_delegate() throws Exception {
268 mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, "other", 0, null, TEST_UID, 0,
269 new Notification(), UserHandle.CURRENT, null, 0);
270 final ApplicationInfo applicationInfo = new ApplicationInfo();
271 applicationInfo.uid = 7; // non-zero
272 when(mMockPackageManager.getApplicationInfo(eq("other"), anyInt())).thenReturn(
273 applicationInfo);
274 when(mMockPackageManager.getApplicationLabel(any())).thenReturn("Other");
275
Ned Burns9512e0c2019-05-30 19:36:04 -0400276 mNotificationInfo.bindNotification(
277 mMockPackageManager,
278 mMockINotificationManager,
279 mVisualStabilityManager,
280 TEST_PACKAGE_NAME,
281 mNotificationChannel,
282 mNotificationChannelSet,
283 mSbn,
284 null,
285 null,
286 null,
287 true,
288 false,
289 IMPORTANCE_DEFAULT,
290 true);
Julia Reynolds268647a2018-10-25 16:54:27 -0400291 final TextView nameView = mNotificationInfo.findViewById(R.id.delegate_name);
292 assertEquals(VISIBLE, nameView.getVisibility());
Julia Reynolds25b27f52019-04-24 11:58:38 -0400293 assertTrue(nameView.getText().toString().contains("Proxied"));
Julia Reynolds268647a2018-10-25 16:54:27 -0400294 final TextView dividerView = mNotificationInfo.findViewById(R.id.pkg_divider);
295 assertEquals(VISIBLE, dividerView.getVisibility());
296 }
297
298 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500299 public void testBindNotification_GroupNameHiddenIfNoGroup() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400300 mNotificationInfo.bindNotification(
301 mMockPackageManager,
302 mMockINotificationManager,
303 mVisualStabilityManager,
304 TEST_PACKAGE_NAME,
305 mNotificationChannel,
306 mNotificationChannelSet,
307 mSbn,
308 null,
309 null,
310 null,
311 true,
312 false,
313 IMPORTANCE_DEFAULT,
314 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500315 final TextView groupNameView = mNotificationInfo.findViewById(R.id.group_name);
316 assertEquals(GONE, groupNameView.getVisibility());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500317 }
318
319 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500320 public void testBindNotification_SetsGroupNameIfNonNull() throws Exception {
321 mNotificationChannel.setGroup("test_group_id");
322 final NotificationChannelGroup notificationChannelGroup =
323 new NotificationChannelGroup("test_group_id", "Test Group Name");
324 when(mMockINotificationManager.getNotificationChannelGroupForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400325 eq("test_group_id"), eq(TEST_PACKAGE_NAME), eq(TEST_UID)))
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500326 .thenReturn(notificationChannelGroup);
Ned Burns9512e0c2019-05-30 19:36:04 -0400327 mNotificationInfo.bindNotification(
328 mMockPackageManager,
329 mMockINotificationManager,
330 mVisualStabilityManager,
331 TEST_PACKAGE_NAME,
332 mNotificationChannel,
333 mNotificationChannelSet,
334 mSbn,
335 null,
336 null,
337 null,
338 true,
339 false,
340 IMPORTANCE_DEFAULT,
341 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500342 final TextView groupNameView = mNotificationInfo.findViewById(R.id.group_name);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500343 assertEquals(View.VISIBLE, groupNameView.getVisibility());
344 assertEquals("Test Group Name", groupNameView.getText());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500345 }
346
347 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500348 public void testBindNotification_SetsTextChannelName() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400349 mNotificationInfo.bindNotification(
350 mMockPackageManager,
351 mMockINotificationManager,
352 mVisualStabilityManager,
353 TEST_PACKAGE_NAME,
354 mNotificationChannel,
355 mNotificationChannelSet,
356 mSbn,
357 null,
358 null,
359 null,
360 true,
361 false,
362 IMPORTANCE_DEFAULT,
363 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500364 final TextView textView = mNotificationInfo.findViewById(R.id.channel_name);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500365 assertEquals(TEST_CHANNEL_NAME, textView.getText());
366 }
367
368 @Test
Geoffrey Pitsch1fbf66e2017-05-09 11:32:27 -0400369 public void testBindNotification_DefaultChannelDoesNotUseChannelName() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400370 mNotificationInfo.bindNotification(
371 mMockPackageManager,
372 mMockINotificationManager,
373 mVisualStabilityManager,
374 TEST_PACKAGE_NAME,
375 mDefaultNotificationChannel,
376 mDefaultNotificationChannelSet,
377 mSbn,
378 null,
379 null,
380 null,
381 true,
382 false,
383 IMPORTANCE_DEFAULT,
384 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500385 final TextView textView = mNotificationInfo.findViewById(R.id.channel_name);
386 assertEquals(GONE, textView.getVisibility());
Geoffrey Pitsch1fbf66e2017-05-09 11:32:27 -0400387 }
388
389 @Test
Rohan Shahdbd64e72018-03-28 14:46:50 -0700390 public void testBindNotification_DefaultChannelUsesChannelNameIfMoreChannelsExist()
391 throws Exception {
392 // Package has one channel by default.
393 when(mMockINotificationManager.getNumNotificationChannelsForPackage(
394 eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(10);
Ned Burns9512e0c2019-05-30 19:36:04 -0400395 mNotificationInfo.bindNotification(
396 mMockPackageManager,
397 mMockINotificationManager,
398 mVisualStabilityManager,
399 TEST_PACKAGE_NAME,
400 mDefaultNotificationChannel,
401 mDefaultNotificationChannelSet,
402 mSbn,
403 null,
404 null,
405 null,
406 true,
407 false,
408 IMPORTANCE_DEFAULT,
409 true);
Rohan Shahdbd64e72018-03-28 14:46:50 -0700410 final TextView textView = mNotificationInfo.findViewById(R.id.channel_name);
411 assertEquals(VISIBLE, textView.getVisibility());
412 }
413
414 @Test
Julia Reynolds437cdb12018-01-03 12:27:24 -0500415 public void testBindNotification_UnblockablePackageUsesChannelName() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400416 mNotificationInfo.bindNotification(
417 mMockPackageManager,
418 mMockINotificationManager,
419 mVisualStabilityManager,
420 TEST_PACKAGE_NAME,
421 mNotificationChannel,
422 mNotificationChannelSet,
423 mSbn,
424 null,
425 null,
426 null,
427 true,
428 true,
429 IMPORTANCE_DEFAULT,
430 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500431 final TextView textView = mNotificationInfo.findViewById(R.id.channel_name);
432 assertEquals(VISIBLE, textView.getVisibility());
Geoffrey Pitsch1fbf66e2017-05-09 11:32:27 -0400433 }
434
435 @Test
Julia Reynolds52a27372019-04-03 11:00:17 -0400436 public void testBindNotification_BlockLink_BlockingHelper() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400437 mNotificationInfo.bindNotification(
438 mMockPackageManager,
439 mMockINotificationManager,
440 mVisualStabilityManager,
441 TEST_PACKAGE_NAME,
442 mNotificationChannel,
443 mNotificationChannelSet,
444 mSbn,
445 null,
446 mock(NotificationInfo.OnSettingsClickListener.class),
447 null,
448 true,
449 false,
450 true /* isBlockingHelper */,
451 IMPORTANCE_DEFAULT,
452 true);
Julia Reynolds52a27372019-04-03 11:00:17 -0400453 final View block =
454 mNotificationInfo.findViewById(R.id.blocking_helper_turn_off_notifications);
Gus Prevas82ad0592018-11-28 14:27:40 -0500455 final View interruptivenessSettings = mNotificationInfo.findViewById(
Julia Reynolds52a27372019-04-03 11:00:17 -0400456 R.id.inline_controls);
Gus Prevas82ad0592018-11-28 14:27:40 -0500457 assertEquals(VISIBLE, block.getVisibility());
458 assertEquals(GONE, interruptivenessSettings.getVisibility());
459 }
460
461 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500462 public void testBindNotification_SetsOnClickListenerForSettings() throws Exception {
463 final CountDownLatch latch = new CountDownLatch(1);
Ned Burns9512e0c2019-05-30 19:36:04 -0400464 mNotificationInfo.bindNotification(
465 mMockPackageManager,
466 mMockINotificationManager,
467 mVisualStabilityManager,
468 TEST_PACKAGE_NAME,
469 mNotificationChannel,
470 mNotificationChannelSet,
471 mSbn,
472 null,
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500473 (View v, NotificationChannel c, int appUid) -> {
Julia Reynolds3aedded2017-03-31 14:42:09 -0400474 assertEquals(mNotificationChannel, c);
475 latch.countDown();
Ned Burns9512e0c2019-05-30 19:36:04 -0400476 },
477 null,
478 true,
479 false,
480 IMPORTANCE_DEFAULT,
481 true);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500482
Julia Reynolds437cdb12018-01-03 12:27:24 -0500483 final View settingsButton = mNotificationInfo.findViewById(R.id.info);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500484 settingsButton.performClick();
485 // Verify that listener was triggered.
486 assertEquals(0, latch.getCount());
487 }
488
489 @Test
Geoffrey Pitsch029a3fa2017-03-30 13:01:57 -0400490 public void testBindNotification_SettingsButtonInvisibleWhenNoClickListener() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400491 mNotificationInfo.bindNotification(
492 mMockPackageManager,
493 mMockINotificationManager,
494 mVisualStabilityManager,
495 TEST_PACKAGE_NAME,
496 mNotificationChannel,
497 mNotificationChannelSet,
498 mSbn,
499 null,
500 null,
501 null,
502 true,
503 false,
504 IMPORTANCE_DEFAULT,
505 true);
Julia Reynolds35765d82018-08-17 11:39:19 -0400506 final View settingsButton = mNotificationInfo.findViewById(R.id.info);
507 assertTrue(settingsButton.getVisibility() != View.VISIBLE);
508 }
509
510 @Test
511 public void testBindNotification_SettingsButtonInvisibleWhenDeviceUnprovisioned()
512 throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400513 mNotificationInfo.bindNotification(
514 mMockPackageManager,
515 mMockINotificationManager,
516 mVisualStabilityManager,
517 TEST_PACKAGE_NAME,
518 mNotificationChannel,
519 mNotificationChannelSet,
520 mSbn,
521 null,
Julia Reynolds35765d82018-08-17 11:39:19 -0400522 (View v, NotificationChannel c, int appUid) -> {
523 assertEquals(mNotificationChannel, c);
Ned Burns9512e0c2019-05-30 19:36:04 -0400524 },
525 null,
526 false,
527 false,
528 IMPORTANCE_DEFAULT,
529 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500530 final View settingsButton = mNotificationInfo.findViewById(R.id.info);
Geoffrey Pitsch029a3fa2017-03-30 13:01:57 -0400531 assertTrue(settingsButton.getVisibility() != View.VISIBLE);
532 }
533
534 @Test
Julia Reynolds437cdb12018-01-03 12:27:24 -0500535 public void testBindNotification_SettingsButtonReappearsAfterSecondBind() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400536 mNotificationInfo.bindNotification(
537 mMockPackageManager,
538 mMockINotificationManager,
539 mVisualStabilityManager,
540 TEST_PACKAGE_NAME,
541 mNotificationChannel,
542 mNotificationChannelSet,
543 mSbn,
544 null,
545 null,
546 null,
547 true,
548 false,
549 IMPORTANCE_DEFAULT,
550 true);
551 mNotificationInfo.bindNotification(
552 mMockPackageManager,
553 mMockINotificationManager,
554 mVisualStabilityManager,
555 TEST_PACKAGE_NAME,
556 mNotificationChannel,
557 mNotificationChannelSet,
558 mSbn,
559 null,
560 (View v, NotificationChannel c, int appUid) -> { },
561 null,
562 true,
563 false,
564 IMPORTANCE_DEFAULT,
565 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500566 final View settingsButton = mNotificationInfo.findViewById(R.id.info);
Geoffrey Pitsch029a3fa2017-03-30 13:01:57 -0400567 assertEquals(View.VISIBLE, settingsButton.getVisibility());
568 }
569
570 @Test
Will Brockmana399f022019-01-30 10:59:36 -0500571 public void testBindNotificationLogging_notBlockingHelper() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400572 mNotificationInfo.bindNotification(
573 mMockPackageManager,
574 mMockINotificationManager,
575 mVisualStabilityManager,
576 TEST_PACKAGE_NAME,
577 mNotificationChannel,
578 mNotificationChannelSet,
579 mSbn,
580 null,
581 null,
582 null,
583 true,
584 false,
585 IMPORTANCE_DEFAULT,
586 true);
Eyal Posenera9cf9c72018-12-18 16:23:54 +0200587 verify(mMetricsLogger).write(argThat(logMaker ->
Will Brockmana399f022019-01-30 10:59:36 -0500588 logMaker.getCategory() == MetricsEvent.ACTION_NOTE_CONTROLS
589 && logMaker.getType() == MetricsEvent.TYPE_OPEN
590 && logMaker.getSubtype() == MetricsEvent.BLOCKING_HELPER_UNKNOWN
591 ));
592 }
593
594 @Test
595 public void testBindNotificationLogging_BlockingHelper() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400596 mNotificationInfo.bindNotification(
597 mMockPackageManager,
598 mMockINotificationManager,
599 mVisualStabilityManager,
600 TEST_PACKAGE_NAME,
601 mNotificationChannel,
602 mNotificationChannelSet,
603 mSbn,
604 null,
605 null,
606 null,
607 false,
Julia Reynolds52a27372019-04-03 11:00:17 -0400608 true,
Ned Burns9512e0c2019-05-30 19:36:04 -0400609 true,
610 IMPORTANCE_DEFAULT,
611 true);
Will Brockmana399f022019-01-30 10:59:36 -0500612 verify(mMetricsLogger).write(argThat(logMaker ->
613 logMaker.getCategory() == MetricsEvent.ACTION_NOTE_CONTROLS
Eyal Poseneraea29ed2019-01-24 09:54:08 +0200614 && logMaker.getType() == MetricsEvent.TYPE_OPEN
Eyal Posenera9cf9c72018-12-18 16:23:54 +0200615 && logMaker.getSubtype() == MetricsEvent.BLOCKING_HELPER_DISPLAY
616 ));
Rohan Shahda5dcdd2018-04-27 17:21:50 -0700617 }
618
619 @Test
620 public void testLogBlockingHelperCounter_logsForBlockingHelper() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400621 mNotificationInfo.bindNotification(
622 mMockPackageManager,
623 mMockINotificationManager,
624 mVisualStabilityManager,
625 TEST_PACKAGE_NAME,
626 mNotificationChannel,
627 mNotificationChannelSet,
628 mSbn,
629 null,
630 null,
631 null,
632 false,
Julia Reynolds52a27372019-04-03 11:00:17 -0400633 true,
Ned Burns9512e0c2019-05-30 19:36:04 -0400634 true,
635 IMPORTANCE_DEFAULT,
636 true);
Rohan Shahda5dcdd2018-04-27 17:21:50 -0700637 mNotificationInfo.logBlockingHelperCounter("HowCanNotifsBeRealIfAppsArent");
William Brockman75cf66a2018-12-21 13:25:01 -0500638 verify(mMetricsLogger).count(eq("HowCanNotifsBeRealIfAppsArent"), eq(1));
Rohan Shahda5dcdd2018-04-27 17:21:50 -0700639 }
640
641 @Test
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500642 public void testOnClickListenerPassesNullChannelForBundle() throws Exception {
643 final CountDownLatch latch = new CountDownLatch(1);
Ned Burns9512e0c2019-05-30 19:36:04 -0400644 mNotificationInfo.bindNotification(
645 mMockPackageManager,
646 mMockINotificationManager,
647 mVisualStabilityManager,
Evan Laird47dc4542019-04-24 15:10:52 -0400648 TEST_PACKAGE_NAME, mNotificationChannel,
Ned Burns9512e0c2019-05-30 19:36:04 -0400649 createMultipleChannelSet(MULTIPLE_CHANNEL_COUNT),
650 mSbn,
651 null,
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500652 (View v, NotificationChannel c, int appUid) -> {
Julia Reynolds3aedded2017-03-31 14:42:09 -0400653 assertEquals(null, c);
654 latch.countDown();
Ned Burns9512e0c2019-05-30 19:36:04 -0400655 },
656 null,
657 true,
658 true,
659 IMPORTANCE_DEFAULT,
660 true);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500661
Julia Reynolds437cdb12018-01-03 12:27:24 -0500662 mNotificationInfo.findViewById(R.id.info).performClick();
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500663 // Verify that listener was triggered.
664 assertEquals(0, latch.getCount());
665 }
666
667 @Test
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500668 @UiThreadTest
Julia Reynolds437cdb12018-01-03 12:27:24 -0500669 public void testBindNotification_ChannelNameInvisibleWhenBundleFromDifferentChannels()
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500670 throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400671 mNotificationInfo.bindNotification(
672 mMockPackageManager,
673 mMockINotificationManager,
674 mVisualStabilityManager,
675 TEST_PACKAGE_NAME,
676 mNotificationChannel,
677 createMultipleChannelSet(MULTIPLE_CHANNEL_COUNT),
678 mSbn,
679 null,
680 null,
681 null,
682 true,
683 false,
684 IMPORTANCE_DEFAULT,
685 true);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500686 final TextView channelNameView =
Julia Reynolds437cdb12018-01-03 12:27:24 -0500687 mNotificationInfo.findViewById(R.id.channel_name);
688 assertEquals(GONE, channelNameView.getVisibility());
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500689 }
690
691 @Test
692 @UiThreadTest
Julia Reynolds437cdb12018-01-03 12:27:24 -0500693 public void testStopInvisibleIfBundleFromDifferentChannels() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400694 mNotificationInfo.bindNotification(
695 mMockPackageManager,
696 mMockINotificationManager,
697 mVisualStabilityManager,
698 TEST_PACKAGE_NAME,
699 mNotificationChannel,
700 createMultipleChannelSet(MULTIPLE_CHANNEL_COUNT),
701 mSbn,
702 null,
703 null,
704 null,
705 true,
706 false,
707 IMPORTANCE_DEFAULT,
708 true);
Julia Reynolds52a27372019-04-03 11:00:17 -0400709 assertEquals(GONE, mNotificationInfo.findViewById(
710 R.id.interruptiveness_settings).getVisibility());
711 assertEquals(VISIBLE, mNotificationInfo.findViewById(
712 R.id.non_configurable_multichannel_text).getVisibility());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500713 }
714
715 @Test
Julia Reynolds52a27372019-04-03 11:00:17 -0400716 public void testBindNotification_whenAppUnblockable() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400717 mNotificationInfo.bindNotification(
718 mMockPackageManager,
719 mMockINotificationManager,
720 mVisualStabilityManager,
721 TEST_PACKAGE_NAME,
722 mNotificationChannel,
723 mNotificationChannelSet,
724 mSbn,
725 null,
726 null,
727 null,
728 true,
729 true,
730 IMPORTANCE_DEFAULT,
731 true);
Julia Reynolds52a27372019-04-03 11:00:17 -0400732 final TextView view = mNotificationInfo.findViewById(R.id.non_configurable_text);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500733 assertEquals(View.VISIBLE, view.getVisibility());
Geoffrey Pitschb43486a2017-06-01 13:45:59 -0400734 assertEquals(mContext.getString(R.string.notification_unblockable_desc),
Julia Reynolds437cdb12018-01-03 12:27:24 -0500735 view.getText());
Julia Reynolds52a27372019-04-03 11:00:17 -0400736 assertEquals(GONE,
737 mNotificationInfo.findViewById(R.id.interruptiveness_settings).getVisibility());
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500738 }
739
740 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500741 public void testBindNotification_DoesNotUpdateNotificationChannel() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400742 mNotificationInfo.bindNotification(
743 mMockPackageManager,
744 mMockINotificationManager,
745 mVisualStabilityManager,
746 TEST_PACKAGE_NAME,
747 mNotificationChannel,
748 mNotificationChannelSet,
749 mSbn,
750 null,
751 null,
752 null,
753 true,
754 false,
755 IMPORTANCE_DEFAULT,
756 true);
Rohan Shahca0447e2018-03-30 15:18:27 -0700757 mTestableLooper.processAllMessages();
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500758 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400759 anyString(), eq(TEST_UID), any());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500760 }
761
762 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500763 public void testDoesNotUpdateNotificationChannelAfterImportanceChanged() throws Exception {
Julia Reynolds437cdb12018-01-03 12:27:24 -0500764 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Ned Burns9512e0c2019-05-30 19:36:04 -0400765 mNotificationInfo.bindNotification(
766 mMockPackageManager,
767 mMockINotificationManager,
768 mVisualStabilityManager,
769 TEST_PACKAGE_NAME,
770 mNotificationChannel,
771 mNotificationChannelSet,
772 mSbn,
773 null,
774 null,
775 null,
776 true,
777 false,
778 IMPORTANCE_LOW,
779 false);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500780
Julia Reynolds8728d002019-04-19 15:46:13 -0400781 mNotificationInfo.findViewById(R.id.alert).performClick();
Rohan Shahca0447e2018-03-30 15:18:27 -0700782 mTestableLooper.processAllMessages();
Julia Reynoldse0341482018-03-08 14:42:50 -0500783 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
784 anyString(), eq(TEST_UID), any());
785 }
786
787 @Test
Gus Prevas9abc5062018-10-31 16:11:04 -0400788 public void testDoesNotUpdateNotificationChannelAfterImportanceChangedSilenced()
789 throws Exception {
790 mNotificationChannel.setImportance(IMPORTANCE_DEFAULT);
Ned Burns9512e0c2019-05-30 19:36:04 -0400791 mNotificationInfo.bindNotification(
792 mMockPackageManager,
793 mMockINotificationManager,
794 mVisualStabilityManager,
795 TEST_PACKAGE_NAME,
796 mNotificationChannel,
797 mNotificationChannelSet,
798 mSbn,
799 null,
800 null,
801 null,
802 true,
803 false,
804 IMPORTANCE_DEFAULT,
805 true);
Gus Prevas9abc5062018-10-31 16:11:04 -0400806
Julia Reynolds8728d002019-04-19 15:46:13 -0400807 mNotificationInfo.findViewById(R.id.silence).performClick();
Gus Prevas9abc5062018-10-31 16:11:04 -0400808 mTestableLooper.processAllMessages();
809 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
810 anyString(), eq(TEST_UID), any());
811 }
812
813 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500814 public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnchanged()
815 throws Exception {
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500816 int originalImportance = mNotificationChannel.getImportance();
Ned Burns9512e0c2019-05-30 19:36:04 -0400817 mNotificationInfo.bindNotification(
818 mMockPackageManager,
819 mMockINotificationManager,
820 mVisualStabilityManager,
821 TEST_PACKAGE_NAME,
822 mNotificationChannel,
823 mNotificationChannelSet,
824 mSbn,
825 null,
826 null,
827 null,
828 true,
829 false,
830 IMPORTANCE_DEFAULT,
831 true);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500832
Mady Mellorc2dbe492017-03-30 13:22:03 -0700833 mNotificationInfo.handleCloseControls(true, false);
Rohan Shahca0447e2018-03-30 15:18:27 -0700834 mTestableLooper.processAllMessages();
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500835 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400836 anyString(), eq(TEST_UID), any());
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500837 assertEquals(originalImportance, mNotificationChannel.getImportance());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500838 }
839
840 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500841 public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnspecified()
842 throws Exception {
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500843 mNotificationChannel.setImportance(IMPORTANCE_UNSPECIFIED);
Ned Burns9512e0c2019-05-30 19:36:04 -0400844 mNotificationInfo.bindNotification(
845 mMockPackageManager,
846 mMockINotificationManager,
847 mVisualStabilityManager,
848 TEST_PACKAGE_NAME,
849 mNotificationChannel,
850 mNotificationChannelSet,
851 mSbn,
852 null,
853 null,
854 null,
855 true,
856 false,
857 IMPORTANCE_UNSPECIFIED,
858 true);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500859
Mady Mellorc2dbe492017-03-30 13:22:03 -0700860 mNotificationInfo.handleCloseControls(true, false);
Rohan Shahca0447e2018-03-30 15:18:27 -0700861
862 mTestableLooper.processAllMessages();
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500863 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400864 anyString(), eq(TEST_UID), any());
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500865 assertEquals(IMPORTANCE_UNSPECIFIED, mNotificationChannel.getImportance());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500866 }
867
868 @Test
Will Brockmana399f022019-01-30 10:59:36 -0500869 public void testCloseControls_nonNullCheckSaveListenerDoesntDelayKeepShowing_BlockingHelper()
Rohan Shahdd588c72018-05-09 20:32:15 -0700870 throws Exception {
871 NotificationInfo.CheckSaveListener listener =
872 mock(NotificationInfo.CheckSaveListener.class);
Julia Reynolds8728d002019-04-19 15:46:13 -0400873 mNotificationChannel.setImportance(IMPORTANCE_DEFAULT);
Ned Burns9512e0c2019-05-30 19:36:04 -0400874 mNotificationInfo.bindNotification(
875 mMockPackageManager,
876 mMockINotificationManager,
877 mVisualStabilityManager,
878 TEST_PACKAGE_NAME,
879 mNotificationChannel /* notificationChannel */,
880 createMultipleChannelSet(10) /* numUniqueChannelsInRow */,
881 mSbn,
Evan Laird47dc4542019-04-24 15:10:52 -0400882 listener /* checkSaveListener */,
Ned Burns9512e0c2019-05-30 19:36:04 -0400883 null /* onSettingsClick */,
884 null /* onAppSettingsClick */,
885 true /* provisioned */,
886 false /* isNonblockable */,
887 true /* isForBlockingHelper */,
888 IMPORTANCE_DEFAULT,
889 true);
Rohan Shahdd588c72018-05-09 20:32:15 -0700890
891 NotificationGuts guts = spy(new NotificationGuts(mContext, null));
892 when(guts.getWindowToken()).thenReturn(mock(IBinder.class));
893 doNothing().when(guts).animateClose(anyInt(), anyInt(), anyBoolean());
894 doNothing().when(guts).setExposed(anyBoolean(), anyBoolean());
895 guts.setGutsContent(mNotificationInfo);
896 mNotificationInfo.setGutsParent(guts);
897
Julia Reynolds52a27372019-04-03 11:00:17 -0400898 mNotificationInfo.findViewById(R.id.keep_showing).performClick();
Rohan Shahdd588c72018-05-09 20:32:15 -0700899
900 verify(mBlockingHelperManager).dismissCurrentBlockingHelper();
901 mTestableLooper.processAllMessages();
902 verify(mMockINotificationManager, times(1))
903 .setNotificationsEnabledWithImportanceLockForPackage(
904 anyString(), eq(TEST_UID), eq(true));
905 }
906
Rohan Shah593e8f12018-05-22 10:06:23 -0700907 @Test
Will Brockmana399f022019-01-30 10:59:36 -0500908 public void testCloseControls_nonNullCheckSaveListenerDoesntDelayDismiss_BlockingHelper()
Rohan Shah593e8f12018-05-22 10:06:23 -0700909 throws Exception {
910 NotificationInfo.CheckSaveListener listener =
911 mock(NotificationInfo.CheckSaveListener.class);
Julia Reynolds8728d002019-04-19 15:46:13 -0400912 mNotificationChannel.setImportance(IMPORTANCE_DEFAULT);
Ned Burns9512e0c2019-05-30 19:36:04 -0400913 mNotificationInfo.bindNotification(
914 mMockPackageManager,
915 mMockINotificationManager,
916 mVisualStabilityManager,
917 TEST_PACKAGE_NAME,
918 mNotificationChannel /* notificationChannel */,
919 createMultipleChannelSet(10) /* numUniqueChannelsInRow */,
920 mSbn,
Evan Laird47dc4542019-04-24 15:10:52 -0400921 listener /* checkSaveListener */,
Ned Burns9512e0c2019-05-30 19:36:04 -0400922 null /* onSettingsClick */,
923 null /* onAppSettingsClick */,
924 false /* isNonblockable */,
925 true /* isForBlockingHelper */,
926 true, IMPORTANCE_DEFAULT,
927 true);
Rohan Shah593e8f12018-05-22 10:06:23 -0700928
929 mNotificationInfo.handleCloseControls(true /* save */, false /* force */);
930
931 mTestableLooper.processAllMessages();
932 verify(listener, times(0)).checkSave(any(Runnable.class), eq(mSbn));
933 }
934
935 @Test
Will Brockmana399f022019-01-30 10:59:36 -0500936 public void testCloseControls_checkSaveListenerDelaysStopNotifications_BlockingHelper()
Rohan Shah593e8f12018-05-22 10:06:23 -0700937 throws Exception {
938 NotificationInfo.CheckSaveListener listener =
939 mock(NotificationInfo.CheckSaveListener.class);
Julia Reynolds8728d002019-04-19 15:46:13 -0400940 mNotificationChannel.setImportance(IMPORTANCE_DEFAULT);
Ned Burns9512e0c2019-05-30 19:36:04 -0400941 mNotificationInfo.bindNotification(
942 mMockPackageManager,
943 mMockINotificationManager,
944 mVisualStabilityManager,
945 TEST_PACKAGE_NAME,
946 mNotificationChannel /* notificationChannel */,
947 createMultipleChannelSet(10) /* numUniqueChannelsInRow */,
948 mSbn,
Evan Laird47dc4542019-04-24 15:10:52 -0400949 listener /* checkSaveListener */,
Ned Burns9512e0c2019-05-30 19:36:04 -0400950 null /* onSettingsClick */,
951 null /* onAppSettingsClick */,
Julia Reynolds35765d82018-08-17 11:39:19 -0400952 true /* provisioned */,
Ned Burns9512e0c2019-05-30 19:36:04 -0400953 false /* isNonblockable */,
954 true /* isForBlockingHelper */,
955 IMPORTANCE_DEFAULT,
956 true);
Rohan Shah593e8f12018-05-22 10:06:23 -0700957
Julia Reynolds52a27372019-04-03 11:00:17 -0400958 mNotificationInfo.findViewById(R.id.deliver_silently).performClick();
Rohan Shah593e8f12018-05-22 10:06:23 -0700959 mTestableLooper.processAllMessages();
960 verify(listener).checkSave(any(Runnable.class), eq(mSbn));
961 }
Rohan Shahdd588c72018-05-09 20:32:15 -0700962
Rohan Shah590e1b22018-04-10 23:48:47 -0400963 @Test
Rohan Shah524cf7b2018-03-15 14:40:02 -0700964 public void testCloseControls_blockingHelperDismissedIfShown() throws Exception {
Julia Reynolds8728d002019-04-19 15:46:13 -0400965 mNotificationChannel.setImportance(IMPORTANCE_DEFAULT);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700966 mNotificationInfo.bindNotification(
967 mMockPackageManager,
968 mMockINotificationManager,
Ned Burns9512e0c2019-05-30 19:36:04 -0400969 mVisualStabilityManager,
Rohan Shah524cf7b2018-03-15 14:40:02 -0700970 TEST_PACKAGE_NAME,
971 mNotificationChannel,
Evan Laird47dc4542019-04-24 15:10:52 -0400972 mNotificationChannelSet /* numChannels */,
Rohan Shah524cf7b2018-03-15 14:40:02 -0700973 mSbn,
974 null /* checkSaveListener */,
975 null /* onSettingsClick */,
976 null /* onAppSettingsClick */,
Rohan Shah63411fc2018-03-28 19:05:52 -0700977 false /* isNonblockable */,
Rohan Shah524cf7b2018-03-15 14:40:02 -0700978 true /* isForBlockingHelper */,
Julia Reynolds35765d82018-08-17 11:39:19 -0400979 true,
Ned Burns9512e0c2019-05-30 19:36:04 -0400980 IMPORTANCE_DEFAULT,
981 true);
Rohan Shahda5dcdd2018-04-27 17:21:50 -0700982 NotificationGuts guts = mock(NotificationGuts.class);
983 doCallRealMethod().when(guts).closeControls(anyInt(), anyInt(), anyBoolean(), anyBoolean());
984 mNotificationInfo.setGutsParent(guts);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700985
Evan Laird7956fe82019-05-30 17:14:57 -0400986 mNotificationInfo.closeControls(mNotificationInfo, true);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700987
988 verify(mBlockingHelperManager).dismissCurrentBlockingHelper();
989 }
990
991 @Test
Nadia Benbernou3b4a93a2019-02-06 16:16:47 -0500992 public void testSilentlyChangedCallsUpdateNotificationChannel_blockingHelper()
993 throws Exception {
Julia Reynolds8728d002019-04-19 15:46:13 -0400994 mNotificationChannel.setImportance(IMPORTANCE_DEFAULT);
Nadia Benbernou3b4a93a2019-02-06 16:16:47 -0500995 mNotificationInfo.bindNotification(
996 mMockPackageManager,
997 mMockINotificationManager,
Ned Burns9512e0c2019-05-30 19:36:04 -0400998 mVisualStabilityManager,
Nadia Benbernou3b4a93a2019-02-06 16:16:47 -0500999 TEST_PACKAGE_NAME,
1000 mNotificationChannel,
Evan Laird47dc4542019-04-24 15:10:52 -04001001 mNotificationChannelSet /* numChannels */,
Nadia Benbernou3b4a93a2019-02-06 16:16:47 -05001002 mSbn,
1003 null /* checkSaveListener */,
1004 null /* onSettingsClick */,
1005 null /* onAppSettingsClick */,
1006 true /*provisioned */,
1007 false /* isNonblockable */,
1008 true /* isForBlockingHelper */,
Nadia Benbernou3b4a93a2019-02-06 16:16:47 -05001009 IMPORTANCE_DEFAULT,
Julia Reynolds8728d002019-04-19 15:46:13 -04001010 true);
Nadia Benbernou3b4a93a2019-02-06 16:16:47 -05001011
1012 mNotificationInfo.findViewById(R.id.deliver_silently).performClick();
1013 waitForUndoButton();
1014 mNotificationInfo.handleCloseControls(true, false);
1015
1016 mTestableLooper.processAllMessages();
1017 ArgumentCaptor<NotificationChannel> updated =
1018 ArgumentCaptor.forClass(NotificationChannel.class);
1019 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
1020 anyString(), eq(TEST_UID), updated.capture());
1021 assertTrue((updated.getValue().getUserLockedFields()
1022 & USER_LOCKED_IMPORTANCE) != 0);
1023 assertEquals(IMPORTANCE_LOW, updated.getValue().getImportance());
1024 }
1025
1026 @Test
Julia Reynolds52a27372019-04-03 11:00:17 -04001027 public void testKeepUpdatesNotificationChannel_blockingHelper() throws Exception {
Julia Reynolds437cdb12018-01-03 12:27:24 -05001028 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Ned Burns9512e0c2019-05-30 19:36:04 -04001029 mNotificationInfo.bindNotification(
1030 mMockPackageManager,
1031 mMockINotificationManager,
1032 mVisualStabilityManager,
1033 TEST_PACKAGE_NAME,
1034 mNotificationChannel,
1035 mNotificationChannelSet,
1036 mSbn,
1037 null,
1038 null,
1039 null,
1040 true,
1041 true,
1042 IMPORTANCE_LOW,
1043 false);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -05001044
Julia Reynolds52a27372019-04-03 11:00:17 -04001045 mNotificationInfo.findViewById(R.id.keep_showing).performClick();
Julia Reynoldsc65656a2018-02-12 09:55:14 -05001046 mNotificationInfo.handleCloseControls(true, false);
1047
Rohan Shahca0447e2018-03-30 15:18:27 -07001048 mTestableLooper.processAllMessages();
Julia Reynoldsc65656a2018-02-12 09:55:14 -05001049 ArgumentCaptor<NotificationChannel> updated =
1050 ArgumentCaptor.forClass(NotificationChannel.class);
1051 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
1052 anyString(), eq(TEST_UID), updated.capture());
1053 assertTrue(0 != (mNotificationChannel.getUserLockedFields() & USER_LOCKED_IMPORTANCE));
1054 assertEquals(IMPORTANCE_LOW, mNotificationChannel.getImportance());
1055 }
1056
1057 @Test
Julia Reynolds52a27372019-04-03 11:00:17 -04001058 public void testNoActionsUpdatesNotificationChannel_blockingHelper() throws Exception {
1059 mNotificationChannel.setImportance(IMPORTANCE_DEFAULT);
Ned Burns9512e0c2019-05-30 19:36:04 -04001060 mNotificationInfo.bindNotification(
1061 mMockPackageManager,
1062 mMockINotificationManager,
1063 mVisualStabilityManager,
1064 TEST_PACKAGE_NAME,
1065 mNotificationChannel,
1066 mNotificationChannelSet,
1067 mSbn,
1068 null,
1069 null,
1070 null,
1071 true,
1072 true,
1073 IMPORTANCE_DEFAULT,
1074 true);
Julia Reynolds52a27372019-04-03 11:00:17 -04001075
1076 mNotificationInfo.handleCloseControls(true, false);
1077
1078 mTestableLooper.processAllMessages();
1079 ArgumentCaptor<NotificationChannel> updated =
1080 ArgumentCaptor.forClass(NotificationChannel.class);
1081 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
1082 anyString(), eq(TEST_UID), updated.capture());
1083 assertTrue(0 != (mNotificationChannel.getUserLockedFields() & USER_LOCKED_IMPORTANCE));
1084 assertEquals(IMPORTANCE_DEFAULT, mNotificationChannel.getImportance());
1085 }
1086
1087 @Test
Gus Prevas9abc5062018-10-31 16:11:04 -04001088 public void testSilenceCallsUpdateNotificationChannel() throws Exception {
1089 mNotificationChannel.setImportance(IMPORTANCE_DEFAULT);
Ned Burns9512e0c2019-05-30 19:36:04 -04001090 mNotificationInfo.bindNotification(
1091 mMockPackageManager,
1092 mMockINotificationManager,
1093 mVisualStabilityManager,
1094 TEST_PACKAGE_NAME,
1095 mNotificationChannel,
1096 mNotificationChannelSet,
1097 mSbn,
1098 null,
1099 null,
1100 null,
1101 true,
1102 false,
1103 IMPORTANCE_DEFAULT,
1104 true);
Gus Prevas9abc5062018-10-31 16:11:04 -04001105
Julia Reynolds8728d002019-04-19 15:46:13 -04001106 mNotificationInfo.findViewById(R.id.silence).performClick();
Julia Reynolds52a27372019-04-03 11:00:17 -04001107 mNotificationInfo.findViewById(R.id.done).performClick();
Gus Prevas9abc5062018-10-31 16:11:04 -04001108 mNotificationInfo.handleCloseControls(true, false);
1109
1110 mTestableLooper.processAllMessages();
1111 ArgumentCaptor<NotificationChannel> updated =
1112 ArgumentCaptor.forClass(NotificationChannel.class);
1113 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
1114 anyString(), eq(TEST_UID), updated.capture());
1115 assertTrue((updated.getValue().getUserLockedFields()
1116 & USER_LOCKED_IMPORTANCE) != 0);
1117 assertEquals(IMPORTANCE_LOW, updated.getValue().getImportance());
1118 }
1119
1120 @Test
1121 public void testUnSilenceCallsUpdateNotificationChannel() throws Exception {
1122 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Ned Burns9512e0c2019-05-30 19:36:04 -04001123 mNotificationInfo.bindNotification(
1124 mMockPackageManager,
1125 mMockINotificationManager,
1126 mVisualStabilityManager,
1127 TEST_PACKAGE_NAME,
1128 mNotificationChannel,
1129 mNotificationChannelSet,
1130 mSbn,
1131 null,
1132 null,
1133 null,
1134 true,
1135 false,
1136 IMPORTANCE_LOW,
1137 false);
Gus Prevas9abc5062018-10-31 16:11:04 -04001138
Julia Reynolds8728d002019-04-19 15:46:13 -04001139 mNotificationInfo.findViewById(R.id.alert).performClick();
Julia Reynolds52a27372019-04-03 11:00:17 -04001140 mNotificationInfo.findViewById(R.id.done).performClick();
Gus Prevas9abc5062018-10-31 16:11:04 -04001141 mNotificationInfo.handleCloseControls(true, false);
1142
1143 mTestableLooper.processAllMessages();
1144 ArgumentCaptor<NotificationChannel> updated =
1145 ArgumentCaptor.forClass(NotificationChannel.class);
1146 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
1147 anyString(), eq(TEST_UID), updated.capture());
1148 assertTrue((updated.getValue().getUserLockedFields()
1149 & USER_LOCKED_IMPORTANCE) != 0);
Julia Reynolds9ae5e642019-02-06 10:19:22 -05001150 assertEquals(IMPORTANCE_DEFAULT, updated.getValue().getImportance());
Gus Prevas9abc5062018-10-31 16:11:04 -04001151 }
1152
1153 @Test
1154 public void testSilenceCallsUpdateNotificationChannel_channelImportanceUnspecified()
1155 throws Exception {
1156 mNotificationChannel.setImportance(IMPORTANCE_UNSPECIFIED);
Ned Burns9512e0c2019-05-30 19:36:04 -04001157 mNotificationInfo.bindNotification(
1158 mMockPackageManager,
1159 mMockINotificationManager,
1160 mVisualStabilityManager,
1161 TEST_PACKAGE_NAME,
1162 mNotificationChannel,
1163 mNotificationChannelSet,
1164 mSbn,
1165 null,
1166 null,
1167 null,
1168 true,
1169 false,
1170 IMPORTANCE_UNSPECIFIED,
1171 true);
Gus Prevas9abc5062018-10-31 16:11:04 -04001172
Julia Reynolds8728d002019-04-19 15:46:13 -04001173 mNotificationInfo.findViewById(R.id.silence).performClick();
Julia Reynolds52a27372019-04-03 11:00:17 -04001174 mNotificationInfo.findViewById(R.id.done).performClick();
Gus Prevas9abc5062018-10-31 16:11:04 -04001175 mNotificationInfo.handleCloseControls(true, false);
1176
1177 mTestableLooper.processAllMessages();
1178 ArgumentCaptor<NotificationChannel> updated =
1179 ArgumentCaptor.forClass(NotificationChannel.class);
1180 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
1181 anyString(), eq(TEST_UID), updated.capture());
1182 assertTrue((updated.getValue().getUserLockedFields()
1183 & USER_LOCKED_IMPORTANCE) != 0);
1184 assertEquals(IMPORTANCE_LOW, updated.getValue().getImportance());
1185 }
1186
1187 @Test
Julia Reynolds8728d002019-04-19 15:46:13 -04001188 public void testSilenceCallsUpdateNotificationChannel_channelImportanceMin()
Gus Prevas9abc5062018-10-31 16:11:04 -04001189 throws Exception {
Julia Reynolds8728d002019-04-19 15:46:13 -04001190 mNotificationChannel.setImportance(IMPORTANCE_MIN);
Ned Burns9512e0c2019-05-30 19:36:04 -04001191 mNotificationInfo.bindNotification(
1192 mMockPackageManager,
1193 mMockINotificationManager,
1194 mVisualStabilityManager,
1195 TEST_PACKAGE_NAME,
1196 mNotificationChannel,
1197 mNotificationChannelSet,
1198 mSbn,
1199 null,
1200 null,
1201 null,
1202 true,
1203 false,
1204 IMPORTANCE_MIN,
1205 false);
Julia Reynolds8728d002019-04-19 15:46:13 -04001206
1207 assertEquals(mContext.getString(R.string.inline_done_button),
1208 ((TextView) mNotificationInfo.findViewById(R.id.done)).getText());
1209 mNotificationInfo.findViewById(R.id.silence).performClick();
1210 assertEquals(mContext.getString(R.string.inline_done_button),
1211 ((TextView) mNotificationInfo.findViewById(R.id.done)).getText());
1212 mNotificationInfo.findViewById(R.id.done).performClick();
1213 mNotificationInfo.handleCloseControls(true, false);
1214
1215 mTestableLooper.processAllMessages();
1216 ArgumentCaptor<NotificationChannel> updated =
1217 ArgumentCaptor.forClass(NotificationChannel.class);
1218 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
1219 anyString(), eq(TEST_UID), updated.capture());
Evan Laird47dc4542019-04-24 15:10:52 -04001220 assertTrue((updated.getValue().getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0);
Julia Reynolds8728d002019-04-19 15:46:13 -04001221 assertEquals(IMPORTANCE_MIN, updated.getValue().getImportance());
1222 }
1223
1224 @Test
1225 public void testAlertCallsUpdateNotificationChannel_channelImportanceMin()
1226 throws Exception {
1227 mNotificationChannel.setImportance(IMPORTANCE_MIN);
Ned Burns9512e0c2019-05-30 19:36:04 -04001228 mNotificationInfo.bindNotification(
1229 mMockPackageManager,
1230 mMockINotificationManager,
1231 mVisualStabilityManager,
1232 TEST_PACKAGE_NAME,
1233 mNotificationChannel,
1234 mNotificationChannelSet,
1235 mSbn,
1236 null,
1237 null,
1238 null,
1239 true,
1240 false,
1241 IMPORTANCE_MIN,
1242 false);
Julia Reynolds8728d002019-04-19 15:46:13 -04001243
1244 assertEquals(mContext.getString(R.string.inline_done_button),
1245 ((TextView) mNotificationInfo.findViewById(R.id.done)).getText());
1246 mNotificationInfo.findViewById(R.id.alert).performClick();
1247 assertEquals(mContext.getString(R.string.inline_ok_button),
1248 ((TextView) mNotificationInfo.findViewById(R.id.done)).getText());
1249 mNotificationInfo.findViewById(R.id.done).performClick();
1250 mNotificationInfo.handleCloseControls(true, false);
1251
1252 mTestableLooper.processAllMessages();
1253 ArgumentCaptor<NotificationChannel> updated =
1254 ArgumentCaptor.forClass(NotificationChannel.class);
1255 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
1256 anyString(), eq(TEST_UID), updated.capture());
Evan Laird47dc4542019-04-24 15:10:52 -04001257 assertTrue((updated.getValue().getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0);
Julia Reynolds8728d002019-04-19 15:46:13 -04001258 assertEquals(IMPORTANCE_DEFAULT, updated.getValue().getImportance());
1259 }
1260
1261 @Test
Ned Burns9512e0c2019-05-30 19:36:04 -04001262 public void testAdjustImportanceTemporarilyAllowsReordering() throws Exception {
1263 mNotificationChannel.setImportance(IMPORTANCE_DEFAULT);
1264 mNotificationInfo.bindNotification(
1265 mMockPackageManager,
1266 mMockINotificationManager,
1267 mVisualStabilityManager,
1268 TEST_PACKAGE_NAME,
1269 mNotificationChannel,
1270 mNotificationChannelSet,
1271 mSbn,
1272 null,
1273 null,
1274 null,
1275 true,
1276 false,
1277 IMPORTANCE_DEFAULT,
1278 true);
1279
1280 mNotificationInfo.findViewById(R.id.silence).performClick();
1281 mNotificationInfo.findViewById(R.id.done).performClick();
1282 mNotificationInfo.handleCloseControls(true, false);
1283
1284 verify(mVisualStabilityManager).temporarilyAllowReordering();
1285 }
1286
1287 @Test
Julia Reynolds8728d002019-04-19 15:46:13 -04001288 public void testDoneText()
1289 throws Exception {
1290 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Ned Burns9512e0c2019-05-30 19:36:04 -04001291 mNotificationInfo.bindNotification(
1292 mMockPackageManager,
1293 mMockINotificationManager,
1294 mVisualStabilityManager,
1295 TEST_PACKAGE_NAME,
1296 mNotificationChannel,
1297 mNotificationChannelSet,
1298 mSbn,
1299 null,
1300 null,
1301 null,
1302 true,
1303 false,
1304 IMPORTANCE_LOW,
1305 false);
Gus Prevas9abc5062018-10-31 16:11:04 -04001306
Julia Reynolds8728d002019-04-19 15:46:13 -04001307 assertEquals(mContext.getString(R.string.inline_done_button),
1308 ((TextView) mNotificationInfo.findViewById(R.id.done)).getText());
1309 mNotificationInfo.findViewById(R.id.alert).performClick();
1310 assertEquals(mContext.getString(R.string.inline_ok_button),
1311 ((TextView) mNotificationInfo.findViewById(R.id.done)).getText());
1312 mNotificationInfo.findViewById(R.id.silence).performClick();
1313 assertEquals(mContext.getString(R.string.inline_done_button),
1314 ((TextView) mNotificationInfo.findViewById(R.id.done)).getText());
1315 }
1316
1317 @Test
1318 public void testUnSilenceCallsUpdateNotificationChannel_channelImportanceUnspecified()
1319 throws Exception {
1320 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Ned Burns9512e0c2019-05-30 19:36:04 -04001321 mNotificationInfo.bindNotification(
1322 mMockPackageManager,
1323 mMockINotificationManager,
1324 mVisualStabilityManager,
1325 TEST_PACKAGE_NAME,
1326 mNotificationChannel,
1327 mNotificationChannelSet,
1328 mSbn,
1329 null,
1330 null,
1331 null,
1332 true,
1333 false,
1334 IMPORTANCE_LOW,
1335 false);
Julia Reynolds8728d002019-04-19 15:46:13 -04001336
1337 mNotificationInfo.findViewById(R.id.alert).performClick();
Julia Reynolds52a27372019-04-03 11:00:17 -04001338 mNotificationInfo.findViewById(R.id.done).performClick();
Gus Prevas9abc5062018-10-31 16:11:04 -04001339 mNotificationInfo.handleCloseControls(true, false);
1340
1341 mTestableLooper.processAllMessages();
1342 ArgumentCaptor<NotificationChannel> updated =
1343 ArgumentCaptor.forClass(NotificationChannel.class);
1344 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
1345 anyString(), eq(TEST_UID), updated.capture());
1346 assertTrue((updated.getValue().getUserLockedFields()
1347 & USER_LOCKED_IMPORTANCE) != 0);
Julia Reynolds9ae5e642019-02-06 10:19:22 -05001348 assertEquals(IMPORTANCE_DEFAULT, updated.getValue().getImportance());
Gus Prevas9abc5062018-10-31 16:11:04 -04001349 }
1350
1351 @Test
Julia Reynolds437cdb12018-01-03 12:27:24 -05001352 public void testCloseControlsDoesNotUpdateIfSaveIsFalse() throws Exception {
1353 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Ned Burns9512e0c2019-05-30 19:36:04 -04001354 mNotificationInfo.bindNotification(
1355 mMockPackageManager,
1356 mMockINotificationManager,
1357 mVisualStabilityManager,
1358 TEST_PACKAGE_NAME,
1359 mNotificationChannel,
1360 mNotificationChannelSet,
1361 mSbn,
1362 null,
1363 null,
1364 null,
1365 true,
1366 false,
1367 IMPORTANCE_LOW,
1368 false);
Julia Reynolds437cdb12018-01-03 12:27:24 -05001369
Julia Reynolds8728d002019-04-19 15:46:13 -04001370 mNotificationInfo.findViewById(R.id.alert).performClick();
Julia Reynolds52a27372019-04-03 11:00:17 -04001371 mNotificationInfo.findViewById(R.id.done).performClick();
Mady Mellorc2dbe492017-03-30 13:22:03 -07001372 mNotificationInfo.handleCloseControls(false, false);
Rohan Shahca0447e2018-03-30 15:18:27 -07001373
1374 mTestableLooper.processAllMessages();
Geoffrey Pitschdf44b602017-02-03 13:31:50 -05001375 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -04001376 eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel));
Geoffrey Pitschdf44b602017-02-03 13:31:50 -05001377 }
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -04001378
1379 @Test
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -04001380 public void testCloseControlsUpdatesWhenCheckSaveListenerUsesCallback() throws Exception {
Julia Reynolds437cdb12018-01-03 12:27:24 -05001381 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Ned Burns9512e0c2019-05-30 19:36:04 -04001382 mNotificationInfo.bindNotification(
1383 mMockPackageManager,
1384 mMockINotificationManager,
1385 mVisualStabilityManager,
1386 TEST_PACKAGE_NAME,
1387 mNotificationChannel,
1388 mNotificationChannelSet,
1389 mSbn,
Eliot Courtney47098cb2017-10-18 17:30:30 +09001390 (Runnable saveImportance, StatusBarNotification sbn) -> {
Julia Reynolds3aedded2017-03-31 14:42:09 -04001391 saveImportance.run();
Ned Burns9512e0c2019-05-30 19:36:04 -04001392 },
1393 null,
1394 null,
1395 true,
1396 false,
1397 IMPORTANCE_LOW,
1398 false
Gus Prevas5a70a4e2018-11-26 17:16:05 -05001399 );
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -04001400
Julia Reynolds8728d002019-04-19 15:46:13 -04001401 mNotificationInfo.findViewById(R.id.alert).performClick();
Julia Reynolds52a27372019-04-03 11:00:17 -04001402 mNotificationInfo.findViewById(R.id.done).performClick();
Gus Prevas533836a2018-09-24 17:15:32 -04001403 mTestableLooper.processAllMessages();
1404 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
1405 eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel));
1406
Mady Mellorc2dbe492017-03-30 13:22:03 -07001407 mNotificationInfo.handleCloseControls(true, false);
Rohan Shahca0447e2018-03-30 15:18:27 -07001408
1409 mTestableLooper.processAllMessages();
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -04001410 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -04001411 eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel));
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -04001412 }
Julia Reynolds3aedded2017-03-31 14:42:09 -04001413
1414 @Test
Julia Reynolds4d1dd792019-04-29 11:48:29 -04001415 public void testCloseControls_withoutHittingApply() throws Exception {
1416 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Ned Burns9512e0c2019-05-30 19:36:04 -04001417 mNotificationInfo.bindNotification(
1418 mMockPackageManager,
1419 mMockINotificationManager,
1420 mVisualStabilityManager,
1421 TEST_PACKAGE_NAME,
1422 mNotificationChannel,
1423 mNotificationChannelSet,
1424 mSbn,
Julia Reynolds4d1dd792019-04-29 11:48:29 -04001425 (Runnable saveImportance, StatusBarNotification sbn) -> {
1426 saveImportance.run();
Ned Burns9512e0c2019-05-30 19:36:04 -04001427 },
1428 null,
1429 null,
1430 true,
1431 false,
1432 IMPORTANCE_LOW,
1433 false
Julia Reynolds4d1dd792019-04-29 11:48:29 -04001434 );
1435
1436 mNotificationInfo.findViewById(R.id.alert).performClick();
1437
1438 assertFalse(mNotificationInfo.shouldBeSaved());
1439 }
1440
1441 @Test
1442 public void testWillBeRemovedReturnsFalse() throws Exception {
1443 assertFalse(mNotificationInfo.willBeRemoved());
1444
Ned Burns9512e0c2019-05-30 19:36:04 -04001445 mNotificationInfo.bindNotification(
1446 mMockPackageManager,
1447 mMockINotificationManager,
1448 mVisualStabilityManager,
1449 TEST_PACKAGE_NAME,
1450 mNotificationChannel,
1451 mNotificationChannelSet,
1452 mSbn,
Julia Reynolds4d1dd792019-04-29 11:48:29 -04001453 (Runnable saveImportance, StatusBarNotification sbn) -> {
1454 saveImportance.run();
Ned Burns9512e0c2019-05-30 19:36:04 -04001455 },
1456 null,
1457 null,
1458 true,
1459 false,
1460 IMPORTANCE_LOW,
1461 false
Julia Reynolds4d1dd792019-04-29 11:48:29 -04001462 );
1463
Geoffrey Pitsch8c8dbde2017-04-20 11:44:33 -04001464 assertFalse(mNotificationInfo.willBeRemoved());
1465 }
Evan Laird47dc4542019-04-24 15:10:52 -04001466
1467 private Set<NotificationChannel> createMultipleChannelSet(int howMany) {
1468 Set<NotificationChannel> multiChannelSet = new HashSet<>();
1469 for (int i = 0; i < howMany; i++) {
1470 if (i == 0) {
1471 multiChannelSet.add(mNotificationChannel);
1472 continue;
1473 }
1474
1475 NotificationChannel channel = new NotificationChannel(
1476 TEST_CHANNEL, TEST_CHANNEL_NAME + i, IMPORTANCE_LOW);
1477
1478 multiChannelSet.add(channel);
1479 }
1480
1481 return multiChannelSet;
1482 }
Geoffrey Pitschdf44b602017-02-03 13:31:50 -05001483}