blob: bdca7efeb6080e8d4ad638dd67722bfd29848cce [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
Mady Mellor53162c12019-10-22 17:12:59 -070019import static android.app.Notification.FLAG_BUBBLE;
Julia Reynoldsc65656a2018-02-12 09:55:14 -050020import static android.app.NotificationChannel.USER_LOCKED_IMPORTANCE;
Gus Prevas9abc5062018-10-31 16:11:04 -040021import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
Julia Reynolds437cdb12018-01-03 12:27:24 -050022import static android.app.NotificationManager.IMPORTANCE_LOW;
Julia Reynoldse0341482018-03-08 14:42:50 -050023import static android.app.NotificationManager.IMPORTANCE_MIN;
Julia Reynoldsc65656a2018-02-12 09:55:14 -050024import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
Julia Reynoldsf7321592017-05-24 16:09:19 -040025import static android.print.PrintManager.PRINT_SPOOLER_PACKAGE_NAME;
Gus Prevas9abc5062018-10-31 16:11:04 -040026import static android.provider.Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL;
Julia Reynolds437cdb12018-01-03 12:27:24 -050027import static android.view.View.GONE;
28import static android.view.View.VISIBLE;
Julia Reynoldsf7321592017-05-24 16:09:19 -040029
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050030import static junit.framework.Assert.assertEquals;
31import static junit.framework.Assert.assertFalse;
32import static junit.framework.Assert.assertTrue;
Julia Reynolds5a311932017-03-01 16:33:44 -050033
William Brockman75cf66a2018-12-21 13:25:01 -050034import static org.mockito.ArgumentMatchers.argThat;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050035import static org.mockito.Mockito.any;
36import static org.mockito.Mockito.anyBoolean;
37import static org.mockito.Mockito.anyInt;
38import static org.mockito.Mockito.anyString;
Rohan Shahda5dcdd2018-04-27 17:21:50 -070039import static org.mockito.Mockito.doCallRealMethod;
40import static org.mockito.Mockito.doNothing;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050041import static org.mockito.Mockito.eq;
42import static org.mockito.Mockito.mock;
43import static org.mockito.Mockito.never;
Rohan Shahda5dcdd2018-04-27 17:21:50 -070044import static org.mockito.Mockito.spy;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050045import static org.mockito.Mockito.times;
46import static org.mockito.Mockito.verify;
47import static org.mockito.Mockito.when;
48
49import android.app.INotificationManager;
Julia Reynolds3aedded2017-03-31 14:42:09 -040050import android.app.Notification;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050051import android.app.NotificationChannel;
52import android.app.NotificationChannelGroup;
Mady Mellor53162c12019-10-22 17:12:59 -070053import android.app.PendingIntent;
54import android.content.Intent;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050055import android.content.pm.ApplicationInfo;
56import android.content.pm.PackageInfo;
57import android.content.pm.PackageManager;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050058import android.graphics.drawable.Drawable;
Mady Mellor53162c12019-10-22 17:12:59 -070059import android.graphics.drawable.Icon;
Rohan Shahda5dcdd2018-04-27 17:21:50 -070060import android.os.IBinder;
Julia Reynolds3aedded2017-03-31 14:42:09 -040061import android.os.UserHandle;
Gus Prevas9abc5062018-10-31 16:11:04 -040062import android.provider.Settings;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050063import android.service.notification.StatusBarNotification;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050064import android.test.suitebuilder.annotation.SmallTest;
Jason Monk340b0e52017-03-08 14:57:56 -050065import android.testing.AndroidTestingRunner;
Julia Reynolds437cdb12018-01-03 12:27:24 -050066import android.testing.PollingCheck;
Rohan Shahca0447e2018-03-30 15:18:27 -070067import android.testing.TestableLooper;
Jason Monk340b0e52017-03-08 14:57:56 -050068import android.testing.UiThreadTest;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050069import android.view.LayoutInflater;
70import android.view.View;
71import android.widget.ImageView;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050072import android.widget.TextView;
Jason Monk340b0e52017-03-08 14:57:56 -050073
Rohan Shahda5dcdd2018-04-27 17:21:50 -070074import com.android.internal.logging.MetricsLogger;
Eyal Posenera9cf9c72018-12-18 16:23:54 +020075import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Rohan Shahca0447e2018-03-30 15:18:27 -070076import com.android.systemui.Dependency;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050077import com.android.systemui.R;
78import com.android.systemui.SysuiTestCase;
Mady Mellor53162c12019-10-22 17:12:59 -070079import com.android.systemui.bubbles.BubbleController;
80import com.android.systemui.bubbles.BubblesTestActivity;
81import com.android.systemui.statusbar.NotificationEntryBuilder;
82import com.android.systemui.statusbar.SbnBuilder;
Ned Burns9512e0c2019-05-30 19:36:04 -040083import com.android.systemui.statusbar.notification.VisualStabilityManager;
Mady Mellor53162c12019-10-22 17:12:59 -070084import com.android.systemui.statusbar.notification.collection.NotificationEntry;
Jason Monkba364322017-03-06 11:19:20 -050085
Gus Prevas9abc5062018-10-31 16:11:04 -040086import org.junit.After;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050087import org.junit.Before;
Rohan Shah524cf7b2018-03-15 14:40:02 -070088import org.junit.Rule;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050089import org.junit.Test;
Jason Monk340b0e52017-03-08 14:57:56 -050090import org.junit.runner.RunWith;
Julia Reynolds8ceb5792017-04-11 11:32:44 -040091import org.mockito.ArgumentCaptor;
Rohan Shah524cf7b2018-03-15 14:40:02 -070092import org.mockito.Mock;
93import org.mockito.junit.MockitoJUnit;
94import org.mockito.junit.MockitoRule;
Julia Reynolds3aedded2017-03-31 14:42:09 -040095
Evan Laird47dc4542019-04-24 15:10:52 -040096import java.util.HashSet;
97import java.util.Set;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050098import java.util.concurrent.CountDownLatch;
99
100@SmallTest
Jason Monk340b0e52017-03-08 14:57:56 -0500101@RunWith(AndroidTestingRunner.class)
Rohan Shahca0447e2018-03-30 15:18:27 -0700102@TestableLooper.RunWithLooper
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500103public class NotificationInfoTest extends SysuiTestCase {
104 private static final String TEST_PACKAGE_NAME = "test_package";
Julia Reynoldsf7321592017-05-24 16:09:19 -0400105 private static final String TEST_SYSTEM_PACKAGE_NAME = PRINT_SPOOLER_PACKAGE_NAME;
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400106 private static final int TEST_UID = 1;
Rohan Shah63411fc2018-03-28 19:05:52 -0700107 private static final int MULTIPLE_CHANNEL_COUNT = 2;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500108 private static final String TEST_CHANNEL = "test_channel";
109 private static final String TEST_CHANNEL_NAME = "TEST CHANNEL NAME";
110
Rohan Shahca0447e2018-03-30 15:18:27 -0700111 private TestableLooper mTestableLooper;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500112 private NotificationInfo mNotificationInfo;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500113 private NotificationChannel mNotificationChannel;
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500114 private NotificationChannel mDefaultNotificationChannel;
Evan Laird47dc4542019-04-24 15:10:52 -0400115 private Set<NotificationChannel> mNotificationChannelSet = new HashSet<>();
116 private Set<NotificationChannel> mDefaultNotificationChannelSet = new HashSet<>();
Julia Reynolds3aedded2017-03-31 14:42:09 -0400117 private StatusBarNotification mSbn;
Mady Mellor53162c12019-10-22 17:12:59 -0700118 private NotificationEntry mEntry;
119 private StatusBarNotification mBubbleSbn;
120 private NotificationEntry mBubbleEntry;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500121
Will Brockmana399f022019-01-30 10:59:36 -0500122 @Rule
123 public MockitoRule mockito = MockitoJUnit.rule();
124 @Mock
125 private MetricsLogger mMetricsLogger;
126 @Mock
127 private INotificationManager mMockINotificationManager;
128 @Mock
129 private PackageManager mMockPackageManager;
130 @Mock
131 private NotificationBlockingHelperManager mBlockingHelperManager;
Ned Burns9512e0c2019-05-30 19:36:04 -0400132 @Mock
133 private VisualStabilityManager mVisualStabilityManager;
Mady Mellor53162c12019-10-22 17:12:59 -0700134 @Mock
135 private BubbleController mBubbleController;
Rohan Shah524cf7b2018-03-15 14:40:02 -0700136
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500137 @Before
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500138 public void setUp() throws Exception {
Rohan Shah524cf7b2018-03-15 14:40:02 -0700139 mDependency.injectTestDependency(
140 NotificationBlockingHelperManager.class,
141 mBlockingHelperManager);
Rohan Shahca0447e2018-03-30 15:18:27 -0700142 mTestableLooper = TestableLooper.get(this);
Mady Mellor53162c12019-10-22 17:12:59 -0700143
Rohan Shahca0447e2018-03-30 15:18:27 -0700144 mDependency.injectTestDependency(Dependency.BG_LOOPER, mTestableLooper.getLooper());
Rohan Shahda5dcdd2018-04-27 17:21:50 -0700145 mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger);
Mady Mellor53162c12019-10-22 17:12:59 -0700146 mDependency.injectTestDependency(BubbleController.class, mBubbleController);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500147 // Inflate the layout
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500148 final LayoutInflater layoutInflater = LayoutInflater.from(mContext);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500149 mNotificationInfo = (NotificationInfo) layoutInflater.inflate(R.layout.notification_info,
150 null);
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500151 mNotificationInfo.setGutsParent(mock(NotificationGuts.class));
Mady Mellor53162c12019-10-22 17:12:59 -0700152 // Our view is never attached to a window so the View#post methods in NotificationInfo never
153 // get called. Setting this will skip the post and do the action immediately.
154 mNotificationInfo.mSkipPost = true;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500155
156 // PackageManager must return a packageInfo and applicationInfo.
157 final PackageInfo packageInfo = new PackageInfo();
158 packageInfo.packageName = TEST_PACKAGE_NAME;
Julia Reynoldsf7321592017-05-24 16:09:19 -0400159 when(mMockPackageManager.getPackageInfo(eq(TEST_PACKAGE_NAME), anyInt()))
160 .thenReturn(packageInfo);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500161 final ApplicationInfo applicationInfo = new ApplicationInfo();
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400162 applicationInfo.uid = TEST_UID; // non-zero
Julia Reynolds268647a2018-10-25 16:54:27 -0400163 when(mMockPackageManager.getApplicationInfo(eq(TEST_PACKAGE_NAME), anyInt())).thenReturn(
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500164 applicationInfo);
Julia Reynoldsf7321592017-05-24 16:09:19 -0400165 final PackageInfo systemPackageInfo = new PackageInfo();
166 systemPackageInfo.packageName = TEST_SYSTEM_PACKAGE_NAME;
167 when(mMockPackageManager.getPackageInfo(eq(TEST_SYSTEM_PACKAGE_NAME), anyInt()))
168 .thenReturn(systemPackageInfo);
169 when(mMockPackageManager.getPackageInfo(eq("android"), anyInt()))
170 .thenReturn(packageInfo);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500171
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500172 // Package has one channel by default.
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500173 when(mMockINotificationManager.getNumNotificationChannelsForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400174 eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(1);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500175
176 // Some test channels.
177 mNotificationChannel = new NotificationChannel(
Julia Reynolds437cdb12018-01-03 12:27:24 -0500178 TEST_CHANNEL, TEST_CHANNEL_NAME, IMPORTANCE_LOW);
Evan Laird47dc4542019-04-24 15:10:52 -0400179 mNotificationChannelSet.add(mNotificationChannel);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500180 mDefaultNotificationChannel = new NotificationChannel(
181 NotificationChannel.DEFAULT_CHANNEL_ID, TEST_CHANNEL_NAME,
Julia Reynolds437cdb12018-01-03 12:27:24 -0500182 IMPORTANCE_LOW);
Evan Laird47dc4542019-04-24 15:10:52 -0400183 mDefaultNotificationChannelSet.add(mDefaultNotificationChannel);
Julia Reynolds33bef2c2017-09-05 11:07:18 -0400184 mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, TEST_UID, 0,
Julia Reynolds3aedded2017-03-31 14:42:09 -0400185 new Notification(), UserHandle.CURRENT, null, 0);
Mady Mellor53162c12019-10-22 17:12:59 -0700186 mEntry = new NotificationEntryBuilder().setSbn(mSbn).build();
187
188 PendingIntent bubbleIntent = PendingIntent.getActivity(mContext, 0,
189 new Intent(mContext, BubblesTestActivity.class), 0);
190 mBubbleSbn = new SbnBuilder(mSbn).setBubbleMetadata(
191 new Notification.BubbleMetadata.Builder()
192 .setIntent(bubbleIntent)
193 .setIcon(Icon.createWithResource(mContext, R.drawable.android)).build())
194 .build();
195 mBubbleEntry = new NotificationEntryBuilder().setSbn(mBubbleSbn).build();
Gus Prevas9abc5062018-10-31 16:11:04 -0400196
197 Settings.Secure.putInt(mContext.getContentResolver(),
198 NOTIFICATION_NEW_INTERRUPTION_MODEL, 1);
199 }
200
201 @After
202 public void tearDown() {
203 Settings.Secure.putInt(mContext.getContentResolver(),
204 NOTIFICATION_NEW_INTERRUPTION_MODEL, 0);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500205 }
206
Julia Reynolds437cdb12018-01-03 12:27:24 -0500207 // TODO: if tests are taking too long replace this with something that makes the animation
208 // finish instantly.
209 private void waitForUndoButton() {
210 PollingCheck.waitFor(1000,
211 () -> VISIBLE == mNotificationInfo.findViewById(R.id.confirmation).getVisibility());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500212 }
Will Brockmana399f022019-01-30 10:59:36 -0500213
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500214 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500215 public void testBindNotification_SetsTextApplicationName() throws Exception {
216 when(mMockPackageManager.getApplicationLabel(any())).thenReturn("App Name");
Ned Burns9512e0c2019-05-30 19:36:04 -0400217 mNotificationInfo.bindNotification(
218 mMockPackageManager,
219 mMockINotificationManager,
220 mVisualStabilityManager,
221 TEST_PACKAGE_NAME,
222 mNotificationChannel,
223 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700224 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400225 null,
226 null,
227 null,
228 true,
229 false,
230 IMPORTANCE_DEFAULT,
231 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500232 final TextView textView = mNotificationInfo.findViewById(R.id.pkgname);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500233 assertTrue(textView.getText().toString().contains("App Name"));
Julia Reynoldse0341482018-03-08 14:42:50 -0500234 assertEquals(VISIBLE, mNotificationInfo.findViewById(R.id.header).getVisibility());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500235 }
236
237 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500238 public void testBindNotification_SetsPackageIcon() throws Exception {
239 final Drawable iconDrawable = mock(Drawable.class);
240 when(mMockPackageManager.getApplicationIcon(any(ApplicationInfo.class)))
241 .thenReturn(iconDrawable);
Ned Burns9512e0c2019-05-30 19:36:04 -0400242 mNotificationInfo.bindNotification(
243 mMockPackageManager,
244 mMockINotificationManager,
245 mVisualStabilityManager,
246 TEST_PACKAGE_NAME,
247 mNotificationChannel,
248 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700249 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400250 null,
251 null,
252 null,
253 true,
254 false,
255 IMPORTANCE_DEFAULT,
256 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500257 final ImageView iconView = mNotificationInfo.findViewById(R.id.pkgicon);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500258 assertEquals(iconDrawable, iconView.getDrawable());
259 }
260
261 @Test
Julia Reynolds268647a2018-10-25 16:54:27 -0400262 public void testBindNotification_noDelegate() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400263 mNotificationInfo.bindNotification(
264 mMockPackageManager,
265 mMockINotificationManager,
266 mVisualStabilityManager,
267 TEST_PACKAGE_NAME,
268 mNotificationChannel,
269 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700270 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400271 null,
272 null,
273 null,
274 true,
275 false,
276 IMPORTANCE_DEFAULT,
277 true);
Julia Reynolds268647a2018-10-25 16:54:27 -0400278 final TextView nameView = mNotificationInfo.findViewById(R.id.delegate_name);
279 assertEquals(GONE, nameView.getVisibility());
280 final TextView dividerView = mNotificationInfo.findViewById(R.id.pkg_divider);
281 assertEquals(GONE, dividerView.getVisibility());
282 }
283
284 @Test
285 public void testBindNotification_delegate() throws Exception {
286 mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, "other", 0, null, TEST_UID, 0,
287 new Notification(), UserHandle.CURRENT, null, 0);
288 final ApplicationInfo applicationInfo = new ApplicationInfo();
289 applicationInfo.uid = 7; // non-zero
290 when(mMockPackageManager.getApplicationInfo(eq("other"), anyInt())).thenReturn(
291 applicationInfo);
292 when(mMockPackageManager.getApplicationLabel(any())).thenReturn("Other");
293
Mady Mellor53162c12019-10-22 17:12:59 -0700294 NotificationEntry entry = new NotificationEntryBuilder().setSbn(mSbn).build();
Ned Burns9512e0c2019-05-30 19:36:04 -0400295 mNotificationInfo.bindNotification(
296 mMockPackageManager,
297 mMockINotificationManager,
298 mVisualStabilityManager,
299 TEST_PACKAGE_NAME,
300 mNotificationChannel,
301 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700302 entry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400303 null,
304 null,
305 null,
306 true,
307 false,
308 IMPORTANCE_DEFAULT,
309 true);
Julia Reynolds268647a2018-10-25 16:54:27 -0400310 final TextView nameView = mNotificationInfo.findViewById(R.id.delegate_name);
311 assertEquals(VISIBLE, nameView.getVisibility());
Julia Reynolds25b27f52019-04-24 11:58:38 -0400312 assertTrue(nameView.getText().toString().contains("Proxied"));
Julia Reynolds268647a2018-10-25 16:54:27 -0400313 final TextView dividerView = mNotificationInfo.findViewById(R.id.pkg_divider);
314 assertEquals(VISIBLE, dividerView.getVisibility());
315 }
316
317 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500318 public void testBindNotification_GroupNameHiddenIfNoGroup() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400319 mNotificationInfo.bindNotification(
320 mMockPackageManager,
321 mMockINotificationManager,
322 mVisualStabilityManager,
323 TEST_PACKAGE_NAME,
324 mNotificationChannel,
325 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700326 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400327 null,
328 null,
329 null,
330 true,
331 false,
332 IMPORTANCE_DEFAULT,
333 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500334 final TextView groupNameView = mNotificationInfo.findViewById(R.id.group_name);
335 assertEquals(GONE, groupNameView.getVisibility());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500336 }
337
338 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500339 public void testBindNotification_SetsGroupNameIfNonNull() throws Exception {
340 mNotificationChannel.setGroup("test_group_id");
341 final NotificationChannelGroup notificationChannelGroup =
342 new NotificationChannelGroup("test_group_id", "Test Group Name");
343 when(mMockINotificationManager.getNotificationChannelGroupForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400344 eq("test_group_id"), eq(TEST_PACKAGE_NAME), eq(TEST_UID)))
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500345 .thenReturn(notificationChannelGroup);
Ned Burns9512e0c2019-05-30 19:36:04 -0400346 mNotificationInfo.bindNotification(
347 mMockPackageManager,
348 mMockINotificationManager,
349 mVisualStabilityManager,
350 TEST_PACKAGE_NAME,
351 mNotificationChannel,
352 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700353 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400354 null,
355 null,
356 null,
357 true,
358 false,
359 IMPORTANCE_DEFAULT,
360 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500361 final TextView groupNameView = mNotificationInfo.findViewById(R.id.group_name);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500362 assertEquals(View.VISIBLE, groupNameView.getVisibility());
363 assertEquals("Test Group Name", groupNameView.getText());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500364 }
365
366 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500367 public void testBindNotification_SetsTextChannelName() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400368 mNotificationInfo.bindNotification(
369 mMockPackageManager,
370 mMockINotificationManager,
371 mVisualStabilityManager,
372 TEST_PACKAGE_NAME,
373 mNotificationChannel,
374 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700375 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400376 null,
377 null,
378 null,
379 true,
380 false,
381 IMPORTANCE_DEFAULT,
382 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500383 final TextView textView = mNotificationInfo.findViewById(R.id.channel_name);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500384 assertEquals(TEST_CHANNEL_NAME, textView.getText());
385 }
386
387 @Test
Geoffrey Pitsch1fbf66e2017-05-09 11:32:27 -0400388 public void testBindNotification_DefaultChannelDoesNotUseChannelName() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400389 mNotificationInfo.bindNotification(
390 mMockPackageManager,
391 mMockINotificationManager,
392 mVisualStabilityManager,
393 TEST_PACKAGE_NAME,
394 mDefaultNotificationChannel,
395 mDefaultNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700396 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400397 null,
398 null,
399 null,
400 true,
401 false,
402 IMPORTANCE_DEFAULT,
403 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500404 final TextView textView = mNotificationInfo.findViewById(R.id.channel_name);
405 assertEquals(GONE, textView.getVisibility());
Geoffrey Pitsch1fbf66e2017-05-09 11:32:27 -0400406 }
407
408 @Test
Rohan Shahdbd64e72018-03-28 14:46:50 -0700409 public void testBindNotification_DefaultChannelUsesChannelNameIfMoreChannelsExist()
410 throws Exception {
411 // Package has one channel by default.
412 when(mMockINotificationManager.getNumNotificationChannelsForPackage(
413 eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(10);
Ned Burns9512e0c2019-05-30 19:36:04 -0400414 mNotificationInfo.bindNotification(
415 mMockPackageManager,
416 mMockINotificationManager,
417 mVisualStabilityManager,
418 TEST_PACKAGE_NAME,
419 mDefaultNotificationChannel,
420 mDefaultNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700421 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400422 null,
423 null,
424 null,
425 true,
426 false,
427 IMPORTANCE_DEFAULT,
428 true);
Rohan Shahdbd64e72018-03-28 14:46:50 -0700429 final TextView textView = mNotificationInfo.findViewById(R.id.channel_name);
430 assertEquals(VISIBLE, textView.getVisibility());
431 }
432
433 @Test
Julia Reynolds437cdb12018-01-03 12:27:24 -0500434 public void testBindNotification_UnblockablePackageUsesChannelName() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400435 mNotificationInfo.bindNotification(
436 mMockPackageManager,
437 mMockINotificationManager,
438 mVisualStabilityManager,
439 TEST_PACKAGE_NAME,
440 mNotificationChannel,
441 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700442 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400443 null,
444 null,
445 null,
446 true,
447 true,
448 IMPORTANCE_DEFAULT,
449 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500450 final TextView textView = mNotificationInfo.findViewById(R.id.channel_name);
451 assertEquals(VISIBLE, textView.getVisibility());
Geoffrey Pitsch1fbf66e2017-05-09 11:32:27 -0400452 }
453
454 @Test
Julia Reynolds52a27372019-04-03 11:00:17 -0400455 public void testBindNotification_BlockLink_BlockingHelper() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400456 mNotificationInfo.bindNotification(
457 mMockPackageManager,
458 mMockINotificationManager,
459 mVisualStabilityManager,
460 TEST_PACKAGE_NAME,
461 mNotificationChannel,
462 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700463 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400464 null,
465 mock(NotificationInfo.OnSettingsClickListener.class),
466 null,
467 true,
468 false,
469 true /* isBlockingHelper */,
470 IMPORTANCE_DEFAULT,
471 true);
Julia Reynolds52a27372019-04-03 11:00:17 -0400472 final View block =
473 mNotificationInfo.findViewById(R.id.blocking_helper_turn_off_notifications);
Gus Prevas82ad0592018-11-28 14:27:40 -0500474 final View interruptivenessSettings = mNotificationInfo.findViewById(
Julia Reynolds52a27372019-04-03 11:00:17 -0400475 R.id.inline_controls);
Gus Prevas82ad0592018-11-28 14:27:40 -0500476 assertEquals(VISIBLE, block.getVisibility());
477 assertEquals(GONE, interruptivenessSettings.getVisibility());
478 }
479
480 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500481 public void testBindNotification_SetsOnClickListenerForSettings() throws Exception {
482 final CountDownLatch latch = new CountDownLatch(1);
Ned Burns9512e0c2019-05-30 19:36:04 -0400483 mNotificationInfo.bindNotification(
484 mMockPackageManager,
485 mMockINotificationManager,
486 mVisualStabilityManager,
487 TEST_PACKAGE_NAME,
488 mNotificationChannel,
489 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700490 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400491 null,
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500492 (View v, NotificationChannel c, int appUid) -> {
Julia Reynolds3aedded2017-03-31 14:42:09 -0400493 assertEquals(mNotificationChannel, c);
494 latch.countDown();
Ned Burns9512e0c2019-05-30 19:36:04 -0400495 },
496 null,
497 true,
498 false,
499 IMPORTANCE_DEFAULT,
500 true);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500501
Julia Reynolds437cdb12018-01-03 12:27:24 -0500502 final View settingsButton = mNotificationInfo.findViewById(R.id.info);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500503 settingsButton.performClick();
504 // Verify that listener was triggered.
505 assertEquals(0, latch.getCount());
506 }
507
508 @Test
Geoffrey Pitsch029a3fa2017-03-30 13:01:57 -0400509 public void testBindNotification_SettingsButtonInvisibleWhenNoClickListener() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400510 mNotificationInfo.bindNotification(
511 mMockPackageManager,
512 mMockINotificationManager,
513 mVisualStabilityManager,
514 TEST_PACKAGE_NAME,
515 mNotificationChannel,
516 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700517 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400518 null,
519 null,
520 null,
521 true,
522 false,
523 IMPORTANCE_DEFAULT,
524 true);
Julia Reynolds35765d82018-08-17 11:39:19 -0400525 final View settingsButton = mNotificationInfo.findViewById(R.id.info);
526 assertTrue(settingsButton.getVisibility() != View.VISIBLE);
527 }
528
529 @Test
530 public void testBindNotification_SettingsButtonInvisibleWhenDeviceUnprovisioned()
531 throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400532 mNotificationInfo.bindNotification(
533 mMockPackageManager,
534 mMockINotificationManager,
535 mVisualStabilityManager,
536 TEST_PACKAGE_NAME,
537 mNotificationChannel,
538 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700539 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400540 null,
Julia Reynolds35765d82018-08-17 11:39:19 -0400541 (View v, NotificationChannel c, int appUid) -> {
542 assertEquals(mNotificationChannel, c);
Ned Burns9512e0c2019-05-30 19:36:04 -0400543 },
544 null,
545 false,
546 false,
547 IMPORTANCE_DEFAULT,
548 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500549 final View settingsButton = mNotificationInfo.findViewById(R.id.info);
Geoffrey Pitsch029a3fa2017-03-30 13:01:57 -0400550 assertTrue(settingsButton.getVisibility() != View.VISIBLE);
551 }
552
553 @Test
Julia Reynolds437cdb12018-01-03 12:27:24 -0500554 public void testBindNotification_SettingsButtonReappearsAfterSecondBind() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400555 mNotificationInfo.bindNotification(
556 mMockPackageManager,
557 mMockINotificationManager,
558 mVisualStabilityManager,
559 TEST_PACKAGE_NAME,
560 mNotificationChannel,
561 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700562 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400563 null,
564 null,
565 null,
566 true,
567 false,
568 IMPORTANCE_DEFAULT,
569 true);
570 mNotificationInfo.bindNotification(
571 mMockPackageManager,
572 mMockINotificationManager,
573 mVisualStabilityManager,
574 TEST_PACKAGE_NAME,
575 mNotificationChannel,
576 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700577 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400578 null,
579 (View v, NotificationChannel c, int appUid) -> { },
580 null,
581 true,
582 false,
583 IMPORTANCE_DEFAULT,
584 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500585 final View settingsButton = mNotificationInfo.findViewById(R.id.info);
Geoffrey Pitsch029a3fa2017-03-30 13:01:57 -0400586 assertEquals(View.VISIBLE, settingsButton.getVisibility());
587 }
588
589 @Test
Will Brockmana399f022019-01-30 10:59:36 -0500590 public void testBindNotificationLogging_notBlockingHelper() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400591 mNotificationInfo.bindNotification(
592 mMockPackageManager,
593 mMockINotificationManager,
594 mVisualStabilityManager,
595 TEST_PACKAGE_NAME,
596 mNotificationChannel,
597 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700598 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400599 null,
600 null,
601 null,
602 true,
603 false,
604 IMPORTANCE_DEFAULT,
605 true);
Eyal Posenera9cf9c72018-12-18 16:23:54 +0200606 verify(mMetricsLogger).write(argThat(logMaker ->
Will Brockmana399f022019-01-30 10:59:36 -0500607 logMaker.getCategory() == MetricsEvent.ACTION_NOTE_CONTROLS
608 && logMaker.getType() == MetricsEvent.TYPE_OPEN
609 && logMaker.getSubtype() == MetricsEvent.BLOCKING_HELPER_UNKNOWN
610 ));
611 }
612
613 @Test
614 public void testBindNotificationLogging_BlockingHelper() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400615 mNotificationInfo.bindNotification(
616 mMockPackageManager,
617 mMockINotificationManager,
618 mVisualStabilityManager,
619 TEST_PACKAGE_NAME,
620 mNotificationChannel,
621 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700622 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400623 null,
624 null,
625 null,
626 false,
Julia Reynolds52a27372019-04-03 11:00:17 -0400627 true,
Ned Burns9512e0c2019-05-30 19:36:04 -0400628 true,
629 IMPORTANCE_DEFAULT,
630 true);
Will Brockmana399f022019-01-30 10:59:36 -0500631 verify(mMetricsLogger).write(argThat(logMaker ->
632 logMaker.getCategory() == MetricsEvent.ACTION_NOTE_CONTROLS
Eyal Poseneraea29ed2019-01-24 09:54:08 +0200633 && logMaker.getType() == MetricsEvent.TYPE_OPEN
Eyal Posenera9cf9c72018-12-18 16:23:54 +0200634 && logMaker.getSubtype() == MetricsEvent.BLOCKING_HELPER_DISPLAY
635 ));
Rohan Shahda5dcdd2018-04-27 17:21:50 -0700636 }
637
638 @Test
639 public void testLogBlockingHelperCounter_logsForBlockingHelper() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400640 mNotificationInfo.bindNotification(
641 mMockPackageManager,
642 mMockINotificationManager,
643 mVisualStabilityManager,
644 TEST_PACKAGE_NAME,
645 mNotificationChannel,
646 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700647 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400648 null,
649 null,
650 null,
651 false,
Julia Reynolds52a27372019-04-03 11:00:17 -0400652 true,
Ned Burns9512e0c2019-05-30 19:36:04 -0400653 true,
654 IMPORTANCE_DEFAULT,
655 true);
Rohan Shahda5dcdd2018-04-27 17:21:50 -0700656 mNotificationInfo.logBlockingHelperCounter("HowCanNotifsBeRealIfAppsArent");
William Brockman75cf66a2018-12-21 13:25:01 -0500657 verify(mMetricsLogger).count(eq("HowCanNotifsBeRealIfAppsArent"), eq(1));
Rohan Shahda5dcdd2018-04-27 17:21:50 -0700658 }
659
660 @Test
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500661 public void testOnClickListenerPassesNullChannelForBundle() throws Exception {
662 final CountDownLatch latch = new CountDownLatch(1);
Ned Burns9512e0c2019-05-30 19:36:04 -0400663 mNotificationInfo.bindNotification(
664 mMockPackageManager,
665 mMockINotificationManager,
666 mVisualStabilityManager,
Evan Laird47dc4542019-04-24 15:10:52 -0400667 TEST_PACKAGE_NAME, mNotificationChannel,
Ned Burns9512e0c2019-05-30 19:36:04 -0400668 createMultipleChannelSet(MULTIPLE_CHANNEL_COUNT),
Mady Mellor53162c12019-10-22 17:12:59 -0700669 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400670 null,
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500671 (View v, NotificationChannel c, int appUid) -> {
Julia Reynolds3aedded2017-03-31 14:42:09 -0400672 assertEquals(null, c);
673 latch.countDown();
Ned Burns9512e0c2019-05-30 19:36:04 -0400674 },
675 null,
676 true,
677 true,
678 IMPORTANCE_DEFAULT,
679 true);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500680
Julia Reynolds437cdb12018-01-03 12:27:24 -0500681 mNotificationInfo.findViewById(R.id.info).performClick();
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500682 // Verify that listener was triggered.
683 assertEquals(0, latch.getCount());
684 }
685
686 @Test
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500687 @UiThreadTest
Julia Reynolds437cdb12018-01-03 12:27:24 -0500688 public void testBindNotification_ChannelNameInvisibleWhenBundleFromDifferentChannels()
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500689 throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400690 mNotificationInfo.bindNotification(
691 mMockPackageManager,
692 mMockINotificationManager,
693 mVisualStabilityManager,
694 TEST_PACKAGE_NAME,
695 mNotificationChannel,
696 createMultipleChannelSet(MULTIPLE_CHANNEL_COUNT),
Mady Mellor53162c12019-10-22 17:12:59 -0700697 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400698 null,
699 null,
700 null,
701 true,
702 false,
703 IMPORTANCE_DEFAULT,
704 true);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500705 final TextView channelNameView =
Julia Reynolds437cdb12018-01-03 12:27:24 -0500706 mNotificationInfo.findViewById(R.id.channel_name);
707 assertEquals(GONE, channelNameView.getVisibility());
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500708 }
709
710 @Test
711 @UiThreadTest
Julia Reynolds437cdb12018-01-03 12:27:24 -0500712 public void testStopInvisibleIfBundleFromDifferentChannels() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400713 mNotificationInfo.bindNotification(
714 mMockPackageManager,
715 mMockINotificationManager,
716 mVisualStabilityManager,
717 TEST_PACKAGE_NAME,
718 mNotificationChannel,
719 createMultipleChannelSet(MULTIPLE_CHANNEL_COUNT),
Mady Mellor53162c12019-10-22 17:12:59 -0700720 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400721 null,
722 null,
723 null,
724 true,
725 false,
726 IMPORTANCE_DEFAULT,
727 true);
Julia Reynolds52a27372019-04-03 11:00:17 -0400728 assertEquals(GONE, mNotificationInfo.findViewById(
729 R.id.interruptiveness_settings).getVisibility());
730 assertEquals(VISIBLE, mNotificationInfo.findViewById(
731 R.id.non_configurable_multichannel_text).getVisibility());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500732 }
733
734 @Test
Julia Reynolds52a27372019-04-03 11:00:17 -0400735 public void testBindNotification_whenAppUnblockable() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400736 mNotificationInfo.bindNotification(
737 mMockPackageManager,
738 mMockINotificationManager,
739 mVisualStabilityManager,
740 TEST_PACKAGE_NAME,
741 mNotificationChannel,
742 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700743 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400744 null,
745 null,
746 null,
747 true,
748 true,
749 IMPORTANCE_DEFAULT,
750 true);
Julia Reynolds52a27372019-04-03 11:00:17 -0400751 final TextView view = mNotificationInfo.findViewById(R.id.non_configurable_text);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500752 assertEquals(View.VISIBLE, view.getVisibility());
Geoffrey Pitschb43486a2017-06-01 13:45:59 -0400753 assertEquals(mContext.getString(R.string.notification_unblockable_desc),
Julia Reynolds437cdb12018-01-03 12:27:24 -0500754 view.getText());
Julia Reynolds52a27372019-04-03 11:00:17 -0400755 assertEquals(GONE,
756 mNotificationInfo.findViewById(R.id.interruptiveness_settings).getVisibility());
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500757 }
758
759 @Test
Mady Mellor53162c12019-10-22 17:12:59 -0700760 public void testBindNotification_alertIsSelected() throws Exception {
761 mNotificationInfo.bindNotification(
762 mMockPackageManager,
763 mMockINotificationManager,
764 mVisualStabilityManager,
765 TEST_PACKAGE_NAME,
766 mNotificationChannel,
767 mNotificationChannelSet,
768 mBubbleEntry,
769 null,
770 null,
771 null,
772 true,
773 false,
774 IMPORTANCE_DEFAULT,
775 true);
776 assertTrue(mNotificationInfo.findViewById(R.id.alert).isSelected());
777 }
778
779 @Test
780 public void testBindNotification_silenceIsSelected() throws Exception {
781 mNotificationInfo.bindNotification(
782 mMockPackageManager,
783 mMockINotificationManager,
784 mVisualStabilityManager,
785 TEST_PACKAGE_NAME,
786 mNotificationChannel,
787 mNotificationChannelSet,
788 mBubbleEntry,
789 null,
790 null,
791 null,
792 true,
793 false,
794 IMPORTANCE_DEFAULT,
795 false);
796 assertTrue(mNotificationInfo.findViewById(R.id.silence).isSelected());
797 }
798
799 @Test
800 public void testBindNotification_bubbleIsSelected() throws Exception {
801 mBubbleEntry.getSbn().getNotification().flags |= FLAG_BUBBLE;
802 mNotificationInfo.bindNotification(
803 mMockPackageManager,
804 mMockINotificationManager,
805 mVisualStabilityManager,
806 TEST_PACKAGE_NAME,
807 mNotificationChannel,
808 mNotificationChannelSet,
809 mBubbleEntry,
810 null,
811 null,
812 null,
813 true,
814 false,
815 IMPORTANCE_DEFAULT,
816 true);
817
818 View bubbleView = mNotificationInfo.findViewById(R.id.bubble);
819 assertEquals(View.VISIBLE, bubbleView.getVisibility());
820 assertTrue(bubbleView.isSelected());
821 }
822
823 @Test
824 public void testBindNotification_whenCanBubble() throws Exception {
825 mNotificationInfo.bindNotification(
826 mMockPackageManager,
827 mMockINotificationManager,
828 mVisualStabilityManager,
829 TEST_PACKAGE_NAME,
830 mNotificationChannel,
831 mNotificationChannelSet,
832 mBubbleEntry,
833 null,
834 null,
835 null,
836 true,
837 false,
838 IMPORTANCE_DEFAULT,
839 true);
840
841 View bubbleView = mNotificationInfo.findViewById(R.id.bubble);
842 assertEquals(View.VISIBLE, bubbleView.getVisibility());
843 assertFalse(bubbleView.isSelected());
844 }
845
846 @Test
847 public void testBindNotification_whenCantBubble() throws Exception {
848 mNotificationInfo.bindNotification(
849 mMockPackageManager,
850 mMockINotificationManager,
851 mVisualStabilityManager,
852 TEST_PACKAGE_NAME,
853 mNotificationChannel,
854 mNotificationChannelSet,
855 mEntry,
856 null,
857 null,
858 null,
859 true,
860 false,
861 IMPORTANCE_DEFAULT,
862 true);
863 View bubbleView = mNotificationInfo.findViewById(R.id.bubble);
864 assertEquals(View.GONE, bubbleView.getVisibility());
865 }
866
867 @Test
868 public void testBubble_promotesBubble() throws Exception {
869 mNotificationInfo.bindNotification(
870 mMockPackageManager,
871 mMockINotificationManager,
872 mVisualStabilityManager,
873 TEST_PACKAGE_NAME,
874 mNotificationChannel,
875 mNotificationChannelSet,
876 mBubbleEntry,
877 null,
878 null,
879 null,
880 true,
881 false,
882 IMPORTANCE_DEFAULT,
883 true);
884
885 assertFalse(mBubbleEntry.isBubble());
886
887 // Promote it
888 mNotificationInfo.findViewById(R.id.bubble).performClick();
889 mNotificationInfo.findViewById(R.id.done).performClick();
890 mNotificationInfo.handleCloseControls(true, false);
891
892 verify(mBubbleController, times(1)).onUserCreatedBubbleFromNotification(mBubbleEntry);
893 }
894
895 @Test
896 public void testAlert_demotesBubble() throws Exception {
897 mBubbleEntry.getSbn().getNotification().flags |= FLAG_BUBBLE;
898
899 mNotificationInfo.bindNotification(
900 mMockPackageManager,
901 mMockINotificationManager,
902 mVisualStabilityManager,
903 TEST_PACKAGE_NAME,
904 mNotificationChannel,
905 mNotificationChannelSet,
906 mBubbleEntry,
907 null,
908 null,
909 null,
910 true,
911 false,
912 IMPORTANCE_DEFAULT,
913 true);
914
915 assertTrue(mBubbleEntry.isBubble());
916
917 // Demote it
918 mNotificationInfo.findViewById(R.id.alert).performClick();
919 mNotificationInfo.findViewById(R.id.done).performClick();
920 mNotificationInfo.handleCloseControls(true, false);
921
922 verify(mBubbleController, times(1)).onUserDemotedBubbleFromNotification(mBubbleEntry);
923 }
924
925 @Test
926 public void testSilence_demotesBubble() throws Exception {
927 mBubbleEntry.getSbn().getNotification().flags |= FLAG_BUBBLE;
928
929 mNotificationInfo.bindNotification(
930 mMockPackageManager,
931 mMockINotificationManager,
932 mVisualStabilityManager,
933 TEST_PACKAGE_NAME,
934 mNotificationChannel,
935 mNotificationChannelSet,
936 mBubbleEntry,
937 null,
938 null,
939 null,
940 true,
941 false,
942 IMPORTANCE_DEFAULT,
943 true);
944
945 assertTrue(mBubbleEntry.isBubble());
946
947 // Demote it
948 mNotificationInfo.findViewById(R.id.silence).performClick();
949 mNotificationInfo.findViewById(R.id.done).performClick();
950 mNotificationInfo.handleCloseControls(true, false);
951
952 verify(mBubbleController, times(1)).onUserDemotedBubbleFromNotification(mBubbleEntry);
953 }
954
955 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500956 public void testBindNotification_DoesNotUpdateNotificationChannel() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400957 mNotificationInfo.bindNotification(
958 mMockPackageManager,
959 mMockINotificationManager,
960 mVisualStabilityManager,
961 TEST_PACKAGE_NAME,
962 mNotificationChannel,
963 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700964 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400965 null,
966 null,
967 null,
968 true,
969 false,
970 IMPORTANCE_DEFAULT,
971 true);
Rohan Shahca0447e2018-03-30 15:18:27 -0700972 mTestableLooper.processAllMessages();
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500973 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400974 anyString(), eq(TEST_UID), any());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500975 }
976
977 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500978 public void testDoesNotUpdateNotificationChannelAfterImportanceChanged() throws Exception {
Julia Reynolds437cdb12018-01-03 12:27:24 -0500979 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Ned Burns9512e0c2019-05-30 19:36:04 -0400980 mNotificationInfo.bindNotification(
981 mMockPackageManager,
982 mMockINotificationManager,
983 mVisualStabilityManager,
984 TEST_PACKAGE_NAME,
985 mNotificationChannel,
986 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700987 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400988 null,
989 null,
990 null,
991 true,
992 false,
993 IMPORTANCE_LOW,
994 false);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500995
Julia Reynolds8728d002019-04-19 15:46:13 -0400996 mNotificationInfo.findViewById(R.id.alert).performClick();
Rohan Shahca0447e2018-03-30 15:18:27 -0700997 mTestableLooper.processAllMessages();
Julia Reynoldse0341482018-03-08 14:42:50 -0500998 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
999 anyString(), eq(TEST_UID), any());
1000 }
1001
1002 @Test
Gus Prevas9abc5062018-10-31 16:11:04 -04001003 public void testDoesNotUpdateNotificationChannelAfterImportanceChangedSilenced()
1004 throws Exception {
1005 mNotificationChannel.setImportance(IMPORTANCE_DEFAULT);
Ned Burns9512e0c2019-05-30 19:36:04 -04001006 mNotificationInfo.bindNotification(
1007 mMockPackageManager,
1008 mMockINotificationManager,
1009 mVisualStabilityManager,
1010 TEST_PACKAGE_NAME,
1011 mNotificationChannel,
1012 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -07001013 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -04001014 null,
1015 null,
1016 null,
1017 true,
1018 false,
1019 IMPORTANCE_DEFAULT,
1020 true);
Gus Prevas9abc5062018-10-31 16:11:04 -04001021
Julia Reynolds8728d002019-04-19 15:46:13 -04001022 mNotificationInfo.findViewById(R.id.silence).performClick();
Gus Prevas9abc5062018-10-31 16:11:04 -04001023 mTestableLooper.processAllMessages();
1024 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
1025 anyString(), eq(TEST_UID), any());
1026 }
1027
1028 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -05001029 public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnchanged()
1030 throws Exception {
Julia Reynoldsc65656a2018-02-12 09:55:14 -05001031 int originalImportance = mNotificationChannel.getImportance();
Ned Burns9512e0c2019-05-30 19:36:04 -04001032 mNotificationInfo.bindNotification(
1033 mMockPackageManager,
1034 mMockINotificationManager,
1035 mVisualStabilityManager,
1036 TEST_PACKAGE_NAME,
1037 mNotificationChannel,
1038 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -07001039 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -04001040 null,
1041 null,
1042 null,
1043 true,
1044 false,
1045 IMPORTANCE_DEFAULT,
1046 true);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -05001047
Mady Mellorc2dbe492017-03-30 13:22:03 -07001048 mNotificationInfo.handleCloseControls(true, false);
Rohan Shahca0447e2018-03-30 15:18:27 -07001049 mTestableLooper.processAllMessages();
Julia Reynoldsc65656a2018-02-12 09:55:14 -05001050 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -04001051 anyString(), eq(TEST_UID), any());
Julia Reynoldsc65656a2018-02-12 09:55:14 -05001052 assertEquals(originalImportance, mNotificationChannel.getImportance());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -05001053 }
1054
1055 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -05001056 public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnspecified()
1057 throws Exception {
Julia Reynoldsc65656a2018-02-12 09:55:14 -05001058 mNotificationChannel.setImportance(IMPORTANCE_UNSPECIFIED);
Ned Burns9512e0c2019-05-30 19:36:04 -04001059 mNotificationInfo.bindNotification(
1060 mMockPackageManager,
1061 mMockINotificationManager,
1062 mVisualStabilityManager,
1063 TEST_PACKAGE_NAME,
1064 mNotificationChannel,
1065 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -07001066 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -04001067 null,
1068 null,
1069 null,
1070 true,
1071 false,
1072 IMPORTANCE_UNSPECIFIED,
1073 true);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -05001074
Mady Mellorc2dbe492017-03-30 13:22:03 -07001075 mNotificationInfo.handleCloseControls(true, false);
Rohan Shahca0447e2018-03-30 15:18:27 -07001076
1077 mTestableLooper.processAllMessages();
Julia Reynoldsc65656a2018-02-12 09:55:14 -05001078 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -04001079 anyString(), eq(TEST_UID), any());
Julia Reynoldsc65656a2018-02-12 09:55:14 -05001080 assertEquals(IMPORTANCE_UNSPECIFIED, mNotificationChannel.getImportance());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -05001081 }
1082
1083 @Test
Will Brockmana399f022019-01-30 10:59:36 -05001084 public void testCloseControls_nonNullCheckSaveListenerDoesntDelayKeepShowing_BlockingHelper()
Rohan Shahdd588c72018-05-09 20:32:15 -07001085 throws Exception {
1086 NotificationInfo.CheckSaveListener listener =
1087 mock(NotificationInfo.CheckSaveListener.class);
Julia Reynolds8728d002019-04-19 15:46:13 -04001088 mNotificationChannel.setImportance(IMPORTANCE_DEFAULT);
Ned Burns9512e0c2019-05-30 19:36:04 -04001089 mNotificationInfo.bindNotification(
1090 mMockPackageManager,
1091 mMockINotificationManager,
1092 mVisualStabilityManager,
1093 TEST_PACKAGE_NAME,
1094 mNotificationChannel /* notificationChannel */,
1095 createMultipleChannelSet(10) /* numUniqueChannelsInRow */,
Mady Mellor53162c12019-10-22 17:12:59 -07001096 mEntry,
Evan Laird47dc4542019-04-24 15:10:52 -04001097 listener /* checkSaveListener */,
Ned Burns9512e0c2019-05-30 19:36:04 -04001098 null /* onSettingsClick */,
1099 null /* onAppSettingsClick */,
1100 true /* provisioned */,
1101 false /* isNonblockable */,
1102 true /* isForBlockingHelper */,
1103 IMPORTANCE_DEFAULT,
1104 true);
Rohan Shahdd588c72018-05-09 20:32:15 -07001105
1106 NotificationGuts guts = spy(new NotificationGuts(mContext, null));
1107 when(guts.getWindowToken()).thenReturn(mock(IBinder.class));
1108 doNothing().when(guts).animateClose(anyInt(), anyInt(), anyBoolean());
1109 doNothing().when(guts).setExposed(anyBoolean(), anyBoolean());
1110 guts.setGutsContent(mNotificationInfo);
1111 mNotificationInfo.setGutsParent(guts);
1112
Julia Reynolds52a27372019-04-03 11:00:17 -04001113 mNotificationInfo.findViewById(R.id.keep_showing).performClick();
Rohan Shahdd588c72018-05-09 20:32:15 -07001114
1115 verify(mBlockingHelperManager).dismissCurrentBlockingHelper();
1116 mTestableLooper.processAllMessages();
1117 verify(mMockINotificationManager, times(1))
1118 .setNotificationsEnabledWithImportanceLockForPackage(
1119 anyString(), eq(TEST_UID), eq(true));
1120 }
1121
Rohan Shah593e8f12018-05-22 10:06:23 -07001122 @Test
Will Brockmana399f022019-01-30 10:59:36 -05001123 public void testCloseControls_nonNullCheckSaveListenerDoesntDelayDismiss_BlockingHelper()
Rohan Shah593e8f12018-05-22 10:06:23 -07001124 throws Exception {
1125 NotificationInfo.CheckSaveListener listener =
1126 mock(NotificationInfo.CheckSaveListener.class);
Julia Reynolds8728d002019-04-19 15:46:13 -04001127 mNotificationChannel.setImportance(IMPORTANCE_DEFAULT);
Ned Burns9512e0c2019-05-30 19:36:04 -04001128 mNotificationInfo.bindNotification(
1129 mMockPackageManager,
1130 mMockINotificationManager,
1131 mVisualStabilityManager,
1132 TEST_PACKAGE_NAME,
1133 mNotificationChannel /* notificationChannel */,
1134 createMultipleChannelSet(10) /* numUniqueChannelsInRow */,
Mady Mellor53162c12019-10-22 17:12:59 -07001135 mEntry,
Evan Laird47dc4542019-04-24 15:10:52 -04001136 listener /* checkSaveListener */,
Ned Burns9512e0c2019-05-30 19:36:04 -04001137 null /* onSettingsClick */,
1138 null /* onAppSettingsClick */,
1139 false /* isNonblockable */,
1140 true /* isForBlockingHelper */,
1141 true, IMPORTANCE_DEFAULT,
1142 true);
Rohan Shah593e8f12018-05-22 10:06:23 -07001143
1144 mNotificationInfo.handleCloseControls(true /* save */, false /* force */);
1145
1146 mTestableLooper.processAllMessages();
1147 verify(listener, times(0)).checkSave(any(Runnable.class), eq(mSbn));
1148 }
1149
1150 @Test
Will Brockmana399f022019-01-30 10:59:36 -05001151 public void testCloseControls_checkSaveListenerDelaysStopNotifications_BlockingHelper()
Rohan Shah593e8f12018-05-22 10:06:23 -07001152 throws Exception {
1153 NotificationInfo.CheckSaveListener listener =
1154 mock(NotificationInfo.CheckSaveListener.class);
Julia Reynolds8728d002019-04-19 15:46:13 -04001155 mNotificationChannel.setImportance(IMPORTANCE_DEFAULT);
Ned Burns9512e0c2019-05-30 19:36:04 -04001156 mNotificationInfo.bindNotification(
1157 mMockPackageManager,
1158 mMockINotificationManager,
1159 mVisualStabilityManager,
1160 TEST_PACKAGE_NAME,
1161 mNotificationChannel /* notificationChannel */,
1162 createMultipleChannelSet(10) /* numUniqueChannelsInRow */,
Mady Mellor53162c12019-10-22 17:12:59 -07001163 mEntry,
Evan Laird47dc4542019-04-24 15:10:52 -04001164 listener /* checkSaveListener */,
Ned Burns9512e0c2019-05-30 19:36:04 -04001165 null /* onSettingsClick */,
1166 null /* onAppSettingsClick */,
Julia Reynolds35765d82018-08-17 11:39:19 -04001167 true /* provisioned */,
Ned Burns9512e0c2019-05-30 19:36:04 -04001168 false /* isNonblockable */,
1169 true /* isForBlockingHelper */,
1170 IMPORTANCE_DEFAULT,
1171 true);
Rohan Shah593e8f12018-05-22 10:06:23 -07001172
Julia Reynolds52a27372019-04-03 11:00:17 -04001173 mNotificationInfo.findViewById(R.id.deliver_silently).performClick();
Rohan Shah593e8f12018-05-22 10:06:23 -07001174 mTestableLooper.processAllMessages();
1175 verify(listener).checkSave(any(Runnable.class), eq(mSbn));
1176 }
Rohan Shahdd588c72018-05-09 20:32:15 -07001177
Rohan Shah590e1b22018-04-10 23:48:47 -04001178 @Test
Rohan Shah524cf7b2018-03-15 14:40:02 -07001179 public void testCloseControls_blockingHelperDismissedIfShown() throws Exception {
Julia Reynolds8728d002019-04-19 15:46:13 -04001180 mNotificationChannel.setImportance(IMPORTANCE_DEFAULT);
Rohan Shah524cf7b2018-03-15 14:40:02 -07001181 mNotificationInfo.bindNotification(
1182 mMockPackageManager,
1183 mMockINotificationManager,
Ned Burns9512e0c2019-05-30 19:36:04 -04001184 mVisualStabilityManager,
Rohan Shah524cf7b2018-03-15 14:40:02 -07001185 TEST_PACKAGE_NAME,
1186 mNotificationChannel,
Evan Laird47dc4542019-04-24 15:10:52 -04001187 mNotificationChannelSet /* numChannels */,
Mady Mellor53162c12019-10-22 17:12:59 -07001188 mEntry,
Rohan Shah524cf7b2018-03-15 14:40:02 -07001189 null /* checkSaveListener */,
1190 null /* onSettingsClick */,
1191 null /* onAppSettingsClick */,
Rohan Shah63411fc2018-03-28 19:05:52 -07001192 false /* isNonblockable */,
Rohan Shah524cf7b2018-03-15 14:40:02 -07001193 true /* isForBlockingHelper */,
Julia Reynolds35765d82018-08-17 11:39:19 -04001194 true,
Ned Burns9512e0c2019-05-30 19:36:04 -04001195 IMPORTANCE_DEFAULT,
1196 true);
Rohan Shahda5dcdd2018-04-27 17:21:50 -07001197 NotificationGuts guts = mock(NotificationGuts.class);
1198 doCallRealMethod().when(guts).closeControls(anyInt(), anyInt(), anyBoolean(), anyBoolean());
1199 mNotificationInfo.setGutsParent(guts);
Rohan Shah524cf7b2018-03-15 14:40:02 -07001200
Evan Laird7956fe82019-05-30 17:14:57 -04001201 mNotificationInfo.closeControls(mNotificationInfo, true);
Rohan Shah524cf7b2018-03-15 14:40:02 -07001202
1203 verify(mBlockingHelperManager).dismissCurrentBlockingHelper();
1204 }
1205
1206 @Test
Nadia Benbernou3b4a93a2019-02-06 16:16:47 -05001207 public void testSilentlyChangedCallsUpdateNotificationChannel_blockingHelper()
1208 throws Exception {
Julia Reynolds8728d002019-04-19 15:46:13 -04001209 mNotificationChannel.setImportance(IMPORTANCE_DEFAULT);
Nadia Benbernou3b4a93a2019-02-06 16:16:47 -05001210 mNotificationInfo.bindNotification(
1211 mMockPackageManager,
1212 mMockINotificationManager,
Ned Burns9512e0c2019-05-30 19:36:04 -04001213 mVisualStabilityManager,
Nadia Benbernou3b4a93a2019-02-06 16:16:47 -05001214 TEST_PACKAGE_NAME,
1215 mNotificationChannel,
Evan Laird47dc4542019-04-24 15:10:52 -04001216 mNotificationChannelSet /* numChannels */,
Mady Mellor53162c12019-10-22 17:12:59 -07001217 mEntry,
Nadia Benbernou3b4a93a2019-02-06 16:16:47 -05001218 null /* checkSaveListener */,
1219 null /* onSettingsClick */,
1220 null /* onAppSettingsClick */,
1221 true /*provisioned */,
1222 false /* isNonblockable */,
1223 true /* isForBlockingHelper */,
Nadia Benbernou3b4a93a2019-02-06 16:16:47 -05001224 IMPORTANCE_DEFAULT,
Julia Reynolds8728d002019-04-19 15:46:13 -04001225 true);
Nadia Benbernou3b4a93a2019-02-06 16:16:47 -05001226
1227 mNotificationInfo.findViewById(R.id.deliver_silently).performClick();
1228 waitForUndoButton();
1229 mNotificationInfo.handleCloseControls(true, false);
1230
1231 mTestableLooper.processAllMessages();
1232 ArgumentCaptor<NotificationChannel> updated =
1233 ArgumentCaptor.forClass(NotificationChannel.class);
1234 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
1235 anyString(), eq(TEST_UID), updated.capture());
1236 assertTrue((updated.getValue().getUserLockedFields()
1237 & USER_LOCKED_IMPORTANCE) != 0);
1238 assertEquals(IMPORTANCE_LOW, updated.getValue().getImportance());
1239 }
1240
1241 @Test
Julia Reynolds52a27372019-04-03 11:00:17 -04001242 public void testKeepUpdatesNotificationChannel_blockingHelper() throws Exception {
Julia Reynolds437cdb12018-01-03 12:27:24 -05001243 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Ned Burns9512e0c2019-05-30 19:36:04 -04001244 mNotificationInfo.bindNotification(
1245 mMockPackageManager,
1246 mMockINotificationManager,
1247 mVisualStabilityManager,
1248 TEST_PACKAGE_NAME,
1249 mNotificationChannel,
1250 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -07001251 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -04001252 null,
1253 null,
1254 null,
1255 true,
1256 true,
1257 IMPORTANCE_LOW,
1258 false);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -05001259
Julia Reynolds52a27372019-04-03 11:00:17 -04001260 mNotificationInfo.findViewById(R.id.keep_showing).performClick();
Julia Reynoldsc65656a2018-02-12 09:55:14 -05001261 mNotificationInfo.handleCloseControls(true, false);
1262
Rohan Shahca0447e2018-03-30 15:18:27 -07001263 mTestableLooper.processAllMessages();
Julia Reynoldsc65656a2018-02-12 09:55:14 -05001264 ArgumentCaptor<NotificationChannel> updated =
1265 ArgumentCaptor.forClass(NotificationChannel.class);
1266 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
1267 anyString(), eq(TEST_UID), updated.capture());
1268 assertTrue(0 != (mNotificationChannel.getUserLockedFields() & USER_LOCKED_IMPORTANCE));
1269 assertEquals(IMPORTANCE_LOW, mNotificationChannel.getImportance());
1270 }
1271
1272 @Test
Julia Reynolds52a27372019-04-03 11:00:17 -04001273 public void testNoActionsUpdatesNotificationChannel_blockingHelper() throws Exception {
1274 mNotificationChannel.setImportance(IMPORTANCE_DEFAULT);
Ned Burns9512e0c2019-05-30 19:36:04 -04001275 mNotificationInfo.bindNotification(
1276 mMockPackageManager,
1277 mMockINotificationManager,
1278 mVisualStabilityManager,
1279 TEST_PACKAGE_NAME,
1280 mNotificationChannel,
1281 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -07001282 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -04001283 null,
1284 null,
1285 null,
1286 true,
1287 true,
1288 IMPORTANCE_DEFAULT,
1289 true);
Julia Reynolds52a27372019-04-03 11:00:17 -04001290
1291 mNotificationInfo.handleCloseControls(true, false);
1292
1293 mTestableLooper.processAllMessages();
1294 ArgumentCaptor<NotificationChannel> updated =
1295 ArgumentCaptor.forClass(NotificationChannel.class);
1296 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
1297 anyString(), eq(TEST_UID), updated.capture());
1298 assertTrue(0 != (mNotificationChannel.getUserLockedFields() & USER_LOCKED_IMPORTANCE));
1299 assertEquals(IMPORTANCE_DEFAULT, mNotificationChannel.getImportance());
1300 }
1301
1302 @Test
Gus Prevas9abc5062018-10-31 16:11:04 -04001303 public void testSilenceCallsUpdateNotificationChannel() throws Exception {
1304 mNotificationChannel.setImportance(IMPORTANCE_DEFAULT);
Ned Burns9512e0c2019-05-30 19:36:04 -04001305 mNotificationInfo.bindNotification(
1306 mMockPackageManager,
1307 mMockINotificationManager,
1308 mVisualStabilityManager,
1309 TEST_PACKAGE_NAME,
1310 mNotificationChannel,
1311 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -07001312 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -04001313 null,
1314 null,
1315 null,
1316 true,
1317 false,
1318 IMPORTANCE_DEFAULT,
1319 true);
Gus Prevas9abc5062018-10-31 16:11:04 -04001320
Julia Reynolds8728d002019-04-19 15:46:13 -04001321 mNotificationInfo.findViewById(R.id.silence).performClick();
Julia Reynolds52a27372019-04-03 11:00:17 -04001322 mNotificationInfo.findViewById(R.id.done).performClick();
Gus Prevas9abc5062018-10-31 16:11:04 -04001323 mNotificationInfo.handleCloseControls(true, false);
1324
1325 mTestableLooper.processAllMessages();
1326 ArgumentCaptor<NotificationChannel> updated =
1327 ArgumentCaptor.forClass(NotificationChannel.class);
1328 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
1329 anyString(), eq(TEST_UID), updated.capture());
1330 assertTrue((updated.getValue().getUserLockedFields()
1331 & USER_LOCKED_IMPORTANCE) != 0);
1332 assertEquals(IMPORTANCE_LOW, updated.getValue().getImportance());
1333 }
1334
1335 @Test
1336 public void testUnSilenceCallsUpdateNotificationChannel() throws Exception {
1337 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Ned Burns9512e0c2019-05-30 19:36:04 -04001338 mNotificationInfo.bindNotification(
1339 mMockPackageManager,
1340 mMockINotificationManager,
1341 mVisualStabilityManager,
1342 TEST_PACKAGE_NAME,
1343 mNotificationChannel,
1344 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -07001345 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -04001346 null,
1347 null,
1348 null,
1349 true,
1350 false,
1351 IMPORTANCE_LOW,
1352 false);
Gus Prevas9abc5062018-10-31 16:11:04 -04001353
Julia Reynolds8728d002019-04-19 15:46:13 -04001354 mNotificationInfo.findViewById(R.id.alert).performClick();
Julia Reynolds52a27372019-04-03 11:00:17 -04001355 mNotificationInfo.findViewById(R.id.done).performClick();
Gus Prevas9abc5062018-10-31 16:11:04 -04001356 mNotificationInfo.handleCloseControls(true, false);
1357
1358 mTestableLooper.processAllMessages();
1359 ArgumentCaptor<NotificationChannel> updated =
1360 ArgumentCaptor.forClass(NotificationChannel.class);
1361 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
1362 anyString(), eq(TEST_UID), updated.capture());
1363 assertTrue((updated.getValue().getUserLockedFields()
1364 & USER_LOCKED_IMPORTANCE) != 0);
Julia Reynolds9ae5e642019-02-06 10:19:22 -05001365 assertEquals(IMPORTANCE_DEFAULT, updated.getValue().getImportance());
Gus Prevas9abc5062018-10-31 16:11:04 -04001366 }
1367
1368 @Test
1369 public void testSilenceCallsUpdateNotificationChannel_channelImportanceUnspecified()
1370 throws Exception {
1371 mNotificationChannel.setImportance(IMPORTANCE_UNSPECIFIED);
Ned Burns9512e0c2019-05-30 19:36:04 -04001372 mNotificationInfo.bindNotification(
1373 mMockPackageManager,
1374 mMockINotificationManager,
1375 mVisualStabilityManager,
1376 TEST_PACKAGE_NAME,
1377 mNotificationChannel,
1378 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -07001379 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -04001380 null,
1381 null,
1382 null,
1383 true,
1384 false,
1385 IMPORTANCE_UNSPECIFIED,
1386 true);
Gus Prevas9abc5062018-10-31 16:11:04 -04001387
Julia Reynolds8728d002019-04-19 15:46:13 -04001388 mNotificationInfo.findViewById(R.id.silence).performClick();
Julia Reynolds52a27372019-04-03 11:00:17 -04001389 mNotificationInfo.findViewById(R.id.done).performClick();
Gus Prevas9abc5062018-10-31 16:11:04 -04001390 mNotificationInfo.handleCloseControls(true, false);
1391
1392 mTestableLooper.processAllMessages();
1393 ArgumentCaptor<NotificationChannel> updated =
1394 ArgumentCaptor.forClass(NotificationChannel.class);
1395 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
1396 anyString(), eq(TEST_UID), updated.capture());
1397 assertTrue((updated.getValue().getUserLockedFields()
1398 & USER_LOCKED_IMPORTANCE) != 0);
1399 assertEquals(IMPORTANCE_LOW, updated.getValue().getImportance());
1400 }
1401
1402 @Test
Julia Reynolds8728d002019-04-19 15:46:13 -04001403 public void testSilenceCallsUpdateNotificationChannel_channelImportanceMin()
Gus Prevas9abc5062018-10-31 16:11:04 -04001404 throws Exception {
Julia Reynolds8728d002019-04-19 15:46:13 -04001405 mNotificationChannel.setImportance(IMPORTANCE_MIN);
Ned Burns9512e0c2019-05-30 19:36:04 -04001406 mNotificationInfo.bindNotification(
1407 mMockPackageManager,
1408 mMockINotificationManager,
1409 mVisualStabilityManager,
1410 TEST_PACKAGE_NAME,
1411 mNotificationChannel,
1412 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -07001413 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -04001414 null,
1415 null,
1416 null,
1417 true,
1418 false,
1419 IMPORTANCE_MIN,
1420 false);
Julia Reynolds8728d002019-04-19 15:46:13 -04001421
1422 assertEquals(mContext.getString(R.string.inline_done_button),
1423 ((TextView) mNotificationInfo.findViewById(R.id.done)).getText());
1424 mNotificationInfo.findViewById(R.id.silence).performClick();
1425 assertEquals(mContext.getString(R.string.inline_done_button),
1426 ((TextView) mNotificationInfo.findViewById(R.id.done)).getText());
1427 mNotificationInfo.findViewById(R.id.done).performClick();
1428 mNotificationInfo.handleCloseControls(true, false);
1429
1430 mTestableLooper.processAllMessages();
1431 ArgumentCaptor<NotificationChannel> updated =
1432 ArgumentCaptor.forClass(NotificationChannel.class);
1433 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
1434 anyString(), eq(TEST_UID), updated.capture());
Evan Laird47dc4542019-04-24 15:10:52 -04001435 assertTrue((updated.getValue().getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0);
Julia Reynolds8728d002019-04-19 15:46:13 -04001436 assertEquals(IMPORTANCE_MIN, updated.getValue().getImportance());
1437 }
1438
1439 @Test
1440 public void testAlertCallsUpdateNotificationChannel_channelImportanceMin()
1441 throws Exception {
1442 mNotificationChannel.setImportance(IMPORTANCE_MIN);
Ned Burns9512e0c2019-05-30 19:36:04 -04001443 mNotificationInfo.bindNotification(
1444 mMockPackageManager,
1445 mMockINotificationManager,
1446 mVisualStabilityManager,
1447 TEST_PACKAGE_NAME,
1448 mNotificationChannel,
1449 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -07001450 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -04001451 null,
1452 null,
1453 null,
1454 true,
1455 false,
1456 IMPORTANCE_MIN,
1457 false);
Julia Reynolds8728d002019-04-19 15:46:13 -04001458
1459 assertEquals(mContext.getString(R.string.inline_done_button),
1460 ((TextView) mNotificationInfo.findViewById(R.id.done)).getText());
1461 mNotificationInfo.findViewById(R.id.alert).performClick();
1462 assertEquals(mContext.getString(R.string.inline_ok_button),
1463 ((TextView) mNotificationInfo.findViewById(R.id.done)).getText());
1464 mNotificationInfo.findViewById(R.id.done).performClick();
1465 mNotificationInfo.handleCloseControls(true, false);
1466
1467 mTestableLooper.processAllMessages();
1468 ArgumentCaptor<NotificationChannel> updated =
1469 ArgumentCaptor.forClass(NotificationChannel.class);
1470 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
1471 anyString(), eq(TEST_UID), updated.capture());
Evan Laird47dc4542019-04-24 15:10:52 -04001472 assertTrue((updated.getValue().getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0);
Julia Reynolds8728d002019-04-19 15:46:13 -04001473 assertEquals(IMPORTANCE_DEFAULT, updated.getValue().getImportance());
1474 }
1475
1476 @Test
Ned Burns9512e0c2019-05-30 19:36:04 -04001477 public void testAdjustImportanceTemporarilyAllowsReordering() throws Exception {
1478 mNotificationChannel.setImportance(IMPORTANCE_DEFAULT);
1479 mNotificationInfo.bindNotification(
1480 mMockPackageManager,
1481 mMockINotificationManager,
1482 mVisualStabilityManager,
1483 TEST_PACKAGE_NAME,
1484 mNotificationChannel,
1485 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -07001486 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -04001487 null,
1488 null,
1489 null,
1490 true,
1491 false,
1492 IMPORTANCE_DEFAULT,
1493 true);
1494
1495 mNotificationInfo.findViewById(R.id.silence).performClick();
1496 mNotificationInfo.findViewById(R.id.done).performClick();
1497 mNotificationInfo.handleCloseControls(true, false);
1498
1499 verify(mVisualStabilityManager).temporarilyAllowReordering();
1500 }
1501
1502 @Test
Julia Reynolds8728d002019-04-19 15:46:13 -04001503 public void testDoneText()
1504 throws Exception {
1505 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Ned Burns9512e0c2019-05-30 19:36:04 -04001506 mNotificationInfo.bindNotification(
1507 mMockPackageManager,
1508 mMockINotificationManager,
1509 mVisualStabilityManager,
1510 TEST_PACKAGE_NAME,
1511 mNotificationChannel,
1512 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -07001513 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -04001514 null,
1515 null,
1516 null,
1517 true,
1518 false,
1519 IMPORTANCE_LOW,
1520 false);
Gus Prevas9abc5062018-10-31 16:11:04 -04001521
Julia Reynolds8728d002019-04-19 15:46:13 -04001522 assertEquals(mContext.getString(R.string.inline_done_button),
1523 ((TextView) mNotificationInfo.findViewById(R.id.done)).getText());
1524 mNotificationInfo.findViewById(R.id.alert).performClick();
1525 assertEquals(mContext.getString(R.string.inline_ok_button),
1526 ((TextView) mNotificationInfo.findViewById(R.id.done)).getText());
1527 mNotificationInfo.findViewById(R.id.silence).performClick();
1528 assertEquals(mContext.getString(R.string.inline_done_button),
1529 ((TextView) mNotificationInfo.findViewById(R.id.done)).getText());
1530 }
1531
1532 @Test
1533 public void testUnSilenceCallsUpdateNotificationChannel_channelImportanceUnspecified()
1534 throws Exception {
1535 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Ned Burns9512e0c2019-05-30 19:36:04 -04001536 mNotificationInfo.bindNotification(
1537 mMockPackageManager,
1538 mMockINotificationManager,
1539 mVisualStabilityManager,
1540 TEST_PACKAGE_NAME,
1541 mNotificationChannel,
1542 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -07001543 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -04001544 null,
1545 null,
1546 null,
1547 true,
1548 false,
1549 IMPORTANCE_LOW,
1550 false);
Julia Reynolds8728d002019-04-19 15:46:13 -04001551
1552 mNotificationInfo.findViewById(R.id.alert).performClick();
Julia Reynolds52a27372019-04-03 11:00:17 -04001553 mNotificationInfo.findViewById(R.id.done).performClick();
Gus Prevas9abc5062018-10-31 16:11:04 -04001554 mNotificationInfo.handleCloseControls(true, false);
1555
1556 mTestableLooper.processAllMessages();
1557 ArgumentCaptor<NotificationChannel> updated =
1558 ArgumentCaptor.forClass(NotificationChannel.class);
1559 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
1560 anyString(), eq(TEST_UID), updated.capture());
1561 assertTrue((updated.getValue().getUserLockedFields()
1562 & USER_LOCKED_IMPORTANCE) != 0);
Julia Reynolds9ae5e642019-02-06 10:19:22 -05001563 assertEquals(IMPORTANCE_DEFAULT, updated.getValue().getImportance());
Gus Prevas9abc5062018-10-31 16:11:04 -04001564 }
1565
1566 @Test
Julia Reynolds437cdb12018-01-03 12:27:24 -05001567 public void testCloseControlsDoesNotUpdateIfSaveIsFalse() throws Exception {
1568 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Ned Burns9512e0c2019-05-30 19:36:04 -04001569 mNotificationInfo.bindNotification(
1570 mMockPackageManager,
1571 mMockINotificationManager,
1572 mVisualStabilityManager,
1573 TEST_PACKAGE_NAME,
1574 mNotificationChannel,
1575 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -07001576 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -04001577 null,
1578 null,
1579 null,
1580 true,
1581 false,
1582 IMPORTANCE_LOW,
1583 false);
Julia Reynolds437cdb12018-01-03 12:27:24 -05001584
Julia Reynolds8728d002019-04-19 15:46:13 -04001585 mNotificationInfo.findViewById(R.id.alert).performClick();
Julia Reynolds52a27372019-04-03 11:00:17 -04001586 mNotificationInfo.findViewById(R.id.done).performClick();
Mady Mellorc2dbe492017-03-30 13:22:03 -07001587 mNotificationInfo.handleCloseControls(false, false);
Rohan Shahca0447e2018-03-30 15:18:27 -07001588
1589 mTestableLooper.processAllMessages();
Geoffrey Pitschdf44b602017-02-03 13:31:50 -05001590 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -04001591 eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel));
Geoffrey Pitschdf44b602017-02-03 13:31:50 -05001592 }
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -04001593
1594 @Test
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -04001595 public void testCloseControlsUpdatesWhenCheckSaveListenerUsesCallback() throws Exception {
Julia Reynolds437cdb12018-01-03 12:27:24 -05001596 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Ned Burns9512e0c2019-05-30 19:36:04 -04001597 mNotificationInfo.bindNotification(
1598 mMockPackageManager,
1599 mMockINotificationManager,
1600 mVisualStabilityManager,
1601 TEST_PACKAGE_NAME,
1602 mNotificationChannel,
1603 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -07001604 mEntry,
Eliot Courtney47098cb2017-10-18 17:30:30 +09001605 (Runnable saveImportance, StatusBarNotification sbn) -> {
Julia Reynolds3aedded2017-03-31 14:42:09 -04001606 saveImportance.run();
Ned Burns9512e0c2019-05-30 19:36:04 -04001607 },
1608 null,
1609 null,
1610 true,
1611 false,
1612 IMPORTANCE_LOW,
1613 false
Gus Prevas5a70a4e2018-11-26 17:16:05 -05001614 );
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -04001615
Julia Reynolds8728d002019-04-19 15:46:13 -04001616 mNotificationInfo.findViewById(R.id.alert).performClick();
Julia Reynolds52a27372019-04-03 11:00:17 -04001617 mNotificationInfo.findViewById(R.id.done).performClick();
Gus Prevas533836a2018-09-24 17:15:32 -04001618 mTestableLooper.processAllMessages();
1619 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
1620 eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel));
1621
Mady Mellorc2dbe492017-03-30 13:22:03 -07001622 mNotificationInfo.handleCloseControls(true, false);
Rohan Shahca0447e2018-03-30 15:18:27 -07001623
1624 mTestableLooper.processAllMessages();
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -04001625 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -04001626 eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel));
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -04001627 }
Julia Reynolds3aedded2017-03-31 14:42:09 -04001628
1629 @Test
Julia Reynolds4d1dd792019-04-29 11:48:29 -04001630 public void testCloseControls_withoutHittingApply() throws Exception {
1631 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Ned Burns9512e0c2019-05-30 19:36:04 -04001632 mNotificationInfo.bindNotification(
1633 mMockPackageManager,
1634 mMockINotificationManager,
1635 mVisualStabilityManager,
1636 TEST_PACKAGE_NAME,
1637 mNotificationChannel,
1638 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -07001639 mEntry,
Julia Reynolds4d1dd792019-04-29 11:48:29 -04001640 (Runnable saveImportance, StatusBarNotification sbn) -> {
1641 saveImportance.run();
Ned Burns9512e0c2019-05-30 19:36:04 -04001642 },
1643 null,
1644 null,
1645 true,
1646 false,
1647 IMPORTANCE_LOW,
1648 false
Julia Reynolds4d1dd792019-04-29 11:48:29 -04001649 );
1650
1651 mNotificationInfo.findViewById(R.id.alert).performClick();
1652
1653 assertFalse(mNotificationInfo.shouldBeSaved());
1654 }
1655
1656 @Test
1657 public void testWillBeRemovedReturnsFalse() throws Exception {
1658 assertFalse(mNotificationInfo.willBeRemoved());
1659
Ned Burns9512e0c2019-05-30 19:36:04 -04001660 mNotificationInfo.bindNotification(
1661 mMockPackageManager,
1662 mMockINotificationManager,
1663 mVisualStabilityManager,
1664 TEST_PACKAGE_NAME,
1665 mNotificationChannel,
1666 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -07001667 mEntry,
Julia Reynolds4d1dd792019-04-29 11:48:29 -04001668 (Runnable saveImportance, StatusBarNotification sbn) -> {
1669 saveImportance.run();
Ned Burns9512e0c2019-05-30 19:36:04 -04001670 },
1671 null,
1672 null,
1673 true,
1674 false,
1675 IMPORTANCE_LOW,
1676 false
Julia Reynolds4d1dd792019-04-29 11:48:29 -04001677 );
1678
Geoffrey Pitsch8c8dbde2017-04-20 11:44:33 -04001679 assertFalse(mNotificationInfo.willBeRemoved());
1680 }
Evan Laird47dc4542019-04-24 15:10:52 -04001681
1682 private Set<NotificationChannel> createMultipleChannelSet(int howMany) {
1683 Set<NotificationChannel> multiChannelSet = new HashSet<>();
1684 for (int i = 0; i < howMany; i++) {
1685 if (i == 0) {
1686 multiChannelSet.add(mNotificationChannel);
1687 continue;
1688 }
1689
1690 NotificationChannel channel = new NotificationChannel(
1691 TEST_CHANNEL, TEST_CHANNEL_NAME + i, IMPORTANCE_LOW);
1692
1693 multiChannelSet.add(channel);
1694 }
1695
1696 return multiChannelSet;
1697 }
Geoffrey Pitschdf44b602017-02-03 13:31:50 -05001698}