blob: b9eb4d1e29c233be2a7b40538567e622d642477e [file] [log] [blame]
Selim Cinek6fd06b52017-03-07 15:54:10 -08001/*
Kevin Han933dc7c2020-01-29 11:17:46 -08002 * Copyright (C) 2020 The Android Open Source Project
Selim Cinek6fd06b52017-03-07 15:54:10 -08003 *
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
Kevin Han933dc7c2020-01-29 11:17:46 -080014 * limitations under the License.
Selim Cinek6fd06b52017-03-07 15:54:10 -080015 */
16
Kevin Han933dc7c2020-01-29 11:17:46 -080017package com.android.systemui.statusbar.notification.row;
Selim Cinek6fd06b52017-03-07 15:54:10 -080018
Mady Mellorfc02cc32019-04-01 14:47:55 -070019import static android.app.Notification.FLAG_BUBBLE;
Julia Reynolds0abae112018-06-08 10:36:57 -040020import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
Mady Mellorb4991e62019-01-10 15:14:51 -080021import static android.app.NotificationManager.IMPORTANCE_HIGH;
Julia Reynolds0abae112018-06-08 10:36:57 -040022
Ned Burns47c98f12019-09-06 17:12:07 -040023import static com.android.systemui.statusbar.NotificationEntryHelper.modifyRanking;
24
Kevin Hance7451c2019-12-11 14:31:53 -080025import static org.junit.Assert.assertTrue;
Selim Cinekc3fec682019-06-06 18:11:07 -070026import static org.mockito.Mockito.mock;
Kevin Han933dc7c2020-01-29 11:17:46 -080027import static org.mockito.Mockito.verify;
Selim Cinekc3fec682019-06-06 18:11:07 -070028
Rohan Shah524cf7b2018-03-15 14:40:02 -070029import android.annotation.Nullable;
Selim Cinek6fd06b52017-03-07 15:54:10 -080030import android.app.ActivityManager;
31import android.app.Notification;
Mark Renouf08bc42a2019-03-07 13:01:59 -050032import android.app.Notification.BubbleMetadata;
Julia Reynolds0abae112018-06-08 10:36:57 -040033import android.app.NotificationChannel;
Mady Mellorb4991e62019-01-10 15:14:51 -080034import android.app.PendingIntent;
Selim Cinek6fd06b52017-03-07 15:54:10 -080035import android.content.Context;
Mady Mellorb4991e62019-01-10 15:14:51 -080036import android.content.Intent;
Ned Burnsd8b51542020-03-13 20:52:43 -040037import android.content.pm.LauncherApps;
Mady Mellorc39b4ae2019-01-09 17:11:37 -080038import android.graphics.drawable.Icon;
Selim Cinek6fd06b52017-03-07 15:54:10 -080039import android.os.UserHandle;
40import android.service.notification.StatusBarNotification;
Kevin Hana7c21be2020-04-01 17:58:35 -070041import android.testing.TestableLooper;
Rohan Shah524cf7b2018-03-15 14:40:02 -070042import android.text.TextUtils;
Selim Cinek6fd06b52017-03-07 15:54:10 -080043import android.view.LayoutInflater;
44import android.widget.RemoteViews;
45
Lucas Dupind236ee32019-10-08 15:33:59 -070046import com.android.systemui.TestableDependency;
47import com.android.systemui.bubbles.BubbleController;
Mark Renoufa9fbb6e2019-02-11 12:48:22 -050048import com.android.systemui.bubbles.BubblesTestActivity;
Dave Mankoffc0211ff2020-02-07 15:36:12 -050049import com.android.systemui.plugins.FalsingManager;
Selim Cinekc3fec682019-06-06 18:11:07 -070050import com.android.systemui.plugins.statusbar.StatusBarStateController;
Kevin Han933dc7c2020-01-29 11:17:46 -080051import com.android.systemui.statusbar.NotificationMediaManager;
52import com.android.systemui.statusbar.NotificationRemoteInputManager;
53import com.android.systemui.statusbar.SmartReplyController;
Steve Elliott46bb2a12020-03-17 11:04:09 -040054import com.android.systemui.statusbar.notification.ConversationNotificationProcessor;
Ned Burnsf81c4c42019-01-07 14:10:43 -050055import com.android.systemui.statusbar.notification.collection.NotificationEntry;
Beverly79c89ec2019-12-13 10:33:01 -050056import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder;
Kevin Han65c38b32020-02-05 16:42:40 -080057import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection;
58import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener;
Ned Burnsd8b51542020-03-13 20:52:43 -040059import com.android.systemui.statusbar.notification.icon.IconBuilder;
60import com.android.systemui.statusbar.notification.icon.IconManager;
Steve Elliott2304e4a2020-04-01 17:03:41 -040061import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier;
Kevin Han5182c9f2020-01-07 17:54:43 -080062import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow.ExpansionLogger;
63import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow.OnExpandClickListener;
Kevin Hanec093092019-12-11 16:47:59 -080064import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationFlag;
Beverly95a0802ac2020-02-10 15:27:40 -050065import com.android.systemui.statusbar.phone.ConfigurationControllerImpl;
yoshiki iguchi4e30e762018-02-06 12:09:23 +090066import com.android.systemui.statusbar.phone.HeadsUpManagerPhone;
Selim Cinekd21232e2019-06-20 14:15:59 -070067import com.android.systemui.statusbar.phone.KeyguardBypassController;
Selim Cinek6fd06b52017-03-07 15:54:10 -080068import com.android.systemui.statusbar.phone.NotificationGroupManager;
wilsonshihe8321942019-10-18 18:39:46 +080069import com.android.systemui.statusbar.phone.NotificationShadeWindowController;
Sergey Nikolaienkovf6ad6322020-02-10 15:46:32 +010070import com.android.systemui.statusbar.policy.SmartReplyConstants;
Hyunyoung Song8f9d34c2019-08-30 14:47:43 -070071import com.android.systemui.tests.R;
Selim Cinek6fd06b52017-03-07 15:54:10 -080072
Kevin Han933dc7c2020-01-29 11:17:46 -080073import org.mockito.ArgumentCaptor;
74
Kevin Hance7451c2019-12-11 14:31:53 -080075import java.util.concurrent.CountDownLatch;
Kevin Hana6d5bb42020-03-17 13:55:49 -070076import java.util.concurrent.Executor;
Kevin Hance7451c2019-12-11 14:31:53 -080077import java.util.concurrent.TimeUnit;
78
Selim Cinek6fd06b52017-03-07 15:54:10 -080079/**
Rohan Shah524cf7b2018-03-15 14:40:02 -070080 * A helper class to create {@link ExpandableNotificationRow} (for both individual and group
81 * notifications).
Selim Cinek6fd06b52017-03-07 15:54:10 -080082 */
83public class NotificationTestHelper {
84
Rohan Shah20790b82018-07-02 17:21:04 -070085 /** Package name for testing purposes. */
86 public static final String PKG = "com.android.systemui";
87 /** System UI id for testing purposes. */
88 public static final int UID = 1000;
Yohei Yukawa72769462019-01-20 09:28:08 -080089 /** Current {@link UserHandle} of the system. */
90 public static final UserHandle USER_HANDLE = UserHandle.of(ActivityManager.getCurrentUser());
Rohan Shah20790b82018-07-02 17:21:04 -070091
Rohan Shah524cf7b2018-03-15 14:40:02 -070092 private static final String GROUP_KEY = "gruKey";
Kevin Han5182c9f2020-01-07 17:54:43 -080093 private static final String APP_NAME = "appName";
Rohan Shah524cf7b2018-03-15 14:40:02 -070094
Selim Cinek6fd06b52017-03-07 15:54:10 -080095 private final Context mContext;
Kevin Hana7c21be2020-04-01 17:58:35 -070096 private final TestableLooper mTestLooper;
Selim Cinek6fd06b52017-03-07 15:54:10 -080097 private int mId;
Selim Cinekc3fec682019-06-06 18:11:07 -070098 private final NotificationGroupManager mGroupManager;
Selim Cinek5ba22542017-04-20 15:16:10 -070099 private ExpandableNotificationRow mRow;
Selim Cinekc3fec682019-06-06 18:11:07 -0700100 private HeadsUpManagerPhone mHeadsUpManager;
Kevin Han933dc7c2020-01-29 11:17:46 -0800101 private final NotifBindPipeline mBindPipeline;
Kevin Han65c38b32020-02-05 16:42:40 -0800102 private final NotifCollectionListener mBindPipelineEntryListener;
Kevin Han933dc7c2020-01-29 11:17:46 -0800103 private final RowContentBindStage mBindStage;
Ned Burnsd8b51542020-03-13 20:52:43 -0400104 private final IconManager mIconManager;
Dave Mankoffc0211ff2020-02-07 15:36:12 -0500105 private StatusBarStateController mStatusBarStateController;
Steve Elliott2304e4a2020-04-01 17:03:41 -0400106 private final PeopleNotificationIdentifier mPeopleNotificationIdentifier;
Selim Cinek6fd06b52017-03-07 15:54:10 -0800107
Kevin Hana7c21be2020-04-01 17:58:35 -0700108 public NotificationTestHelper(
109 Context context,
110 TestableDependency dependency,
111 TestableLooper testLooper) {
Selim Cinek6fd06b52017-03-07 15:54:10 -0800112 mContext = context;
Kevin Hana7c21be2020-04-01 17:58:35 -0700113 mTestLooper = testLooper;
Lucas Dupind236ee32019-10-08 15:33:59 -0700114 dependency.injectMockDependency(NotificationMediaManager.class);
115 dependency.injectMockDependency(BubbleController.class);
wilsonshihe8321942019-10-18 18:39:46 +0800116 dependency.injectMockDependency(NotificationShadeWindowController.class);
Dave Mankoffc0211ff2020-02-07 15:36:12 -0500117 mStatusBarStateController = mock(StatusBarStateController.class);
Steve Elliottd38a70f2020-05-11 14:01:08 -0400118 mGroupManager = new NotificationGroupManager(
119 mStatusBarStateController,
120 () -> mock(PeopleNotificationIdentifier.class));
Dave Mankoffc0211ff2020-02-07 15:36:12 -0500121 mHeadsUpManager = new HeadsUpManagerPhone(mContext, mStatusBarStateController,
Beverly95a0802ac2020-02-10 15:27:40 -0500122 mock(KeyguardBypassController.class), mock(NotificationGroupManager.class),
123 mock(ConfigurationControllerImpl.class));
Kevina97ea052018-09-11 13:53:18 -0700124 mGroupManager.setHeadsUpManager(mHeadsUpManager);
Ned Burnsd8b51542020-03-13 20:52:43 -0400125 mIconManager = new IconManager(
126 mock(CommonNotifCollection.class),
127 mock(LauncherApps.class),
128 new IconBuilder(mContext));
Kevin Han933dc7c2020-01-29 11:17:46 -0800129
Kevin Han933dc7c2020-01-29 11:17:46 -0800130 NotificationContentInflater contentBinder = new NotificationContentInflater(
131 mock(NotifRemoteViewCache.class),
Sergey Nikolaienkovf6ad6322020-02-10 15:46:32 +0100132 mock(NotificationRemoteInputManager.class),
133 () -> mock(SmartReplyConstants.class),
Steve Elliott46bb2a12020-03-17 11:04:09 -0400134 () -> mock(SmartReplyController.class),
Kevin Hana6d5bb42020-03-17 13:55:49 -0700135 mock(ConversationNotificationProcessor.class),
136 mock(Executor.class));
Kevin Han933dc7c2020-01-29 11:17:46 -0800137 contentBinder.setInflateSynchronously(true);
Kevin Hanc1f04482020-02-07 12:23:52 -0800138 mBindStage = new RowContentBindStage(contentBinder,
139 mock(NotifInflationErrorManager.class),
140 mock(RowContentBindStageLogger.class));
Kevin Han933dc7c2020-01-29 11:17:46 -0800141
Kevin Han65c38b32020-02-05 16:42:40 -0800142 CommonNotifCollection collection = mock(CommonNotifCollection.class);
Kevin Han933dc7c2020-01-29 11:17:46 -0800143
Kevin Hana7c21be2020-04-01 17:58:35 -0700144 mBindPipeline = new NotifBindPipeline(
145 collection,
146 mock(NotifBindPipelineLogger.class),
147 mTestLooper.getLooper());
Kevin Han933dc7c2020-01-29 11:17:46 -0800148 mBindPipeline.setStage(mBindStage);
149
Kevin Han65c38b32020-02-05 16:42:40 -0800150 ArgumentCaptor<NotifCollectionListener> collectionListenerCaptor =
151 ArgumentCaptor.forClass(NotifCollectionListener.class);
152 verify(collection).addCollectionListener(collectionListenerCaptor.capture());
153 mBindPipelineEntryListener = collectionListenerCaptor.getValue();
Steve Elliott2304e4a2020-04-01 17:03:41 -0400154 mPeopleNotificationIdentifier = mock(PeopleNotificationIdentifier.class);
Selim Cinek6fd06b52017-03-07 15:54:10 -0800155 }
156
Kevind4660b22018-09-27 10:57:35 -0700157 /**
158 * Creates a generic row.
159 *
160 * @return a generic row with no special properties.
161 * @throws Exception
162 */
Rohan Shah524cf7b2018-03-15 14:40:02 -0700163 public ExpandableNotificationRow createRow() throws Exception {
Yohei Yukawa72769462019-01-20 09:28:08 -0800164 return createRow(PKG, UID, USER_HANDLE);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700165 }
166
Kevind4660b22018-09-27 10:57:35 -0700167 /**
168 * Create a row with the package and user id specified.
169 *
170 * @param pkg package
171 * @param uid user id
172 * @return a row with a notification using the package and user id
173 * @throws Exception
174 */
Yohei Yukawa72769462019-01-20 09:28:08 -0800175 public ExpandableNotificationRow createRow(String pkg, int uid, UserHandle userHandle)
176 throws Exception {
177 return createRow(pkg, uid, userHandle, false /* isGroupSummary */, null /* groupKey */);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700178 }
179
Kevind4660b22018-09-27 10:57:35 -0700180 /**
181 * Creates a row based off the notification given.
182 *
183 * @param notification the notification
184 * @return a row built off the notification
185 * @throws Exception
186 */
Rohan Shah524cf7b2018-03-15 14:40:02 -0700187 public ExpandableNotificationRow createRow(Notification notification) throws Exception {
Yohei Yukawa72769462019-01-20 09:28:08 -0800188 return generateRow(notification, PKG, UID, USER_HANDLE, 0 /* extraInflationFlags */);
Kevind4660b22018-09-27 10:57:35 -0700189 }
190
191 /**
192 * Create a row with the specified content views inflated in addition to the default.
193 *
194 * @param extraInflationFlags the flags corresponding to the additional content views that
195 * should be inflated
196 * @return a row with the specified content views inflated in addition to the default
197 * @throws Exception
198 */
199 public ExpandableNotificationRow createRow(@InflationFlag int extraInflationFlags)
200 throws Exception {
Yohei Yukawa72769462019-01-20 09:28:08 -0800201 return generateRow(createNotification(), PKG, UID, USER_HANDLE, extraInflationFlags);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700202 }
203
204 /**
205 * Returns an {@link ExpandableNotificationRow} group with the given number of child
206 * notifications.
207 */
208 public ExpandableNotificationRow createGroup(int numChildren) throws Exception {
209 ExpandableNotificationRow row = createGroupSummary(GROUP_KEY);
210 for (int i = 0; i < numChildren; i++) {
211 ExpandableNotificationRow childRow = createGroupChild(GROUP_KEY);
212 row.addChildNotification(childRow);
213 }
214 return row;
215 }
216
217 /** Returns a group notification with 2 child notifications. */
218 public ExpandableNotificationRow createGroup() throws Exception {
219 return createGroup(2);
220 }
221
222 private ExpandableNotificationRow createGroupSummary(String groupkey) throws Exception {
Yohei Yukawa72769462019-01-20 09:28:08 -0800223 return createRow(PKG, UID, USER_HANDLE, true /* isGroupSummary */, groupkey);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700224 }
225
226 private ExpandableNotificationRow createGroupChild(String groupkey) throws Exception {
Yohei Yukawa72769462019-01-20 09:28:08 -0800227 return createRow(PKG, UID, USER_HANDLE, false /* isGroupSummary */, groupkey);
Mady Mellorb4991e62019-01-10 15:14:51 -0800228 }
229
230 /**
231 * Returns an {@link ExpandableNotificationRow} that should be shown as a bubble.
Mark Renouffec45da2019-03-13 13:24:27 -0400232 */
Beverlya53fb0d2020-01-29 15:26:13 -0500233 public ExpandableNotificationRow createBubbleInGroup()
234 throws Exception {
235 return createBubble(makeBubbleMetadata(null), PKG, true);
236 }
237
238 /**
239 * Returns an {@link ExpandableNotificationRow} that should be shown as a bubble.
240 */
Mark Renouffec45da2019-03-13 13:24:27 -0400241 public ExpandableNotificationRow createBubble()
242 throws Exception {
Beverlya53fb0d2020-01-29 15:26:13 -0500243 return createBubble(makeBubbleMetadata(null), PKG, false);
Mark Renouffec45da2019-03-13 13:24:27 -0400244 }
245
246 /**
247 * Returns an {@link ExpandableNotificationRow} that should be shown as a bubble.
Mark Renouf08bc42a2019-03-07 13:01:59 -0500248 *
249 * @param deleteIntent the intent to assign to {@link BubbleMetadata#deleteIntent}
250 */
251 public ExpandableNotificationRow createBubble(@Nullable PendingIntent deleteIntent)
252 throws Exception {
Beverlya53fb0d2020-01-29 15:26:13 -0500253 return createBubble(makeBubbleMetadata(deleteIntent), PKG, false);
Mady Mellore80930e2019-03-21 16:00:45 -0700254 }
255
256 /**
257 * Returns an {@link ExpandableNotificationRow} that should be shown as a bubble.
258 *
259 * @param bubbleMetadata the {@link BubbleMetadata} to use
260 */
261 public ExpandableNotificationRow createBubble(BubbleMetadata bubbleMetadata, String pkg)
262 throws Exception {
Beverlya53fb0d2020-01-29 15:26:13 -0500263 return createBubble(bubbleMetadata, pkg, false);
264 }
265
266 private ExpandableNotificationRow createBubble(BubbleMetadata bubbleMetadata, String pkg,
267 boolean inGroup)
268 throws Exception {
Mady Mellore80930e2019-03-21 16:00:45 -0700269 Notification n = createNotification(false /* isGroupSummary */,
Beverlya53fb0d2020-01-29 15:26:13 -0500270 inGroup ? GROUP_KEY : null /* groupKey */, bubbleMetadata);
Mady Mellorfc02cc32019-04-01 14:47:55 -0700271 n.flags |= FLAG_BUBBLE;
Mady Melloraa8fef22019-04-11 13:36:40 -0700272 ExpandableNotificationRow row = generateRow(n, pkg, UID, USER_HANDLE,
273 0 /* extraInflationFlags */, IMPORTANCE_HIGH);
Ned Burns47c98f12019-09-06 17:12:07 -0400274 modifyRanking(row.getEntry())
275 .setCanBubble(true)
276 .build();
Mady Melloraa8fef22019-04-11 13:36:40 -0700277 return row;
Mady Mellore80930e2019-03-21 16:00:45 -0700278 }
279
280 /**
Rohan Shah524cf7b2018-03-15 14:40:02 -0700281 * Creates a notification row with the given details.
282 *
283 * @param pkg package used for creating a {@link StatusBarNotification}
284 * @param uid uid used for creating a {@link StatusBarNotification}
285 * @param isGroupSummary whether the notification row is a group summary
286 * @param groupKey the group key for the notification group used across notifications
287 * @return a row with that's either a standalone notification or a group notification if the
288 * groupKey is non-null
289 * @throws Exception
290 */
291 private ExpandableNotificationRow createRow(
292 String pkg,
293 int uid,
Yohei Yukawa72769462019-01-20 09:28:08 -0800294 UserHandle userHandle,
Rohan Shah524cf7b2018-03-15 14:40:02 -0700295 boolean isGroupSummary,
Mady Mellorb4991e62019-01-10 15:14:51 -0800296 @Nullable String groupKey)
Rohan Shah524cf7b2018-03-15 14:40:02 -0700297 throws Exception {
Kevind4660b22018-09-27 10:57:35 -0700298 Notification notif = createNotification(isGroupSummary, groupKey);
Yohei Yukawa72769462019-01-20 09:28:08 -0800299 return generateRow(notif, pkg, uid, userHandle, 0 /* inflationFlags */);
Kevind4660b22018-09-27 10:57:35 -0700300 }
301
302 /**
303 * Creates a generic notification.
304 *
305 * @return a notification with no special properties
306 */
Julia Reynolds0c245002019-03-27 16:10:11 -0400307 public Notification createNotification() {
Kevind4660b22018-09-27 10:57:35 -0700308 return createNotification(false /* isGroupSummary */, null /* groupKey */);
309 }
310
311 /**
312 * Creates a notification with the given parameters.
313 *
314 * @param isGroupSummary whether the notification is a group summary
315 * @param groupKey the group key for the notification group used across notifications
316 * @return a notification that is in the group specified or standalone if unspecified
317 */
Mady Mellorb4991e62019-01-10 15:14:51 -0800318 private Notification createNotification(boolean isGroupSummary, @Nullable String groupKey) {
Mady Mellore80930e2019-03-21 16:00:45 -0700319 return createNotification(isGroupSummary, groupKey, null /* bubble metadata */);
Mady Mellorb4991e62019-01-10 15:14:51 -0800320 }
321
322 /**
323 * Creates a notification with the given parameters.
324 *
325 * @param isGroupSummary whether the notification is a group summary
326 * @param groupKey the group key for the notification group used across notifications
Mady Mellore80930e2019-03-21 16:00:45 -0700327 * @param bubbleMetadata the bubble metadata to use for this notification if it exists.
Mady Mellorb4991e62019-01-10 15:14:51 -0800328 * @return a notification that is in the group specified or standalone if unspecified
329 */
Mark Renouf9ba6cea2019-04-17 11:53:50 -0400330 public Notification createNotification(boolean isGroupSummary,
Mady Mellore80930e2019-03-21 16:00:45 -0700331 @Nullable String groupKey, @Nullable BubbleMetadata bubbleMetadata) {
Selim Cinek6fd06b52017-03-07 15:54:10 -0800332 Notification publicVersion = new Notification.Builder(mContext).setSmallIcon(
333 R.drawable.ic_person)
334 .setCustomContentView(new RemoteViews(mContext.getPackageName(),
335 R.layout.custom_view_dark))
336 .build();
Kevind4660b22018-09-27 10:57:35 -0700337 Notification.Builder notificationBuilder = new Notification.Builder(mContext, "channelId")
338 .setSmallIcon(R.drawable.ic_person)
339 .setContentTitle("Title")
340 .setContentText("Text")
Kevind5022f92018-10-08 18:30:26 -0700341 .setPublicVersion(publicVersion)
342 .setStyle(new Notification.BigTextStyle().bigText("Big Text"));
Rohan Shah524cf7b2018-03-15 14:40:02 -0700343 if (isGroupSummary) {
344 notificationBuilder.setGroupSummary(true);
345 }
346 if (!TextUtils.isEmpty(groupKey)) {
347 notificationBuilder.setGroup(groupKey);
348 }
Mady Mellore80930e2019-03-21 16:00:45 -0700349 if (bubbleMetadata != null) {
350 notificationBuilder.setBubbleMetadata(bubbleMetadata);
Mady Mellorb4991e62019-01-10 15:14:51 -0800351 }
Kevind4660b22018-09-27 10:57:35 -0700352 return notificationBuilder.build();
Julia Reynoldsfc640012018-02-21 12:25:27 -0500353 }
354
Dave Mankoffc0211ff2020-02-07 15:36:12 -0500355 public StatusBarStateController getStatusBarStateController() {
356 return mStatusBarStateController;
357 }
358
Rohan Shah524cf7b2018-03-15 14:40:02 -0700359 private ExpandableNotificationRow generateRow(
360 Notification notification,
361 String pkg,
362 int uid,
Yohei Yukawa72769462019-01-20 09:28:08 -0800363 UserHandle userHandle,
Mady Mellorb4991e62019-01-10 15:14:51 -0800364 @InflationFlag int extraInflationFlags)
365 throws Exception {
Yohei Yukawa72769462019-01-20 09:28:08 -0800366 return generateRow(notification, pkg, uid, userHandle, extraInflationFlags,
367 IMPORTANCE_DEFAULT);
Mady Mellorb4991e62019-01-10 15:14:51 -0800368 }
369
370 private ExpandableNotificationRow generateRow(
371 Notification notification,
372 String pkg,
373 int uid,
Yohei Yukawa72769462019-01-20 09:28:08 -0800374 UserHandle userHandle,
Mady Mellorb4991e62019-01-10 15:14:51 -0800375 @InflationFlag int extraInflationFlags,
376 int importance)
Julia Reynoldsfc640012018-02-21 12:25:27 -0500377 throws Exception {
Selim Cinek10790672017-03-08 16:33:05 -0800378 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
379 mContext.LAYOUT_INFLATER_SERVICE);
Jason Monk6dceace2018-05-15 20:24:07 -0400380 mRow = (ExpandableNotificationRow) inflater.inflate(
381 R.layout.status_bar_notification_row,
382 null /* root */,
383 false /* attachToRoot */);
Selim Cinek5ba22542017-04-20 15:16:10 -0700384 ExpandableNotificationRow row = mRow;
Ned Burns636c3792019-09-11 16:59:07 -0400385
Ned Burns296aec162019-09-04 17:30:59 -0400386 final NotificationChannel channel =
387 new NotificationChannel(
388 notification.getChannelId(),
389 notification.getChannelId(),
390 importance);
Hall Liu9866aa82020-03-12 12:55:50 -0700391 channel.setBlockable(true);
Ned Burns296aec162019-09-04 17:30:59 -0400392
Ned Burns636c3792019-09-11 16:59:07 -0400393 NotificationEntry entry = new NotificationEntryBuilder()
394 .setPkg(pkg)
395 .setOpPkg(pkg)
396 .setId(mId++)
397 .setUid(uid)
398 .setInitialPid(2000)
399 .setNotification(notification)
400 .setUser(userHandle)
401 .setPostTime(System.currentTimeMillis())
402 .setChannel(channel)
403 .build();
404
Evan Laird94492852018-10-25 13:43:01 -0400405 entry.setRow(row);
Ned Burnsd8b51542020-03-13 20:52:43 -0400406 mIconManager.createIcons(entry);
Kevind4660b22018-09-27 10:57:35 -0700407 row.setEntry(entry);
Kevin Han5182c9f2020-01-07 17:54:43 -0800408
Kevin Han65c38b32020-02-05 16:42:40 -0800409 mBindPipelineEntryListener.onEntryInit(entry);
Kevin Han933dc7c2020-01-29 11:17:46 -0800410 mBindPipeline.manageRow(entry, row);
Kevin Han5182c9f2020-01-07 17:54:43 -0800411
412 row.initialize(
413 APP_NAME,
414 entry.getKey(),
415 mock(ExpansionLogger.class),
416 mock(KeyguardBypassController.class),
417 mGroupManager,
418 mHeadsUpManager,
Kevin Han933dc7c2020-01-29 11:17:46 -0800419 mBindStage,
Dave Mankoffc0211ff2020-02-07 15:36:12 -0500420 mock(OnExpandClickListener.class),
421 mock(NotificationMediaManager.class),
422 mock(ExpandableNotificationRow.OnAppOpsClickListener.class),
423 mock(FalsingManager.class),
Steve Elliott2304e4a2020-04-01 17:03:41 -0400424 mStatusBarStateController,
425 mPeopleNotificationIdentifier);
Kevin Han5182c9f2020-01-07 17:54:43 -0800426 row.setAboveShelfChangedListener(aboveShelf -> { });
Kevin Han933dc7c2020-01-29 11:17:46 -0800427 mBindStage.getStageParams(entry).requireContentViews(extraInflationFlags);
Kevin Hana7c21be2020-04-01 17:58:35 -0700428 inflateAndWait(entry);
Selim Cinek6fd06b52017-03-07 15:54:10 -0800429
Rohan Shah524cf7b2018-03-15 14:40:02 -0700430 // This would be done as part of onAsyncInflationFinished, but we skip large amounts of
431 // the callback chain, so we need to make up for not adding it to the group manager
432 // here.
433 mGroupManager.onEntryAdded(entry);
Selim Cinek6fd06b52017-03-07 15:54:10 -0800434 return row;
435 }
Mady Mellorc39b4ae2019-01-09 17:11:37 -0800436
Kevin Hana7c21be2020-04-01 17:58:35 -0700437 private void inflateAndWait(NotificationEntry entry) throws Exception {
Kevin Hance7451c2019-12-11 14:31:53 -0800438 CountDownLatch countDownLatch = new CountDownLatch(1);
Kevin Hana7c21be2020-04-01 17:58:35 -0700439 mBindStage.requestRebind(entry, en -> countDownLatch.countDown());
440 mTestLooper.processAllMessages();
Kevin Hance7451c2019-12-11 14:31:53 -0800441 assertTrue(countDownLatch.await(500, TimeUnit.MILLISECONDS));
442 }
443
Mark Renouf08bc42a2019-03-07 13:01:59 -0500444 private BubbleMetadata makeBubbleMetadata(PendingIntent deleteIntent) {
Mark Renoufa9fbb6e2019-02-11 12:48:22 -0500445 Intent target = new Intent(mContext, BubblesTestActivity.class);
446 PendingIntent bubbleIntent = PendingIntent.getActivity(mContext, 0, target, 0);
Mark Renouf08bc42a2019-03-07 13:01:59 -0500447
Mady Melloraa9ce172020-03-17 10:34:20 -0700448 return new BubbleMetadata.Builder(bubbleIntent,
Mady Mellor2ac2d3a2020-01-08 17:18:54 -0800449 Icon.createWithResource(mContext, R.drawable.android))
Mark Renouf08bc42a2019-03-07 13:01:59 -0500450 .setDeleteIntent(deleteIntent)
Mady Mellorc39b4ae2019-01-09 17:11:37 -0800451 .setDesiredHeight(314)
452 .build();
453 }
Selim Cinek6fd06b52017-03-07 15:54:10 -0800454}