Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 1 | /* |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 2 | * Copyright (C) 2020 The Android Open Source Project |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 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 |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 14 | * limitations under the License. |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 15 | */ |
| 16 | |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification.row; |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 18 | |
Mady Mellor | fc02cc3 | 2019-04-01 14:47:55 -0700 | [diff] [blame] | 19 | import static android.app.Notification.FLAG_BUBBLE; |
Julia Reynolds | 0abae11 | 2018-06-08 10:36:57 -0400 | [diff] [blame] | 20 | import static android.app.NotificationManager.IMPORTANCE_DEFAULT; |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 21 | import static android.app.NotificationManager.IMPORTANCE_HIGH; |
Julia Reynolds | 0abae11 | 2018-06-08 10:36:57 -0400 | [diff] [blame] | 22 | |
Ned Burns | 47c98f1 | 2019-09-06 17:12:07 -0400 | [diff] [blame] | 23 | import static com.android.systemui.statusbar.NotificationEntryHelper.modifyRanking; |
| 24 | |
Kevin Han | ce7451c | 2019-12-11 14:31:53 -0800 | [diff] [blame] | 25 | import static org.junit.Assert.assertTrue; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 26 | import static org.mockito.Mockito.mock; |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 27 | import static org.mockito.Mockito.verify; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 28 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 29 | import android.annotation.Nullable; |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 30 | import android.app.ActivityManager; |
| 31 | import android.app.Notification; |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 32 | import android.app.Notification.BubbleMetadata; |
Julia Reynolds | 0abae11 | 2018-06-08 10:36:57 -0400 | [diff] [blame] | 33 | import android.app.NotificationChannel; |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 34 | import android.app.PendingIntent; |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 35 | import android.content.Context; |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 36 | import android.content.Intent; |
Ned Burns | d8b5154 | 2020-03-13 20:52:43 -0400 | [diff] [blame] | 37 | import android.content.pm.LauncherApps; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 38 | import android.graphics.drawable.Icon; |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 39 | import android.os.UserHandle; |
| 40 | import android.service.notification.StatusBarNotification; |
Kevin Han | a7c21be | 2020-04-01 17:58:35 -0700 | [diff] [blame] | 41 | import android.testing.TestableLooper; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 42 | import android.text.TextUtils; |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 43 | import android.view.LayoutInflater; |
| 44 | import android.widget.RemoteViews; |
| 45 | |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 46 | import com.android.systemui.TestableDependency; |
| 47 | import com.android.systemui.bubbles.BubbleController; |
Mark Renouf | a9fbb6e | 2019-02-11 12:48:22 -0500 | [diff] [blame] | 48 | import com.android.systemui.bubbles.BubblesTestActivity; |
Dave Mankoff | c0211ff | 2020-02-07 15:36:12 -0500 | [diff] [blame] | 49 | import com.android.systemui.plugins.FalsingManager; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 50 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 51 | import com.android.systemui.statusbar.NotificationMediaManager; |
| 52 | import com.android.systemui.statusbar.NotificationRemoteInputManager; |
| 53 | import com.android.systemui.statusbar.SmartReplyController; |
Steve Elliott | 46bb2a1 | 2020-03-17 11:04:09 -0400 | [diff] [blame] | 54 | import com.android.systemui.statusbar.notification.ConversationNotificationProcessor; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 55 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Beverly | 79c89ec | 2019-12-13 10:33:01 -0500 | [diff] [blame] | 56 | import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder; |
Kevin Han | 65c38b3 | 2020-02-05 16:42:40 -0800 | [diff] [blame] | 57 | import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection; |
| 58 | import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener; |
Ned Burns | d8b5154 | 2020-03-13 20:52:43 -0400 | [diff] [blame] | 59 | import com.android.systemui.statusbar.notification.icon.IconBuilder; |
| 60 | import com.android.systemui.statusbar.notification.icon.IconManager; |
Steve Elliott | 2304e4a | 2020-04-01 17:03:41 -0400 | [diff] [blame] | 61 | import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier; |
Kevin Han | 5182c9f | 2020-01-07 17:54:43 -0800 | [diff] [blame] | 62 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow.ExpansionLogger; |
| 63 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow.OnExpandClickListener; |
Kevin Han | ec09309 | 2019-12-11 16:47:59 -0800 | [diff] [blame] | 64 | import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationFlag; |
Beverly | 95a0802ac | 2020-02-10 15:27:40 -0500 | [diff] [blame] | 65 | import com.android.systemui.statusbar.phone.ConfigurationControllerImpl; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 66 | import com.android.systemui.statusbar.phone.HeadsUpManagerPhone; |
Selim Cinek | d21232e | 2019-06-20 14:15:59 -0700 | [diff] [blame] | 67 | import com.android.systemui.statusbar.phone.KeyguardBypassController; |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 68 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 69 | import com.android.systemui.statusbar.phone.NotificationShadeWindowController; |
Sergey Nikolaienkov | f6ad632 | 2020-02-10 15:46:32 +0100 | [diff] [blame] | 70 | import com.android.systemui.statusbar.policy.SmartReplyConstants; |
Hyunyoung Song | 8f9d34c | 2019-08-30 14:47:43 -0700 | [diff] [blame] | 71 | import com.android.systemui.tests.R; |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 72 | |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 73 | import org.mockito.ArgumentCaptor; |
| 74 | |
Kevin Han | ce7451c | 2019-12-11 14:31:53 -0800 | [diff] [blame] | 75 | import java.util.concurrent.CountDownLatch; |
Kevin Han | a6d5bb4 | 2020-03-17 13:55:49 -0700 | [diff] [blame] | 76 | import java.util.concurrent.Executor; |
Kevin Han | ce7451c | 2019-12-11 14:31:53 -0800 | [diff] [blame] | 77 | import java.util.concurrent.TimeUnit; |
| 78 | |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 79 | /** |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 80 | * A helper class to create {@link ExpandableNotificationRow} (for both individual and group |
| 81 | * notifications). |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 82 | */ |
| 83 | public class NotificationTestHelper { |
| 84 | |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 85 | /** 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 Yukawa | 7276946 | 2019-01-20 09:28:08 -0800 | [diff] [blame] | 89 | /** Current {@link UserHandle} of the system. */ |
| 90 | public static final UserHandle USER_HANDLE = UserHandle.of(ActivityManager.getCurrentUser()); |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 91 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 92 | private static final String GROUP_KEY = "gruKey"; |
Kevin Han | 5182c9f | 2020-01-07 17:54:43 -0800 | [diff] [blame] | 93 | private static final String APP_NAME = "appName"; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 94 | |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 95 | private final Context mContext; |
Kevin Han | a7c21be | 2020-04-01 17:58:35 -0700 | [diff] [blame] | 96 | private final TestableLooper mTestLooper; |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 97 | private int mId; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 98 | private final NotificationGroupManager mGroupManager; |
Selim Cinek | 5ba2254 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 99 | private ExpandableNotificationRow mRow; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 100 | private HeadsUpManagerPhone mHeadsUpManager; |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 101 | private final NotifBindPipeline mBindPipeline; |
Kevin Han | 65c38b3 | 2020-02-05 16:42:40 -0800 | [diff] [blame] | 102 | private final NotifCollectionListener mBindPipelineEntryListener; |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 103 | private final RowContentBindStage mBindStage; |
Ned Burns | d8b5154 | 2020-03-13 20:52:43 -0400 | [diff] [blame] | 104 | private final IconManager mIconManager; |
Dave Mankoff | c0211ff | 2020-02-07 15:36:12 -0500 | [diff] [blame] | 105 | private StatusBarStateController mStatusBarStateController; |
Steve Elliott | 2304e4a | 2020-04-01 17:03:41 -0400 | [diff] [blame] | 106 | private final PeopleNotificationIdentifier mPeopleNotificationIdentifier; |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 107 | |
Kevin Han | a7c21be | 2020-04-01 17:58:35 -0700 | [diff] [blame] | 108 | public NotificationTestHelper( |
| 109 | Context context, |
| 110 | TestableDependency dependency, |
| 111 | TestableLooper testLooper) { |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 112 | mContext = context; |
Kevin Han | a7c21be | 2020-04-01 17:58:35 -0700 | [diff] [blame] | 113 | mTestLooper = testLooper; |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 114 | dependency.injectMockDependency(NotificationMediaManager.class); |
| 115 | dependency.injectMockDependency(BubbleController.class); |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 116 | dependency.injectMockDependency(NotificationShadeWindowController.class); |
Dave Mankoff | c0211ff | 2020-02-07 15:36:12 -0500 | [diff] [blame] | 117 | mStatusBarStateController = mock(StatusBarStateController.class); |
| 118 | mGroupManager = new NotificationGroupManager(mStatusBarStateController); |
| 119 | mHeadsUpManager = new HeadsUpManagerPhone(mContext, mStatusBarStateController, |
Beverly | 95a0802ac | 2020-02-10 15:27:40 -0500 | [diff] [blame] | 120 | mock(KeyguardBypassController.class), mock(NotificationGroupManager.class), |
| 121 | mock(ConfigurationControllerImpl.class)); |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 122 | mGroupManager.setHeadsUpManager(mHeadsUpManager); |
Ned Burns | d8b5154 | 2020-03-13 20:52:43 -0400 | [diff] [blame] | 123 | mIconManager = new IconManager( |
| 124 | mock(CommonNotifCollection.class), |
| 125 | mock(LauncherApps.class), |
| 126 | new IconBuilder(mContext)); |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 127 | |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 128 | NotificationContentInflater contentBinder = new NotificationContentInflater( |
| 129 | mock(NotifRemoteViewCache.class), |
Sergey Nikolaienkov | f6ad632 | 2020-02-10 15:46:32 +0100 | [diff] [blame] | 130 | mock(NotificationRemoteInputManager.class), |
| 131 | () -> mock(SmartReplyConstants.class), |
Steve Elliott | 46bb2a1 | 2020-03-17 11:04:09 -0400 | [diff] [blame] | 132 | () -> mock(SmartReplyController.class), |
Kevin Han | a6d5bb4 | 2020-03-17 13:55:49 -0700 | [diff] [blame] | 133 | mock(ConversationNotificationProcessor.class), |
| 134 | mock(Executor.class)); |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 135 | contentBinder.setInflateSynchronously(true); |
Kevin Han | c1f0448 | 2020-02-07 12:23:52 -0800 | [diff] [blame] | 136 | mBindStage = new RowContentBindStage(contentBinder, |
| 137 | mock(NotifInflationErrorManager.class), |
| 138 | mock(RowContentBindStageLogger.class)); |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 139 | |
Kevin Han | 65c38b3 | 2020-02-05 16:42:40 -0800 | [diff] [blame] | 140 | CommonNotifCollection collection = mock(CommonNotifCollection.class); |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 141 | |
Kevin Han | a7c21be | 2020-04-01 17:58:35 -0700 | [diff] [blame] | 142 | mBindPipeline = new NotifBindPipeline( |
| 143 | collection, |
| 144 | mock(NotifBindPipelineLogger.class), |
| 145 | mTestLooper.getLooper()); |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 146 | mBindPipeline.setStage(mBindStage); |
| 147 | |
Kevin Han | 65c38b3 | 2020-02-05 16:42:40 -0800 | [diff] [blame] | 148 | ArgumentCaptor<NotifCollectionListener> collectionListenerCaptor = |
| 149 | ArgumentCaptor.forClass(NotifCollectionListener.class); |
| 150 | verify(collection).addCollectionListener(collectionListenerCaptor.capture()); |
| 151 | mBindPipelineEntryListener = collectionListenerCaptor.getValue(); |
Steve Elliott | 2304e4a | 2020-04-01 17:03:41 -0400 | [diff] [blame] | 152 | mPeopleNotificationIdentifier = mock(PeopleNotificationIdentifier.class); |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 153 | } |
| 154 | |
Kevin | d4660b2 | 2018-09-27 10:57:35 -0700 | [diff] [blame] | 155 | /** |
| 156 | * Creates a generic row. |
| 157 | * |
| 158 | * @return a generic row with no special properties. |
| 159 | * @throws Exception |
| 160 | */ |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 161 | public ExpandableNotificationRow createRow() throws Exception { |
Yohei Yukawa | 7276946 | 2019-01-20 09:28:08 -0800 | [diff] [blame] | 162 | return createRow(PKG, UID, USER_HANDLE); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Kevin | d4660b2 | 2018-09-27 10:57:35 -0700 | [diff] [blame] | 165 | /** |
| 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 Yukawa | 7276946 | 2019-01-20 09:28:08 -0800 | [diff] [blame] | 173 | public ExpandableNotificationRow createRow(String pkg, int uid, UserHandle userHandle) |
| 174 | throws Exception { |
| 175 | return createRow(pkg, uid, userHandle, false /* isGroupSummary */, null /* groupKey */); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Kevin | d4660b2 | 2018-09-27 10:57:35 -0700 | [diff] [blame] | 178 | /** |
| 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 Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 185 | public ExpandableNotificationRow createRow(Notification notification) throws Exception { |
Yohei Yukawa | 7276946 | 2019-01-20 09:28:08 -0800 | [diff] [blame] | 186 | return generateRow(notification, PKG, UID, USER_HANDLE, 0 /* extraInflationFlags */); |
Kevin | d4660b2 | 2018-09-27 10:57:35 -0700 | [diff] [blame] | 187 | } |
| 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 Yukawa | 7276946 | 2019-01-20 09:28:08 -0800 | [diff] [blame] | 199 | return generateRow(createNotification(), PKG, UID, USER_HANDLE, extraInflationFlags); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 200 | } |
| 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 Yukawa | 7276946 | 2019-01-20 09:28:08 -0800 | [diff] [blame] | 221 | return createRow(PKG, UID, USER_HANDLE, true /* isGroupSummary */, groupkey); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | private ExpandableNotificationRow createGroupChild(String groupkey) throws Exception { |
Yohei Yukawa | 7276946 | 2019-01-20 09:28:08 -0800 | [diff] [blame] | 225 | return createRow(PKG, UID, USER_HANDLE, false /* isGroupSummary */, groupkey); |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | /** |
| 229 | * Returns an {@link ExpandableNotificationRow} that should be shown as a bubble. |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 230 | */ |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 231 | 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 Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 239 | public ExpandableNotificationRow createBubble() |
| 240 | throws Exception { |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 241 | return createBubble(makeBubbleMetadata(null), PKG, false); |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | /** |
| 245 | * Returns an {@link ExpandableNotificationRow} that should be shown as a bubble. |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 246 | * |
| 247 | * @param deleteIntent the intent to assign to {@link BubbleMetadata#deleteIntent} |
| 248 | */ |
| 249 | public ExpandableNotificationRow createBubble(@Nullable PendingIntent deleteIntent) |
| 250 | throws Exception { |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 251 | return createBubble(makeBubbleMetadata(deleteIntent), PKG, false); |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 252 | } |
| 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 { |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 261 | return createBubble(bubbleMetadata, pkg, false); |
| 262 | } |
| 263 | |
| 264 | private ExpandableNotificationRow createBubble(BubbleMetadata bubbleMetadata, String pkg, |
| 265 | boolean inGroup) |
| 266 | throws Exception { |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 267 | Notification n = createNotification(false /* isGroupSummary */, |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 268 | inGroup ? GROUP_KEY : null /* groupKey */, bubbleMetadata); |
Mady Mellor | fc02cc3 | 2019-04-01 14:47:55 -0700 | [diff] [blame] | 269 | n.flags |= FLAG_BUBBLE; |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 270 | ExpandableNotificationRow row = generateRow(n, pkg, UID, USER_HANDLE, |
| 271 | 0 /* extraInflationFlags */, IMPORTANCE_HIGH); |
Ned Burns | 47c98f1 | 2019-09-06 17:12:07 -0400 | [diff] [blame] | 272 | modifyRanking(row.getEntry()) |
| 273 | .setCanBubble(true) |
| 274 | .build(); |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 275 | return row; |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | /** |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 279 | * 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 Yukawa | 7276946 | 2019-01-20 09:28:08 -0800 | [diff] [blame] | 292 | UserHandle userHandle, |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 293 | boolean isGroupSummary, |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 294 | @Nullable String groupKey) |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 295 | throws Exception { |
Kevin | d4660b2 | 2018-09-27 10:57:35 -0700 | [diff] [blame] | 296 | Notification notif = createNotification(isGroupSummary, groupKey); |
Yohei Yukawa | 7276946 | 2019-01-20 09:28:08 -0800 | [diff] [blame] | 297 | return generateRow(notif, pkg, uid, userHandle, 0 /* inflationFlags */); |
Kevin | d4660b2 | 2018-09-27 10:57:35 -0700 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /** |
| 301 | * Creates a generic notification. |
| 302 | * |
| 303 | * @return a notification with no special properties |
| 304 | */ |
Julia Reynolds | 0c24500 | 2019-03-27 16:10:11 -0400 | [diff] [blame] | 305 | public Notification createNotification() { |
Kevin | d4660b2 | 2018-09-27 10:57:35 -0700 | [diff] [blame] | 306 | 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 Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 316 | private Notification createNotification(boolean isGroupSummary, @Nullable String groupKey) { |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 317 | return createNotification(isGroupSummary, groupKey, null /* bubble metadata */); |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 318 | } |
| 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 Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 325 | * @param bubbleMetadata the bubble metadata to use for this notification if it exists. |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 326 | * @return a notification that is in the group specified or standalone if unspecified |
| 327 | */ |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 328 | public Notification createNotification(boolean isGroupSummary, |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 329 | @Nullable String groupKey, @Nullable BubbleMetadata bubbleMetadata) { |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 330 | 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(); |
Kevin | d4660b2 | 2018-09-27 10:57:35 -0700 | [diff] [blame] | 335 | Notification.Builder notificationBuilder = new Notification.Builder(mContext, "channelId") |
| 336 | .setSmallIcon(R.drawable.ic_person) |
| 337 | .setContentTitle("Title") |
| 338 | .setContentText("Text") |
Kevin | d5022f9 | 2018-10-08 18:30:26 -0700 | [diff] [blame] | 339 | .setPublicVersion(publicVersion) |
| 340 | .setStyle(new Notification.BigTextStyle().bigText("Big Text")); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 341 | if (isGroupSummary) { |
| 342 | notificationBuilder.setGroupSummary(true); |
| 343 | } |
| 344 | if (!TextUtils.isEmpty(groupKey)) { |
| 345 | notificationBuilder.setGroup(groupKey); |
| 346 | } |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 347 | if (bubbleMetadata != null) { |
| 348 | notificationBuilder.setBubbleMetadata(bubbleMetadata); |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 349 | } |
Kevin | d4660b2 | 2018-09-27 10:57:35 -0700 | [diff] [blame] | 350 | return notificationBuilder.build(); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 351 | } |
| 352 | |
Dave Mankoff | c0211ff | 2020-02-07 15:36:12 -0500 | [diff] [blame] | 353 | public StatusBarStateController getStatusBarStateController() { |
| 354 | return mStatusBarStateController; |
| 355 | } |
| 356 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 357 | private ExpandableNotificationRow generateRow( |
| 358 | Notification notification, |
| 359 | String pkg, |
| 360 | int uid, |
Yohei Yukawa | 7276946 | 2019-01-20 09:28:08 -0800 | [diff] [blame] | 361 | UserHandle userHandle, |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 362 | @InflationFlag int extraInflationFlags) |
| 363 | throws Exception { |
Yohei Yukawa | 7276946 | 2019-01-20 09:28:08 -0800 | [diff] [blame] | 364 | return generateRow(notification, pkg, uid, userHandle, extraInflationFlags, |
| 365 | IMPORTANCE_DEFAULT); |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | private ExpandableNotificationRow generateRow( |
| 369 | Notification notification, |
| 370 | String pkg, |
| 371 | int uid, |
Yohei Yukawa | 7276946 | 2019-01-20 09:28:08 -0800 | [diff] [blame] | 372 | UserHandle userHandle, |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 373 | @InflationFlag int extraInflationFlags, |
| 374 | int importance) |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 375 | throws Exception { |
Selim Cinek | 1079067 | 2017-03-08 16:33:05 -0800 | [diff] [blame] | 376 | LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( |
| 377 | mContext.LAYOUT_INFLATER_SERVICE); |
Jason Monk | 6dceace | 2018-05-15 20:24:07 -0400 | [diff] [blame] | 378 | mRow = (ExpandableNotificationRow) inflater.inflate( |
| 379 | R.layout.status_bar_notification_row, |
| 380 | null /* root */, |
| 381 | false /* attachToRoot */); |
Selim Cinek | 5ba2254 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 382 | ExpandableNotificationRow row = mRow; |
Ned Burns | 636c379 | 2019-09-11 16:59:07 -0400 | [diff] [blame] | 383 | |
Ned Burns | 296aec16 | 2019-09-04 17:30:59 -0400 | [diff] [blame] | 384 | final NotificationChannel channel = |
| 385 | new NotificationChannel( |
| 386 | notification.getChannelId(), |
| 387 | notification.getChannelId(), |
| 388 | importance); |
Hall Liu | 9866aa8 | 2020-03-12 12:55:50 -0700 | [diff] [blame] | 389 | channel.setBlockable(true); |
Ned Burns | 296aec16 | 2019-09-04 17:30:59 -0400 | [diff] [blame] | 390 | |
Ned Burns | 636c379 | 2019-09-11 16:59:07 -0400 | [diff] [blame] | 391 | 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 Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 403 | entry.setRow(row); |
Ned Burns | d8b5154 | 2020-03-13 20:52:43 -0400 | [diff] [blame] | 404 | mIconManager.createIcons(entry); |
Kevin | d4660b2 | 2018-09-27 10:57:35 -0700 | [diff] [blame] | 405 | row.setEntry(entry); |
Kevin Han | 5182c9f | 2020-01-07 17:54:43 -0800 | [diff] [blame] | 406 | |
Kevin Han | 65c38b3 | 2020-02-05 16:42:40 -0800 | [diff] [blame] | 407 | mBindPipelineEntryListener.onEntryInit(entry); |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 408 | mBindPipeline.manageRow(entry, row); |
Kevin Han | 5182c9f | 2020-01-07 17:54:43 -0800 | [diff] [blame] | 409 | |
| 410 | row.initialize( |
| 411 | APP_NAME, |
| 412 | entry.getKey(), |
| 413 | mock(ExpansionLogger.class), |
| 414 | mock(KeyguardBypassController.class), |
| 415 | mGroupManager, |
| 416 | mHeadsUpManager, |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 417 | mBindStage, |
Dave Mankoff | c0211ff | 2020-02-07 15:36:12 -0500 | [diff] [blame] | 418 | mock(OnExpandClickListener.class), |
| 419 | mock(NotificationMediaManager.class), |
| 420 | mock(ExpandableNotificationRow.OnAppOpsClickListener.class), |
| 421 | mock(FalsingManager.class), |
Steve Elliott | 2304e4a | 2020-04-01 17:03:41 -0400 | [diff] [blame] | 422 | mStatusBarStateController, |
| 423 | mPeopleNotificationIdentifier); |
Kevin Han | 5182c9f | 2020-01-07 17:54:43 -0800 | [diff] [blame] | 424 | row.setAboveShelfChangedListener(aboveShelf -> { }); |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 425 | mBindStage.getStageParams(entry).requireContentViews(extraInflationFlags); |
Kevin Han | a7c21be | 2020-04-01 17:58:35 -0700 | [diff] [blame] | 426 | inflateAndWait(entry); |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 427 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 428 | // 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 Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 432 | return row; |
| 433 | } |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 434 | |
Kevin Han | a7c21be | 2020-04-01 17:58:35 -0700 | [diff] [blame] | 435 | private void inflateAndWait(NotificationEntry entry) throws Exception { |
Kevin Han | ce7451c | 2019-12-11 14:31:53 -0800 | [diff] [blame] | 436 | CountDownLatch countDownLatch = new CountDownLatch(1); |
Kevin Han | a7c21be | 2020-04-01 17:58:35 -0700 | [diff] [blame] | 437 | mBindStage.requestRebind(entry, en -> countDownLatch.countDown()); |
| 438 | mTestLooper.processAllMessages(); |
Kevin Han | ce7451c | 2019-12-11 14:31:53 -0800 | [diff] [blame] | 439 | assertTrue(countDownLatch.await(500, TimeUnit.MILLISECONDS)); |
| 440 | } |
| 441 | |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 442 | private BubbleMetadata makeBubbleMetadata(PendingIntent deleteIntent) { |
Mark Renouf | a9fbb6e | 2019-02-11 12:48:22 -0500 | [diff] [blame] | 443 | Intent target = new Intent(mContext, BubblesTestActivity.class); |
| 444 | PendingIntent bubbleIntent = PendingIntent.getActivity(mContext, 0, target, 0); |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 445 | |
Mady Mellor | aa9ce17 | 2020-03-17 10:34:20 -0700 | [diff] [blame] | 446 | return new BubbleMetadata.Builder(bubbleIntent, |
Mady Mellor | 2ac2d3a | 2020-01-08 17:18:54 -0800 | [diff] [blame] | 447 | Icon.createWithResource(mContext, R.drawable.android)) |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 448 | .setDeleteIntent(deleteIntent) |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 449 | .setDesiredHeight(314) |
| 450 | .build(); |
| 451 | } |
Selim Cinek | 6fd06b5 | 2017-03-07 15:54:10 -0800 | [diff] [blame] | 452 | } |