blob: 07f2085a1b764c934346e3113273818a40aaad33 [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);
118 mGroupManager = new NotificationGroupManager(mStatusBarStateController);
119 mHeadsUpManager = new HeadsUpManagerPhone(mContext, mStatusBarStateController,
Beverly95a0802ac2020-02-10 15:27:40 -0500120 mock(KeyguardBypassController.class), mock(NotificationGroupManager.class),
121 mock(ConfigurationControllerImpl.class));
Kevina97ea052018-09-11 13:53:18 -0700122 mGroupManager.setHeadsUpManager(mHeadsUpManager);
Ned Burnsd8b51542020-03-13 20:52:43 -0400123 mIconManager = new IconManager(
124 mock(CommonNotifCollection.class),
125 mock(LauncherApps.class),
126 new IconBuilder(mContext));
Kevin Han933dc7c2020-01-29 11:17:46 -0800127
Kevin Han933dc7c2020-01-29 11:17:46 -0800128 NotificationContentInflater contentBinder = new NotificationContentInflater(
129 mock(NotifRemoteViewCache.class),
Sergey Nikolaienkovf6ad6322020-02-10 15:46:32 +0100130 mock(NotificationRemoteInputManager.class),
131 () -> mock(SmartReplyConstants.class),
Steve Elliott46bb2a12020-03-17 11:04:09 -0400132 () -> mock(SmartReplyController.class),
Kevin Hana6d5bb42020-03-17 13:55:49 -0700133 mock(ConversationNotificationProcessor.class),
134 mock(Executor.class));
Kevin Han933dc7c2020-01-29 11:17:46 -0800135 contentBinder.setInflateSynchronously(true);
Kevin Hanc1f04482020-02-07 12:23:52 -0800136 mBindStage = new RowContentBindStage(contentBinder,
137 mock(NotifInflationErrorManager.class),
138 mock(RowContentBindStageLogger.class));
Kevin Han933dc7c2020-01-29 11:17:46 -0800139
Kevin Han65c38b32020-02-05 16:42:40 -0800140 CommonNotifCollection collection = mock(CommonNotifCollection.class);
Kevin Han933dc7c2020-01-29 11:17:46 -0800141
Kevin Hana7c21be2020-04-01 17:58:35 -0700142 mBindPipeline = new NotifBindPipeline(
143 collection,
144 mock(NotifBindPipelineLogger.class),
145 mTestLooper.getLooper());
Kevin Han933dc7c2020-01-29 11:17:46 -0800146 mBindPipeline.setStage(mBindStage);
147
Kevin Han65c38b32020-02-05 16:42:40 -0800148 ArgumentCaptor<NotifCollectionListener> collectionListenerCaptor =
149 ArgumentCaptor.forClass(NotifCollectionListener.class);
150 verify(collection).addCollectionListener(collectionListenerCaptor.capture());
151 mBindPipelineEntryListener = collectionListenerCaptor.getValue();
Steve Elliott2304e4a2020-04-01 17:03:41 -0400152 mPeopleNotificationIdentifier = mock(PeopleNotificationIdentifier.class);
Selim Cinek6fd06b52017-03-07 15:54:10 -0800153 }
154
Kevind4660b22018-09-27 10:57:35 -0700155 /**
156 * Creates a generic row.
157 *
158 * @return a generic row with no special properties.
159 * @throws Exception
160 */
Rohan Shah524cf7b2018-03-15 14:40:02 -0700161 public ExpandableNotificationRow createRow() throws Exception {
Yohei Yukawa72769462019-01-20 09:28:08 -0800162 return createRow(PKG, UID, USER_HANDLE);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700163 }
164
Kevind4660b22018-09-27 10:57:35 -0700165 /**
166 * Create a row with the package and user id specified.
167 *
168 * @param pkg package
169 * @param uid user id
170 * @return a row with a notification using the package and user id
171 * @throws Exception
172 */
Yohei Yukawa72769462019-01-20 09:28:08 -0800173 public ExpandableNotificationRow createRow(String pkg, int uid, UserHandle userHandle)
174 throws Exception {
175 return createRow(pkg, uid, userHandle, false /* isGroupSummary */, null /* groupKey */);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700176 }
177
Kevind4660b22018-09-27 10:57:35 -0700178 /**
179 * Creates a row based off the notification given.
180 *
181 * @param notification the notification
182 * @return a row built off the notification
183 * @throws Exception
184 */
Rohan Shah524cf7b2018-03-15 14:40:02 -0700185 public ExpandableNotificationRow createRow(Notification notification) throws Exception {
Yohei Yukawa72769462019-01-20 09:28:08 -0800186 return generateRow(notification, PKG, UID, USER_HANDLE, 0 /* extraInflationFlags */);
Kevind4660b22018-09-27 10:57:35 -0700187 }
188
189 /**
190 * Create a row with the specified content views inflated in addition to the default.
191 *
192 * @param extraInflationFlags the flags corresponding to the additional content views that
193 * should be inflated
194 * @return a row with the specified content views inflated in addition to the default
195 * @throws Exception
196 */
197 public ExpandableNotificationRow createRow(@InflationFlag int extraInflationFlags)
198 throws Exception {
Yohei Yukawa72769462019-01-20 09:28:08 -0800199 return generateRow(createNotification(), PKG, UID, USER_HANDLE, extraInflationFlags);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700200 }
201
202 /**
203 * Returns an {@link ExpandableNotificationRow} group with the given number of child
204 * notifications.
205 */
206 public ExpandableNotificationRow createGroup(int numChildren) throws Exception {
207 ExpandableNotificationRow row = createGroupSummary(GROUP_KEY);
208 for (int i = 0; i < numChildren; i++) {
209 ExpandableNotificationRow childRow = createGroupChild(GROUP_KEY);
210 row.addChildNotification(childRow);
211 }
212 return row;
213 }
214
215 /** Returns a group notification with 2 child notifications. */
216 public ExpandableNotificationRow createGroup() throws Exception {
217 return createGroup(2);
218 }
219
220 private ExpandableNotificationRow createGroupSummary(String groupkey) throws Exception {
Yohei Yukawa72769462019-01-20 09:28:08 -0800221 return createRow(PKG, UID, USER_HANDLE, true /* isGroupSummary */, groupkey);
Rohan Shah524cf7b2018-03-15 14:40:02 -0700222 }
223
224 private ExpandableNotificationRow createGroupChild(String groupkey) throws Exception {
Yohei Yukawa72769462019-01-20 09:28:08 -0800225 return createRow(PKG, UID, USER_HANDLE, false /* isGroupSummary */, groupkey);
Mady Mellorb4991e62019-01-10 15:14:51 -0800226 }
227
228 /**
229 * Returns an {@link ExpandableNotificationRow} that should be shown as a bubble.
Mark Renouffec45da2019-03-13 13:24:27 -0400230 */
Beverlya53fb0d2020-01-29 15:26:13 -0500231 public ExpandableNotificationRow createBubbleInGroup()
232 throws Exception {
233 return createBubble(makeBubbleMetadata(null), PKG, true);
234 }
235
236 /**
237 * Returns an {@link ExpandableNotificationRow} that should be shown as a bubble.
238 */
Mark Renouffec45da2019-03-13 13:24:27 -0400239 public ExpandableNotificationRow createBubble()
240 throws Exception {
Beverlya53fb0d2020-01-29 15:26:13 -0500241 return createBubble(makeBubbleMetadata(null), PKG, false);
Mark Renouffec45da2019-03-13 13:24:27 -0400242 }
243
244 /**
245 * Returns an {@link ExpandableNotificationRow} that should be shown as a bubble.
Mark Renouf08bc42a2019-03-07 13:01:59 -0500246 *
247 * @param deleteIntent the intent to assign to {@link BubbleMetadata#deleteIntent}
248 */
249 public ExpandableNotificationRow createBubble(@Nullable PendingIntent deleteIntent)
250 throws Exception {
Beverlya53fb0d2020-01-29 15:26:13 -0500251 return createBubble(makeBubbleMetadata(deleteIntent), PKG, false);
Mady Mellore80930e2019-03-21 16:00:45 -0700252 }
253
254 /**
255 * Returns an {@link ExpandableNotificationRow} that should be shown as a bubble.
256 *
257 * @param bubbleMetadata the {@link BubbleMetadata} to use
258 */
259 public ExpandableNotificationRow createBubble(BubbleMetadata bubbleMetadata, String pkg)
260 throws Exception {
Beverlya53fb0d2020-01-29 15:26:13 -0500261 return createBubble(bubbleMetadata, pkg, false);
262 }
263
264 private ExpandableNotificationRow createBubble(BubbleMetadata bubbleMetadata, String pkg,
265 boolean inGroup)
266 throws Exception {
Mady Mellore80930e2019-03-21 16:00:45 -0700267 Notification n = createNotification(false /* isGroupSummary */,
Beverlya53fb0d2020-01-29 15:26:13 -0500268 inGroup ? GROUP_KEY : null /* groupKey */, bubbleMetadata);
Mady Mellorfc02cc32019-04-01 14:47:55 -0700269 n.flags |= FLAG_BUBBLE;
Mady Melloraa8fef22019-04-11 13:36:40 -0700270 ExpandableNotificationRow row = generateRow(n, pkg, UID, USER_HANDLE,
271 0 /* extraInflationFlags */, IMPORTANCE_HIGH);
Ned Burns47c98f12019-09-06 17:12:07 -0400272 modifyRanking(row.getEntry())
273 .setCanBubble(true)
274 .build();
Mady Melloraa8fef22019-04-11 13:36:40 -0700275 return row;
Mady Mellore80930e2019-03-21 16:00:45 -0700276 }
277
278 /**
Rohan Shah524cf7b2018-03-15 14:40:02 -0700279 * Creates a notification row with the given details.
280 *
281 * @param pkg package used for creating a {@link StatusBarNotification}
282 * @param uid uid used for creating a {@link StatusBarNotification}
283 * @param isGroupSummary whether the notification row is a group summary
284 * @param groupKey the group key for the notification group used across notifications
285 * @return a row with that's either a standalone notification or a group notification if the
286 * groupKey is non-null
287 * @throws Exception
288 */
289 private ExpandableNotificationRow createRow(
290 String pkg,
291 int uid,
Yohei Yukawa72769462019-01-20 09:28:08 -0800292 UserHandle userHandle,
Rohan Shah524cf7b2018-03-15 14:40:02 -0700293 boolean isGroupSummary,
Mady Mellorb4991e62019-01-10 15:14:51 -0800294 @Nullable String groupKey)
Rohan Shah524cf7b2018-03-15 14:40:02 -0700295 throws Exception {
Kevind4660b22018-09-27 10:57:35 -0700296 Notification notif = createNotification(isGroupSummary, groupKey);
Yohei Yukawa72769462019-01-20 09:28:08 -0800297 return generateRow(notif, pkg, uid, userHandle, 0 /* inflationFlags */);
Kevind4660b22018-09-27 10:57:35 -0700298 }
299
300 /**
301 * Creates a generic notification.
302 *
303 * @return a notification with no special properties
304 */
Julia Reynolds0c245002019-03-27 16:10:11 -0400305 public Notification createNotification() {
Kevind4660b22018-09-27 10:57:35 -0700306 return createNotification(false /* isGroupSummary */, null /* groupKey */);
307 }
308
309 /**
310 * Creates a notification with the given parameters.
311 *
312 * @param isGroupSummary whether the notification is a group summary
313 * @param groupKey the group key for the notification group used across notifications
314 * @return a notification that is in the group specified or standalone if unspecified
315 */
Mady Mellorb4991e62019-01-10 15:14:51 -0800316 private Notification createNotification(boolean isGroupSummary, @Nullable String groupKey) {
Mady Mellore80930e2019-03-21 16:00:45 -0700317 return createNotification(isGroupSummary, groupKey, null /* bubble metadata */);
Mady Mellorb4991e62019-01-10 15:14:51 -0800318 }
319
320 /**
321 * Creates a notification with the given parameters.
322 *
323 * @param isGroupSummary whether the notification is a group summary
324 * @param groupKey the group key for the notification group used across notifications
Mady Mellore80930e2019-03-21 16:00:45 -0700325 * @param bubbleMetadata the bubble metadata to use for this notification if it exists.
Mady Mellorb4991e62019-01-10 15:14:51 -0800326 * @return a notification that is in the group specified or standalone if unspecified
327 */
Mark Renouf9ba6cea2019-04-17 11:53:50 -0400328 public Notification createNotification(boolean isGroupSummary,
Mady Mellore80930e2019-03-21 16:00:45 -0700329 @Nullable String groupKey, @Nullable BubbleMetadata bubbleMetadata) {
Selim Cinek6fd06b52017-03-07 15:54:10 -0800330 Notification publicVersion = new Notification.Builder(mContext).setSmallIcon(
331 R.drawable.ic_person)
332 .setCustomContentView(new RemoteViews(mContext.getPackageName(),
333 R.layout.custom_view_dark))
334 .build();
Kevind4660b22018-09-27 10:57:35 -0700335 Notification.Builder notificationBuilder = new Notification.Builder(mContext, "channelId")
336 .setSmallIcon(R.drawable.ic_person)
337 .setContentTitle("Title")
338 .setContentText("Text")
Kevind5022f92018-10-08 18:30:26 -0700339 .setPublicVersion(publicVersion)
340 .setStyle(new Notification.BigTextStyle().bigText("Big Text"));
Rohan Shah524cf7b2018-03-15 14:40:02 -0700341 if (isGroupSummary) {
342 notificationBuilder.setGroupSummary(true);
343 }
344 if (!TextUtils.isEmpty(groupKey)) {
345 notificationBuilder.setGroup(groupKey);
346 }
Mady Mellore80930e2019-03-21 16:00:45 -0700347 if (bubbleMetadata != null) {
348 notificationBuilder.setBubbleMetadata(bubbleMetadata);
Mady Mellorb4991e62019-01-10 15:14:51 -0800349 }
Kevind4660b22018-09-27 10:57:35 -0700350 return notificationBuilder.build();
Julia Reynoldsfc640012018-02-21 12:25:27 -0500351 }
352
Dave Mankoffc0211ff2020-02-07 15:36:12 -0500353 public StatusBarStateController getStatusBarStateController() {
354 return mStatusBarStateController;
355 }
356
Rohan Shah524cf7b2018-03-15 14:40:02 -0700357 private ExpandableNotificationRow generateRow(
358 Notification notification,
359 String pkg,
360 int uid,
Yohei Yukawa72769462019-01-20 09:28:08 -0800361 UserHandle userHandle,
Mady Mellorb4991e62019-01-10 15:14:51 -0800362 @InflationFlag int extraInflationFlags)
363 throws Exception {
Yohei Yukawa72769462019-01-20 09:28:08 -0800364 return generateRow(notification, pkg, uid, userHandle, extraInflationFlags,
365 IMPORTANCE_DEFAULT);
Mady Mellorb4991e62019-01-10 15:14:51 -0800366 }
367
368 private ExpandableNotificationRow generateRow(
369 Notification notification,
370 String pkg,
371 int uid,
Yohei Yukawa72769462019-01-20 09:28:08 -0800372 UserHandle userHandle,
Mady Mellorb4991e62019-01-10 15:14:51 -0800373 @InflationFlag int extraInflationFlags,
374 int importance)
Julia Reynoldsfc640012018-02-21 12:25:27 -0500375 throws Exception {
Selim Cinek10790672017-03-08 16:33:05 -0800376 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
377 mContext.LAYOUT_INFLATER_SERVICE);
Jason Monk6dceace2018-05-15 20:24:07 -0400378 mRow = (ExpandableNotificationRow) inflater.inflate(
379 R.layout.status_bar_notification_row,
380 null /* root */,
381 false /* attachToRoot */);
Selim Cinek5ba22542017-04-20 15:16:10 -0700382 ExpandableNotificationRow row = mRow;
Ned Burns636c3792019-09-11 16:59:07 -0400383
Ned Burns296aec162019-09-04 17:30:59 -0400384 final NotificationChannel channel =
385 new NotificationChannel(
386 notification.getChannelId(),
387 notification.getChannelId(),
388 importance);
Hall Liu9866aa82020-03-12 12:55:50 -0700389 channel.setBlockable(true);
Ned Burns296aec162019-09-04 17:30:59 -0400390
Ned Burns636c3792019-09-11 16:59:07 -0400391 NotificationEntry entry = new NotificationEntryBuilder()
392 .setPkg(pkg)
393 .setOpPkg(pkg)
394 .setId(mId++)
395 .setUid(uid)
396 .setInitialPid(2000)
397 .setNotification(notification)
398 .setUser(userHandle)
399 .setPostTime(System.currentTimeMillis())
400 .setChannel(channel)
401 .build();
402
Evan Laird94492852018-10-25 13:43:01 -0400403 entry.setRow(row);
Ned Burnsd8b51542020-03-13 20:52:43 -0400404 mIconManager.createIcons(entry);
Kevind4660b22018-09-27 10:57:35 -0700405 row.setEntry(entry);
Kevin Han5182c9f2020-01-07 17:54:43 -0800406
Kevin Han65c38b32020-02-05 16:42:40 -0800407 mBindPipelineEntryListener.onEntryInit(entry);
Kevin Han933dc7c2020-01-29 11:17:46 -0800408 mBindPipeline.manageRow(entry, row);
Kevin Han5182c9f2020-01-07 17:54:43 -0800409
410 row.initialize(
411 APP_NAME,
412 entry.getKey(),
413 mock(ExpansionLogger.class),
414 mock(KeyguardBypassController.class),
415 mGroupManager,
416 mHeadsUpManager,
Kevin Han933dc7c2020-01-29 11:17:46 -0800417 mBindStage,
Dave Mankoffc0211ff2020-02-07 15:36:12 -0500418 mock(OnExpandClickListener.class),
419 mock(NotificationMediaManager.class),
420 mock(ExpandableNotificationRow.OnAppOpsClickListener.class),
421 mock(FalsingManager.class),
Steve Elliott2304e4a2020-04-01 17:03:41 -0400422 mStatusBarStateController,
423 mPeopleNotificationIdentifier);
Kevin Han5182c9f2020-01-07 17:54:43 -0800424 row.setAboveShelfChangedListener(aboveShelf -> { });
Kevin Han933dc7c2020-01-29 11:17:46 -0800425 mBindStage.getStageParams(entry).requireContentViews(extraInflationFlags);
Kevin Hana7c21be2020-04-01 17:58:35 -0700426 inflateAndWait(entry);
Selim Cinek6fd06b52017-03-07 15:54:10 -0800427
Rohan Shah524cf7b2018-03-15 14:40:02 -0700428 // This would be done as part of onAsyncInflationFinished, but we skip large amounts of
429 // the callback chain, so we need to make up for not adding it to the group manager
430 // here.
431 mGroupManager.onEntryAdded(entry);
Selim Cinek6fd06b52017-03-07 15:54:10 -0800432 return row;
433 }
Mady Mellorc39b4ae2019-01-09 17:11:37 -0800434
Kevin Hana7c21be2020-04-01 17:58:35 -0700435 private void inflateAndWait(NotificationEntry entry) throws Exception {
Kevin Hance7451c2019-12-11 14:31:53 -0800436 CountDownLatch countDownLatch = new CountDownLatch(1);
Kevin Hana7c21be2020-04-01 17:58:35 -0700437 mBindStage.requestRebind(entry, en -> countDownLatch.countDown());
438 mTestLooper.processAllMessages();
Kevin Hance7451c2019-12-11 14:31:53 -0800439 assertTrue(countDownLatch.await(500, TimeUnit.MILLISECONDS));
440 }
441
Mark Renouf08bc42a2019-03-07 13:01:59 -0500442 private BubbleMetadata makeBubbleMetadata(PendingIntent deleteIntent) {
Mark Renoufa9fbb6e2019-02-11 12:48:22 -0500443 Intent target = new Intent(mContext, BubblesTestActivity.class);
444 PendingIntent bubbleIntent = PendingIntent.getActivity(mContext, 0, target, 0);
Mark Renouf08bc42a2019-03-07 13:01:59 -0500445
Mady Melloraa9ce172020-03-17 10:34:20 -0700446 return new BubbleMetadata.Builder(bubbleIntent,
Mady Mellor2ac2d3a2020-01-08 17:18:54 -0800447 Icon.createWithResource(mContext, R.drawable.android))
Mark Renouf08bc42a2019-03-07 13:01:59 -0500448 .setDeleteIntent(deleteIntent)
Mady Mellorc39b4ae2019-01-09 17:11:37 -0800449 .setDesiredHeight(314)
450 .build();
451 }
Selim Cinek6fd06b52017-03-07 15:54:10 -0800452}