blob: ed4642344dba1e156850650f0ebbdd8a2f5265ca [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;
Beverly7c1ad5b2019-12-05 17:17:15 -050023import static android.app.NotificationManager.IMPORTANCE_HIGH;
Gus Prevas5a70a4e2018-11-26 17:16:05 -050024import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE;
Julia Reynoldsb5867452018-02-28 16:31:35 -050025
Ned Burns60e94592019-09-06 14:47:25 -040026import static com.android.systemui.statusbar.NotificationEntryHelper.modifyRanking;
27
yoshiki iguchia85c2a02018-01-12 11:28:06 +090028import static junit.framework.Assert.assertNotNull;
Kevina5ff1fa2018-08-21 16:35:48 -070029import static junit.framework.Assert.assertNull;
30import static junit.framework.Assert.assertTrue;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090031
32import static org.junit.Assert.assertEquals;
33import static org.junit.Assert.fail;
34import static org.mockito.ArgumentMatchers.any;
35import static org.mockito.ArgumentMatchers.anyBoolean;
36import static org.mockito.ArgumentMatchers.anyInt;
Evan Laird47dc4542019-04-24 15:10:52 -040037import static org.mockito.ArgumentMatchers.anySet;
Rohan Shah524cf7b2018-03-15 14:40:02 -070038import static org.mockito.ArgumentMatchers.eq;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090039import static org.mockito.Mockito.doNothing;
Kevina5ff1fa2018-08-21 16:35:48 -070040import static org.mockito.Mockito.doReturn;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090041import static org.mockito.Mockito.mock;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090042import static org.mockito.Mockito.spy;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090043import static org.mockito.Mockito.times;
Gus Prevas9abc5062018-10-31 16:11:04 -040044import static org.mockito.Mockito.verify;
45import static org.mockito.Mockito.when;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090046
Rohan Shah524cf7b2018-03-15 14:40:02 -070047import android.app.INotificationManager;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090048import android.app.Notification;
49import android.app.NotificationChannel;
Julia Reynoldsb5867452018-02-28 16:31:35 -050050import android.content.Intent;
Steve Elliott46bb2a12020-03-17 11:04:09 -040051import android.content.pm.LauncherApps;
Rohan Shah524cf7b2018-03-15 14:40:02 -070052import android.content.pm.PackageManager;
Steve Elliott46bb2a12020-03-17 11:04:09 -040053import android.content.pm.ShortcutManager;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090054import android.os.Binder;
55import android.os.Handler;
Julia Reynoldsb5867452018-02-28 16:31:35 -050056import android.provider.Settings;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090057import android.service.notification.StatusBarNotification;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090058import android.testing.AndroidTestingRunner;
59import android.testing.TestableLooper;
Julia Reynoldsb5867452018-02-28 16:31:35 -050060import android.util.ArraySet;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090061import android.view.View;
Dave Mankoff5fe07f72019-11-19 22:14:41 -050062import android.view.accessibility.AccessibilityManager;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090063
Brett Chabot84151d92019-02-27 15:37:59 -080064import androidx.test.filters.SmallTest;
65
TreeHugger Robotee8e1ae2019-01-18 19:26:40 +000066import com.android.internal.logging.MetricsLogger;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090067import com.android.systemui.SysuiTestCase;
68import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
Lucas Dupind236ee32019-10-08 15:33:59 -070069import com.android.systemui.statusbar.NotificationLockscreenUserManager;
Rohan Shah20790b82018-07-02 17:21:04 -070070import com.android.systemui.statusbar.NotificationPresenter;
Gus Prevas21437b32018-12-05 10:36:13 -050071import com.android.systemui.statusbar.notification.NotificationActivityStarter;
Ned Burns9512e0c2019-05-30 19:36:04 -040072import com.android.systemui.statusbar.notification.VisualStabilityManager;
Ned Burnsf81c4c42019-01-07 14:10:43 -050073import com.android.systemui.statusbar.notification.collection.NotificationEntry;
Beverlye558f1d2020-01-07 16:28:58 -050074import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider;
Steve Elliott2304e4a2020-04-01 17:03:41 -040075import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier;
Gus Prevas5a70a4e2018-11-26 17:16:05 -050076import com.android.systemui.statusbar.notification.row.NotificationGutsManager.OnSettingsClickListener;
Rohan Shah20790b82018-07-02 17:21:04 -070077import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
Evan Laird03cf3502019-05-31 16:46:48 -040078import com.android.systemui.statusbar.phone.StatusBar;
Jason Monk297c04e2018-08-23 17:16:59 -040079import com.android.systemui.statusbar.policy.DeviceProvisionedController;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090080
81import org.junit.Before;
Selim Cinek2476ed72019-03-07 13:19:23 -080082import org.junit.Ignore;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090083import org.junit.Rule;
84import org.junit.Test;
85import org.junit.runner.RunWith;
Julia Reynoldsb5867452018-02-28 16:31:35 -050086import org.mockito.ArgumentCaptor;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090087import org.mockito.Mock;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090088import org.mockito.junit.MockitoJUnit;
Gus Prevas9abc5062018-10-31 16:11:04 -040089import org.mockito.junit.MockitoRule;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090090
Rohan Shah524cf7b2018-03-15 14:40:02 -070091/**
92 * Tests for {@link NotificationGutsManager}.
93 */
yoshiki iguchia85c2a02018-01-12 11:28:06 +090094@SmallTest
95@RunWith(AndroidTestingRunner.class)
Jason Monka716bac2018-12-05 15:48:21 -050096@TestableLooper.RunWithLooper
yoshiki iguchia85c2a02018-01-12 11:28:06 +090097public class NotificationGutsManagerTest extends SysuiTestCase {
98 private static final String TEST_CHANNEL_ID = "NotificationManagerServiceTestChannelId";
99
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900100 private NotificationChannel mTestNotificationChannel = new NotificationChannel(
Gus Prevas9abc5062018-10-31 16:11:04 -0400101 TEST_CHANNEL_ID, TEST_CHANNEL_ID, IMPORTANCE_DEFAULT);
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900102 private TestableLooper mTestableLooper;
103 private Handler mHandler;
104 private NotificationTestHelper mHelper;
105 private NotificationGutsManager mGutsManager;
106
107 @Rule public MockitoRule mockito = MockitoJUnit.rule();
TreeHugger Robotee8e1ae2019-01-18 19:26:40 +0000108 @Mock private MetricsLogger mMetricsLogger;
Ned Burns9512e0c2019-05-30 19:36:04 -0400109 @Mock private VisualStabilityManager mVisualStabilityManager;
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900110 @Mock private NotificationPresenter mPresenter;
Gus Prevas21437b32018-12-05 10:36:13 -0500111 @Mock private NotificationActivityStarter mNotificationActivityStarter;
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900112 @Mock private NotificationStackScrollLayout mStackScroller;
113 @Mock private NotificationInfo.CheckSaveListener mCheckSaveListener;
Jason Monk297c04e2018-08-23 17:16:59 -0400114 @Mock private OnSettingsClickListener mOnSettingsClickListener;
115 @Mock private DeviceProvisionedController mDeviceProvisionedController;
Evan Laird03cf3502019-05-31 16:46:48 -0400116 @Mock private StatusBar mStatusBar;
Dave Mankoff5fe07f72019-11-19 22:14:41 -0500117 @Mock private AccessibilityManager mAccessibilityManager;
Beverlye558f1d2020-01-07 16:28:58 -0500118 @Mock private HighPriorityProvider mHighPriorityProvider;
Steve Elliott46bb2a12020-03-17 11:04:09 -0400119 @Mock private INotificationManager mINotificationManager;
120 @Mock private LauncherApps mLauncherApps;
121 @Mock private ShortcutManager mShortcutManager;
Steve Elliott2304e4a2020-04-01 17:03:41 -0400122 @Mock private PeopleNotificationIdentifier mPeopleNotificationIdentifier;
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900123
124 @Before
125 public void setUp() {
126 mTestableLooper = TestableLooper.get(this);
Beverly1467c9e2020-02-18 13:31:29 -0500127 allowTestableLooperAsMainThread();
Jason Monk297c04e2018-08-23 17:16:59 -0400128 mDependency.injectTestDependency(DeviceProvisionedController.class,
129 mDeviceProvisionedController);
TreeHugger Robotee8e1ae2019-01-18 19:26:40 +0000130 mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger);
Ned Burns9512e0c2019-05-30 19:36:04 -0400131 mDependency.injectTestDependency(VisualStabilityManager.class, mVisualStabilityManager);
Lucas Dupind236ee32019-10-08 15:33:59 -0700132 mDependency.injectMockDependency(NotificationLockscreenUserManager.class);
Jason Monk6dceace2018-05-15 20:24:07 -0400133 mHandler = Handler.createAsync(mTestableLooper.getLooper());
Kevin Hana7c21be2020-04-01 17:58:35 -0700134 mHelper = new NotificationTestHelper(mContext, mDependency, TestableLooper.get(this));
Dave Mankoff5fe07f72019-11-19 22:14:41 -0500135 when(mAccessibilityManager.isTouchExplorationEnabled()).thenReturn(false);
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900136
Dave Mankoff4dd47fa2019-11-07 10:44:48 -0500137 mGutsManager = new NotificationGutsManager(mContext, mVisualStabilityManager,
Steve Elliott46bb2a12020-03-17 11:04:09 -0400138 () -> mStatusBar, mHandler, mAccessibilityManager, mHighPriorityProvider,
139 mINotificationManager, mLauncherApps, mShortcutManager);
Kevina5ff1fa2018-08-21 16:35:48 -0700140 mGutsManager.setUpWithPresenter(mPresenter, mStackScroller,
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900141 mCheckSaveListener, mOnSettingsClickListener);
Gus Prevas21437b32018-12-05 10:36:13 -0500142 mGutsManager.setNotificationActivityStarter(mNotificationActivityStarter);
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900143 }
144
145 ////////////////////////////////////////////////////////////////////////////////////////////////
146 // Test methods:
147
148 @Test
149 public void testOpenAndCloseGuts() {
150 NotificationGuts guts = spy(new NotificationGuts(mContext));
151 when(guts.post(any())).thenAnswer(invocation -> {
152 mHandler.post(((Runnable) invocation.getArguments()[0]));
153 return null;
154 });
155
156 // Test doesn't support animation since the guts view is not attached.
Rohan Shah524cf7b2018-03-15 14:40:02 -0700157 doNothing().when(guts).openControls(
158 eq(true) /* shouldDoCircularReveal */,
159 anyInt(),
160 anyInt(),
161 anyBoolean(),
162 any(Runnable.class));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900163
164 ExpandableNotificationRow realRow = createTestNotificationRow();
165 NotificationMenuRowPlugin.MenuItem menuItem = createTestMenuItem(realRow);
166
167 ExpandableNotificationRow row = spy(realRow);
168 when(row.getWindowToken()).thenReturn(new Binder());
169 when(row.getGuts()).thenReturn(guts);
170
Evan Laird03cf3502019-05-31 16:46:48 -0400171 assertTrue(mGutsManager.openGutsInternal(row, 0, 0, menuItem));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900172 assertEquals(View.INVISIBLE, guts.getVisibility());
173 mTestableLooper.processAllMessages();
Rohan Shah524cf7b2018-03-15 14:40:02 -0700174 verify(guts).openControls(
175 eq(true),
176 anyInt(),
177 anyInt(),
178 anyBoolean(),
179 any(Runnable.class));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900180
181 assertEquals(View.VISIBLE, guts.getVisibility());
182 mGutsManager.closeAndSaveGuts(false, false, false, 0, 0, false);
183
184 verify(guts).closeControls(anyBoolean(), anyBoolean(), anyInt(), anyInt(), anyBoolean());
185 verify(row, times(1)).setGutsView(any());
186 }
187
188 @Test
189 public void testChangeDensityOrFontScale() {
190 NotificationGuts guts = spy(new NotificationGuts(mContext));
191 when(guts.post(any())).thenAnswer(invocation -> {
192 mHandler.post(((Runnable) invocation.getArguments()[0]));
193 return null;
194 });
195
196 // Test doesn't support animation since the guts view is not attached.
Rohan Shah524cf7b2018-03-15 14:40:02 -0700197 doNothing().when(guts).openControls(
198 eq(true) /* shouldDoCircularReveal */,
199 anyInt(),
200 anyInt(),
201 anyBoolean(),
202 any(Runnable.class));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900203
204 ExpandableNotificationRow realRow = createTestNotificationRow();
205 NotificationMenuRowPlugin.MenuItem menuItem = createTestMenuItem(realRow);
206
207 ExpandableNotificationRow row = spy(realRow);
Evan Laird94492852018-10-25 13:43:01 -0400208
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900209 when(row.getWindowToken()).thenReturn(new Binder());
210 when(row.getGuts()).thenReturn(guts);
Evan Lairde55c6012019-03-13 12:54:37 -0400211 doNothing().when(row).ensureGutsInflated();
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900212
Ned Burnsf81c4c42019-01-07 14:10:43 -0500213 NotificationEntry realEntry = realRow.getEntry();
214 NotificationEntry entry = spy(realEntry);
Evan Laird94492852018-10-25 13:43:01 -0400215
216 when(entry.getRow()).thenReturn(row);
217 when(entry.getGuts()).thenReturn(guts);
218
Evan Laird03cf3502019-05-31 16:46:48 -0400219 assertTrue(mGutsManager.openGutsInternal(row, 0, 0, menuItem));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900220 mTestableLooper.processAllMessages();
Rohan Shah524cf7b2018-03-15 14:40:02 -0700221 verify(guts).openControls(
222 eq(true),
223 anyInt(),
224 anyInt(),
225 anyBoolean(),
226 any(Runnable.class));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900227
Evan Laird94492852018-10-25 13:43:01 -0400228 // called once by mGutsManager.bindGuts() in mGutsManager.openGuts()
229 verify(row).setGutsView(any());
230
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900231 row.onDensityOrFontScaleChanged();
Evan Laird94492852018-10-25 13:43:01 -0400232 mGutsManager.onDensityOrFontScaleChanged(entry);
233
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900234 mTestableLooper.processAllMessages();
235
236 mGutsManager.closeAndSaveGuts(false, false, false, 0, 0, false);
237
238 verify(guts).closeControls(anyBoolean(), anyBoolean(), anyInt(), anyInt(), anyBoolean());
Evan Laird94492852018-10-25 13:43:01 -0400239
240 // called again by mGutsManager.bindGuts(), in mGutsManager.onDensityOrFontScaleChanged()
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900241 verify(row, times(2)).setGutsView(any());
242 }
243
Julia Reynoldsb5867452018-02-28 16:31:35 -0500244 @Test
245 public void testAppOpsSettingsIntent_camera() {
246 ArraySet<Integer> ops = new ArraySet<>();
247 ops.add(OP_CAMERA);
248 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
249 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500250 verify(mNotificationActivityStarter, times(1))
251 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500252 assertEquals(Intent.ACTION_MANAGE_APP_PERMISSIONS, captor.getValue().getAction());
253 }
254
255 @Test
256 public void testAppOpsSettingsIntent_mic() {
257 ArraySet<Integer> ops = new ArraySet<>();
258 ops.add(OP_RECORD_AUDIO);
259 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
260 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500261 verify(mNotificationActivityStarter, times(1))
262 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500263 assertEquals(Intent.ACTION_MANAGE_APP_PERMISSIONS, captor.getValue().getAction());
264 }
265
266 @Test
267 public void testAppOpsSettingsIntent_camera_mic() {
268 ArraySet<Integer> ops = new ArraySet<>();
269 ops.add(OP_CAMERA);
270 ops.add(OP_RECORD_AUDIO);
271 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
272 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500273 verify(mNotificationActivityStarter, times(1))
274 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500275 assertEquals(Intent.ACTION_MANAGE_APP_PERMISSIONS, captor.getValue().getAction());
276 }
277
278 @Test
279 public void testAppOpsSettingsIntent_overlay() {
280 ArraySet<Integer> ops = new ArraySet<>();
281 ops.add(OP_SYSTEM_ALERT_WINDOW);
282 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
283 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500284 verify(mNotificationActivityStarter, times(1))
285 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Bernardo Rufino8fefb942019-11-25 19:51:09 +0000286 assertEquals(Settings.ACTION_MANAGE_APP_OVERLAY_PERMISSION, captor.getValue().getAction());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500287 }
288
289 @Test
290 public void testAppOpsSettingsIntent_camera_mic_overlay() {
291 ArraySet<Integer> ops = new ArraySet<>();
292 ops.add(OP_CAMERA);
293 ops.add(OP_RECORD_AUDIO);
294 ops.add(OP_SYSTEM_ALERT_WINDOW);
295 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
296 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500297 verify(mNotificationActivityStarter, times(1))
298 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500299 assertEquals(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, captor.getValue().getAction());
300 }
301
302 @Test
303 public void testAppOpsSettingsIntent_camera_overlay() {
304 ArraySet<Integer> ops = new ArraySet<>();
305 ops.add(OP_CAMERA);
306 ops.add(OP_SYSTEM_ALERT_WINDOW);
307 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
308 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500309 verify(mNotificationActivityStarter, times(1))
310 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500311 assertEquals(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, captor.getValue().getAction());
312 }
313
314 @Test
315 public void testAppOpsSettingsIntent_mic_overlay() {
316 ArraySet<Integer> ops = new ArraySet<>();
317 ops.add(OP_RECORD_AUDIO);
318 ops.add(OP_SYSTEM_ALERT_WINDOW);
319 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
320 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500321 verify(mNotificationActivityStarter, times(1))
322 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500323 assertEquals(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, captor.getValue().getAction());
324 }
325
Rohan Shah524cf7b2018-03-15 14:40:02 -0700326 @Test
Gus Prevascaed15c2019-01-18 14:19:51 -0500327 public void testInitializeNotificationInfoView_highPriority() throws Exception {
Gus Prevas9abc5062018-10-31 16:11:04 -0400328 NotificationInfo notificationInfoView = mock(NotificationInfo.class);
329 ExpandableNotificationRow row = spy(mHelper.createRow());
Beverly7c1ad5b2019-12-05 17:17:15 -0500330 final NotificationEntry entry = row.getEntry();
331 modifyRanking(entry)
Ned Burns60e94592019-09-06 14:47:25 -0400332 .setUserSentiment(USER_SENTIMENT_NEGATIVE)
Beverly7c1ad5b2019-12-05 17:17:15 -0500333 .setImportance(IMPORTANCE_HIGH)
Ned Burns60e94592019-09-06 14:47:25 -0400334 .build();
Gus Prevas9abc5062018-10-31 16:11:04 -0400335
Beverly7c1ad5b2019-12-05 17:17:15 -0500336 when(row.getIsNonblockable()).thenReturn(false);
Beverlye558f1d2020-01-07 16:28:58 -0500337 when(mHighPriorityProvider.isHighPriority(entry)).thenReturn(true);
Beverly7c1ad5b2019-12-05 17:17:15 -0500338 StatusBarNotification statusBarNotification = entry.getSbn();
Gus Prevas5a70a4e2018-11-26 17:16:05 -0500339 mGutsManager.initializeNotificationInfo(row, notificationInfoView);
Gus Prevas9abc5062018-10-31 16:11:04 -0400340
341 verify(notificationInfoView).bindNotification(
342 any(PackageManager.class),
343 any(INotificationManager.class),
Ned Burns9512e0c2019-05-30 19:36:04 -0400344 eq(mVisualStabilityManager),
Gus Prevas9abc5062018-10-31 16:11:04 -0400345 eq(statusBarNotification.getPackageName()),
346 any(NotificationChannel.class),
Evan Laird47dc4542019-04-24 15:10:52 -0400347 anySet(),
Mady Mellor53162c12019-10-22 17:12:59 -0700348 eq(entry),
Gus Prevas9abc5062018-10-31 16:11:04 -0400349 any(NotificationInfo.OnSettingsClickListener.class),
350 any(NotificationInfo.OnAppSettingsClickListener.class),
351 eq(false),
352 eq(false),
Gus Prevascaed15c2019-01-18 14:19:51 -0500353 eq(true) /* wasShownHighPriority */);
Julia Reynolds35765d82018-08-17 11:39:19 -0400354 }
355
356 @Test
357 public void testInitializeNotificationInfoView_PassesAlongProvisionedState() throws Exception {
358 NotificationInfo notificationInfoView = mock(NotificationInfo.class);
359 ExpandableNotificationRow row = spy(mHelper.createRow());
360 row.setBlockingHelperShowing(false);
Ned Burns47c98f12019-09-06 17:12:07 -0400361 modifyRanking(row.getEntry())
362 .setUserSentiment(USER_SENTIMENT_NEGATIVE)
363 .build();
Julia Reynolds35765d82018-08-17 11:39:19 -0400364 when(row.getIsNonblockable()).thenReturn(false);
Ned Burns1c2b85a42019-11-14 15:37:03 -0500365 StatusBarNotification statusBarNotification = row.getEntry().getSbn();
Mady Mellor53162c12019-10-22 17:12:59 -0700366 NotificationEntry entry = row.getEntry();
367
Jason Monk297c04e2018-08-23 17:16:59 -0400368 when(mDeviceProvisionedController.isDeviceProvisioned()).thenReturn(true);
Julia Reynolds35765d82018-08-17 11:39:19 -0400369
Gus Prevas5a70a4e2018-11-26 17:16:05 -0500370 mGutsManager.initializeNotificationInfo(row, notificationInfoView);
Julia Reynolds35765d82018-08-17 11:39:19 -0400371
372 verify(notificationInfoView).bindNotification(
373 any(PackageManager.class),
374 any(INotificationManager.class),
Ned Burns9512e0c2019-05-30 19:36:04 -0400375 eq(mVisualStabilityManager),
Julia Reynolds35765d82018-08-17 11:39:19 -0400376 eq(statusBarNotification.getPackageName()),
377 any(NotificationChannel.class),
Evan Laird47dc4542019-04-24 15:10:52 -0400378 anySet(),
Mady Mellor53162c12019-10-22 17:12:59 -0700379 eq(entry),
Julia Reynolds35765d82018-08-17 11:39:19 -0400380 any(NotificationInfo.OnSettingsClickListener.class),
381 any(NotificationInfo.OnAppSettingsClickListener.class),
382 eq(true),
383 eq(false),
Gus Prevascaed15c2019-01-18 14:19:51 -0500384 eq(false) /* wasShownHighPriority */);
Gus Prevas894d9152018-11-12 13:51:40 -0500385 }
386
387 @Test
388 public void testInitializeNotificationInfoView_withInitialAction() throws Exception {
389 NotificationInfo notificationInfoView = mock(NotificationInfo.class);
390 ExpandableNotificationRow row = spy(mHelper.createRow());
391 row.setBlockingHelperShowing(true);
Ned Burns47c98f12019-09-06 17:12:07 -0400392 modifyRanking(row.getEntry())
393 .setUserSentiment(USER_SENTIMENT_NEGATIVE)
394 .build();
Gus Prevas894d9152018-11-12 13:51:40 -0500395 when(row.getIsNonblockable()).thenReturn(false);
Ned Burns1c2b85a42019-11-14 15:37:03 -0500396 StatusBarNotification statusBarNotification = row.getEntry().getSbn();
Mady Mellor53162c12019-10-22 17:12:59 -0700397 NotificationEntry entry = row.getEntry();
Gus Prevas894d9152018-11-12 13:51:40 -0500398
Gus Prevas5a70a4e2018-11-26 17:16:05 -0500399 mGutsManager.initializeNotificationInfo(row, notificationInfoView);
Gus Prevas894d9152018-11-12 13:51:40 -0500400
401 verify(notificationInfoView).bindNotification(
402 any(PackageManager.class),
403 any(INotificationManager.class),
Ned Burns9512e0c2019-05-30 19:36:04 -0400404 eq(mVisualStabilityManager),
Gus Prevas894d9152018-11-12 13:51:40 -0500405 eq(statusBarNotification.getPackageName()),
406 any(NotificationChannel.class),
Evan Laird47dc4542019-04-24 15:10:52 -0400407 anySet(),
Mady Mellor53162c12019-10-22 17:12:59 -0700408 eq(entry),
Gus Prevas894d9152018-11-12 13:51:40 -0500409 any(NotificationInfo.OnSettingsClickListener.class),
410 any(NotificationInfo.OnAppSettingsClickListener.class),
411 eq(false),
412 eq(false),
Gus Prevascaed15c2019-01-18 14:19:51 -0500413 eq(false) /* wasShownHighPriority */);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700414 }
415
Kevina5ff1fa2018-08-21 16:35:48 -0700416 @Test
417 public void testShouldExtendLifetime() {
418 NotificationGuts guts = new NotificationGuts(mContext);
419 ExpandableNotificationRow row = spy(createTestNotificationRow());
420 doReturn(guts).when(row).getGuts();
Ned Burnsf81c4c42019-01-07 14:10:43 -0500421 NotificationEntry entry = row.getEntry();
Evan Laird94492852018-10-25 13:43:01 -0400422 entry.setRow(row);
Kevina5ff1fa2018-08-21 16:35:48 -0700423 mGutsManager.setExposedGuts(guts);
424
425 assertTrue(mGutsManager.shouldExtendLifetime(entry));
426 }
427
428 @Test
Selim Cinek2476ed72019-03-07 13:19:23 -0800429 @Ignore
Kevine9e938c2018-09-06 13:38:11 -0700430 public void testSetShouldManageLifetime_setShouldManage() {
Ned Burnsf81c4c42019-01-07 14:10:43 -0500431 NotificationEntry entry = createTestNotificationRow().getEntry();
Kevine9e938c2018-09-06 13:38:11 -0700432 mGutsManager.setShouldManageLifetime(entry, true /* shouldManage */);
Kevina5ff1fa2018-08-21 16:35:48 -0700433
Ned Burns00b4b2d2019-10-17 22:09:27 -0400434 assertTrue(entry.getKey().equals(mGutsManager.mKeyToRemoveOnGutsClosed));
Kevina5ff1fa2018-08-21 16:35:48 -0700435 }
436
437 @Test
Kevine9e938c2018-09-06 13:38:11 -0700438 public void testSetShouldManageLifetime_setShouldNotManage() {
Ned Burnsf81c4c42019-01-07 14:10:43 -0500439 NotificationEntry entry = createTestNotificationRow().getEntry();
Ned Burns00b4b2d2019-10-17 22:09:27 -0400440 mGutsManager.mKeyToRemoveOnGutsClosed = entry.getKey();
Kevine9e938c2018-09-06 13:38:11 -0700441 mGutsManager.setShouldManageLifetime(entry, false /* shouldManage */);
Kevina5ff1fa2018-08-21 16:35:48 -0700442
443 assertNull(mGutsManager.mKeyToRemoveOnGutsClosed);
444 }
445
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900446 ////////////////////////////////////////////////////////////////////////////////////////////////
447 // Utility methods:
448
449 private ExpandableNotificationRow createTestNotificationRow() {
450 Notification.Builder nb = new Notification.Builder(mContext,
451 mTestNotificationChannel.getId())
452 .setContentTitle("foo")
453 .setColorized(true)
454 .setFlag(Notification.FLAG_CAN_COLORIZE, true)
455 .setSmallIcon(android.R.drawable.sym_def_app_icon);
456
457 try {
458 ExpandableNotificationRow row = mHelper.createRow(nb.build());
Ned Burns60e94592019-09-06 14:47:25 -0400459 modifyRanking(row.getEntry())
460 .setChannel(mTestNotificationChannel)
461 .build();
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900462 return row;
463 } catch (Exception e) {
464 fail();
465 return null;
466 }
467 }
468
469 private NotificationMenuRowPlugin.MenuItem createTestMenuItem(ExpandableNotificationRow row) {
Steve Elliott2304e4a2020-04-01 17:03:41 -0400470 NotificationMenuRowPlugin menuRow =
471 new NotificationMenuRow(mContext, mPeopleNotificationIdentifier);
Ned Burns1c2b85a42019-11-14 15:37:03 -0500472 menuRow.createMenu(row, row.getEntry().getSbn());
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900473
474 NotificationMenuRowPlugin.MenuItem menuItem = menuRow.getLongpressMenuItem(mContext);
475 assertNotNull(menuItem);
476 return menuItem;
477 }
478}