blob: 5813740712b6e26daf1a22eec18bfc4564ea9715 [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;
Evan Laird31ca5472020-04-08 17:45:24 -040069import com.android.systemui.settings.CurrentUserContextTracker;
Lucas Dupind236ee32019-10-08 15:33:59 -070070import com.android.systemui.statusbar.NotificationLockscreenUserManager;
Rohan Shah20790b82018-07-02 17:21:04 -070071import com.android.systemui.statusbar.NotificationPresenter;
Gus Prevas21437b32018-12-05 10:36:13 -050072import com.android.systemui.statusbar.notification.NotificationActivityStarter;
Ned Burns9512e0c2019-05-30 19:36:04 -040073import com.android.systemui.statusbar.notification.VisualStabilityManager;
Ned Burnsf81c4c42019-01-07 14:10:43 -050074import com.android.systemui.statusbar.notification.collection.NotificationEntry;
Beverlye558f1d2020-01-07 16:28:58 -050075import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider;
Steve Elliott2304e4a2020-04-01 17:03:41 -040076import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier;
Gus Prevas5a70a4e2018-11-26 17:16:05 -050077import com.android.systemui.statusbar.notification.row.NotificationGutsManager.OnSettingsClickListener;
Rohan Shah20790b82018-07-02 17:21:04 -070078import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout;
Evan Laird03cf3502019-05-31 16:46:48 -040079import com.android.systemui.statusbar.phone.StatusBar;
Jason Monk297c04e2018-08-23 17:16:59 -040080import com.android.systemui.statusbar.policy.DeviceProvisionedController;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090081
82import org.junit.Before;
Selim Cinek2476ed72019-03-07 13:19:23 -080083import org.junit.Ignore;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090084import org.junit.Rule;
85import org.junit.Test;
86import org.junit.runner.RunWith;
Evan Laird31ca5472020-04-08 17:45:24 -040087import org.mockito.Answers;
Julia Reynoldsb5867452018-02-28 16:31:35 -050088import org.mockito.ArgumentCaptor;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090089import org.mockito.Mock;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090090import org.mockito.junit.MockitoJUnit;
Gus Prevas9abc5062018-10-31 16:11:04 -040091import org.mockito.junit.MockitoRule;
yoshiki iguchia85c2a02018-01-12 11:28:06 +090092
Evan Laird31ca5472020-04-08 17:45:24 -040093import javax.inject.Provider;
94
Rohan Shah524cf7b2018-03-15 14:40:02 -070095/**
96 * Tests for {@link NotificationGutsManager}.
97 */
yoshiki iguchia85c2a02018-01-12 11:28:06 +090098@SmallTest
99@RunWith(AndroidTestingRunner.class)
Jason Monka716bac2018-12-05 15:48:21 -0500100@TestableLooper.RunWithLooper
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900101public class NotificationGutsManagerTest extends SysuiTestCase {
102 private static final String TEST_CHANNEL_ID = "NotificationManagerServiceTestChannelId";
103
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900104 private NotificationChannel mTestNotificationChannel = new NotificationChannel(
Gus Prevas9abc5062018-10-31 16:11:04 -0400105 TEST_CHANNEL_ID, TEST_CHANNEL_ID, IMPORTANCE_DEFAULT);
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900106 private TestableLooper mTestableLooper;
107 private Handler mHandler;
108 private NotificationTestHelper mHelper;
109 private NotificationGutsManager mGutsManager;
110
111 @Rule public MockitoRule mockito = MockitoJUnit.rule();
TreeHugger Robotee8e1ae2019-01-18 19:26:40 +0000112 @Mock private MetricsLogger mMetricsLogger;
Ned Burns9512e0c2019-05-30 19:36:04 -0400113 @Mock private VisualStabilityManager mVisualStabilityManager;
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900114 @Mock private NotificationPresenter mPresenter;
Gus Prevas21437b32018-12-05 10:36:13 -0500115 @Mock private NotificationActivityStarter mNotificationActivityStarter;
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900116 @Mock private NotificationStackScrollLayout mStackScroller;
117 @Mock private NotificationInfo.CheckSaveListener mCheckSaveListener;
Jason Monk297c04e2018-08-23 17:16:59 -0400118 @Mock private OnSettingsClickListener mOnSettingsClickListener;
119 @Mock private DeviceProvisionedController mDeviceProvisionedController;
Evan Laird03cf3502019-05-31 16:46:48 -0400120 @Mock private StatusBar mStatusBar;
Dave Mankoff5fe07f72019-11-19 22:14:41 -0500121 @Mock private AccessibilityManager mAccessibilityManager;
Beverlye558f1d2020-01-07 16:28:58 -0500122 @Mock private HighPriorityProvider mHighPriorityProvider;
Steve Elliott46bb2a12020-03-17 11:04:09 -0400123 @Mock private INotificationManager mINotificationManager;
124 @Mock private LauncherApps mLauncherApps;
125 @Mock private ShortcutManager mShortcutManager;
Steve Elliott2304e4a2020-04-01 17:03:41 -0400126 @Mock private PeopleNotificationIdentifier mPeopleNotificationIdentifier;
Evan Laird31ca5472020-04-08 17:45:24 -0400127 @Mock private CurrentUserContextTracker mContextTracker;
128 @Mock(answer = Answers.RETURNS_SELF)
129 private PriorityOnboardingDialogController.Builder mBuilder;
130 private Provider<PriorityOnboardingDialogController.Builder> mProvider = () -> mBuilder;
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900131
132 @Before
133 public void setUp() {
134 mTestableLooper = TestableLooper.get(this);
Beverly1467c9e2020-02-18 13:31:29 -0500135 allowTestableLooperAsMainThread();
Jason Monk297c04e2018-08-23 17:16:59 -0400136 mDependency.injectTestDependency(DeviceProvisionedController.class,
137 mDeviceProvisionedController);
TreeHugger Robotee8e1ae2019-01-18 19:26:40 +0000138 mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger);
Ned Burns9512e0c2019-05-30 19:36:04 -0400139 mDependency.injectTestDependency(VisualStabilityManager.class, mVisualStabilityManager);
Lucas Dupind236ee32019-10-08 15:33:59 -0700140 mDependency.injectMockDependency(NotificationLockscreenUserManager.class);
Jason Monk6dceace2018-05-15 20:24:07 -0400141 mHandler = Handler.createAsync(mTestableLooper.getLooper());
Kevin Hana7c21be2020-04-01 17:58:35 -0700142 mHelper = new NotificationTestHelper(mContext, mDependency, TestableLooper.get(this));
Dave Mankoff5fe07f72019-11-19 22:14:41 -0500143 when(mAccessibilityManager.isTouchExplorationEnabled()).thenReturn(false);
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900144
Dave Mankoff4dd47fa2019-11-07 10:44:48 -0500145 mGutsManager = new NotificationGutsManager(mContext, mVisualStabilityManager,
Steve Elliott46bb2a12020-03-17 11:04:09 -0400146 () -> mStatusBar, mHandler, mAccessibilityManager, mHighPriorityProvider,
Evan Laird31ca5472020-04-08 17:45:24 -0400147 mINotificationManager, mLauncherApps, mShortcutManager, mContextTracker, mProvider);
Kevina5ff1fa2018-08-21 16:35:48 -0700148 mGutsManager.setUpWithPresenter(mPresenter, mStackScroller,
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900149 mCheckSaveListener, mOnSettingsClickListener);
Gus Prevas21437b32018-12-05 10:36:13 -0500150 mGutsManager.setNotificationActivityStarter(mNotificationActivityStarter);
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900151 }
152
153 ////////////////////////////////////////////////////////////////////////////////////////////////
154 // Test methods:
155
156 @Test
157 public void testOpenAndCloseGuts() {
158 NotificationGuts guts = spy(new NotificationGuts(mContext));
159 when(guts.post(any())).thenAnswer(invocation -> {
160 mHandler.post(((Runnable) invocation.getArguments()[0]));
161 return null;
162 });
163
164 // Test doesn't support animation since the guts view is not attached.
Rohan Shah524cf7b2018-03-15 14:40:02 -0700165 doNothing().when(guts).openControls(
166 eq(true) /* shouldDoCircularReveal */,
167 anyInt(),
168 anyInt(),
169 anyBoolean(),
170 any(Runnable.class));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900171
172 ExpandableNotificationRow realRow = createTestNotificationRow();
173 NotificationMenuRowPlugin.MenuItem menuItem = createTestMenuItem(realRow);
174
175 ExpandableNotificationRow row = spy(realRow);
176 when(row.getWindowToken()).thenReturn(new Binder());
177 when(row.getGuts()).thenReturn(guts);
178
Evan Laird03cf3502019-05-31 16:46:48 -0400179 assertTrue(mGutsManager.openGutsInternal(row, 0, 0, menuItem));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900180 assertEquals(View.INVISIBLE, guts.getVisibility());
181 mTestableLooper.processAllMessages();
Rohan Shah524cf7b2018-03-15 14:40:02 -0700182 verify(guts).openControls(
183 eq(true),
184 anyInt(),
185 anyInt(),
186 anyBoolean(),
187 any(Runnable.class));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900188
189 assertEquals(View.VISIBLE, guts.getVisibility());
190 mGutsManager.closeAndSaveGuts(false, false, false, 0, 0, false);
191
192 verify(guts).closeControls(anyBoolean(), anyBoolean(), anyInt(), anyInt(), anyBoolean());
193 verify(row, times(1)).setGutsView(any());
194 }
195
196 @Test
197 public void testChangeDensityOrFontScale() {
198 NotificationGuts guts = spy(new NotificationGuts(mContext));
199 when(guts.post(any())).thenAnswer(invocation -> {
200 mHandler.post(((Runnable) invocation.getArguments()[0]));
201 return null;
202 });
203
204 // Test doesn't support animation since the guts view is not attached.
Rohan Shah524cf7b2018-03-15 14:40:02 -0700205 doNothing().when(guts).openControls(
206 eq(true) /* shouldDoCircularReveal */,
207 anyInt(),
208 anyInt(),
209 anyBoolean(),
210 any(Runnable.class));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900211
212 ExpandableNotificationRow realRow = createTestNotificationRow();
213 NotificationMenuRowPlugin.MenuItem menuItem = createTestMenuItem(realRow);
214
215 ExpandableNotificationRow row = spy(realRow);
Evan Laird94492852018-10-25 13:43:01 -0400216
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900217 when(row.getWindowToken()).thenReturn(new Binder());
218 when(row.getGuts()).thenReturn(guts);
Evan Lairde55c6012019-03-13 12:54:37 -0400219 doNothing().when(row).ensureGutsInflated();
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900220
Ned Burnsf81c4c42019-01-07 14:10:43 -0500221 NotificationEntry realEntry = realRow.getEntry();
222 NotificationEntry entry = spy(realEntry);
Evan Laird94492852018-10-25 13:43:01 -0400223
224 when(entry.getRow()).thenReturn(row);
225 when(entry.getGuts()).thenReturn(guts);
226
Evan Laird03cf3502019-05-31 16:46:48 -0400227 assertTrue(mGutsManager.openGutsInternal(row, 0, 0, menuItem));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900228 mTestableLooper.processAllMessages();
Rohan Shah524cf7b2018-03-15 14:40:02 -0700229 verify(guts).openControls(
230 eq(true),
231 anyInt(),
232 anyInt(),
233 anyBoolean(),
234 any(Runnable.class));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900235
Evan Laird94492852018-10-25 13:43:01 -0400236 // called once by mGutsManager.bindGuts() in mGutsManager.openGuts()
237 verify(row).setGutsView(any());
238
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900239 row.onDensityOrFontScaleChanged();
Evan Laird94492852018-10-25 13:43:01 -0400240 mGutsManager.onDensityOrFontScaleChanged(entry);
241
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900242 mTestableLooper.processAllMessages();
243
244 mGutsManager.closeAndSaveGuts(false, false, false, 0, 0, false);
245
246 verify(guts).closeControls(anyBoolean(), anyBoolean(), anyInt(), anyInt(), anyBoolean());
Evan Laird94492852018-10-25 13:43:01 -0400247
248 // called again by mGutsManager.bindGuts(), in mGutsManager.onDensityOrFontScaleChanged()
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900249 verify(row, times(2)).setGutsView(any());
250 }
251
Julia Reynoldsb5867452018-02-28 16:31:35 -0500252 @Test
253 public void testAppOpsSettingsIntent_camera() {
254 ArraySet<Integer> ops = new ArraySet<>();
255 ops.add(OP_CAMERA);
256 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
257 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500258 verify(mNotificationActivityStarter, times(1))
259 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500260 assertEquals(Intent.ACTION_MANAGE_APP_PERMISSIONS, captor.getValue().getAction());
261 }
262
263 @Test
264 public void testAppOpsSettingsIntent_mic() {
265 ArraySet<Integer> ops = new ArraySet<>();
266 ops.add(OP_RECORD_AUDIO);
267 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
268 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500269 verify(mNotificationActivityStarter, times(1))
270 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500271 assertEquals(Intent.ACTION_MANAGE_APP_PERMISSIONS, captor.getValue().getAction());
272 }
273
274 @Test
275 public void testAppOpsSettingsIntent_camera_mic() {
276 ArraySet<Integer> ops = new ArraySet<>();
277 ops.add(OP_CAMERA);
278 ops.add(OP_RECORD_AUDIO);
279 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
280 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500281 verify(mNotificationActivityStarter, times(1))
282 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500283 assertEquals(Intent.ACTION_MANAGE_APP_PERMISSIONS, captor.getValue().getAction());
284 }
285
286 @Test
287 public void testAppOpsSettingsIntent_overlay() {
288 ArraySet<Integer> ops = new ArraySet<>();
289 ops.add(OP_SYSTEM_ALERT_WINDOW);
290 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
291 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500292 verify(mNotificationActivityStarter, times(1))
293 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Bernardo Rufino8fefb942019-11-25 19:51:09 +0000294 assertEquals(Settings.ACTION_MANAGE_APP_OVERLAY_PERMISSION, captor.getValue().getAction());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500295 }
296
297 @Test
298 public void testAppOpsSettingsIntent_camera_mic_overlay() {
299 ArraySet<Integer> ops = new ArraySet<>();
300 ops.add(OP_CAMERA);
301 ops.add(OP_RECORD_AUDIO);
302 ops.add(OP_SYSTEM_ALERT_WINDOW);
303 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
304 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500305 verify(mNotificationActivityStarter, times(1))
306 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500307 assertEquals(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, captor.getValue().getAction());
308 }
309
310 @Test
311 public void testAppOpsSettingsIntent_camera_overlay() {
312 ArraySet<Integer> ops = new ArraySet<>();
313 ops.add(OP_CAMERA);
314 ops.add(OP_SYSTEM_ALERT_WINDOW);
315 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
316 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500317 verify(mNotificationActivityStarter, times(1))
318 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500319 assertEquals(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, captor.getValue().getAction());
320 }
321
322 @Test
323 public void testAppOpsSettingsIntent_mic_overlay() {
324 ArraySet<Integer> ops = new ArraySet<>();
325 ops.add(OP_RECORD_AUDIO);
326 ops.add(OP_SYSTEM_ALERT_WINDOW);
327 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
328 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500329 verify(mNotificationActivityStarter, times(1))
330 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500331 assertEquals(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, captor.getValue().getAction());
332 }
333
Rohan Shah524cf7b2018-03-15 14:40:02 -0700334 @Test
Gus Prevascaed15c2019-01-18 14:19:51 -0500335 public void testInitializeNotificationInfoView_highPriority() throws Exception {
Gus Prevas9abc5062018-10-31 16:11:04 -0400336 NotificationInfo notificationInfoView = mock(NotificationInfo.class);
337 ExpandableNotificationRow row = spy(mHelper.createRow());
Beverly7c1ad5b2019-12-05 17:17:15 -0500338 final NotificationEntry entry = row.getEntry();
339 modifyRanking(entry)
Ned Burns60e94592019-09-06 14:47:25 -0400340 .setUserSentiment(USER_SENTIMENT_NEGATIVE)
Beverly7c1ad5b2019-12-05 17:17:15 -0500341 .setImportance(IMPORTANCE_HIGH)
Ned Burns60e94592019-09-06 14:47:25 -0400342 .build();
Gus Prevas9abc5062018-10-31 16:11:04 -0400343
Beverly7c1ad5b2019-12-05 17:17:15 -0500344 when(row.getIsNonblockable()).thenReturn(false);
Beverlye558f1d2020-01-07 16:28:58 -0500345 when(mHighPriorityProvider.isHighPriority(entry)).thenReturn(true);
Beverly7c1ad5b2019-12-05 17:17:15 -0500346 StatusBarNotification statusBarNotification = entry.getSbn();
Gus Prevas5a70a4e2018-11-26 17:16:05 -0500347 mGutsManager.initializeNotificationInfo(row, notificationInfoView);
Gus Prevas9abc5062018-10-31 16:11:04 -0400348
349 verify(notificationInfoView).bindNotification(
350 any(PackageManager.class),
351 any(INotificationManager.class),
Ned Burns9512e0c2019-05-30 19:36:04 -0400352 eq(mVisualStabilityManager),
Gus Prevas9abc5062018-10-31 16:11:04 -0400353 eq(statusBarNotification.getPackageName()),
354 any(NotificationChannel.class),
Evan Laird47dc4542019-04-24 15:10:52 -0400355 anySet(),
Mady Mellor53162c12019-10-22 17:12:59 -0700356 eq(entry),
Gus Prevas9abc5062018-10-31 16:11:04 -0400357 any(NotificationInfo.OnSettingsClickListener.class),
358 any(NotificationInfo.OnAppSettingsClickListener.class),
359 eq(false),
360 eq(false),
Gus Prevascaed15c2019-01-18 14:19:51 -0500361 eq(true) /* wasShownHighPriority */);
Julia Reynolds35765d82018-08-17 11:39:19 -0400362 }
363
364 @Test
365 public void testInitializeNotificationInfoView_PassesAlongProvisionedState() throws Exception {
366 NotificationInfo notificationInfoView = mock(NotificationInfo.class);
367 ExpandableNotificationRow row = spy(mHelper.createRow());
368 row.setBlockingHelperShowing(false);
Ned Burns47c98f12019-09-06 17:12:07 -0400369 modifyRanking(row.getEntry())
370 .setUserSentiment(USER_SENTIMENT_NEGATIVE)
371 .build();
Julia Reynolds35765d82018-08-17 11:39:19 -0400372 when(row.getIsNonblockable()).thenReturn(false);
Ned Burns1c2b85a42019-11-14 15:37:03 -0500373 StatusBarNotification statusBarNotification = row.getEntry().getSbn();
Mady Mellor53162c12019-10-22 17:12:59 -0700374 NotificationEntry entry = row.getEntry();
375
Jason Monk297c04e2018-08-23 17:16:59 -0400376 when(mDeviceProvisionedController.isDeviceProvisioned()).thenReturn(true);
Julia Reynolds35765d82018-08-17 11:39:19 -0400377
Gus Prevas5a70a4e2018-11-26 17:16:05 -0500378 mGutsManager.initializeNotificationInfo(row, notificationInfoView);
Julia Reynolds35765d82018-08-17 11:39:19 -0400379
380 verify(notificationInfoView).bindNotification(
381 any(PackageManager.class),
382 any(INotificationManager.class),
Ned Burns9512e0c2019-05-30 19:36:04 -0400383 eq(mVisualStabilityManager),
Julia Reynolds35765d82018-08-17 11:39:19 -0400384 eq(statusBarNotification.getPackageName()),
385 any(NotificationChannel.class),
Evan Laird47dc4542019-04-24 15:10:52 -0400386 anySet(),
Mady Mellor53162c12019-10-22 17:12:59 -0700387 eq(entry),
Julia Reynolds35765d82018-08-17 11:39:19 -0400388 any(NotificationInfo.OnSettingsClickListener.class),
389 any(NotificationInfo.OnAppSettingsClickListener.class),
390 eq(true),
391 eq(false),
Gus Prevascaed15c2019-01-18 14:19:51 -0500392 eq(false) /* wasShownHighPriority */);
Gus Prevas894d9152018-11-12 13:51:40 -0500393 }
394
395 @Test
396 public void testInitializeNotificationInfoView_withInitialAction() throws Exception {
397 NotificationInfo notificationInfoView = mock(NotificationInfo.class);
398 ExpandableNotificationRow row = spy(mHelper.createRow());
399 row.setBlockingHelperShowing(true);
Ned Burns47c98f12019-09-06 17:12:07 -0400400 modifyRanking(row.getEntry())
401 .setUserSentiment(USER_SENTIMENT_NEGATIVE)
402 .build();
Gus Prevas894d9152018-11-12 13:51:40 -0500403 when(row.getIsNonblockable()).thenReturn(false);
Ned Burns1c2b85a42019-11-14 15:37:03 -0500404 StatusBarNotification statusBarNotification = row.getEntry().getSbn();
Mady Mellor53162c12019-10-22 17:12:59 -0700405 NotificationEntry entry = row.getEntry();
Gus Prevas894d9152018-11-12 13:51:40 -0500406
Gus Prevas5a70a4e2018-11-26 17:16:05 -0500407 mGutsManager.initializeNotificationInfo(row, notificationInfoView);
Gus Prevas894d9152018-11-12 13:51:40 -0500408
409 verify(notificationInfoView).bindNotification(
410 any(PackageManager.class),
411 any(INotificationManager.class),
Ned Burns9512e0c2019-05-30 19:36:04 -0400412 eq(mVisualStabilityManager),
Gus Prevas894d9152018-11-12 13:51:40 -0500413 eq(statusBarNotification.getPackageName()),
414 any(NotificationChannel.class),
Evan Laird47dc4542019-04-24 15:10:52 -0400415 anySet(),
Mady Mellor53162c12019-10-22 17:12:59 -0700416 eq(entry),
Gus Prevas894d9152018-11-12 13:51:40 -0500417 any(NotificationInfo.OnSettingsClickListener.class),
418 any(NotificationInfo.OnAppSettingsClickListener.class),
419 eq(false),
420 eq(false),
Gus Prevascaed15c2019-01-18 14:19:51 -0500421 eq(false) /* wasShownHighPriority */);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700422 }
423
Kevina5ff1fa2018-08-21 16:35:48 -0700424 @Test
425 public void testShouldExtendLifetime() {
426 NotificationGuts guts = new NotificationGuts(mContext);
427 ExpandableNotificationRow row = spy(createTestNotificationRow());
428 doReturn(guts).when(row).getGuts();
Ned Burnsf81c4c42019-01-07 14:10:43 -0500429 NotificationEntry entry = row.getEntry();
Evan Laird94492852018-10-25 13:43:01 -0400430 entry.setRow(row);
Kevina5ff1fa2018-08-21 16:35:48 -0700431 mGutsManager.setExposedGuts(guts);
432
433 assertTrue(mGutsManager.shouldExtendLifetime(entry));
434 }
435
436 @Test
Selim Cinek2476ed72019-03-07 13:19:23 -0800437 @Ignore
Kevine9e938c2018-09-06 13:38:11 -0700438 public void testSetShouldManageLifetime_setShouldManage() {
Ned Burnsf81c4c42019-01-07 14:10:43 -0500439 NotificationEntry entry = createTestNotificationRow().getEntry();
Kevine9e938c2018-09-06 13:38:11 -0700440 mGutsManager.setShouldManageLifetime(entry, true /* shouldManage */);
Kevina5ff1fa2018-08-21 16:35:48 -0700441
Ned Burns00b4b2d2019-10-17 22:09:27 -0400442 assertTrue(entry.getKey().equals(mGutsManager.mKeyToRemoveOnGutsClosed));
Kevina5ff1fa2018-08-21 16:35:48 -0700443 }
444
445 @Test
Kevine9e938c2018-09-06 13:38:11 -0700446 public void testSetShouldManageLifetime_setShouldNotManage() {
Ned Burnsf81c4c42019-01-07 14:10:43 -0500447 NotificationEntry entry = createTestNotificationRow().getEntry();
Ned Burns00b4b2d2019-10-17 22:09:27 -0400448 mGutsManager.mKeyToRemoveOnGutsClosed = entry.getKey();
Kevine9e938c2018-09-06 13:38:11 -0700449 mGutsManager.setShouldManageLifetime(entry, false /* shouldManage */);
Kevina5ff1fa2018-08-21 16:35:48 -0700450
451 assertNull(mGutsManager.mKeyToRemoveOnGutsClosed);
452 }
453
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900454 ////////////////////////////////////////////////////////////////////////////////////////////////
455 // Utility methods:
456
457 private ExpandableNotificationRow createTestNotificationRow() {
458 Notification.Builder nb = new Notification.Builder(mContext,
459 mTestNotificationChannel.getId())
460 .setContentTitle("foo")
461 .setColorized(true)
462 .setFlag(Notification.FLAG_CAN_COLORIZE, true)
463 .setSmallIcon(android.R.drawable.sym_def_app_icon);
464
465 try {
466 ExpandableNotificationRow row = mHelper.createRow(nb.build());
Ned Burns60e94592019-09-06 14:47:25 -0400467 modifyRanking(row.getEntry())
468 .setChannel(mTestNotificationChannel)
469 .build();
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900470 return row;
471 } catch (Exception e) {
472 fail();
473 return null;
474 }
475 }
476
477 private NotificationMenuRowPlugin.MenuItem createTestMenuItem(ExpandableNotificationRow row) {
Steve Elliott2304e4a2020-04-01 17:03:41 -0400478 NotificationMenuRowPlugin menuRow =
479 new NotificationMenuRow(mContext, mPeopleNotificationIdentifier);
Ned Burns1c2b85a42019-11-14 15:37:03 -0500480 menuRow.createMenu(row, row.getEntry().getSbn());
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900481
482 NotificationMenuRowPlugin.MenuItem menuItem = menuRow.getLongpressMenuItem(mContext);
483 assertNotNull(menuItem);
484 return menuItem;
485 }
486}