blob: da7d249cc5ef874054a1cf97482dd87b59930610 [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;
Evan Laird18bd6e62019-08-30 16:39:25 -0400126 @Mock private ChannelEditorDialogController mChannelEditorDialogController;
Steve Elliott2304e4a2020-04-01 17:03:41 -0400127 @Mock private PeopleNotificationIdentifier mPeopleNotificationIdentifier;
Evan Laird31ca5472020-04-08 17:45:24 -0400128 @Mock private CurrentUserContextTracker mContextTracker;
129 @Mock(answer = Answers.RETURNS_SELF)
130 private PriorityOnboardingDialogController.Builder mBuilder;
131 private Provider<PriorityOnboardingDialogController.Builder> mProvider = () -> mBuilder;
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900132
133 @Before
134 public void setUp() {
135 mTestableLooper = TestableLooper.get(this);
Beverly1467c9e2020-02-18 13:31:29 -0500136 allowTestableLooperAsMainThread();
Jason Monk297c04e2018-08-23 17:16:59 -0400137 mDependency.injectTestDependency(DeviceProvisionedController.class,
138 mDeviceProvisionedController);
TreeHugger Robotee8e1ae2019-01-18 19:26:40 +0000139 mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger);
Ned Burns9512e0c2019-05-30 19:36:04 -0400140 mDependency.injectTestDependency(VisualStabilityManager.class, mVisualStabilityManager);
Lucas Dupind236ee32019-10-08 15:33:59 -0700141 mDependency.injectMockDependency(NotificationLockscreenUserManager.class);
Jason Monk6dceace2018-05-15 20:24:07 -0400142 mHandler = Handler.createAsync(mTestableLooper.getLooper());
Kevin Hana7c21be2020-04-01 17:58:35 -0700143 mHelper = new NotificationTestHelper(mContext, mDependency, TestableLooper.get(this));
Dave Mankoff5fe07f72019-11-19 22:14:41 -0500144 when(mAccessibilityManager.isTouchExplorationEnabled()).thenReturn(false);
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900145
Dave Mankoff4dd47fa2019-11-07 10:44:48 -0500146 mGutsManager = new NotificationGutsManager(mContext, mVisualStabilityManager,
Steve Elliott6771f542020-05-26 13:31:10 -0400147 () -> mStatusBar, mHandler, mHandler, mAccessibilityManager, mHighPriorityProvider,
Evan Laird18bd6e62019-08-30 16:39:25 -0400148 mINotificationManager, mLauncherApps, mShortcutManager,
149 mChannelEditorDialogController, mContextTracker, mProvider);
Kevina5ff1fa2018-08-21 16:35:48 -0700150 mGutsManager.setUpWithPresenter(mPresenter, mStackScroller,
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900151 mCheckSaveListener, mOnSettingsClickListener);
Gus Prevas21437b32018-12-05 10:36:13 -0500152 mGutsManager.setNotificationActivityStarter(mNotificationActivityStarter);
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900153 }
154
155 ////////////////////////////////////////////////////////////////////////////////////////////////
156 // Test methods:
157
158 @Test
159 public void testOpenAndCloseGuts() {
160 NotificationGuts guts = spy(new NotificationGuts(mContext));
161 when(guts.post(any())).thenAnswer(invocation -> {
162 mHandler.post(((Runnable) invocation.getArguments()[0]));
163 return null;
164 });
165
166 // Test doesn't support animation since the guts view is not attached.
Rohan Shah524cf7b2018-03-15 14:40:02 -0700167 doNothing().when(guts).openControls(
168 eq(true) /* shouldDoCircularReveal */,
169 anyInt(),
170 anyInt(),
171 anyBoolean(),
172 any(Runnable.class));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900173
174 ExpandableNotificationRow realRow = createTestNotificationRow();
175 NotificationMenuRowPlugin.MenuItem menuItem = createTestMenuItem(realRow);
176
177 ExpandableNotificationRow row = spy(realRow);
178 when(row.getWindowToken()).thenReturn(new Binder());
179 when(row.getGuts()).thenReturn(guts);
180
Evan Laird03cf3502019-05-31 16:46:48 -0400181 assertTrue(mGutsManager.openGutsInternal(row, 0, 0, menuItem));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900182 assertEquals(View.INVISIBLE, guts.getVisibility());
183 mTestableLooper.processAllMessages();
Rohan Shah524cf7b2018-03-15 14:40:02 -0700184 verify(guts).openControls(
185 eq(true),
186 anyInt(),
187 anyInt(),
188 anyBoolean(),
189 any(Runnable.class));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900190
191 assertEquals(View.VISIBLE, guts.getVisibility());
192 mGutsManager.closeAndSaveGuts(false, false, false, 0, 0, false);
193
194 verify(guts).closeControls(anyBoolean(), anyBoolean(), anyInt(), anyInt(), anyBoolean());
195 verify(row, times(1)).setGutsView(any());
196 }
197
198 @Test
199 public void testChangeDensityOrFontScale() {
200 NotificationGuts guts = spy(new NotificationGuts(mContext));
201 when(guts.post(any())).thenAnswer(invocation -> {
202 mHandler.post(((Runnable) invocation.getArguments()[0]));
203 return null;
204 });
205
206 // Test doesn't support animation since the guts view is not attached.
Rohan Shah524cf7b2018-03-15 14:40:02 -0700207 doNothing().when(guts).openControls(
208 eq(true) /* shouldDoCircularReveal */,
209 anyInt(),
210 anyInt(),
211 anyBoolean(),
212 any(Runnable.class));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900213
214 ExpandableNotificationRow realRow = createTestNotificationRow();
215 NotificationMenuRowPlugin.MenuItem menuItem = createTestMenuItem(realRow);
216
217 ExpandableNotificationRow row = spy(realRow);
Evan Laird94492852018-10-25 13:43:01 -0400218
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900219 when(row.getWindowToken()).thenReturn(new Binder());
220 when(row.getGuts()).thenReturn(guts);
Evan Lairde55c6012019-03-13 12:54:37 -0400221 doNothing().when(row).ensureGutsInflated();
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900222
Ned Burnsf81c4c42019-01-07 14:10:43 -0500223 NotificationEntry realEntry = realRow.getEntry();
224 NotificationEntry entry = spy(realEntry);
Evan Laird94492852018-10-25 13:43:01 -0400225
226 when(entry.getRow()).thenReturn(row);
227 when(entry.getGuts()).thenReturn(guts);
228
Evan Laird03cf3502019-05-31 16:46:48 -0400229 assertTrue(mGutsManager.openGutsInternal(row, 0, 0, menuItem));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900230 mTestableLooper.processAllMessages();
Rohan Shah524cf7b2018-03-15 14:40:02 -0700231 verify(guts).openControls(
232 eq(true),
233 anyInt(),
234 anyInt(),
235 anyBoolean(),
236 any(Runnable.class));
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900237
Evan Laird94492852018-10-25 13:43:01 -0400238 // called once by mGutsManager.bindGuts() in mGutsManager.openGuts()
239 verify(row).setGutsView(any());
240
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900241 row.onDensityOrFontScaleChanged();
Evan Laird94492852018-10-25 13:43:01 -0400242 mGutsManager.onDensityOrFontScaleChanged(entry);
243
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900244 mTestableLooper.processAllMessages();
245
246 mGutsManager.closeAndSaveGuts(false, false, false, 0, 0, false);
247
248 verify(guts).closeControls(anyBoolean(), anyBoolean(), anyInt(), anyInt(), anyBoolean());
Evan Laird94492852018-10-25 13:43:01 -0400249
250 // called again by mGutsManager.bindGuts(), in mGutsManager.onDensityOrFontScaleChanged()
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900251 verify(row, times(2)).setGutsView(any());
252 }
253
Julia Reynoldsb5867452018-02-28 16:31:35 -0500254 @Test
255 public void testAppOpsSettingsIntent_camera() {
256 ArraySet<Integer> ops = new ArraySet<>();
257 ops.add(OP_CAMERA);
258 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
259 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500260 verify(mNotificationActivityStarter, times(1))
261 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500262 assertEquals(Intent.ACTION_MANAGE_APP_PERMISSIONS, captor.getValue().getAction());
263 }
264
265 @Test
266 public void testAppOpsSettingsIntent_mic() {
267 ArraySet<Integer> ops = new ArraySet<>();
268 ops.add(OP_RECORD_AUDIO);
269 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
270 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500271 verify(mNotificationActivityStarter, times(1))
272 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500273 assertEquals(Intent.ACTION_MANAGE_APP_PERMISSIONS, captor.getValue().getAction());
274 }
275
276 @Test
277 public void testAppOpsSettingsIntent_camera_mic() {
278 ArraySet<Integer> ops = new ArraySet<>();
279 ops.add(OP_CAMERA);
280 ops.add(OP_RECORD_AUDIO);
281 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
282 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500283 verify(mNotificationActivityStarter, times(1))
284 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500285 assertEquals(Intent.ACTION_MANAGE_APP_PERMISSIONS, captor.getValue().getAction());
286 }
287
288 @Test
289 public void testAppOpsSettingsIntent_overlay() {
290 ArraySet<Integer> ops = new ArraySet<>();
291 ops.add(OP_SYSTEM_ALERT_WINDOW);
292 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
293 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500294 verify(mNotificationActivityStarter, times(1))
295 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Bernardo Rufino8fefb942019-11-25 19:51:09 +0000296 assertEquals(Settings.ACTION_MANAGE_APP_OVERLAY_PERMISSION, captor.getValue().getAction());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500297 }
298
299 @Test
300 public void testAppOpsSettingsIntent_camera_mic_overlay() {
301 ArraySet<Integer> ops = new ArraySet<>();
302 ops.add(OP_CAMERA);
303 ops.add(OP_RECORD_AUDIO);
304 ops.add(OP_SYSTEM_ALERT_WINDOW);
305 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
306 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500307 verify(mNotificationActivityStarter, times(1))
308 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500309 assertEquals(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, captor.getValue().getAction());
310 }
311
312 @Test
313 public void testAppOpsSettingsIntent_camera_overlay() {
314 ArraySet<Integer> ops = new ArraySet<>();
315 ops.add(OP_CAMERA);
316 ops.add(OP_SYSTEM_ALERT_WINDOW);
317 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
318 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500319 verify(mNotificationActivityStarter, times(1))
320 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500321 assertEquals(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, captor.getValue().getAction());
322 }
323
324 @Test
325 public void testAppOpsSettingsIntent_mic_overlay() {
326 ArraySet<Integer> ops = new ArraySet<>();
327 ops.add(OP_RECORD_AUDIO);
328 ops.add(OP_SYSTEM_ALERT_WINDOW);
329 mGutsManager.startAppOpsSettingsActivity("", 0, ops, null);
330 ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Gus Prevas21437b32018-12-05 10:36:13 -0500331 verify(mNotificationActivityStarter, times(1))
332 .startNotificationGutsIntent(captor.capture(), anyInt(), any());
Julia Reynoldsb5867452018-02-28 16:31:35 -0500333 assertEquals(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, captor.getValue().getAction());
334 }
335
Rohan Shah524cf7b2018-03-15 14:40:02 -0700336 @Test
Gus Prevascaed15c2019-01-18 14:19:51 -0500337 public void testInitializeNotificationInfoView_highPriority() throws Exception {
Gus Prevas9abc5062018-10-31 16:11:04 -0400338 NotificationInfo notificationInfoView = mock(NotificationInfo.class);
339 ExpandableNotificationRow row = spy(mHelper.createRow());
Beverly7c1ad5b2019-12-05 17:17:15 -0500340 final NotificationEntry entry = row.getEntry();
341 modifyRanking(entry)
Ned Burns60e94592019-09-06 14:47:25 -0400342 .setUserSentiment(USER_SENTIMENT_NEGATIVE)
Beverly7c1ad5b2019-12-05 17:17:15 -0500343 .setImportance(IMPORTANCE_HIGH)
Ned Burns60e94592019-09-06 14:47:25 -0400344 .build();
Gus Prevas9abc5062018-10-31 16:11:04 -0400345
Beverly7c1ad5b2019-12-05 17:17:15 -0500346 when(row.getIsNonblockable()).thenReturn(false);
Beverlye558f1d2020-01-07 16:28:58 -0500347 when(mHighPriorityProvider.isHighPriority(entry)).thenReturn(true);
Beverly7c1ad5b2019-12-05 17:17:15 -0500348 StatusBarNotification statusBarNotification = entry.getSbn();
Gus Prevas5a70a4e2018-11-26 17:16:05 -0500349 mGutsManager.initializeNotificationInfo(row, notificationInfoView);
Gus Prevas9abc5062018-10-31 16:11:04 -0400350
351 verify(notificationInfoView).bindNotification(
352 any(PackageManager.class),
353 any(INotificationManager.class),
Ned Burns9512e0c2019-05-30 19:36:04 -0400354 eq(mVisualStabilityManager),
Evan Laird18bd6e62019-08-30 16:39:25 -0400355 eq(mChannelEditorDialogController),
Gus Prevas9abc5062018-10-31 16:11:04 -0400356 eq(statusBarNotification.getPackageName()),
357 any(NotificationChannel.class),
Evan Laird47dc4542019-04-24 15:10:52 -0400358 anySet(),
Mady Mellor53162c12019-10-22 17:12:59 -0700359 eq(entry),
Gus Prevas9abc5062018-10-31 16:11:04 -0400360 any(NotificationInfo.OnSettingsClickListener.class),
361 any(NotificationInfo.OnAppSettingsClickListener.class),
362 eq(false),
363 eq(false),
Gus Prevascaed15c2019-01-18 14:19:51 -0500364 eq(true) /* wasShownHighPriority */);
Julia Reynolds35765d82018-08-17 11:39:19 -0400365 }
366
367 @Test
368 public void testInitializeNotificationInfoView_PassesAlongProvisionedState() throws Exception {
369 NotificationInfo notificationInfoView = mock(NotificationInfo.class);
370 ExpandableNotificationRow row = spy(mHelper.createRow());
371 row.setBlockingHelperShowing(false);
Ned Burns47c98f12019-09-06 17:12:07 -0400372 modifyRanking(row.getEntry())
373 .setUserSentiment(USER_SENTIMENT_NEGATIVE)
374 .build();
Julia Reynolds35765d82018-08-17 11:39:19 -0400375 when(row.getIsNonblockable()).thenReturn(false);
Ned Burns1c2b85a42019-11-14 15:37:03 -0500376 StatusBarNotification statusBarNotification = row.getEntry().getSbn();
Mady Mellor53162c12019-10-22 17:12:59 -0700377 NotificationEntry entry = row.getEntry();
378
Jason Monk297c04e2018-08-23 17:16:59 -0400379 when(mDeviceProvisionedController.isDeviceProvisioned()).thenReturn(true);
Julia Reynolds35765d82018-08-17 11:39:19 -0400380
Gus Prevas5a70a4e2018-11-26 17:16:05 -0500381 mGutsManager.initializeNotificationInfo(row, notificationInfoView);
Julia Reynolds35765d82018-08-17 11:39:19 -0400382
383 verify(notificationInfoView).bindNotification(
384 any(PackageManager.class),
385 any(INotificationManager.class),
Ned Burns9512e0c2019-05-30 19:36:04 -0400386 eq(mVisualStabilityManager),
Evan Laird18bd6e62019-08-30 16:39:25 -0400387 eq(mChannelEditorDialogController),
Julia Reynolds35765d82018-08-17 11:39:19 -0400388 eq(statusBarNotification.getPackageName()),
389 any(NotificationChannel.class),
Evan Laird47dc4542019-04-24 15:10:52 -0400390 anySet(),
Mady Mellor53162c12019-10-22 17:12:59 -0700391 eq(entry),
Julia Reynolds35765d82018-08-17 11:39:19 -0400392 any(NotificationInfo.OnSettingsClickListener.class),
393 any(NotificationInfo.OnAppSettingsClickListener.class),
394 eq(true),
395 eq(false),
Gus Prevascaed15c2019-01-18 14:19:51 -0500396 eq(false) /* wasShownHighPriority */);
Gus Prevas894d9152018-11-12 13:51:40 -0500397 }
398
399 @Test
400 public void testInitializeNotificationInfoView_withInitialAction() throws Exception {
401 NotificationInfo notificationInfoView = mock(NotificationInfo.class);
402 ExpandableNotificationRow row = spy(mHelper.createRow());
403 row.setBlockingHelperShowing(true);
Ned Burns47c98f12019-09-06 17:12:07 -0400404 modifyRanking(row.getEntry())
405 .setUserSentiment(USER_SENTIMENT_NEGATIVE)
406 .build();
Gus Prevas894d9152018-11-12 13:51:40 -0500407 when(row.getIsNonblockable()).thenReturn(false);
Ned Burns1c2b85a42019-11-14 15:37:03 -0500408 StatusBarNotification statusBarNotification = row.getEntry().getSbn();
Mady Mellor53162c12019-10-22 17:12:59 -0700409 NotificationEntry entry = row.getEntry();
Gus Prevas894d9152018-11-12 13:51:40 -0500410
Gus Prevas5a70a4e2018-11-26 17:16:05 -0500411 mGutsManager.initializeNotificationInfo(row, notificationInfoView);
Gus Prevas894d9152018-11-12 13:51:40 -0500412
413 verify(notificationInfoView).bindNotification(
414 any(PackageManager.class),
415 any(INotificationManager.class),
Ned Burns9512e0c2019-05-30 19:36:04 -0400416 eq(mVisualStabilityManager),
Evan Laird18bd6e62019-08-30 16:39:25 -0400417 eq(mChannelEditorDialogController),
Gus Prevas894d9152018-11-12 13:51:40 -0500418 eq(statusBarNotification.getPackageName()),
419 any(NotificationChannel.class),
Evan Laird47dc4542019-04-24 15:10:52 -0400420 anySet(),
Mady Mellor53162c12019-10-22 17:12:59 -0700421 eq(entry),
Gus Prevas894d9152018-11-12 13:51:40 -0500422 any(NotificationInfo.OnSettingsClickListener.class),
423 any(NotificationInfo.OnAppSettingsClickListener.class),
424 eq(false),
425 eq(false),
Gus Prevascaed15c2019-01-18 14:19:51 -0500426 eq(false) /* wasShownHighPriority */);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700427 }
428
Kevina5ff1fa2018-08-21 16:35:48 -0700429 @Test
430 public void testShouldExtendLifetime() {
431 NotificationGuts guts = new NotificationGuts(mContext);
432 ExpandableNotificationRow row = spy(createTestNotificationRow());
433 doReturn(guts).when(row).getGuts();
Ned Burnsf81c4c42019-01-07 14:10:43 -0500434 NotificationEntry entry = row.getEntry();
Evan Laird94492852018-10-25 13:43:01 -0400435 entry.setRow(row);
Kevina5ff1fa2018-08-21 16:35:48 -0700436 mGutsManager.setExposedGuts(guts);
437
438 assertTrue(mGutsManager.shouldExtendLifetime(entry));
439 }
440
441 @Test
Selim Cinek2476ed72019-03-07 13:19:23 -0800442 @Ignore
Kevine9e938c2018-09-06 13:38:11 -0700443 public void testSetShouldManageLifetime_setShouldManage() {
Ned Burnsf81c4c42019-01-07 14:10:43 -0500444 NotificationEntry entry = createTestNotificationRow().getEntry();
Kevine9e938c2018-09-06 13:38:11 -0700445 mGutsManager.setShouldManageLifetime(entry, true /* shouldManage */);
Kevina5ff1fa2018-08-21 16:35:48 -0700446
Ned Burns00b4b2d2019-10-17 22:09:27 -0400447 assertTrue(entry.getKey().equals(mGutsManager.mKeyToRemoveOnGutsClosed));
Kevina5ff1fa2018-08-21 16:35:48 -0700448 }
449
450 @Test
Kevine9e938c2018-09-06 13:38:11 -0700451 public void testSetShouldManageLifetime_setShouldNotManage() {
Ned Burnsf81c4c42019-01-07 14:10:43 -0500452 NotificationEntry entry = createTestNotificationRow().getEntry();
Ned Burns00b4b2d2019-10-17 22:09:27 -0400453 mGutsManager.mKeyToRemoveOnGutsClosed = entry.getKey();
Kevine9e938c2018-09-06 13:38:11 -0700454 mGutsManager.setShouldManageLifetime(entry, false /* shouldManage */);
Kevina5ff1fa2018-08-21 16:35:48 -0700455
456 assertNull(mGutsManager.mKeyToRemoveOnGutsClosed);
457 }
458
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900459 ////////////////////////////////////////////////////////////////////////////////////////////////
460 // Utility methods:
461
462 private ExpandableNotificationRow createTestNotificationRow() {
463 Notification.Builder nb = new Notification.Builder(mContext,
464 mTestNotificationChannel.getId())
465 .setContentTitle("foo")
466 .setColorized(true)
467 .setFlag(Notification.FLAG_CAN_COLORIZE, true)
468 .setSmallIcon(android.R.drawable.sym_def_app_icon);
469
470 try {
471 ExpandableNotificationRow row = mHelper.createRow(nb.build());
Ned Burns60e94592019-09-06 14:47:25 -0400472 modifyRanking(row.getEntry())
473 .setChannel(mTestNotificationChannel)
474 .build();
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900475 return row;
476 } catch (Exception e) {
477 fail();
478 return null;
479 }
480 }
481
482 private NotificationMenuRowPlugin.MenuItem createTestMenuItem(ExpandableNotificationRow row) {
Steve Elliott2304e4a2020-04-01 17:03:41 -0400483 NotificationMenuRowPlugin menuRow =
484 new NotificationMenuRow(mContext, mPeopleNotificationIdentifier);
Ned Burns1c2b85a42019-11-14 15:37:03 -0500485 menuRow.createMenu(row, row.getEntry().getSbn());
yoshiki iguchia85c2a02018-01-12 11:28:06 +0900486
487 NotificationMenuRowPlugin.MenuItem menuItem = menuRow.getLongpressMenuItem(mContext);
488 assertNotNull(menuItem);
489 return menuItem;
490 }
491}