blob: ff849c3720f329dc68e55b72b60e10ddf2d4e0c0 [file] [log] [blame]
yoshiki iguchia85c2a02018-01-12 11:28:06 +09001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
Rohan Shah20790b82018-07-02 17:21:04 -070017package com.android.systemui.statusbar.notification.row;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090018
Julia Reynoldsb5867452018-02-28 16:31:35 -050019import static android.app.AppOpsManager.OP_CAMERA;
20import static android.app.AppOpsManager.OP_RECORD_AUDIO;
21import static android.app.AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
Gus Prevas9abc5062018-10-31 16:11:04 -040022import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
Gus Prevas5a70a4e2018-11-26 17:16:05 -050023import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE;
Julia Reynoldsb5867452018-02-28 16:31:35 -050024
yoshiki iguchia85c2a02018-01-12 11:28:06 +090025import static junit.framework.Assert.assertNotNull;
Kevina5ff1fa2018-08-21 16:35:48 -070026import static junit.framework.Assert.assertNull;
27import static junit.framework.Assert.assertTrue;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090028
29import static org.junit.Assert.assertEquals;
30import static org.junit.Assert.fail;
31import static org.mockito.ArgumentMatchers.any;
32import static org.mockito.ArgumentMatchers.anyBoolean;
33import static org.mockito.ArgumentMatchers.anyInt;
Rohan Shah524cf7b2018-03-15 14:40:02 -070034import static org.mockito.ArgumentMatchers.eq;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090035import static org.mockito.Mockito.doNothing;
Kevina5ff1fa2018-08-21 16:35:48 -070036import static org.mockito.Mockito.doReturn;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090037import static org.mockito.Mockito.mock;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090038import static org.mockito.Mockito.spy;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090039import static org.mockito.Mockito.times;
Gus Prevas9abc5062018-10-31 16:11:04 -040040import static org.mockito.Mockito.verify;
41import static org.mockito.Mockito.when;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090042
Rohan Shah524cf7b2018-03-15 14:40:02 -070043import android.app.INotificationManager;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090044import android.app.Notification;
45import android.app.NotificationChannel;
Julia Reynoldsb5867452018-02-28 16:31:35 -050046import android.content.Intent;
Rohan Shah524cf7b2018-03-15 14:40:02 -070047import android.content.pm.PackageManager;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090048import android.os.Binder;
49import android.os.Handler;
Julia Reynoldsb5867452018-02-28 16:31:35 -050050import android.provider.Settings;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090051import android.service.notification.StatusBarNotification;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090052import android.testing.AndroidTestingRunner;
53import android.testing.TestableLooper;
Julia Reynoldsb5867452018-02-28 16:31:35 -050054import android.util.ArraySet;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090055import android.view.View;
56
Brett Chabot84151d92019-02-27 15:37:59 -080057import androidx.test.filters.SmallTest;
58
TreeHugger Robotee8e1ae2019-01-18 19:26:40 +000059import com.android.internal.logging.MetricsLogger;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090060import com.android.systemui.SysuiTestCase;
61import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
Rohan Shah20790b82018-07-02 17:21:04 -070062import com.android.systemui.statusbar.NotificationPresenter;
63import com.android.systemui.statusbar.NotificationTestHelper;
Gus Prevas21437b32018-12-05 10:36:13 -050064import com.android.systemui.statusbar.notification.NotificationActivityStarter;
Ned Burnsf81c4c42019-01-07 14:10:43 -050065import com.android.systemui.statusbar.notification.collection.NotificationEntry;
Gus Prevas5a70a4e2018-11-26 17:16:05 -050066import com.android.systemui.statusbar.notification.row.NotificationGutsManager.OnSettingsClickListener;
Rohan Shah20790b82018-07-02 17:21:04 -070067import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
Jason Monk297c04e2018-08-23 17:16:59 -040068import com.android.systemui.statusbar.policy.DeviceProvisionedController;
Jason Monka716bac2018-12-05 15:48:21 -050069import com.android.systemui.util.Assert;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090070
71import org.junit.Before;
Selim Cinek2476ed72019-03-07 13:19:23 -080072import org.junit.Ignore;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090073import org.junit.Rule;
74import org.junit.Test;
75import org.junit.runner.RunWith;
Julia Reynoldsb5867452018-02-28 16:31:35 -050076import org.mockito.ArgumentCaptor;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090077import org.mockito.Mock;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090078import org.mockito.junit.MockitoJUnit;
Gus Prevas9abc5062018-10-31 16:11:04 -040079import org.mockito.junit.MockitoRule;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090080
Rohan Shah524cf7b2018-03-15 14:40:02 -070081/**
82 * Tests for {@link NotificationGutsManager}.
83 */
yoshiki iguchia85c2a02018-01-12 11:28:06 +090084@SmallTest
85@RunWith(AndroidTestingRunner.class)
Jason Monka716bac2018-12-05 15:48:21 -050086@TestableLooper.RunWithLooper
yoshiki iguchia85c2a02018-01-12 11:28:06 +090087public class NotificationGutsManagerTest extends SysuiTestCase {
88 private static final String TEST_CHANNEL_ID = "NotificationManagerServiceTestChannelId";
89
yoshiki iguchia85c2a02018-01-12 11:28:06 +090090 private NotificationChannel mTestNotificationChannel = new NotificationChannel(
Gus Prevas9abc5062018-10-31 16:11:04 -040091 TEST_CHANNEL_ID, TEST_CHANNEL_ID, IMPORTANCE_DEFAULT);
yoshiki iguchia85c2a02018-01-12 11:28:06 +090092 private TestableLooper mTestableLooper;
93 private Handler mHandler;
94 private NotificationTestHelper mHelper;
95 private NotificationGutsManager mGutsManager;
96
97 @Rule public MockitoRule mockito = MockitoJUnit.rule();
TreeHugger Robotee8e1ae2019-01-18 19:26:40 +000098 @Mock private MetricsLogger mMetricsLogger;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090099 @Mock private NotificationPresenter mPresenter;
Gus Prevas21437b32018-12-05 10:36:13 -0500100 @Mock private NotificationActivityStarter mNotificationActivityStarter;
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900101 @Mock private NotificationStackScrollLayout mStackScroller;
102 @Mock private NotificationInfo.CheckSaveListener mCheckSaveListener;
Jason Monk297c04e2018-08-23 17:16:59 -0400103 @Mock private OnSettingsClickListener mOnSettingsClickListener;
104 @Mock private DeviceProvisionedController mDeviceProvisionedController;
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900105
106 @Before
107 public void setUp() {
108 mTestableLooper = TestableLooper.get(this);
Jason Monka716bac2018-12-05 15:48:21 -0500109 Assert.sMainLooper = TestableLooper.get(this).getLooper();
Jason Monk297c04e2018-08-23 17:16:59 -0400110 mDependency.injectTestDependency(DeviceProvisionedController.class,
111 mDeviceProvisionedController);
TreeHugger Robotee8e1ae2019-01-18 19:26:40 +0000112 mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger);
Jason Monk6dceace2018-05-15 20:24:07 -0400113 mHandler = Handler.createAsync(mTestableLooper.getLooper());
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900114
115 mHelper = new NotificationTestHelper(mContext);
116
117 mGutsManager = new NotificationGutsManager(mContext);
Kevina5ff1fa2018-08-21 16:35:48 -0700118 mGutsManager.setUpWithPresenter(mPresenter, mStackScroller,
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900119 mCheckSaveListener, mOnSettingsClickListener);
Gus Prevas21437b32018-12-05 10:36:13 -0500120 mGutsManager.setNotificationActivityStarter(mNotificationActivityStarter);
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900121 }
122
123 ////////////////////////////////////////////////////////////////////////////////////////////////
124 // Test methods:
125
126 @Test
127 public void testOpenAndCloseGuts() {
128 NotificationGuts guts = spy(new NotificationGuts(mContext));
129 when(guts.post(any())).thenAnswer(invocation -> {
130 mHandler.post(((Runnable) invocation.getArguments()[0]));
131 return null;
132 });
133
134 // Test doesn't support animation since the guts view is not attached.
Rohan Shah524cf7b2018-03-15 14:40:02 -0700135 doNothing().when(guts).openControls(
136 eq(true) /* shouldDoCircularReveal */,
137 anyInt(),
138 anyInt(),
139 anyBoolean(),
140 any(Runnable.class));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900141
142 ExpandableNotificationRow realRow = createTestNotificationRow();
143 NotificationMenuRowPlugin.MenuItem menuItem = createTestMenuItem(realRow);
144
145 ExpandableNotificationRow row = spy(realRow);
146 when(row.getWindowToken()).thenReturn(new Binder());
147 when(row.getGuts()).thenReturn(guts);
148
TreeHugger Robotee8e1ae2019-01-18 19:26:40 +0000149 assertTrue(mGutsManager.openGuts(row, 0, 0, menuItem));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900150 assertEquals(View.INVISIBLE, guts.getVisibility());
151 mTestableLooper.processAllMessages();
Rohan Shah524cf7b2018-03-15 14:40:02 -0700152 verify(guts).openControls(
153 eq(true),
154 anyInt(),
155 anyInt(),
156 anyBoolean(),
157 any(Runnable.class));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900158
159 assertEquals(View.VISIBLE, guts.getVisibility());
160 mGutsManager.closeAndSaveGuts(false, false, false, 0, 0, false);
161
162 verify(guts).closeControls(anyBoolean(), anyBoolean(), anyInt(), anyInt(), anyBoolean());
163 verify(row, times(1)).setGutsView(any());
164 }
165
166 @Test
167 public void testChangeDensityOrFontScale() {
168 NotificationGuts guts = spy(new NotificationGuts(mContext));
169 when(guts.post(any())).thenAnswer(invocation -> {
170 mHandler.post(((Runnable) invocation.getArguments()[0]));
171 return null;
172 });
173
174 // Test doesn't support animation since the guts view is not attached.
Rohan Shah524cf7b2018-03-15 14:40:02 -0700175 doNothing().when(guts).openControls(
176 eq(true) /* shouldDoCircularReveal */,
177 anyInt(),
178 anyInt(),
179 anyBoolean(),
180 any(Runnable.class));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900181
182 ExpandableNotificationRow realRow = createTestNotificationRow();
183 NotificationMenuRowPlugin.MenuItem menuItem = createTestMenuItem(realRow);
184
185 ExpandableNotificationRow row = spy(realRow);
Evan Laird94492852018-10-25 13:43:01 -0400186
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900187 when(row.getWindowToken()).thenReturn(new Binder());
188 when(row.getGuts()).thenReturn(guts);
189 doNothing().when(row).inflateGuts();
190
Ned Burnsf81c4c42019-01-07 14:10:43 -0500191 NotificationEntry realEntry = realRow.getEntry();
192 NotificationEntry entry = spy(realEntry);
Evan Laird94492852018-10-25 13:43:01 -0400193
194 when(entry.getRow()).thenReturn(row);
195 when(entry.getGuts()).thenReturn(guts);
196
TreeHugger Robotee8e1ae2019-01-18 19:26:40 +0000197 assertTrue(mGutsManager.openGuts(row, 0, 0, menuItem));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900198 mTestableLooper.processAllMessages();
Rohan Shah524cf7b2018-03-15 14:40:02 -0700199 verify(guts).openControls(
200 eq(true),
201 anyInt(),
202 anyInt(),
203 anyBoolean(),
204 any(Runnable.class));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900205
Evan Laird94492852018-10-25 13:43:01 -0400206 // called once by mGutsManager.bindGuts() in mGutsManager.openGuts()
207 verify(row).setGutsView(any());
208
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900209 row.onDensityOrFontScaleChanged();
Evan Laird94492852018-10-25 13:43:01 -0400210 mGutsManager.onDensityOrFontScaleChanged(entry);
211
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900212 mTestableLooper.processAllMessages();
213
214 mGutsManager.closeAndSaveGuts(false, false, false, 0, 0, false);
215
216 verify(guts).closeControls(anyBoolean(), anyBoolean(), anyInt(), anyInt(), anyBoolean());
Evan Laird94492852018-10-25 13:43:01 -0400217
218 // called again by mGutsManager.bindGuts(), in mGutsManager.onDensityOrFontScaleChanged()
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900219 verify(row, times(2)).setGutsView(any());
220 }
221
Julia Reynoldsb5867452018-02-28 16:31:35 -0500222 @Test
223 public void testAppOpsSettingsIntent_camera() {
224 ArraySet<Integer> ops = new ArraySet<>();
225 ops.add(OP_CAMERA);
226 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
227 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500228 verify(mNotificationActivityStarter, times(1))
229 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500230 assertEquals(Intent.ACTION_MANAGE_APP_PERMISSIONS, captor.getValue().getAction());
231 }
232
233 @Test
234 public void testAppOpsSettingsIntent_mic() {
235 ArraySet<Integer> ops = new ArraySet<>();
236 ops.add(OP_RECORD_AUDIO);
237 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
238 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500239 verify(mNotificationActivityStarter, times(1))
240 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500241 assertEquals(Intent.ACTION_MANAGE_APP_PERMISSIONS, captor.getValue().getAction());
242 }
243
244 @Test
245 public void testAppOpsSettingsIntent_camera_mic() {
246 ArraySet<Integer> ops = new ArraySet<>();
247 ops.add(OP_CAMERA);
248 ops.add(OP_RECORD_AUDIO);
249 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
250 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500251 verify(mNotificationActivityStarter, times(1))
252 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500253 assertEquals(Intent.ACTION_MANAGE_APP_PERMISSIONS, captor.getValue().getAction());
254 }
255
256 @Test
257 public void testAppOpsSettingsIntent_overlay() {
258 ArraySet<Integer> ops = new ArraySet<>();
259 ops.add(OP_SYSTEM_ALERT_WINDOW);
260 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
261 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500262 verify(mNotificationActivityStarter, times(1))
263 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500264 assertEquals(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, captor.getValue().getAction());
265 }
266
267 @Test
268 public void testAppOpsSettingsIntent_camera_mic_overlay() {
269 ArraySet<Integer> ops = new ArraySet<>();
270 ops.add(OP_CAMERA);
271 ops.add(OP_RECORD_AUDIO);
272 ops.add(OP_SYSTEM_ALERT_WINDOW);
273 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
274 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500275 verify(mNotificationActivityStarter, times(1))
276 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500277 assertEquals(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, captor.getValue().getAction());
278 }
279
280 @Test
281 public void testAppOpsSettingsIntent_camera_overlay() {
282 ArraySet<Integer> ops = new ArraySet<>();
283 ops.add(OP_CAMERA);
284 ops.add(OP_SYSTEM_ALERT_WINDOW);
285 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
286 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500287 verify(mNotificationActivityStarter, times(1))
288 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500289 assertEquals(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, captor.getValue().getAction());
290 }
291
292 @Test
293 public void testAppOpsSettingsIntent_mic_overlay() {
294 ArraySet<Integer> ops = new ArraySet<>();
295 ops.add(OP_RECORD_AUDIO);
296 ops.add(OP_SYSTEM_ALERT_WINDOW);
297 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
298 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500299 verify(mNotificationActivityStarter, times(1))
300 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500301 assertEquals(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, captor.getValue().getAction());
302 }
303
Rohan Shah524cf7b2018-03-15 14:40:02 -0700304 @Test
305 public void testInitializeNotificationInfoView_showBlockingHelper() throws Exception {
306 NotificationInfo notificationInfoView = mock(NotificationInfo.class);
Rohan Shah63411fc2018-03-28 19:05:52 -0700307 ExpandableNotificationRow row = spy(mHelper.createRow());
Rohan Shah524cf7b2018-03-15 14:40:02 -0700308 row.setBlockingHelperShowing(true);
309 row.getEntry().userSentiment = USER_SENTIMENT_NEGATIVE;
Rohan Shah63411fc2018-03-28 19:05:52 -0700310 when(row.getIsNonblockable()).thenReturn(false);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700311 StatusBarNotification statusBarNotification = row.getStatusBarNotification();
312
Gus Prevas5a70a4e2018-11-26 17:16:05 -0500313 mGutsManager.initializeNotificationInfo(row, notificationInfoView);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700314
315 verify(notificationInfoView).bindNotification(
316 any(PackageManager.class),
317 any(INotificationManager.class),
318 eq(statusBarNotification.getPackageName()),
Julia Reynolds0abae112018-06-08 10:36:57 -0400319 any(NotificationChannel.class),
Rohan Shah524cf7b2018-03-15 14:40:02 -0700320 anyInt(),
321 eq(statusBarNotification),
322 any(NotificationInfo.CheckSaveListener.class),
323 any(NotificationInfo.OnSettingsClickListener.class),
324 any(NotificationInfo.OnAppSettingsClickListener.class),
Rohan Shah63411fc2018-03-28 19:05:52 -0700325 eq(false),
Julia Reynolds35765d82018-08-17 11:39:19 -0400326 eq(false),
Rohan Shah524cf7b2018-03-15 14:40:02 -0700327 eq(true) /* isForBlockingHelper */,
Gus Prevas9abc5062018-10-31 16:11:04 -0400328 eq(true) /* isUserSentimentNegative */,
Gus Prevascaed15c2019-01-18 14:19:51 -0500329 eq(0),
330 eq(false) /* wasShownHighPriority */);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700331 }
332
333 @Test
334 public void testInitializeNotificationInfoView_dontShowBlockingHelper() throws Exception {
335 NotificationInfo notificationInfoView = mock(NotificationInfo.class);
Rohan Shah63411fc2018-03-28 19:05:52 -0700336 ExpandableNotificationRow row = spy(mHelper.createRow());
Rohan Shah524cf7b2018-03-15 14:40:02 -0700337 row.setBlockingHelperShowing(false);
338 row.getEntry().userSentiment = USER_SENTIMENT_NEGATIVE;
Rohan Shah63411fc2018-03-28 19:05:52 -0700339 when(row.getIsNonblockable()).thenReturn(false);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700340 StatusBarNotification statusBarNotification = row.getStatusBarNotification();
341
Gus Prevas5a70a4e2018-11-26 17:16:05 -0500342 mGutsManager.initializeNotificationInfo(row, notificationInfoView);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700343
344 verify(notificationInfoView).bindNotification(
345 any(PackageManager.class),
346 any(INotificationManager.class),
347 eq(statusBarNotification.getPackageName()),
Julia Reynolds0abae112018-06-08 10:36:57 -0400348 any(NotificationChannel.class),
Rohan Shah524cf7b2018-03-15 14:40:02 -0700349 anyInt(),
350 eq(statusBarNotification),
351 any(NotificationInfo.CheckSaveListener.class),
352 any(NotificationInfo.OnSettingsClickListener.class),
353 any(NotificationInfo.OnAppSettingsClickListener.class),
Rohan Shah63411fc2018-03-28 19:05:52 -0700354 eq(false),
Julia Reynolds35765d82018-08-17 11:39:19 -0400355 eq(false),
356 eq(false) /* isForBlockingHelper */,
Gus Prevas9abc5062018-10-31 16:11:04 -0400357 eq(true) /* isUserSentimentNegative */,
Gus Prevascaed15c2019-01-18 14:19:51 -0500358 eq(0),
359 eq(false) /* wasShownHighPriority */);
Gus Prevas9abc5062018-10-31 16:11:04 -0400360 }
361
362 @Test
Gus Prevascaed15c2019-01-18 14:19:51 -0500363 public void testInitializeNotificationInfoView_highPriority() throws Exception {
Gus Prevas9abc5062018-10-31 16:11:04 -0400364 NotificationInfo notificationInfoView = mock(NotificationInfo.class);
365 ExpandableNotificationRow row = spy(mHelper.createRow());
366 row.setBlockingHelperShowing(true);
367 row.getEntry().userSentiment = USER_SENTIMENT_NEGATIVE;
368 row.getEntry().importance = IMPORTANCE_DEFAULT;
Gus Prevascaed15c2019-01-18 14:19:51 -0500369 row.getEntry().setIsHighPriority(true);
Gus Prevas9abc5062018-10-31 16:11:04 -0400370 when(row.getIsNonblockable()).thenReturn(false);
371 StatusBarNotification statusBarNotification = row.getStatusBarNotification();
372
Gus Prevas5a70a4e2018-11-26 17:16:05 -0500373 mGutsManager.initializeNotificationInfo(row, notificationInfoView);
Gus Prevas9abc5062018-10-31 16:11:04 -0400374
375 verify(notificationInfoView).bindNotification(
376 any(PackageManager.class),
377 any(INotificationManager.class),
378 eq(statusBarNotification.getPackageName()),
379 any(NotificationChannel.class),
380 anyInt(),
381 eq(statusBarNotification),
382 any(NotificationInfo.CheckSaveListener.class),
383 any(NotificationInfo.OnSettingsClickListener.class),
384 any(NotificationInfo.OnAppSettingsClickListener.class),
385 eq(false),
386 eq(false),
387 eq(true) /* isForBlockingHelper */,
388 eq(true) /* isUserSentimentNegative */,
Gus Prevascaed15c2019-01-18 14:19:51 -0500389 eq(IMPORTANCE_DEFAULT),
390 eq(true) /* wasShownHighPriority */);
Julia Reynolds35765d82018-08-17 11:39:19 -0400391 }
392
393 @Test
394 public void testInitializeNotificationInfoView_PassesAlongProvisionedState() throws Exception {
395 NotificationInfo notificationInfoView = mock(NotificationInfo.class);
396 ExpandableNotificationRow row = spy(mHelper.createRow());
397 row.setBlockingHelperShowing(false);
398 row.getEntry().userSentiment = USER_SENTIMENT_NEGATIVE;
399 when(row.getIsNonblockable()).thenReturn(false);
400 StatusBarNotification statusBarNotification = row.getStatusBarNotification();
Jason Monk297c04e2018-08-23 17:16:59 -0400401 when(mDeviceProvisionedController.isDeviceProvisioned()).thenReturn(true);
Julia Reynolds35765d82018-08-17 11:39:19 -0400402
Gus Prevas5a70a4e2018-11-26 17:16:05 -0500403 mGutsManager.initializeNotificationInfo(row, notificationInfoView);
Julia Reynolds35765d82018-08-17 11:39:19 -0400404
405 verify(notificationInfoView).bindNotification(
406 any(PackageManager.class),
407 any(INotificationManager.class),
408 eq(statusBarNotification.getPackageName()),
409 any(NotificationChannel.class),
410 anyInt(),
411 eq(statusBarNotification),
412 any(NotificationInfo.CheckSaveListener.class),
413 any(NotificationInfo.OnSettingsClickListener.class),
414 any(NotificationInfo.OnAppSettingsClickListener.class),
415 eq(true),
416 eq(false),
Rohan Shah524cf7b2018-03-15 14:40:02 -0700417 eq(false) /* isForBlockingHelper */,
Gus Prevas9abc5062018-10-31 16:11:04 -0400418 eq(true) /* isUserSentimentNegative */,
Gus Prevascaed15c2019-01-18 14:19:51 -0500419 eq(0),
420 eq(false) /* wasShownHighPriority */);
Gus Prevas894d9152018-11-12 13:51:40 -0500421 }
422
423 @Test
424 public void testInitializeNotificationInfoView_withInitialAction() throws Exception {
425 NotificationInfo notificationInfoView = mock(NotificationInfo.class);
426 ExpandableNotificationRow row = spy(mHelper.createRow());
427 row.setBlockingHelperShowing(true);
428 row.getEntry().userSentiment = USER_SENTIMENT_NEGATIVE;
429 when(row.getIsNonblockable()).thenReturn(false);
430 StatusBarNotification statusBarNotification = row.getStatusBarNotification();
431
Gus Prevas5a70a4e2018-11-26 17:16:05 -0500432 mGutsManager.initializeNotificationInfo(row, notificationInfoView);
Gus Prevas894d9152018-11-12 13:51:40 -0500433
434 verify(notificationInfoView).bindNotification(
435 any(PackageManager.class),
436 any(INotificationManager.class),
437 eq(statusBarNotification.getPackageName()),
438 any(NotificationChannel.class),
439 anyInt(),
440 eq(statusBarNotification),
441 any(NotificationInfo.CheckSaveListener.class),
442 any(NotificationInfo.OnSettingsClickListener.class),
443 any(NotificationInfo.OnAppSettingsClickListener.class),
444 eq(false),
445 eq(false),
446 eq(true) /* isForBlockingHelper */,
447 eq(true) /* isUserSentimentNegative */,
Gus Prevascaed15c2019-01-18 14:19:51 -0500448 eq(0),
449 eq(false) /* wasShownHighPriority */);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700450 }
451
Kevina5ff1fa2018-08-21 16:35:48 -0700452 @Test
453 public void testShouldExtendLifetime() {
454 NotificationGuts guts = new NotificationGuts(mContext);
455 ExpandableNotificationRow row = spy(createTestNotificationRow());
456 doReturn(guts).when(row).getGuts();
Ned Burnsf81c4c42019-01-07 14:10:43 -0500457 NotificationEntry entry = row.getEntry();
Evan Laird94492852018-10-25 13:43:01 -0400458 entry.setRow(row);
Kevina5ff1fa2018-08-21 16:35:48 -0700459 mGutsManager.setExposedGuts(guts);
460
461 assertTrue(mGutsManager.shouldExtendLifetime(entry));
462 }
463
464 @Test
Selim Cinek2476ed72019-03-07 13:19:23 -0800465 @Ignore
Kevine9e938c2018-09-06 13:38:11 -0700466 public void testSetShouldManageLifetime_setShouldManage() {
Ned Burnsf81c4c42019-01-07 14:10:43 -0500467 NotificationEntry entry = createTestNotificationRow().getEntry();
Kevine9e938c2018-09-06 13:38:11 -0700468 mGutsManager.setShouldManageLifetime(entry, true /* shouldManage */);
Kevina5ff1fa2018-08-21 16:35:48 -0700469
470 assertTrue(entry.key.equals(mGutsManager.mKeyToRemoveOnGutsClosed));
471 }
472
473 @Test
Kevine9e938c2018-09-06 13:38:11 -0700474 public void testSetShouldManageLifetime_setShouldNotManage() {
Ned Burnsf81c4c42019-01-07 14:10:43 -0500475 NotificationEntry entry = createTestNotificationRow().getEntry();
Kevina5ff1fa2018-08-21 16:35:48 -0700476 mGutsManager.mKeyToRemoveOnGutsClosed = entry.key;
Kevine9e938c2018-09-06 13:38:11 -0700477 mGutsManager.setShouldManageLifetime(entry, false /* shouldManage */);
Kevina5ff1fa2018-08-21 16:35:48 -0700478
479 assertNull(mGutsManager.mKeyToRemoveOnGutsClosed);
480 }
481
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900482 ////////////////////////////////////////////////////////////////////////////////////////////////
483 // Utility methods:
484
485 private ExpandableNotificationRow createTestNotificationRow() {
486 Notification.Builder nb = new Notification.Builder(mContext,
487 mTestNotificationChannel.getId())
488 .setContentTitle("foo")
489 .setColorized(true)
490 .setFlag(Notification.FLAG_CAN_COLORIZE, true)
491 .setSmallIcon(android.R.drawable.sym_def_app_icon);
492
493 try {
494 ExpandableNotificationRow row = mHelper.createRow(nb.build());
495 row.getEntry().channel = mTestNotificationChannel;
496 return row;
497 } catch (Exception e) {
498 fail();
499 return null;
500 }
501 }
502
503 private NotificationMenuRowPlugin.MenuItem createTestMenuItem(ExpandableNotificationRow row) {
504 NotificationMenuRowPlugin menuRow = new NotificationMenuRow(mContext);
505 menuRow.createMenu(row, row.getStatusBarNotification());
506
507 NotificationMenuRowPlugin.MenuItem menuItem = menuRow.getLongpressMenuItem(mContext);
508 assertNotNull(menuItem);
509 return menuItem;
510 }
511}