blob: 6bf60721cd8ed39c0fe6f4a9a50eb13c9f11e242 [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
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050033import static org.mockito.Mockito.any;
34import static org.mockito.Mockito.anyBoolean;
35import static org.mockito.Mockito.anyInt;
36import static org.mockito.Mockito.anyString;
37import static org.mockito.Mockito.eq;
38import static org.mockito.Mockito.mock;
39import static org.mockito.Mockito.never;
40import static org.mockito.Mockito.times;
41import static org.mockito.Mockito.verify;
42import static org.mockito.Mockito.when;
43
44import android.app.INotificationManager;
Julia Reynolds3aedded2017-03-31 14:42:09 -040045import android.app.Notification;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050046import android.app.NotificationChannel;
47import android.app.NotificationChannelGroup;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050048import android.content.pm.ApplicationInfo;
49import android.content.pm.PackageInfo;
50import android.content.pm.PackageManager;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050051import android.graphics.drawable.Drawable;
Julia Reynolds3aedded2017-03-31 14:42:09 -040052import android.os.UserHandle;
Gus Prevas9abc5062018-10-31 16:11:04 -040053import android.provider.Settings;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050054import android.service.notification.StatusBarNotification;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050055import android.test.suitebuilder.annotation.SmallTest;
Jason Monk340b0e52017-03-08 14:57:56 -050056import android.testing.AndroidTestingRunner;
Rohan Shahca0447e2018-03-30 15:18:27 -070057import android.testing.TestableLooper;
Jason Monk340b0e52017-03-08 14:57:56 -050058import android.testing.UiThreadTest;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050059import android.view.LayoutInflater;
60import android.view.View;
61import android.widget.ImageView;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050062import android.widget.TextView;
Jason Monk340b0e52017-03-08 14:57:56 -050063
Rohan Shahda5dcdd2018-04-27 17:21:50 -070064import com.android.internal.logging.MetricsLogger;
Rohan Shahca0447e2018-03-30 15:18:27 -070065import com.android.systemui.Dependency;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050066import com.android.systemui.R;
67import com.android.systemui.SysuiTestCase;
Ned Burns9512e0c2019-05-30 19:36:04 -040068import com.android.systemui.statusbar.notification.VisualStabilityManager;
Mady Mellor53162c12019-10-22 17:12:59 -070069import com.android.systemui.statusbar.notification.collection.NotificationEntry;
Beverly79c89ec2019-12-13 10:33:01 -050070import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder;
Jason Monkba364322017-03-06 11:19:20 -050071
Gus Prevas9abc5062018-10-31 16:11:04 -040072import org.junit.After;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050073import org.junit.Before;
Rohan Shah524cf7b2018-03-15 14:40:02 -070074import org.junit.Rule;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050075import org.junit.Test;
Jason Monk340b0e52017-03-08 14:57:56 -050076import org.junit.runner.RunWith;
Julia Reynolds8ceb5792017-04-11 11:32:44 -040077import org.mockito.ArgumentCaptor;
Rohan Shah524cf7b2018-03-15 14:40:02 -070078import org.mockito.Mock;
79import org.mockito.junit.MockitoJUnit;
80import org.mockito.junit.MockitoRule;
Julia Reynolds3aedded2017-03-31 14:42:09 -040081
Evan Laird47dc4542019-04-24 15:10:52 -040082import java.util.HashSet;
83import java.util.Set;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050084import java.util.concurrent.CountDownLatch;
85
86@SmallTest
Jason Monk340b0e52017-03-08 14:57:56 -050087@RunWith(AndroidTestingRunner.class)
Rohan Shahca0447e2018-03-30 15:18:27 -070088@TestableLooper.RunWithLooper
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050089public class NotificationInfoTest extends SysuiTestCase {
90 private static final String TEST_PACKAGE_NAME = "test_package";
Julia Reynoldsf7321592017-05-24 16:09:19 -040091 private static final String TEST_SYSTEM_PACKAGE_NAME = PRINT_SPOOLER_PACKAGE_NAME;
Geoffrey Pitschd034d292017-05-12 11:59:20 -040092 private static final int TEST_UID = 1;
Rohan Shah63411fc2018-03-28 19:05:52 -070093 private static final int MULTIPLE_CHANNEL_COUNT = 2;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050094 private static final String TEST_CHANNEL = "test_channel";
95 private static final String TEST_CHANNEL_NAME = "TEST CHANNEL NAME";
96
Rohan Shahca0447e2018-03-30 15:18:27 -070097 private TestableLooper mTestableLooper;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050098 private NotificationInfo mNotificationInfo;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -050099 private NotificationChannel mNotificationChannel;
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500100 private NotificationChannel mDefaultNotificationChannel;
Evan Laird47dc4542019-04-24 15:10:52 -0400101 private Set<NotificationChannel> mNotificationChannelSet = new HashSet<>();
102 private Set<NotificationChannel> mDefaultNotificationChannelSet = new HashSet<>();
Julia Reynolds3aedded2017-03-31 14:42:09 -0400103 private StatusBarNotification mSbn;
Mady Mellor53162c12019-10-22 17:12:59 -0700104 private NotificationEntry mEntry;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500105
Will Brockmana399f022019-01-30 10:59:36 -0500106 @Rule
107 public MockitoRule mockito = MockitoJUnit.rule();
108 @Mock
109 private MetricsLogger mMetricsLogger;
110 @Mock
111 private INotificationManager mMockINotificationManager;
112 @Mock
113 private PackageManager mMockPackageManager;
114 @Mock
Ned Burns9512e0c2019-05-30 19:36:04 -0400115 private VisualStabilityManager mVisualStabilityManager;
Evan Laird18bd6e62019-08-30 16:39:25 -0400116 @Mock
117 private ChannelEditorDialogController mChannelEditorDialogController;
Rohan Shah524cf7b2018-03-15 14:40:02 -0700118
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500119 @Before
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500120 public void setUp() throws Exception {
Rohan Shahca0447e2018-03-30 15:18:27 -0700121 mTestableLooper = TestableLooper.get(this);
Mady Mellor53162c12019-10-22 17:12:59 -0700122
Rohan Shahca0447e2018-03-30 15:18:27 -0700123 mDependency.injectTestDependency(Dependency.BG_LOOPER, mTestableLooper.getLooper());
Rohan Shahda5dcdd2018-04-27 17:21:50 -0700124 mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500125 // Inflate the layout
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500126 final LayoutInflater layoutInflater = LayoutInflater.from(mContext);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500127 mNotificationInfo = (NotificationInfo) layoutInflater.inflate(R.layout.notification_info,
128 null);
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500129 mNotificationInfo.setGutsParent(mock(NotificationGuts.class));
Mady Mellor53162c12019-10-22 17:12:59 -0700130 // Our view is never attached to a window so the View#post methods in NotificationInfo never
131 // get called. Setting this will skip the post and do the action immediately.
132 mNotificationInfo.mSkipPost = true;
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500133
134 // PackageManager must return a packageInfo and applicationInfo.
135 final PackageInfo packageInfo = new PackageInfo();
136 packageInfo.packageName = TEST_PACKAGE_NAME;
Julia Reynoldsf7321592017-05-24 16:09:19 -0400137 when(mMockPackageManager.getPackageInfo(eq(TEST_PACKAGE_NAME), anyInt()))
138 .thenReturn(packageInfo);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500139 final ApplicationInfo applicationInfo = new ApplicationInfo();
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400140 applicationInfo.uid = TEST_UID; // non-zero
Julia Reynolds268647a2018-10-25 16:54:27 -0400141 when(mMockPackageManager.getApplicationInfo(eq(TEST_PACKAGE_NAME), anyInt())).thenReturn(
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500142 applicationInfo);
Julia Reynoldsf7321592017-05-24 16:09:19 -0400143 final PackageInfo systemPackageInfo = new PackageInfo();
144 systemPackageInfo.packageName = TEST_SYSTEM_PACKAGE_NAME;
145 when(mMockPackageManager.getPackageInfo(eq(TEST_SYSTEM_PACKAGE_NAME), anyInt()))
146 .thenReturn(systemPackageInfo);
147 when(mMockPackageManager.getPackageInfo(eq("android"), anyInt()))
148 .thenReturn(packageInfo);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500149
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500150 // Package has one channel by default.
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500151 when(mMockINotificationManager.getNumNotificationChannelsForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400152 eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(1);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500153
154 // Some test channels.
155 mNotificationChannel = new NotificationChannel(
Julia Reynolds437cdb12018-01-03 12:27:24 -0500156 TEST_CHANNEL, TEST_CHANNEL_NAME, IMPORTANCE_LOW);
Evan Laird47dc4542019-04-24 15:10:52 -0400157 mNotificationChannelSet.add(mNotificationChannel);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500158 mDefaultNotificationChannel = new NotificationChannel(
159 NotificationChannel.DEFAULT_CHANNEL_ID, TEST_CHANNEL_NAME,
Julia Reynolds437cdb12018-01-03 12:27:24 -0500160 IMPORTANCE_LOW);
Evan Laird47dc4542019-04-24 15:10:52 -0400161 mDefaultNotificationChannelSet.add(mDefaultNotificationChannel);
Julia Reynolds33bef2c2017-09-05 11:07:18 -0400162 mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, TEST_UID, 0,
Julia Reynolds3aedded2017-03-31 14:42:09 -0400163 new Notification(), UserHandle.CURRENT, null, 0);
Mady Mellor53162c12019-10-22 17:12:59 -0700164 mEntry = new NotificationEntryBuilder().setSbn(mSbn).build();
165
Gus Prevas9abc5062018-10-31 16:11:04 -0400166 Settings.Secure.putInt(mContext.getContentResolver(),
167 NOTIFICATION_NEW_INTERRUPTION_MODEL, 1);
168 }
169
170 @After
171 public void tearDown() {
172 Settings.Secure.putInt(mContext.getContentResolver(),
173 NOTIFICATION_NEW_INTERRUPTION_MODEL, 0);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500174 }
175
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500176 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500177 public void testBindNotification_SetsTextApplicationName() throws Exception {
178 when(mMockPackageManager.getApplicationLabel(any())).thenReturn("App Name");
Ned Burns9512e0c2019-05-30 19:36:04 -0400179 mNotificationInfo.bindNotification(
180 mMockPackageManager,
181 mMockINotificationManager,
182 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400183 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400184 TEST_PACKAGE_NAME,
185 mNotificationChannel,
186 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700187 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400188 null,
189 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400190 true,
191 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400192 true);
Julia Reynolds143441a2020-03-03 08:57:42 -0500193 final TextView textView = mNotificationInfo.findViewById(R.id.pkg_name);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500194 assertTrue(textView.getText().toString().contains("App Name"));
Julia Reynoldse0341482018-03-08 14:42:50 -0500195 assertEquals(VISIBLE, mNotificationInfo.findViewById(R.id.header).getVisibility());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500196 }
197
198 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500199 public void testBindNotification_SetsPackageIcon() throws Exception {
200 final Drawable iconDrawable = mock(Drawable.class);
201 when(mMockPackageManager.getApplicationIcon(any(ApplicationInfo.class)))
202 .thenReturn(iconDrawable);
Ned Burns9512e0c2019-05-30 19:36:04 -0400203 mNotificationInfo.bindNotification(
204 mMockPackageManager,
205 mMockINotificationManager,
206 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400207 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400208 TEST_PACKAGE_NAME,
209 mNotificationChannel,
210 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700211 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400212 null,
213 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400214 true,
215 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400216 true);
Julia Reynolds143441a2020-03-03 08:57:42 -0500217 final ImageView iconView = mNotificationInfo.findViewById(R.id.pkg_icon);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500218 assertEquals(iconDrawable, iconView.getDrawable());
219 }
220
221 @Test
Julia Reynolds268647a2018-10-25 16:54:27 -0400222 public void testBindNotification_noDelegate() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400223 mNotificationInfo.bindNotification(
224 mMockPackageManager,
225 mMockINotificationManager,
226 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400227 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400228 TEST_PACKAGE_NAME,
229 mNotificationChannel,
230 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700231 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400232 null,
233 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400234 true,
235 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400236 true);
Julia Reynolds268647a2018-10-25 16:54:27 -0400237 final TextView nameView = mNotificationInfo.findViewById(R.id.delegate_name);
238 assertEquals(GONE, nameView.getVisibility());
Julia Reynolds268647a2018-10-25 16:54:27 -0400239 }
240
241 @Test
242 public void testBindNotification_delegate() throws Exception {
243 mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, "other", 0, null, TEST_UID, 0,
244 new Notification(), UserHandle.CURRENT, null, 0);
245 final ApplicationInfo applicationInfo = new ApplicationInfo();
246 applicationInfo.uid = 7; // non-zero
247 when(mMockPackageManager.getApplicationInfo(eq("other"), anyInt())).thenReturn(
248 applicationInfo);
249 when(mMockPackageManager.getApplicationLabel(any())).thenReturn("Other");
250
Mady Mellor53162c12019-10-22 17:12:59 -0700251 NotificationEntry entry = new NotificationEntryBuilder().setSbn(mSbn).build();
Ned Burns9512e0c2019-05-30 19:36:04 -0400252 mNotificationInfo.bindNotification(
253 mMockPackageManager,
254 mMockINotificationManager,
255 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400256 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400257 TEST_PACKAGE_NAME,
258 mNotificationChannel,
259 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700260 entry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400261 null,
262 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400263 true,
264 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400265 true);
Julia Reynolds268647a2018-10-25 16:54:27 -0400266 final TextView nameView = mNotificationInfo.findViewById(R.id.delegate_name);
267 assertEquals(VISIBLE, nameView.getVisibility());
Julia Reynolds25b27f52019-04-24 11:58:38 -0400268 assertTrue(nameView.getText().toString().contains("Proxied"));
Julia Reynolds268647a2018-10-25 16:54:27 -0400269 }
270
271 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500272 public void testBindNotification_GroupNameHiddenIfNoGroup() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400273 mNotificationInfo.bindNotification(
274 mMockPackageManager,
275 mMockINotificationManager,
276 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400277 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400278 TEST_PACKAGE_NAME,
279 mNotificationChannel,
280 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700281 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400282 null,
283 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400284 true,
285 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400286 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500287 final TextView groupNameView = mNotificationInfo.findViewById(R.id.group_name);
288 assertEquals(GONE, groupNameView.getVisibility());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500289 }
290
291 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500292 public void testBindNotification_SetsGroupNameIfNonNull() throws Exception {
293 mNotificationChannel.setGroup("test_group_id");
294 final NotificationChannelGroup notificationChannelGroup =
295 new NotificationChannelGroup("test_group_id", "Test Group Name");
296 when(mMockINotificationManager.getNotificationChannelGroupForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400297 eq("test_group_id"), eq(TEST_PACKAGE_NAME), eq(TEST_UID)))
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500298 .thenReturn(notificationChannelGroup);
Ned Burns9512e0c2019-05-30 19:36:04 -0400299 mNotificationInfo.bindNotification(
300 mMockPackageManager,
301 mMockINotificationManager,
302 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400303 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400304 TEST_PACKAGE_NAME,
305 mNotificationChannel,
306 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700307 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400308 null,
309 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400310 true,
311 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400312 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500313 final TextView groupNameView = mNotificationInfo.findViewById(R.id.group_name);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500314 assertEquals(View.VISIBLE, groupNameView.getVisibility());
315 assertEquals("Test Group Name", groupNameView.getText());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500316 }
317
318 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500319 public void testBindNotification_SetsTextChannelName() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400320 mNotificationInfo.bindNotification(
321 mMockPackageManager,
322 mMockINotificationManager,
323 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400324 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400325 TEST_PACKAGE_NAME,
326 mNotificationChannel,
327 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700328 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400329 null,
330 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400331 true,
332 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400333 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500334 final TextView textView = mNotificationInfo.findViewById(R.id.channel_name);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500335 assertEquals(TEST_CHANNEL_NAME, textView.getText());
336 }
337
338 @Test
Geoffrey Pitsch1fbf66e2017-05-09 11:32:27 -0400339 public void testBindNotification_DefaultChannelDoesNotUseChannelName() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400340 mNotificationInfo.bindNotification(
341 mMockPackageManager,
342 mMockINotificationManager,
343 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400344 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400345 TEST_PACKAGE_NAME,
346 mDefaultNotificationChannel,
347 mDefaultNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700348 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400349 null,
350 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400351 true,
352 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400353 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500354 final TextView textView = mNotificationInfo.findViewById(R.id.channel_name);
355 assertEquals(GONE, textView.getVisibility());
Geoffrey Pitsch1fbf66e2017-05-09 11:32:27 -0400356 }
357
358 @Test
Rohan Shahdbd64e72018-03-28 14:46:50 -0700359 public void testBindNotification_DefaultChannelUsesChannelNameIfMoreChannelsExist()
360 throws Exception {
Julia Reynolds143441a2020-03-03 08:57:42 -0500361 // Package has more than one channel by default.
Rohan Shahdbd64e72018-03-28 14:46:50 -0700362 when(mMockINotificationManager.getNumNotificationChannelsForPackage(
363 eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(10);
Ned Burns9512e0c2019-05-30 19:36:04 -0400364 mNotificationInfo.bindNotification(
365 mMockPackageManager,
366 mMockINotificationManager,
367 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400368 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400369 TEST_PACKAGE_NAME,
370 mDefaultNotificationChannel,
371 mDefaultNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700372 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400373 null,
374 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400375 true,
376 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400377 true);
Rohan Shahdbd64e72018-03-28 14:46:50 -0700378 final TextView textView = mNotificationInfo.findViewById(R.id.channel_name);
379 assertEquals(VISIBLE, textView.getVisibility());
380 }
381
382 @Test
Julia Reynolds437cdb12018-01-03 12:27:24 -0500383 public void testBindNotification_UnblockablePackageUsesChannelName() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400384 mNotificationInfo.bindNotification(
385 mMockPackageManager,
386 mMockINotificationManager,
387 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400388 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400389 TEST_PACKAGE_NAME,
390 mNotificationChannel,
391 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700392 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400393 null,
394 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400395 true,
396 true,
Ned Burns9512e0c2019-05-30 19:36:04 -0400397 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500398 final TextView textView = mNotificationInfo.findViewById(R.id.channel_name);
399 assertEquals(VISIBLE, textView.getVisibility());
Geoffrey Pitsch1fbf66e2017-05-09 11:32:27 -0400400 }
401
402 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500403 public void testBindNotification_SetsOnClickListenerForSettings() throws Exception {
404 final CountDownLatch latch = new CountDownLatch(1);
Ned Burns9512e0c2019-05-30 19:36:04 -0400405 mNotificationInfo.bindNotification(
406 mMockPackageManager,
407 mMockINotificationManager,
408 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400409 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400410 TEST_PACKAGE_NAME,
411 mNotificationChannel,
412 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700413 mEntry,
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500414 (View v, NotificationChannel c, int appUid) -> {
Julia Reynolds3aedded2017-03-31 14:42:09 -0400415 assertEquals(mNotificationChannel, c);
416 latch.countDown();
Ned Burns9512e0c2019-05-30 19:36:04 -0400417 },
418 null,
419 true,
420 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400421 true);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500422
Julia Reynolds437cdb12018-01-03 12:27:24 -0500423 final View settingsButton = mNotificationInfo.findViewById(R.id.info);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500424 settingsButton.performClick();
425 // Verify that listener was triggered.
426 assertEquals(0, latch.getCount());
427 }
428
429 @Test
Geoffrey Pitsch029a3fa2017-03-30 13:01:57 -0400430 public void testBindNotification_SettingsButtonInvisibleWhenNoClickListener() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400431 mNotificationInfo.bindNotification(
432 mMockPackageManager,
433 mMockINotificationManager,
434 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400435 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400436 TEST_PACKAGE_NAME,
437 mNotificationChannel,
438 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700439 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400440 null,
441 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400442 true,
443 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400444 true);
Julia Reynolds35765d82018-08-17 11:39:19 -0400445 final View settingsButton = mNotificationInfo.findViewById(R.id.info);
446 assertTrue(settingsButton.getVisibility() != View.VISIBLE);
447 }
448
449 @Test
450 public void testBindNotification_SettingsButtonInvisibleWhenDeviceUnprovisioned()
451 throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400452 mNotificationInfo.bindNotification(
453 mMockPackageManager,
454 mMockINotificationManager,
455 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400456 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400457 TEST_PACKAGE_NAME,
458 mNotificationChannel,
459 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700460 mEntry,
Julia Reynolds35765d82018-08-17 11:39:19 -0400461 (View v, NotificationChannel c, int appUid) -> {
462 assertEquals(mNotificationChannel, c);
Ned Burns9512e0c2019-05-30 19:36:04 -0400463 },
464 null,
465 false,
466 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400467 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500468 final View settingsButton = mNotificationInfo.findViewById(R.id.info);
Geoffrey Pitsch029a3fa2017-03-30 13:01:57 -0400469 assertTrue(settingsButton.getVisibility() != View.VISIBLE);
470 }
471
472 @Test
Julia Reynolds437cdb12018-01-03 12:27:24 -0500473 public void testBindNotification_SettingsButtonReappearsAfterSecondBind() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400474 mNotificationInfo.bindNotification(
475 mMockPackageManager,
476 mMockINotificationManager,
477 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400478 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400479 TEST_PACKAGE_NAME,
480 mNotificationChannel,
481 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700482 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400483 null,
484 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400485 true,
486 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400487 true);
488 mNotificationInfo.bindNotification(
489 mMockPackageManager,
490 mMockINotificationManager,
491 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400492 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400493 TEST_PACKAGE_NAME,
494 mNotificationChannel,
495 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700496 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400497 (View v, NotificationChannel c, int appUid) -> { },
498 null,
499 true,
500 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400501 true);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500502 final View settingsButton = mNotificationInfo.findViewById(R.id.info);
Geoffrey Pitsch029a3fa2017-03-30 13:01:57 -0400503 assertEquals(View.VISIBLE, settingsButton.getVisibility());
504 }
505
506 @Test
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500507 public void testOnClickListenerPassesNullChannelForBundle() throws Exception {
508 final CountDownLatch latch = new CountDownLatch(1);
Ned Burns9512e0c2019-05-30 19:36:04 -0400509 mNotificationInfo.bindNotification(
510 mMockPackageManager,
511 mMockINotificationManager,
512 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400513 mChannelEditorDialogController,
Evan Laird47dc4542019-04-24 15:10:52 -0400514 TEST_PACKAGE_NAME, mNotificationChannel,
Ned Burns9512e0c2019-05-30 19:36:04 -0400515 createMultipleChannelSet(MULTIPLE_CHANNEL_COUNT),
Mady Mellor53162c12019-10-22 17:12:59 -0700516 mEntry,
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500517 (View v, NotificationChannel c, int appUid) -> {
Julia Reynolds3aedded2017-03-31 14:42:09 -0400518 assertEquals(null, c);
519 latch.countDown();
Ned Burns9512e0c2019-05-30 19:36:04 -0400520 },
521 null,
522 true,
523 true,
Ned Burns9512e0c2019-05-30 19:36:04 -0400524 true);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500525
Julia Reynolds437cdb12018-01-03 12:27:24 -0500526 mNotificationInfo.findViewById(R.id.info).performClick();
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500527 // Verify that listener was triggered.
528 assertEquals(0, latch.getCount());
529 }
530
531 @Test
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500532 @UiThreadTest
Julia Reynolds437cdb12018-01-03 12:27:24 -0500533 public void testBindNotification_ChannelNameInvisibleWhenBundleFromDifferentChannels()
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500534 throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400535 mNotificationInfo.bindNotification(
536 mMockPackageManager,
537 mMockINotificationManager,
538 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400539 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400540 TEST_PACKAGE_NAME,
541 mNotificationChannel,
542 createMultipleChannelSet(MULTIPLE_CHANNEL_COUNT),
Mady Mellor53162c12019-10-22 17:12:59 -0700543 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400544 null,
545 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400546 true,
547 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400548 true);
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500549 final TextView channelNameView =
Julia Reynolds437cdb12018-01-03 12:27:24 -0500550 mNotificationInfo.findViewById(R.id.channel_name);
551 assertEquals(GONE, channelNameView.getVisibility());
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500552 }
553
554 @Test
555 @UiThreadTest
Julia Reynolds437cdb12018-01-03 12:27:24 -0500556 public void testStopInvisibleIfBundleFromDifferentChannels() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400557 mNotificationInfo.bindNotification(
558 mMockPackageManager,
559 mMockINotificationManager,
560 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400561 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400562 TEST_PACKAGE_NAME,
563 mNotificationChannel,
564 createMultipleChannelSet(MULTIPLE_CHANNEL_COUNT),
Mady Mellor53162c12019-10-22 17:12:59 -0700565 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400566 null,
567 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400568 true,
569 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400570 true);
Julia Reynolds52a27372019-04-03 11:00:17 -0400571 assertEquals(GONE, mNotificationInfo.findViewById(
572 R.id.interruptiveness_settings).getVisibility());
573 assertEquals(VISIBLE, mNotificationInfo.findViewById(
574 R.id.non_configurable_multichannel_text).getVisibility());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500575 }
576
577 @Test
Julia Reynolds52a27372019-04-03 11:00:17 -0400578 public void testBindNotification_whenAppUnblockable() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400579 mNotificationInfo.bindNotification(
580 mMockPackageManager,
581 mMockINotificationManager,
582 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400583 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400584 TEST_PACKAGE_NAME,
585 mNotificationChannel,
586 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700587 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400588 null,
589 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400590 true,
591 true,
Ned Burns9512e0c2019-05-30 19:36:04 -0400592 true);
Julia Reynolds52a27372019-04-03 11:00:17 -0400593 final TextView view = mNotificationInfo.findViewById(R.id.non_configurable_text);
Julia Reynolds437cdb12018-01-03 12:27:24 -0500594 assertEquals(View.VISIBLE, view.getVisibility());
Geoffrey Pitschb43486a2017-06-01 13:45:59 -0400595 assertEquals(mContext.getString(R.string.notification_unblockable_desc),
Julia Reynolds437cdb12018-01-03 12:27:24 -0500596 view.getText());
Julia Reynolds52a27372019-04-03 11:00:17 -0400597 assertEquals(GONE,
598 mNotificationInfo.findViewById(R.id.interruptiveness_settings).getVisibility());
Geoffrey Pitschd0856f02017-02-16 10:51:18 -0500599 }
600
601 @Test
Mady Mellor53162c12019-10-22 17:12:59 -0700602 public void testBindNotification_alertIsSelected() throws Exception {
603 mNotificationInfo.bindNotification(
604 mMockPackageManager,
605 mMockINotificationManager,
606 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400607 mChannelEditorDialogController,
Mady Mellor53162c12019-10-22 17:12:59 -0700608 TEST_PACKAGE_NAME,
609 mNotificationChannel,
610 mNotificationChannelSet,
Julia Reynoldsc3e922b2020-01-16 16:12:56 -0500611 mEntry,
Mady Mellor53162c12019-10-22 17:12:59 -0700612 null,
613 null,
Mady Mellor53162c12019-10-22 17:12:59 -0700614 true,
615 false,
Mady Mellor53162c12019-10-22 17:12:59 -0700616 true);
617 assertTrue(mNotificationInfo.findViewById(R.id.alert).isSelected());
618 }
619
620 @Test
621 public void testBindNotification_silenceIsSelected() throws Exception {
622 mNotificationInfo.bindNotification(
623 mMockPackageManager,
624 mMockINotificationManager,
625 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400626 mChannelEditorDialogController,
Mady Mellor53162c12019-10-22 17:12:59 -0700627 TEST_PACKAGE_NAME,
628 mNotificationChannel,
629 mNotificationChannelSet,
Julia Reynoldsc3e922b2020-01-16 16:12:56 -0500630 mEntry,
Mady Mellor53162c12019-10-22 17:12:59 -0700631 null,
632 null,
Mady Mellor53162c12019-10-22 17:12:59 -0700633 true,
634 false,
Mady Mellor53162c12019-10-22 17:12:59 -0700635 false);
636 assertTrue(mNotificationInfo.findViewById(R.id.silence).isSelected());
637 }
638
639 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500640 public void testBindNotification_DoesNotUpdateNotificationChannel() throws Exception {
Ned Burns9512e0c2019-05-30 19:36:04 -0400641 mNotificationInfo.bindNotification(
642 mMockPackageManager,
643 mMockINotificationManager,
644 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400645 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400646 TEST_PACKAGE_NAME,
647 mNotificationChannel,
648 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700649 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400650 null,
651 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400652 true,
653 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400654 true);
Rohan Shahca0447e2018-03-30 15:18:27 -0700655 mTestableLooper.processAllMessages();
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500656 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400657 anyString(), eq(TEST_UID), any());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500658 }
659
660 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500661 public void testDoesNotUpdateNotificationChannelAfterImportanceChanged() throws Exception {
Julia Reynolds437cdb12018-01-03 12:27:24 -0500662 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Ned Burns9512e0c2019-05-30 19:36:04 -0400663 mNotificationInfo.bindNotification(
664 mMockPackageManager,
665 mMockINotificationManager,
666 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400667 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400668 TEST_PACKAGE_NAME,
669 mNotificationChannel,
670 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700671 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400672 null,
673 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400674 true,
675 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400676 false);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500677
Julia Reynolds8728d002019-04-19 15:46:13 -0400678 mNotificationInfo.findViewById(R.id.alert).performClick();
Rohan Shahca0447e2018-03-30 15:18:27 -0700679 mTestableLooper.processAllMessages();
Julia Reynoldse0341482018-03-08 14:42:50 -0500680 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
681 anyString(), eq(TEST_UID), any());
682 }
683
684 @Test
Gus Prevas9abc5062018-10-31 16:11:04 -0400685 public void testDoesNotUpdateNotificationChannelAfterImportanceChangedSilenced()
686 throws Exception {
687 mNotificationChannel.setImportance(IMPORTANCE_DEFAULT);
Ned Burns9512e0c2019-05-30 19:36:04 -0400688 mNotificationInfo.bindNotification(
689 mMockPackageManager,
690 mMockINotificationManager,
691 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400692 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400693 TEST_PACKAGE_NAME,
694 mNotificationChannel,
695 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700696 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400697 null,
698 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400699 true,
700 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400701 true);
Gus Prevas9abc5062018-10-31 16:11:04 -0400702
Julia Reynolds8728d002019-04-19 15:46:13 -0400703 mNotificationInfo.findViewById(R.id.silence).performClick();
Gus Prevas9abc5062018-10-31 16:11:04 -0400704 mTestableLooper.processAllMessages();
705 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
706 anyString(), eq(TEST_UID), any());
707 }
708
709 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500710 public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnchanged()
711 throws Exception {
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500712 int originalImportance = mNotificationChannel.getImportance();
Ned Burns9512e0c2019-05-30 19:36:04 -0400713 mNotificationInfo.bindNotification(
714 mMockPackageManager,
715 mMockINotificationManager,
716 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400717 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400718 TEST_PACKAGE_NAME,
719 mNotificationChannel,
720 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700721 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400722 null,
723 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400724 true,
725 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400726 true);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500727
Mady Mellorc2dbe492017-03-30 13:22:03 -0700728 mNotificationInfo.handleCloseControls(true, false);
Rohan Shahca0447e2018-03-30 15:18:27 -0700729 mTestableLooper.processAllMessages();
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500730 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400731 anyString(), eq(TEST_UID), any());
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500732 assertEquals(originalImportance, mNotificationChannel.getImportance());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500733 }
734
735 @Test
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500736 public void testHandleCloseControls_DoesNotUpdateNotificationChannelIfUnspecified()
737 throws Exception {
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500738 mNotificationChannel.setImportance(IMPORTANCE_UNSPECIFIED);
Ned Burns9512e0c2019-05-30 19:36:04 -0400739 mNotificationInfo.bindNotification(
740 mMockPackageManager,
741 mMockINotificationManager,
742 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400743 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400744 TEST_PACKAGE_NAME,
745 mNotificationChannel,
746 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700747 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400748 null,
749 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400750 true,
751 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400752 true);
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500753
Mady Mellorc2dbe492017-03-30 13:22:03 -0700754 mNotificationInfo.handleCloseControls(true, false);
Rohan Shahca0447e2018-03-30 15:18:27 -0700755
756 mTestableLooper.processAllMessages();
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500757 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -0400758 anyString(), eq(TEST_UID), any());
Julia Reynoldsc65656a2018-02-12 09:55:14 -0500759 assertEquals(IMPORTANCE_UNSPECIFIED, mNotificationChannel.getImportance());
Geoffrey Pitschdf44b602017-02-03 13:31:50 -0500760 }
761
762 @Test
Gus Prevas9abc5062018-10-31 16:11:04 -0400763 public void testSilenceCallsUpdateNotificationChannel() throws Exception {
764 mNotificationChannel.setImportance(IMPORTANCE_DEFAULT);
Ned Burns9512e0c2019-05-30 19:36:04 -0400765 mNotificationInfo.bindNotification(
766 mMockPackageManager,
767 mMockINotificationManager,
768 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400769 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400770 TEST_PACKAGE_NAME,
771 mNotificationChannel,
772 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700773 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400774 null,
775 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400776 true,
777 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400778 true);
Gus Prevas9abc5062018-10-31 16:11:04 -0400779
Julia Reynolds8728d002019-04-19 15:46:13 -0400780 mNotificationInfo.findViewById(R.id.silence).performClick();
Julia Reynolds52a27372019-04-03 11:00:17 -0400781 mNotificationInfo.findViewById(R.id.done).performClick();
Gus Prevas9abc5062018-10-31 16:11:04 -0400782 mNotificationInfo.handleCloseControls(true, false);
783
784 mTestableLooper.processAllMessages();
785 ArgumentCaptor<NotificationChannel> updated =
786 ArgumentCaptor.forClass(NotificationChannel.class);
787 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
788 anyString(), eq(TEST_UID), updated.capture());
789 assertTrue((updated.getValue().getUserLockedFields()
790 & USER_LOCKED_IMPORTANCE) != 0);
791 assertEquals(IMPORTANCE_LOW, updated.getValue().getImportance());
792 }
793
794 @Test
795 public void testUnSilenceCallsUpdateNotificationChannel() throws Exception {
796 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Ned Burns9512e0c2019-05-30 19:36:04 -0400797 mNotificationInfo.bindNotification(
798 mMockPackageManager,
799 mMockINotificationManager,
800 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400801 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400802 TEST_PACKAGE_NAME,
803 mNotificationChannel,
804 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700805 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400806 null,
807 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400808 true,
809 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400810 false);
Gus Prevas9abc5062018-10-31 16:11:04 -0400811
Julia Reynolds8728d002019-04-19 15:46:13 -0400812 mNotificationInfo.findViewById(R.id.alert).performClick();
Julia Reynolds52a27372019-04-03 11:00:17 -0400813 mNotificationInfo.findViewById(R.id.done).performClick();
Gus Prevas9abc5062018-10-31 16:11:04 -0400814 mNotificationInfo.handleCloseControls(true, false);
815
816 mTestableLooper.processAllMessages();
817 ArgumentCaptor<NotificationChannel> updated =
818 ArgumentCaptor.forClass(NotificationChannel.class);
819 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
820 anyString(), eq(TEST_UID), updated.capture());
821 assertTrue((updated.getValue().getUserLockedFields()
822 & USER_LOCKED_IMPORTANCE) != 0);
Julia Reynolds9ae5e642019-02-06 10:19:22 -0500823 assertEquals(IMPORTANCE_DEFAULT, updated.getValue().getImportance());
Gus Prevas9abc5062018-10-31 16:11:04 -0400824 }
825
826 @Test
827 public void testSilenceCallsUpdateNotificationChannel_channelImportanceUnspecified()
828 throws Exception {
829 mNotificationChannel.setImportance(IMPORTANCE_UNSPECIFIED);
Ned Burns9512e0c2019-05-30 19:36:04 -0400830 mNotificationInfo.bindNotification(
831 mMockPackageManager,
832 mMockINotificationManager,
833 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400834 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400835 TEST_PACKAGE_NAME,
836 mNotificationChannel,
837 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700838 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400839 null,
840 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400841 true,
842 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400843 true);
Gus Prevas9abc5062018-10-31 16:11:04 -0400844
Julia Reynolds8728d002019-04-19 15:46:13 -0400845 mNotificationInfo.findViewById(R.id.silence).performClick();
Julia Reynolds52a27372019-04-03 11:00:17 -0400846 mNotificationInfo.findViewById(R.id.done).performClick();
Gus Prevas9abc5062018-10-31 16:11:04 -0400847 mNotificationInfo.handleCloseControls(true, false);
848
849 mTestableLooper.processAllMessages();
850 ArgumentCaptor<NotificationChannel> updated =
851 ArgumentCaptor.forClass(NotificationChannel.class);
852 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
853 anyString(), eq(TEST_UID), updated.capture());
854 assertTrue((updated.getValue().getUserLockedFields()
855 & USER_LOCKED_IMPORTANCE) != 0);
856 assertEquals(IMPORTANCE_LOW, updated.getValue().getImportance());
857 }
858
859 @Test
Julia Reynolds8728d002019-04-19 15:46:13 -0400860 public void testSilenceCallsUpdateNotificationChannel_channelImportanceMin()
Gus Prevas9abc5062018-10-31 16:11:04 -0400861 throws Exception {
Julia Reynolds8728d002019-04-19 15:46:13 -0400862 mNotificationChannel.setImportance(IMPORTANCE_MIN);
Ned Burns9512e0c2019-05-30 19:36:04 -0400863 mNotificationInfo.bindNotification(
864 mMockPackageManager,
865 mMockINotificationManager,
866 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400867 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400868 TEST_PACKAGE_NAME,
869 mNotificationChannel,
870 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700871 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400872 null,
873 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400874 true,
875 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400876 false);
Julia Reynolds8728d002019-04-19 15:46:13 -0400877
878 assertEquals(mContext.getString(R.string.inline_done_button),
879 ((TextView) mNotificationInfo.findViewById(R.id.done)).getText());
880 mNotificationInfo.findViewById(R.id.silence).performClick();
881 assertEquals(mContext.getString(R.string.inline_done_button),
882 ((TextView) mNotificationInfo.findViewById(R.id.done)).getText());
883 mNotificationInfo.findViewById(R.id.done).performClick();
884 mNotificationInfo.handleCloseControls(true, false);
885
886 mTestableLooper.processAllMessages();
887 ArgumentCaptor<NotificationChannel> updated =
888 ArgumentCaptor.forClass(NotificationChannel.class);
889 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
890 anyString(), eq(TEST_UID), updated.capture());
Evan Laird47dc4542019-04-24 15:10:52 -0400891 assertTrue((updated.getValue().getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0);
Julia Reynolds8728d002019-04-19 15:46:13 -0400892 assertEquals(IMPORTANCE_MIN, updated.getValue().getImportance());
893 }
894
895 @Test
896 public void testAlertCallsUpdateNotificationChannel_channelImportanceMin()
897 throws Exception {
898 mNotificationChannel.setImportance(IMPORTANCE_MIN);
Ned Burns9512e0c2019-05-30 19:36:04 -0400899 mNotificationInfo.bindNotification(
900 mMockPackageManager,
901 mMockINotificationManager,
902 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400903 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400904 TEST_PACKAGE_NAME,
905 mNotificationChannel,
906 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700907 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400908 null,
909 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400910 true,
911 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400912 false);
Julia Reynolds8728d002019-04-19 15:46:13 -0400913
914 assertEquals(mContext.getString(R.string.inline_done_button),
915 ((TextView) mNotificationInfo.findViewById(R.id.done)).getText());
916 mNotificationInfo.findViewById(R.id.alert).performClick();
917 assertEquals(mContext.getString(R.string.inline_ok_button),
918 ((TextView) mNotificationInfo.findViewById(R.id.done)).getText());
919 mNotificationInfo.findViewById(R.id.done).performClick();
920 mNotificationInfo.handleCloseControls(true, false);
921
922 mTestableLooper.processAllMessages();
923 ArgumentCaptor<NotificationChannel> updated =
924 ArgumentCaptor.forClass(NotificationChannel.class);
925 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
926 anyString(), eq(TEST_UID), updated.capture());
Evan Laird47dc4542019-04-24 15:10:52 -0400927 assertTrue((updated.getValue().getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0);
Julia Reynolds8728d002019-04-19 15:46:13 -0400928 assertEquals(IMPORTANCE_DEFAULT, updated.getValue().getImportance());
929 }
930
931 @Test
Ned Burns9512e0c2019-05-30 19:36:04 -0400932 public void testAdjustImportanceTemporarilyAllowsReordering() throws Exception {
933 mNotificationChannel.setImportance(IMPORTANCE_DEFAULT);
934 mNotificationInfo.bindNotification(
935 mMockPackageManager,
936 mMockINotificationManager,
937 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400938 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400939 TEST_PACKAGE_NAME,
940 mNotificationChannel,
941 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700942 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400943 null,
944 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400945 true,
946 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400947 true);
948
949 mNotificationInfo.findViewById(R.id.silence).performClick();
950 mNotificationInfo.findViewById(R.id.done).performClick();
951 mNotificationInfo.handleCloseControls(true, false);
952
953 verify(mVisualStabilityManager).temporarilyAllowReordering();
954 }
955
956 @Test
Julia Reynolds8728d002019-04-19 15:46:13 -0400957 public void testDoneText()
958 throws Exception {
959 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Ned Burns9512e0c2019-05-30 19:36:04 -0400960 mNotificationInfo.bindNotification(
961 mMockPackageManager,
962 mMockINotificationManager,
963 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400964 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400965 TEST_PACKAGE_NAME,
966 mNotificationChannel,
967 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700968 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400969 null,
970 null,
Ned Burns9512e0c2019-05-30 19:36:04 -0400971 true,
972 false,
Ned Burns9512e0c2019-05-30 19:36:04 -0400973 false);
Gus Prevas9abc5062018-10-31 16:11:04 -0400974
Julia Reynolds8728d002019-04-19 15:46:13 -0400975 assertEquals(mContext.getString(R.string.inline_done_button),
976 ((TextView) mNotificationInfo.findViewById(R.id.done)).getText());
977 mNotificationInfo.findViewById(R.id.alert).performClick();
978 assertEquals(mContext.getString(R.string.inline_ok_button),
979 ((TextView) mNotificationInfo.findViewById(R.id.done)).getText());
980 mNotificationInfo.findViewById(R.id.silence).performClick();
981 assertEquals(mContext.getString(R.string.inline_done_button),
982 ((TextView) mNotificationInfo.findViewById(R.id.done)).getText());
983 }
984
985 @Test
986 public void testUnSilenceCallsUpdateNotificationChannel_channelImportanceUnspecified()
987 throws Exception {
988 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Ned Burns9512e0c2019-05-30 19:36:04 -0400989 mNotificationInfo.bindNotification(
990 mMockPackageManager,
991 mMockINotificationManager,
992 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -0400993 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -0400994 TEST_PACKAGE_NAME,
995 mNotificationChannel,
996 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -0700997 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -0400998 null,
999 null,
Ned Burns9512e0c2019-05-30 19:36:04 -04001000 true,
1001 false,
Ned Burns9512e0c2019-05-30 19:36:04 -04001002 false);
Julia Reynolds8728d002019-04-19 15:46:13 -04001003
1004 mNotificationInfo.findViewById(R.id.alert).performClick();
Julia Reynolds52a27372019-04-03 11:00:17 -04001005 mNotificationInfo.findViewById(R.id.done).performClick();
Gus Prevas9abc5062018-10-31 16:11:04 -04001006 mNotificationInfo.handleCloseControls(true, false);
1007
1008 mTestableLooper.processAllMessages();
1009 ArgumentCaptor<NotificationChannel> updated =
1010 ArgumentCaptor.forClass(NotificationChannel.class);
1011 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
1012 anyString(), eq(TEST_UID), updated.capture());
1013 assertTrue((updated.getValue().getUserLockedFields()
1014 & USER_LOCKED_IMPORTANCE) != 0);
Julia Reynolds9ae5e642019-02-06 10:19:22 -05001015 assertEquals(IMPORTANCE_DEFAULT, updated.getValue().getImportance());
Gus Prevas9abc5062018-10-31 16:11:04 -04001016 }
1017
1018 @Test
Julia Reynolds437cdb12018-01-03 12:27:24 -05001019 public void testCloseControlsDoesNotUpdateIfSaveIsFalse() throws Exception {
1020 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Ned Burns9512e0c2019-05-30 19:36:04 -04001021 mNotificationInfo.bindNotification(
1022 mMockPackageManager,
1023 mMockINotificationManager,
1024 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -04001025 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -04001026 TEST_PACKAGE_NAME,
1027 mNotificationChannel,
1028 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -07001029 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -04001030 null,
1031 null,
Ned Burns9512e0c2019-05-30 19:36:04 -04001032 true,
1033 false,
Ned Burns9512e0c2019-05-30 19:36:04 -04001034 false);
Julia Reynolds437cdb12018-01-03 12:27:24 -05001035
Julia Reynolds8728d002019-04-19 15:46:13 -04001036 mNotificationInfo.findViewById(R.id.alert).performClick();
Julia Reynolds52a27372019-04-03 11:00:17 -04001037 mNotificationInfo.findViewById(R.id.done).performClick();
Mady Mellorc2dbe492017-03-30 13:22:03 -07001038 mNotificationInfo.handleCloseControls(false, false);
Rohan Shahca0447e2018-03-30 15:18:27 -07001039
1040 mTestableLooper.processAllMessages();
Geoffrey Pitschdf44b602017-02-03 13:31:50 -05001041 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -04001042 eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel));
Geoffrey Pitschdf44b602017-02-03 13:31:50 -05001043 }
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -04001044
1045 @Test
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -04001046 public void testCloseControlsUpdatesWhenCheckSaveListenerUsesCallback() throws Exception {
Julia Reynolds437cdb12018-01-03 12:27:24 -05001047 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Ned Burns9512e0c2019-05-30 19:36:04 -04001048 mNotificationInfo.bindNotification(
1049 mMockPackageManager,
1050 mMockINotificationManager,
1051 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -04001052 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -04001053 TEST_PACKAGE_NAME,
1054 mNotificationChannel,
1055 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -07001056 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -04001057 null,
1058 null,
1059 true,
1060 false,
Ned Burns9512e0c2019-05-30 19:36:04 -04001061 false
Gus Prevas5a70a4e2018-11-26 17:16:05 -05001062 );
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -04001063
Julia Reynolds8728d002019-04-19 15:46:13 -04001064 mNotificationInfo.findViewById(R.id.alert).performClick();
Julia Reynolds52a27372019-04-03 11:00:17 -04001065 mNotificationInfo.findViewById(R.id.done).performClick();
Gus Prevas533836a2018-09-24 17:15:32 -04001066 mTestableLooper.processAllMessages();
1067 verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
1068 eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel));
1069
Mady Mellorc2dbe492017-03-30 13:22:03 -07001070 mNotificationInfo.handleCloseControls(true, false);
Rohan Shahca0447e2018-03-30 15:18:27 -07001071
1072 mTestableLooper.processAllMessages();
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -04001073 verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
Geoffrey Pitschd034d292017-05-12 11:59:20 -04001074 eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel));
Geoffrey Pitsch5278d3d2017-03-29 13:39:10 -04001075 }
Julia Reynolds3aedded2017-03-31 14:42:09 -04001076
1077 @Test
Julia Reynolds4d1dd792019-04-29 11:48:29 -04001078 public void testCloseControls_withoutHittingApply() throws Exception {
1079 mNotificationChannel.setImportance(IMPORTANCE_LOW);
Ned Burns9512e0c2019-05-30 19:36:04 -04001080 mNotificationInfo.bindNotification(
1081 mMockPackageManager,
1082 mMockINotificationManager,
1083 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -04001084 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -04001085 TEST_PACKAGE_NAME,
1086 mNotificationChannel,
1087 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -07001088 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -04001089 null,
1090 null,
1091 true,
1092 false,
Ned Burns9512e0c2019-05-30 19:36:04 -04001093 false
Julia Reynolds4d1dd792019-04-29 11:48:29 -04001094 );
1095
1096 mNotificationInfo.findViewById(R.id.alert).performClick();
1097
1098 assertFalse(mNotificationInfo.shouldBeSaved());
1099 }
1100
1101 @Test
1102 public void testWillBeRemovedReturnsFalse() throws Exception {
1103 assertFalse(mNotificationInfo.willBeRemoved());
1104
Ned Burns9512e0c2019-05-30 19:36:04 -04001105 mNotificationInfo.bindNotification(
1106 mMockPackageManager,
1107 mMockINotificationManager,
1108 mVisualStabilityManager,
Evan Laird18bd6e62019-08-30 16:39:25 -04001109 mChannelEditorDialogController,
Ned Burns9512e0c2019-05-30 19:36:04 -04001110 TEST_PACKAGE_NAME,
1111 mNotificationChannel,
1112 mNotificationChannelSet,
Mady Mellor53162c12019-10-22 17:12:59 -07001113 mEntry,
Ned Burns9512e0c2019-05-30 19:36:04 -04001114 null,
1115 null,
1116 true,
1117 false,
Ned Burns9512e0c2019-05-30 19:36:04 -04001118 false
Julia Reynolds4d1dd792019-04-29 11:48:29 -04001119 );
1120
Geoffrey Pitsch8c8dbde2017-04-20 11:44:33 -04001121 assertFalse(mNotificationInfo.willBeRemoved());
1122 }
Evan Laird47dc4542019-04-24 15:10:52 -04001123
1124 private Set<NotificationChannel> createMultipleChannelSet(int howMany) {
1125 Set<NotificationChannel> multiChannelSet = new HashSet<>();
1126 for (int i = 0; i < howMany; i++) {
1127 if (i == 0) {
1128 multiChannelSet.add(mNotificationChannel);
1129 continue;
1130 }
1131
1132 NotificationChannel channel = new NotificationChannel(
1133 TEST_CHANNEL, TEST_CHANNEL_NAME + i, IMPORTANCE_LOW);
1134
1135 multiChannelSet.add(channel);
1136 }
1137
1138 return multiChannelSet;
1139 }
Geoffrey Pitschdf44b602017-02-03 13:31:50 -05001140}