blob: 3ef693a1ec989e6b68a231c82664f61346066301 [file] [log] [blame]
Mady Mellorebdbbb92018-11-15 14:36:48 -08001/*
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
17package com.android.systemui.bubbles;
18
Mady Melloraa8fef22019-04-11 13:36:40 -070019import static android.app.Notification.FLAG_BUBBLE;
Mady Mellorc2ff0112019-03-28 14:18:06 -070020import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL;
21import static android.service.notification.NotificationListenerService.REASON_CANCEL;
22import static android.service.notification.NotificationListenerService.REASON_CANCEL_ALL;
Beverlya53fb0d2020-01-29 15:26:13 -050023import static android.service.notification.NotificationListenerService.REASON_GROUP_SUMMARY_CANCELED;
Mady Mellor1a4e86f2019-05-03 16:07:23 -070024
Mady Mellorfc02cc32019-04-01 14:47:55 -070025import static com.google.common.truth.Truth.assertThat;
26
Mady Melloredd4ee12019-01-18 10:45:11 -080027import static org.junit.Assert.assertEquals;
Mady Mellorebdbbb92018-11-15 14:36:48 -080028import static org.junit.Assert.assertFalse;
Mady Mellored99c272019-06-13 15:58:30 -070029import static org.junit.Assert.assertNotNull;
30import static org.junit.Assert.assertNull;
Mady Mellorebdbbb92018-11-15 14:36:48 -080031import static org.junit.Assert.assertTrue;
Mady Mellorc2ff0112019-03-28 14:18:06 -070032import static org.mockito.ArgumentMatchers.any;
Mady Mellorfc02cc32019-04-01 14:47:55 -070033import static org.mockito.ArgumentMatchers.anyBoolean;
Mady Mellorc2ff0112019-03-28 14:18:06 -070034import static org.mockito.ArgumentMatchers.anyInt;
Beverly85d4c192019-09-30 11:40:39 -040035import static org.mockito.ArgumentMatchers.anyString;
Beverlya53fb0d2020-01-29 15:26:13 -050036import static org.mockito.ArgumentMatchers.eq;
Ned Burns01e38212019-01-03 16:32:52 -050037import static org.mockito.Mockito.atLeastOnce;
Mady Melloraa8fef22019-04-11 13:36:40 -070038import static org.mockito.Mockito.mock;
Mark Renouf08bc42a2019-03-07 13:01:59 -050039import static org.mockito.Mockito.never;
40import static org.mockito.Mockito.times;
Ned Burns01e38212019-01-03 16:32:52 -050041import static org.mockito.Mockito.verify;
42import static org.mockito.Mockito.when;
Mady Mellorebdbbb92018-11-15 14:36:48 -080043
44import android.app.IActivityManager;
Mady Mellor9adfe6a2020-03-30 17:23:26 -070045import android.app.INotificationManager;
Mady Mellore80930e2019-03-21 16:00:45 -070046import android.app.Notification;
Mark Renouf08bc42a2019-03-07 13:01:59 -050047import android.app.PendingIntent;
Heemin Seogafb3dbc2019-11-04 16:05:19 -080048import android.content.res.Resources;
Beverly Taid1e175c2020-03-10 16:37:04 +000049import android.hardware.display.AmbientDisplayConfiguration;
Mady Mellor80c25b22019-06-17 14:40:37 -070050import android.hardware.face.FaceManager;
Beverly Taid1e175c2020-03-10 16:37:04 +000051import android.os.Handler;
52import android.os.PowerManager;
53import android.service.dreams.IDreamManager;
Joshua Tsujidd4d9f92019-05-13 13:57:38 -040054import android.service.notification.ZenModeConfig;
Mady Mellorebdbbb92018-11-15 14:36:48 -080055import android.testing.AndroidTestingRunner;
56import android.testing.TestableLooper;
57import android.view.WindowManager;
Mady Mellorebdbbb92018-11-15 14:36:48 -080058
Brett Chabot84151d92019-02-27 15:37:59 -080059import androidx.test.filters.SmallTest;
60
Dave Mankoff2aff6c32019-10-14 17:40:37 -040061import com.android.internal.colorextraction.ColorExtractor;
Heemin Seogafb3dbc2019-11-04 16:05:19 -080062import com.android.systemui.SystemUIFactory;
Mady Mellorebdbbb92018-11-15 14:36:48 -080063import com.android.systemui.SysuiTestCase;
Dave Mankoff2aff6c32019-10-14 17:40:37 -040064import com.android.systemui.colorextraction.SysuiColorExtractor;
Ned Burnsaaeb44b2020-02-12 23:48:26 -050065import com.android.systemui.dump.DumpManager;
Joshua Tsujibe60a582020-03-23 17:17:26 -040066import com.android.systemui.model.SysUiState;
Mady Mellorc55b4122019-06-07 18:14:02 -070067import com.android.systemui.plugins.statusbar.StatusBarStateController;
Joshua Tsujibe60a582020-03-23 17:17:26 -040068import com.android.systemui.shared.system.QuickStepContract;
Beverlya53fb0d2020-01-29 15:26:13 -050069import com.android.systemui.statusbar.FeatureFlags;
Mark Renoufc19b4732019-06-26 12:08:33 -040070import com.android.systemui.statusbar.NotificationLockscreenUserManager;
Mady Mellorc2ff0112019-03-28 14:18:06 -070071import com.android.systemui.statusbar.NotificationRemoveInterceptor;
Heemin Seogafb3dbc2019-11-04 16:05:19 -080072import com.android.systemui.statusbar.SuperStatusBarViewFactory;
Lucas Dupine25c4872019-07-29 13:51:35 -070073import com.android.systemui.statusbar.SysuiStatusBarStateController;
Ned Burns01e38212019-01-03 16:32:52 -050074import com.android.systemui.statusbar.notification.NotificationEntryListener;
75import com.android.systemui.statusbar.notification.NotificationEntryManager;
Mady Mellorc55b4122019-06-07 18:14:02 -070076import com.android.systemui.statusbar.notification.NotificationFilter;
Beverlya53fb0d2020-01-29 15:26:13 -050077import com.android.systemui.statusbar.notification.collection.NotifPipeline;
Mady Mellor8d25b202019-06-25 13:59:28 -070078import com.android.systemui.statusbar.notification.collection.NotificationEntry;
Dave Mankoff56fe9e42020-01-08 15:42:06 -050079import com.android.systemui.statusbar.notification.row.ActivatableNotificationView;
Mady Mellorebdbbb92018-11-15 14:36:48 -080080import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
Kevin Han933dc7c2020-01-29 11:17:46 -080081import com.android.systemui.statusbar.notification.row.NotificationTestHelper;
Dave Mankoff56fe9e42020-01-08 15:42:06 -050082import com.android.systemui.statusbar.notification.row.dagger.NotificationRowComponent;
Mady Mellorebdbbb92018-11-15 14:36:48 -080083import com.android.systemui.statusbar.phone.DozeParameters;
Lucas Dupine25c4872019-07-29 13:51:35 -070084import com.android.systemui.statusbar.phone.KeyguardBypassController;
Dave Mankoffc0d9a7d2020-02-27 17:15:52 -050085import com.android.systemui.statusbar.phone.LockscreenLockIconController;
Ned Burns296aec162019-09-04 17:30:59 -040086import com.android.systemui.statusbar.phone.NotificationGroupManager;
wilsonshihe8321942019-10-18 18:39:46 +080087import com.android.systemui.statusbar.phone.NotificationShadeWindowController;
Fabian Kozynskib00c70b2020-04-03 12:41:31 -040088import com.android.systemui.statusbar.phone.NotificationShadeWindowView;
Mady Mellor7f234902019-10-20 12:06:29 -070089import com.android.systemui.statusbar.phone.ShadeController;
Lucas Dupinbd7366d2019-09-25 13:39:21 -070090import com.android.systemui.statusbar.policy.BatteryController;
Lyn Hanf1c9b8b2019-03-14 16:49:48 -070091import com.android.systemui.statusbar.policy.ConfigurationController;
Mady Melloraa8fef22019-04-11 13:36:40 -070092import com.android.systemui.statusbar.policy.HeadsUpManager;
Joshua Tsujidd4d9f92019-05-13 13:57:38 -040093import com.android.systemui.statusbar.policy.ZenModeController;
Joshua Tsuji7155bf12020-02-13 16:14:29 -050094import com.android.systemui.util.FloatingContentCoordinator;
Heemin Seogafb3dbc2019-11-04 16:05:19 -080095import com.android.systemui.util.InjectionInflationController;
Mady Mellorebdbbb92018-11-15 14:36:48 -080096
Lyn Han89274b42020-03-25 00:56:26 -070097import com.google.common.collect.ImmutableList;
98
Mady Mellorebdbbb92018-11-15 14:36:48 -080099import org.junit.Before;
100import org.junit.Test;
101import org.junit.runner.RunWith;
Ned Burns01e38212019-01-03 16:32:52 -0500102import org.mockito.ArgumentCaptor;
103import org.mockito.Captor;
Mady Mellorebdbbb92018-11-15 14:36:48 -0800104import org.mockito.Mock;
105import org.mockito.MockitoAnnotations;
106
Beverlya53fb0d2020-01-29 15:26:13 -0500107import java.util.List;
108
109/**
110 * Tests the NotificationEntryManager setup with BubbleController.
111 * The {@link NotifPipeline} setup with BubbleController is tested in
112 * {@link NewNotifPipelineBubbleControllerTest}.
113 */
Mady Mellorebdbbb92018-11-15 14:36:48 -0800114@SmallTest
115@RunWith(AndroidTestingRunner.class)
116@TestableLooper.RunWithLooper(setAsMainLooper = true)
117public class BubbleControllerTest extends SysuiTestCase {
Mady Mellorebdbbb92018-11-15 14:36:48 -0800118 @Mock
Ned Burns01e38212019-01-03 16:32:52 -0500119 private NotificationEntryManager mNotificationEntryManager;
120 @Mock
Mady Mellor22f2f072019-04-18 13:26:18 -0700121 private NotificationGroupManager mNotificationGroupManager;
122 @Mock
Mady Mellorebdbbb92018-11-15 14:36:48 -0800123 private WindowManager mWindowManager;
124 @Mock
125 private IActivityManager mActivityManager;
126 @Mock
127 private DozeParameters mDozeParameters;
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700128 @Mock
129 private ConfigurationController mConfigurationController;
Joshua Tsujidd4d9f92019-05-13 13:57:38 -0400130 @Mock
131 private ZenModeController mZenModeController;
132 @Mock
133 private ZenModeConfig mZenModeConfig;
Mady Mellor80c25b22019-06-17 14:40:37 -0700134 @Mock
135 private FaceManager mFaceManager;
Mark Renoufc19b4732019-06-26 12:08:33 -0400136 @Mock
137 private NotificationLockscreenUserManager mLockscreenUserManager;
Mady Mellorf474e0d2019-08-01 11:08:40 -0700138 @Mock
Lucas Dupine25c4872019-07-29 13:51:35 -0700139 private SysuiStatusBarStateController mStatusBarStateController;
140 @Mock
141 private KeyguardBypassController mKeyguardBypassController;
Joshua Tsuji7155bf12020-02-13 16:14:29 -0500142 @Mock
143 private FloatingContentCoordinator mFloatingContentCoordinator;
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700144
Joshua Tsujibe60a582020-03-23 17:17:26 -0400145 private SysUiState mSysUiState;
146 private boolean mSysUiStateBubblesExpanded;
147
Ned Burns01e38212019-01-03 16:32:52 -0500148 @Captor
149 private ArgumentCaptor<NotificationEntryListener> mEntryListenerCaptor;
Mady Mellorc2ff0112019-03-28 14:18:06 -0700150 @Captor
151 private ArgumentCaptor<NotificationRemoveInterceptor> mRemoveInterceptorCaptor;
Mady Mellorebdbbb92018-11-15 14:36:48 -0800152
153 private TestableBubbleController mBubbleController;
wilsonshihe8321942019-10-18 18:39:46 +0800154 private NotificationShadeWindowController mNotificationShadeWindowController;
Ned Burns01e38212019-01-03 16:32:52 -0500155 private NotificationEntryListener mEntryListener;
Mady Mellorc2ff0112019-03-28 14:18:06 -0700156 private NotificationRemoveInterceptor mRemoveInterceptor;
Mady Mellorebdbbb92018-11-15 14:36:48 -0800157
158 private NotificationTestHelper mNotificationTestHelper;
159 private ExpandableNotificationRow mRow;
160 private ExpandableNotificationRow mRow2;
Mady Mellorfc02cc32019-04-01 14:47:55 -0700161 private ExpandableNotificationRow mNonBubbleNotifRow;
Mady Mellorebdbbb92018-11-15 14:36:48 -0800162
Mady Mellorb4991e62019-01-10 15:14:51 -0800163 @Mock
Mady Melloracb12152019-01-29 15:24:48 -0800164 private BubbleController.BubbleStateChangeListener mBubbleStateChangeListener;
165 @Mock
166 private BubbleController.BubbleExpandListener mBubbleExpandListener;
Mark Renouf6b2331c2019-03-21 13:40:08 -0400167 @Mock
Mark Renouf08bc42a2019-03-07 13:01:59 -0500168 private PendingIntent mDeleteIntent;
Dave Mankoff2aff6c32019-10-14 17:40:37 -0400169 @Mock
170 private SysuiColorExtractor mColorExtractor;
171 @Mock
172 ColorExtractor.GradientColors mGradientColors;
Heemin Seogafb3dbc2019-11-04 16:05:19 -0800173 @Mock
174 private Resources mResources;
Mady Mellor7f234902019-10-20 12:06:29 -0700175 @Mock
Heemin Seogba6337f2019-12-10 15:34:37 -0800176 private ShadeController mShadeController;
Aran Inkaa4dfa72019-11-18 16:49:07 -0500177 @Mock
Dave Mankoff56fe9e42020-01-08 15:42:06 -0500178 private NotificationRowComponent mNotificationRowComponent;
Beverlya53fb0d2020-01-29 15:26:13 -0500179 @Mock
180 private NotifPipeline mNotifPipeline;
181 @Mock
182 private FeatureFlags mFeatureFlagsOldPipeline;
183 @Mock
Ned Burnsaaeb44b2020-02-12 23:48:26 -0500184 private DumpManager mDumpManager;
Dave Mankoffc0d9a7d2020-02-27 17:15:52 -0500185 @Mock
186 private LockscreenLockIconController mLockIconController;
Fabian Kozynskib00c70b2020-04-03 12:41:31 -0400187 @Mock
188 private NotificationShadeWindowView mNotificationShadeWindowView;
Mark Renouf08bc42a2019-03-07 13:01:59 -0500189
Heemin Seogafb3dbc2019-11-04 16:05:19 -0800190 private SuperStatusBarViewFactory mSuperStatusBarViewFactory;
Mady Mellorcfd06c12019-02-13 14:32:12 -0800191 private BubbleData mBubbleData;
192
Mady Mellorb8aaf972019-11-26 10:28:00 -0800193 private TestableLooper mTestableLooper;
194
Mady Mellorebdbbb92018-11-15 14:36:48 -0800195 @Before
196 public void setUp() throws Exception {
197 MockitoAnnotations.initMocks(this);
Mady Mellorb8aaf972019-11-26 10:28:00 -0800198
199 mTestableLooper = TestableLooper.get(this);
200
Mady Mellor80c25b22019-06-17 14:40:37 -0700201 mContext.addMockSystemService(FaceManager.class, mFaceManager);
Dave Mankoff2aff6c32019-10-14 17:40:37 -0400202 when(mColorExtractor.getNeutralColors()).thenReturn(mGradientColors);
Mady Mellorebdbbb92018-11-15 14:36:48 -0800203
Heemin Seogafb3dbc2019-11-04 16:05:19 -0800204 mSuperStatusBarViewFactory = new SuperStatusBarViewFactory(mContext,
Dave Mankoff56fe9e42020-01-08 15:42:06 -0500205 new InjectionInflationController(SystemUIFactory.getInstance().getRootComponent()),
206 new NotificationRowComponent.Builder() {
207 @Override
208 public NotificationRowComponent.Builder activatableNotificationView(
209 ActivatableNotificationView view) {
210 return this;
211 }
212
213 @Override
214 public NotificationRowComponent build() {
215 return mNotificationRowComponent;
216 }
Dave Mankoffc0d9a7d2020-02-27 17:15:52 -0500217 },
218 mLockIconController);
Heemin Seogafb3dbc2019-11-04 16:05:19 -0800219
Mady Mellorebdbbb92018-11-15 14:36:48 -0800220 // Bubbles get added to status bar window view
wilsonshihe8321942019-10-18 18:39:46 +0800221 mNotificationShadeWindowController = new NotificationShadeWindowController(mContext,
222 mWindowManager, mActivityManager, mDozeParameters, mStatusBarStateController,
Lucas Dupind73410a2020-02-18 12:54:41 -0800223 mConfigurationController, mKeyguardBypassController, mColorExtractor,
Ned Burnsaaeb44b2020-02-12 23:48:26 -0500224 mDumpManager);
Fabian Kozynskib00c70b2020-04-03 12:41:31 -0400225 mNotificationShadeWindowController.setNotificationShadeView(mNotificationShadeWindowView);
wilsonshihe8321942019-10-18 18:39:46 +0800226 mNotificationShadeWindowController.attach();
Mady Mellorebdbbb92018-11-15 14:36:48 -0800227
228 // Need notifications for bubbles
Kevin Hana7c21be2020-04-01 17:58:35 -0700229 mNotificationTestHelper = new NotificationTestHelper(
230 mContext,
231 mDependency,
232 TestableLooper.get(this));
Mark Renouf08bc42a2019-03-07 13:01:59 -0500233 mRow = mNotificationTestHelper.createBubble(mDeleteIntent);
234 mRow2 = mNotificationTestHelper.createBubble(mDeleteIntent);
Mady Mellorfc02cc32019-04-01 14:47:55 -0700235 mNonBubbleNotifRow = mNotificationTestHelper.createRow();
Mady Mellor3ed46202019-03-26 20:22:35 -0700236
Ned Burns01e38212019-01-03 16:32:52 -0500237 // Return non-null notification data from the NEM
Evan Laird181de622019-10-24 09:53:02 -0400238 when(mNotificationEntryManager
239 .getActiveNotificationUnfiltered(mRow.getEntry().getKey())).thenReturn(
240 mRow.getEntry());
Ned Burns01e38212019-01-03 16:32:52 -0500241
Joshua Tsujidd4d9f92019-05-13 13:57:38 -0400242 mZenModeConfig.suppressedVisualEffects = 0;
243 when(mZenModeController.getConfig()).thenReturn(mZenModeConfig);
244
Joshua Tsujibe60a582020-03-23 17:17:26 -0400245 mSysUiState = new SysUiState();
246 mSysUiState.addCallback(sysUiFlags ->
247 mSysUiStateBubblesExpanded =
248 (sysUiFlags & QuickStepContract.SYSUI_STATE_BUBBLES_EXPANDED) != 0);
249
Beverly Taid1e175c2020-03-10 16:37:04 +0000250 TestableNotificationInterruptStateProviderImpl interruptionStateProvider =
251 new TestableNotificationInterruptStateProviderImpl(mContext.getContentResolver(),
252 mock(PowerManager.class),
253 mock(IDreamManager.class),
254 mock(AmbientDisplayConfiguration.class),
Mady Mellorc55b4122019-06-07 18:14:02 -0700255 mock(NotificationFilter.class),
Lucas Dupinbd7366d2019-09-25 13:39:21 -0700256 mock(StatusBarStateController.class),
Beverly Taid1e175c2020-03-10 16:37:04 +0000257 mock(BatteryController.class),
258 mock(HeadsUpManager.class),
259 mock(Handler.class)
260 );
Mark Renouf71a3af62019-04-08 15:02:54 -0400261 mBubbleData = new BubbleData(mContext);
Beverlya53fb0d2020-01-29 15:26:13 -0500262 when(mFeatureFlagsOldPipeline.isNewNotifPipelineRenderingEnabled()).thenReturn(false);
Ned Burnsaaeb44b2020-02-12 23:48:26 -0500263 mBubbleController = new TestableBubbleController(
264 mContext,
wilsonshihe8321942019-10-18 18:39:46 +0800265 mNotificationShadeWindowController,
Mady Mellor7f234902019-10-20 12:06:29 -0700266 mStatusBarStateController,
267 mShadeController,
Mady Mellor22f2f072019-04-18 13:26:18 -0700268 mBubbleData,
269 mConfigurationController,
270 interruptionStateProvider,
271 mZenModeController,
272 mLockscreenUserManager,
Mady Mellor7f234902019-10-20 12:06:29 -0700273 mNotificationGroupManager,
Beverlya53fb0d2020-01-29 15:26:13 -0500274 mNotificationEntryManager,
275 mNotifPipeline,
276 mFeatureFlagsOldPipeline,
Ned Burnsaaeb44b2020-02-12 23:48:26 -0500277 mDumpManager,
Joshua Tsujibe60a582020-03-23 17:17:26 -0400278 mFloatingContentCoordinator,
Mady Mellor9adfe6a2020-03-30 17:23:26 -0700279 mSysUiState,
280 mock(INotificationManager.class));
Mady Melloracb12152019-01-29 15:24:48 -0800281 mBubbleController.setBubbleStateChangeListener(mBubbleStateChangeListener);
282 mBubbleController.setExpandListener(mBubbleExpandListener);
Ned Burns01e38212019-01-03 16:32:52 -0500283
284 // Get a reference to the BubbleController's entry listener
285 verify(mNotificationEntryManager, atLeastOnce())
286 .addNotificationEntryListener(mEntryListenerCaptor.capture());
287 mEntryListener = mEntryListenerCaptor.getValue();
Mady Mellorc2ff0112019-03-28 14:18:06 -0700288 // And the remove interceptor
289 verify(mNotificationEntryManager, atLeastOnce())
Evan Laird04373662020-01-24 17:37:39 -0500290 .addNotificationRemoveInterceptor(mRemoveInterceptorCaptor.capture());
Mady Mellorc2ff0112019-03-28 14:18:06 -0700291 mRemoveInterceptor = mRemoveInterceptorCaptor.getValue();
Mady Mellorebdbbb92018-11-15 14:36:48 -0800292 }
293
294 @Test
Mady Mellorebdbbb92018-11-15 14:36:48 -0800295 public void testAddBubble() {
Mark Renouff97ed462019-04-05 13:46:24 -0400296 mBubbleController.updateBubble(mRow.getEntry());
Mady Mellorebdbbb92018-11-15 14:36:48 -0800297 assertTrue(mBubbleController.hasBubbles());
Mady Melloracb12152019-01-29 15:24:48 -0800298
299 verify(mBubbleStateChangeListener).onHasBubblesChanged(true);
Joshua Tsujibe60a582020-03-23 17:17:26 -0400300 assertFalse(mSysUiStateBubblesExpanded);
Mady Mellorebdbbb92018-11-15 14:36:48 -0800301 }
302
303 @Test
304 public void testHasBubbles() {
305 assertFalse(mBubbleController.hasBubbles());
Mark Renouff97ed462019-04-05 13:46:24 -0400306 mBubbleController.updateBubble(mRow.getEntry());
Mady Mellorebdbbb92018-11-15 14:36:48 -0800307 assertTrue(mBubbleController.hasBubbles());
Joshua Tsujibe60a582020-03-23 17:17:26 -0400308 assertFalse(mSysUiStateBubblesExpanded);
Mady Mellorebdbbb92018-11-15 14:36:48 -0800309 }
310
311 @Test
312 public void testRemoveBubble() {
Mark Renouff97ed462019-04-05 13:46:24 -0400313 mBubbleController.updateBubble(mRow.getEntry());
Ned Burns00b4b2d2019-10-17 22:09:27 -0400314 assertNotNull(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()));
Mady Mellorebdbbb92018-11-15 14:36:48 -0800315 assertTrue(mBubbleController.hasBubbles());
Beverly85d4c192019-09-30 11:40:39 -0400316 verify(mNotificationEntryManager).updateNotifications(any());
Mady Melloracb12152019-01-29 15:24:48 -0800317 verify(mBubbleStateChangeListener).onHasBubblesChanged(true);
318
Ned Burns00b4b2d2019-10-17 22:09:27 -0400319 mBubbleController.removeBubble(
Beverlya53fb0d2020-01-29 15:26:13 -0500320 mRow.getEntry(), BubbleController.DISMISS_USER_GESTURE);
wilsonshihe8321942019-10-18 18:39:46 +0800321 assertFalse(mNotificationShadeWindowController.getBubblesShowing());
Ned Burns00b4b2d2019-10-17 22:09:27 -0400322 assertNull(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()));
Beverly85d4c192019-09-30 11:40:39 -0400323 verify(mNotificationEntryManager, times(2)).updateNotifications(anyString());
Mady Melloracb12152019-01-29 15:24:48 -0800324 verify(mBubbleStateChangeListener).onHasBubblesChanged(false);
Joshua Tsujibe60a582020-03-23 17:17:26 -0400325
326 assertFalse(mSysUiStateBubblesExpanded);
Mady Mellorebdbbb92018-11-15 14:36:48 -0800327 }
328
329 @Test
Lyn Han89274b42020-03-25 00:56:26 -0700330 public void testPromoteBubble_autoExpand() {
331 mBubbleController.updateBubble(mRow2.getEntry());
332 mBubbleController.updateBubble(mRow.getEntry());
333 mBubbleController.removeBubble(
334 mRow.getEntry(), BubbleController.DISMISS_USER_GESTURE);
335
336 Bubble b = mBubbleData.getOverflowBubbleWithKey(mRow.getEntry().getKey());
337 assertThat(mBubbleData.getOverflowBubbles()).isEqualTo(ImmutableList.of(b));
338
339 Bubble b2 = mBubbleData.getBubbleWithKey(mRow2.getEntry().getKey());
340 assertThat(mBubbleData.getSelectedBubble()).isEqualTo(b2);
341
342 mBubbleController.promoteBubbleFromOverflow(b);
343 assertThat(mBubbleData.getSelectedBubble()).isEqualTo(b);
344 }
345
346 @Test
Mady Mellorc2ff0112019-03-28 14:18:06 -0700347 public void testRemoveBubble_withDismissedNotif() {
Mady Mellor78133512020-01-31 08:45:52 -0800348 mEntryListener.onPendingEntryAdded(mRow.getEntry());
Mady Mellorc2ff0112019-03-28 14:18:06 -0700349 mBubbleController.updateBubble(mRow.getEntry());
350
351 assertTrue(mBubbleController.hasBubbles());
Ned Burns00b4b2d2019-10-17 22:09:27 -0400352 assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500353 mRow.getEntry()));
Mady Mellorc2ff0112019-03-28 14:18:06 -0700354
355 // Make it look like dismissed notif
Mady Mellorf44b6832020-01-14 13:26:14 -0800356 mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).setSuppressNotification(true);
Mady Mellorc2ff0112019-03-28 14:18:06 -0700357
358 // Now remove the bubble
Ned Burns00b4b2d2019-10-17 22:09:27 -0400359 mBubbleController.removeBubble(
Beverlya53fb0d2020-01-29 15:26:13 -0500360 mRow.getEntry(), BubbleController.DISMISS_USER_GESTURE);
Mady Mellorc2ff0112019-03-28 14:18:06 -0700361
362 // Since the notif is dismissed, once the bubble is removed, performRemoveNotification gets
363 // called to really remove the notif
364 verify(mNotificationEntryManager, times(1)).performRemoveNotification(
Beverlya53fb0d2020-01-29 15:26:13 -0500365 eq(mRow.getEntry().getSbn()), anyInt());
Mady Mellorc2ff0112019-03-28 14:18:06 -0700366 assertFalse(mBubbleController.hasBubbles());
Joshua Tsujibe60a582020-03-23 17:17:26 -0400367
368 assertFalse(mSysUiStateBubblesExpanded);
Mady Mellorc2ff0112019-03-28 14:18:06 -0700369 }
370
371 @Test
Mady Mellorebdbbb92018-11-15 14:36:48 -0800372 public void testDismissStack() {
Mark Renouff97ed462019-04-05 13:46:24 -0400373 mBubbleController.updateBubble(mRow.getEntry());
Beverly85d4c192019-09-30 11:40:39 -0400374 verify(mNotificationEntryManager, times(1)).updateNotifications(any());
Ned Burns00b4b2d2019-10-17 22:09:27 -0400375 assertNotNull(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()));
Mark Renouff97ed462019-04-05 13:46:24 -0400376 mBubbleController.updateBubble(mRow2.getEntry());
Beverly85d4c192019-09-30 11:40:39 -0400377 verify(mNotificationEntryManager, times(2)).updateNotifications(any());
Ned Burns00b4b2d2019-10-17 22:09:27 -0400378 assertNotNull(mBubbleData.getBubbleWithKey(mRow2.getEntry().getKey()));
Mady Mellorebdbbb92018-11-15 14:36:48 -0800379 assertTrue(mBubbleController.hasBubbles());
380
Joshua Tsuji7dd88b02020-03-27 17:43:09 -0400381 mBubbleData.dismissAll(BubbleController.DISMISS_USER_GESTURE);
wilsonshihe8321942019-10-18 18:39:46 +0800382 assertFalse(mNotificationShadeWindowController.getBubblesShowing());
Beverly85d4c192019-09-30 11:40:39 -0400383 verify(mNotificationEntryManager, times(3)).updateNotifications(any());
Ned Burns00b4b2d2019-10-17 22:09:27 -0400384 assertNull(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()));
385 assertNull(mBubbleData.getBubbleWithKey(mRow2.getEntry().getKey()));
Joshua Tsujibe60a582020-03-23 17:17:26 -0400386
387 assertFalse(mSysUiStateBubblesExpanded);
Mady Mellorebdbbb92018-11-15 14:36:48 -0800388 }
389
390 @Test
Mady Melloracb12152019-01-29 15:24:48 -0800391 public void testExpandCollapseStack() {
Mady Mellorebdbbb92018-11-15 14:36:48 -0800392 assertFalse(mBubbleController.isStackExpanded());
Mady Melloracb12152019-01-29 15:24:48 -0800393
394 // Mark it as a bubble and add it explicitly
Mady Mellor78133512020-01-31 08:45:52 -0800395 mEntryListener.onPendingEntryAdded(mRow.getEntry());
Mark Renouff97ed462019-04-05 13:46:24 -0400396 mBubbleController.updateBubble(mRow.getEntry());
Mady Mellorebdbbb92018-11-15 14:36:48 -0800397
Mady Mellorce23c462019-06-17 17:30:07 -0700398 // We should have bubbles & their notifs should not be suppressed
Mady Melloracb12152019-01-29 15:24:48 -0800399 assertTrue(mBubbleController.hasBubbles());
Ned Burns00b4b2d2019-10-17 22:09:27 -0400400 assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500401 mRow.getEntry()));
wilsonshihe8321942019-10-18 18:39:46 +0800402 assertFalse(mNotificationShadeWindowController.getBubbleExpanded());
Mady Melloracb12152019-01-29 15:24:48 -0800403
404 // Expand the stack
Mady Mellorebdbbb92018-11-15 14:36:48 -0800405 BubbleStackView stackView = mBubbleController.getStackView();
Joshua Tsuji7dd88b02020-03-27 17:43:09 -0400406 mBubbleData.setExpanded(true);
Mady Mellorebdbbb92018-11-15 14:36:48 -0800407 assertTrue(mBubbleController.isStackExpanded());
Ned Burns00b4b2d2019-10-17 22:09:27 -0400408 verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().getKey());
wilsonshihe8321942019-10-18 18:39:46 +0800409 assertTrue(mNotificationShadeWindowController.getBubbleExpanded());
Mady Mellorebdbbb92018-11-15 14:36:48 -0800410
Joshua Tsujibe60a582020-03-23 17:17:26 -0400411 assertTrue(mSysUiStateBubblesExpanded);
412
Mady Mellorce23c462019-06-17 17:30:07 -0700413 // Make sure the notif is suppressed
Ned Burns00b4b2d2019-10-17 22:09:27 -0400414 assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500415 mRow.getEntry()));
Mady Melloracb12152019-01-29 15:24:48 -0800416
417 // Collapse
Mark Renouf71a3af62019-04-08 15:02:54 -0400418 mBubbleController.collapseStack();
Ned Burns00b4b2d2019-10-17 22:09:27 -0400419 verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow.getEntry().getKey());
Mady Mellorebdbbb92018-11-15 14:36:48 -0800420 assertFalse(mBubbleController.isStackExpanded());
wilsonshihe8321942019-10-18 18:39:46 +0800421 assertFalse(mNotificationShadeWindowController.getBubbleExpanded());
Joshua Tsujibe60a582020-03-23 17:17:26 -0400422
423 assertFalse(mSysUiStateBubblesExpanded);
Mady Mellorebdbbb92018-11-15 14:36:48 -0800424 }
425
426 @Test
Mady Melloracb12152019-01-29 15:24:48 -0800427 public void testCollapseAfterChangingExpandedBubble() {
428 // Mark it as a bubble and add it explicitly
Mady Mellor78133512020-01-31 08:45:52 -0800429 mEntryListener.onPendingEntryAdded(mRow.getEntry());
430 mEntryListener.onPendingEntryAdded(mRow2.getEntry());
Mark Renouff97ed462019-04-05 13:46:24 -0400431 mBubbleController.updateBubble(mRow.getEntry());
432 mBubbleController.updateBubble(mRow2.getEntry());
Mady Mellorebdbbb92018-11-15 14:36:48 -0800433
Mady Mellorce23c462019-06-17 17:30:07 -0700434 // We should have bubbles & their notifs should not be suppressed
Mady Melloracb12152019-01-29 15:24:48 -0800435 assertTrue(mBubbleController.hasBubbles());
Mady Mellorce23c462019-06-17 17:30:07 -0700436 assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500437 mRow.getEntry()));
Ned Burns00b4b2d2019-10-17 22:09:27 -0400438 assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500439 mRow2.getEntry()));
Mady Melloracb12152019-01-29 15:24:48 -0800440
441 // Expand
Mady Mellorebdbbb92018-11-15 14:36:48 -0800442 BubbleStackView stackView = mBubbleController.getStackView();
Joshua Tsuji7dd88b02020-03-27 17:43:09 -0400443 mBubbleData.setExpanded(true);
Mady Mellorebdbbb92018-11-15 14:36:48 -0800444 assertTrue(mBubbleController.isStackExpanded());
Ned Burns00b4b2d2019-10-17 22:09:27 -0400445 verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow2.getEntry().getKey());
Mady Mellorebdbbb92018-11-15 14:36:48 -0800446
Joshua Tsujibe60a582020-03-23 17:17:26 -0400447 assertTrue(mSysUiStateBubblesExpanded);
448
Mark Renoufba5ab512019-05-02 15:21:01 -0400449 // Last added is the one that is expanded
Mady Mellorb8aaf972019-11-26 10:28:00 -0800450 assertEquals(mRow2.getEntry(), mBubbleData.getSelectedBubble().getEntry());
Ned Burns00b4b2d2019-10-17 22:09:27 -0400451 assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500452 mRow2.getEntry()));
Mark Renouf71a3af62019-04-08 15:02:54 -0400453
Mark Renoufba5ab512019-05-02 15:21:01 -0400454 // Switch which bubble is expanded
Joshua Tsuji7dd88b02020-03-27 17:43:09 -0400455 mBubbleData.setSelectedBubble(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()));
Mady Mellorf44b6832020-01-14 13:26:14 -0800456 mBubbleData.setExpanded(true);
Lyn Han9f66c3b2020-03-05 23:59:29 -0800457 assertEquals(mRow.getEntry(),
458 mBubbleData.getBubbleWithKey(stackView.getExpandedBubble().getKey()).getEntry());
Ned Burns00b4b2d2019-10-17 22:09:27 -0400459 assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500460 mRow.getEntry()));
Mark Renoufba5ab512019-05-02 15:21:01 -0400461
Mady Melloracb12152019-01-29 15:24:48 -0800462 // collapse for previous bubble
Ned Burns00b4b2d2019-10-17 22:09:27 -0400463 verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow2.getEntry().getKey());
Mady Melloracb12152019-01-29 15:24:48 -0800464 // expand for selected bubble
Ned Burns00b4b2d2019-10-17 22:09:27 -0400465 verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().getKey());
Mady Melloredd4ee12019-01-18 10:45:11 -0800466
Mady Melloracb12152019-01-29 15:24:48 -0800467 // Collapse
Mady Mellorebdbbb92018-11-15 14:36:48 -0800468 mBubbleController.collapseStack();
469 assertFalse(mBubbleController.isStackExpanded());
Joshua Tsujibe60a582020-03-23 17:17:26 -0400470
471 assertFalse(mSysUiStateBubblesExpanded);
Mady Mellorebdbbb92018-11-15 14:36:48 -0800472 }
473
Ned Burns01e38212019-01-03 16:32:52 -0500474 @Test
Mady Melloraea895f02019-07-10 14:37:48 -0700475 public void testExpansionRemovesShowInShadeAndDot() {
Mady Melloracb12152019-01-29 15:24:48 -0800476 // Mark it as a bubble and add it explicitly
Mady Mellor78133512020-01-31 08:45:52 -0800477 mEntryListener.onPendingEntryAdded(mRow.getEntry());
Mark Renouff97ed462019-04-05 13:46:24 -0400478 mBubbleController.updateBubble(mRow.getEntry());
Mady Melloracb12152019-01-29 15:24:48 -0800479
Mady Mellorce23c462019-06-17 17:30:07 -0700480 // We should have bubbles & their notifs should not be suppressed
Mady Melloracb12152019-01-29 15:24:48 -0800481 assertTrue(mBubbleController.hasBubbles());
Ned Burns00b4b2d2019-10-17 22:09:27 -0400482 assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500483 mRow.getEntry()));
Mady Mellorb8aaf972019-11-26 10:28:00 -0800484
485 mTestableLooper.processAllMessages();
486 assertTrue(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showDot());
Mady Melloracb12152019-01-29 15:24:48 -0800487
488 // Expand
Joshua Tsuji7dd88b02020-03-27 17:43:09 -0400489 mBubbleData.setExpanded(true);
Mady Melloracb12152019-01-29 15:24:48 -0800490 assertTrue(mBubbleController.isStackExpanded());
Ned Burns00b4b2d2019-10-17 22:09:27 -0400491 verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().getKey());
Mady Melloracb12152019-01-29 15:24:48 -0800492
Joshua Tsujibe60a582020-03-23 17:17:26 -0400493 assertTrue(mSysUiStateBubblesExpanded);
494
Mady Mellorce23c462019-06-17 17:30:07 -0700495 // Notif is suppressed after expansion
Ned Burns00b4b2d2019-10-17 22:09:27 -0400496 assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500497 mRow.getEntry()));
Mady Melloraea895f02019-07-10 14:37:48 -0700498 // Notif shouldn't show dot after expansion
Mady Mellorb8aaf972019-11-26 10:28:00 -0800499 assertFalse(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showDot());
Mady Melloraea895f02019-07-10 14:37:48 -0700500 }
501
502 @Test
503 public void testUpdateWhileExpanded_DoesntChangeShowInShadeAndDot() {
504 // Mark it as a bubble and add it explicitly
Mady Mellor78133512020-01-31 08:45:52 -0800505 mEntryListener.onPendingEntryAdded(mRow.getEntry());
Mady Melloraea895f02019-07-10 14:37:48 -0700506 mBubbleController.updateBubble(mRow.getEntry());
507
508 // We should have bubbles & their notifs should not be suppressed
509 assertTrue(mBubbleController.hasBubbles());
Ned Burns00b4b2d2019-10-17 22:09:27 -0400510 assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500511 mRow.getEntry()));
Mady Mellorb8aaf972019-11-26 10:28:00 -0800512
513 mTestableLooper.processAllMessages();
514 assertTrue(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showDot());
Mady Melloraea895f02019-07-10 14:37:48 -0700515
516 // Expand
Joshua Tsuji7dd88b02020-03-27 17:43:09 -0400517 mBubbleData.setExpanded(true);
Mady Melloraea895f02019-07-10 14:37:48 -0700518 assertTrue(mBubbleController.isStackExpanded());
Ned Burns00b4b2d2019-10-17 22:09:27 -0400519 verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().getKey());
Mady Melloraea895f02019-07-10 14:37:48 -0700520
Joshua Tsujibe60a582020-03-23 17:17:26 -0400521 assertTrue(mSysUiStateBubblesExpanded);
522
Mady Melloraea895f02019-07-10 14:37:48 -0700523 // Notif is suppressed after expansion
Ned Burns00b4b2d2019-10-17 22:09:27 -0400524 assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500525 mRow.getEntry()));
Mady Melloraea895f02019-07-10 14:37:48 -0700526 // Notif shouldn't show dot after expansion
Mady Mellorb8aaf972019-11-26 10:28:00 -0800527 assertFalse(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showDot());
Mady Melloraea895f02019-07-10 14:37:48 -0700528
529 // Send update
530 mEntryListener.onPreEntryUpdated(mRow.getEntry());
531
532 // Nothing should have changed
533 // Notif is suppressed after expansion
Ned Burns00b4b2d2019-10-17 22:09:27 -0400534 assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500535 mRow.getEntry()));
Mady Melloraea895f02019-07-10 14:37:48 -0700536 // Notif shouldn't show dot after expansion
Mady Mellorb8aaf972019-11-26 10:28:00 -0800537 assertFalse(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showDot());
Mady Melloracb12152019-01-29 15:24:48 -0800538 }
539
540 @Test
541 public void testRemoveLastExpandedCollapses() {
542 // Mark it as a bubble and add it explicitly
Mady Mellor78133512020-01-31 08:45:52 -0800543 mEntryListener.onPendingEntryAdded(mRow.getEntry());
544 mEntryListener.onPendingEntryAdded(mRow2.getEntry());
Mark Renouff97ed462019-04-05 13:46:24 -0400545 mBubbleController.updateBubble(mRow.getEntry());
546 mBubbleController.updateBubble(mRow2.getEntry());
Mady Melloracb12152019-01-29 15:24:48 -0800547 verify(mBubbleStateChangeListener).onHasBubblesChanged(true);
548
549 // Expand
550 BubbleStackView stackView = mBubbleController.getStackView();
Joshua Tsuji7dd88b02020-03-27 17:43:09 -0400551 mBubbleData.setExpanded(true);
Mady Melloracb12152019-01-29 15:24:48 -0800552
Joshua Tsujibe60a582020-03-23 17:17:26 -0400553 assertTrue(mSysUiStateBubblesExpanded);
554
Mady Melloracb12152019-01-29 15:24:48 -0800555 assertTrue(mBubbleController.isStackExpanded());
Ned Burns00b4b2d2019-10-17 22:09:27 -0400556 verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow2.getEntry().getKey());
Mady Melloracb12152019-01-29 15:24:48 -0800557
Mark Renoufba5ab512019-05-02 15:21:01 -0400558 // Last added is the one that is expanded
Lyn Han9f66c3b2020-03-05 23:59:29 -0800559 assertEquals(mRow2.getEntry(),
560 mBubbleData.getBubbleWithKey(stackView.getExpandedBubble().getKey()).getEntry());
Ned Burns00b4b2d2019-10-17 22:09:27 -0400561 assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500562 mRow2.getEntry()));
Mady Melloracb12152019-01-29 15:24:48 -0800563
564 // Dismiss currently expanded
Lyn Han9f66c3b2020-03-05 23:59:29 -0800565 mBubbleController.removeBubble(
566 mBubbleData.getBubbleWithKey(stackView.getExpandedBubble().getKey()).getEntry(),
Mark Renouf08bc42a2019-03-07 13:01:59 -0500567 BubbleController.DISMISS_USER_GESTURE);
Ned Burns00b4b2d2019-10-17 22:09:27 -0400568 verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow2.getEntry().getKey());
Mady Melloracb12152019-01-29 15:24:48 -0800569
Mark Renoufba5ab512019-05-02 15:21:01 -0400570 // Make sure first bubble is selected
Lyn Han9f66c3b2020-03-05 23:59:29 -0800571 assertEquals(mRow.getEntry(),
572 mBubbleData.getBubbleWithKey(stackView.getExpandedBubble().getKey()).getEntry());
Ned Burns00b4b2d2019-10-17 22:09:27 -0400573 verify(mBubbleExpandListener).onBubbleExpandChanged(true, mRow.getEntry().getKey());
Mady Melloracb12152019-01-29 15:24:48 -0800574
575 // Dismiss that one
Lyn Han9f66c3b2020-03-05 23:59:29 -0800576 mBubbleController.removeBubble(
577 mBubbleData.getBubbleWithKey(stackView.getExpandedBubble().getKey()).getEntry(),
Mark Renouf08bc42a2019-03-07 13:01:59 -0500578 BubbleController.DISMISS_USER_GESTURE);
Mady Melloracb12152019-01-29 15:24:48 -0800579
580 // Make sure state changes and collapse happens
Ned Burns00b4b2d2019-10-17 22:09:27 -0400581 verify(mBubbleExpandListener).onBubbleExpandChanged(false, mRow.getEntry().getKey());
Mady Melloracb12152019-01-29 15:24:48 -0800582 verify(mBubbleStateChangeListener).onHasBubblesChanged(false);
583 assertFalse(mBubbleController.hasBubbles());
Joshua Tsujibe60a582020-03-23 17:17:26 -0400584
585 assertFalse(mSysUiStateBubblesExpanded);
Mady Melloracb12152019-01-29 15:24:48 -0800586 }
587
588 @Test
Mady Mellorb25f9062019-12-09 12:12:57 -0800589 public void testAutoExpand_fails_noFlag() {
Mady Mellore80930e2019-03-21 16:00:45 -0700590 assertFalse(mBubbleController.isStackExpanded());
Mady Mellor8d25b202019-06-25 13:59:28 -0700591 setMetadataFlags(mRow.getEntry(),
592 Notification.BubbleMetadata.FLAG_AUTO_EXPAND_BUBBLE, false /* enableFlag */);
Mady Mellore80930e2019-03-21 16:00:45 -0700593
594 // Add the auto expand bubble
Mady Mellor78133512020-01-31 08:45:52 -0800595 mEntryListener.onPendingEntryAdded(mRow.getEntry());
Mady Mellor8d25b202019-06-25 13:59:28 -0700596 mBubbleController.updateBubble(mRow.getEntry());
Mady Mellore80930e2019-03-21 16:00:45 -0700597
598 // Expansion shouldn't change
599 verify(mBubbleExpandListener, never()).onBubbleExpandChanged(false /* expanded */,
Ned Burns00b4b2d2019-10-17 22:09:27 -0400600 mRow.getEntry().getKey());
Mady Mellore80930e2019-03-21 16:00:45 -0700601 assertFalse(mBubbleController.isStackExpanded());
602
603 // # of bubbles should change
604 verify(mBubbleStateChangeListener).onHasBubblesChanged(true /* hasBubbles */);
Joshua Tsujibe60a582020-03-23 17:17:26 -0400605
606 assertFalse(mSysUiStateBubblesExpanded);
Mady Mellore80930e2019-03-21 16:00:45 -0700607 }
608
609 @Test
Mady Mellorb25f9062019-12-09 12:12:57 -0800610 public void testAutoExpand_succeeds_withFlag() {
Mady Mellor8d25b202019-06-25 13:59:28 -0700611 setMetadataFlags(mRow.getEntry(),
612 Notification.BubbleMetadata.FLAG_AUTO_EXPAND_BUBBLE, true /* enableFlag */);
Mady Mellore80930e2019-03-21 16:00:45 -0700613
614 // Add the auto expand bubble
Mady Mellor78133512020-01-31 08:45:52 -0800615 mEntryListener.onPendingEntryAdded(mRow.getEntry());
Mady Mellor8d25b202019-06-25 13:59:28 -0700616 mBubbleController.updateBubble(mRow.getEntry());
Mady Mellore80930e2019-03-21 16:00:45 -0700617
618 // Expansion should change
619 verify(mBubbleExpandListener).onBubbleExpandChanged(true /* expanded */,
Ned Burns00b4b2d2019-10-17 22:09:27 -0400620 mRow.getEntry().getKey());
Mady Mellore80930e2019-03-21 16:00:45 -0700621 assertTrue(mBubbleController.isStackExpanded());
622
623 // # of bubbles should change
624 verify(mBubbleStateChangeListener).onHasBubblesChanged(true /* hasBubbles */);
Joshua Tsujibe60a582020-03-23 17:17:26 -0400625
626 assertTrue(mSysUiStateBubblesExpanded);
Mady Mellore80930e2019-03-21 16:00:45 -0700627 }
628
Mady Mellor3ed46202019-03-26 20:22:35 -0700629 @Test
Mady Mellorb25f9062019-12-09 12:12:57 -0800630 public void testSuppressNotif_onInitialNotif() {
Mady Mellor8d25b202019-06-25 13:59:28 -0700631 setMetadataFlags(mRow.getEntry(),
632 Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION, true /* enableFlag */);
Mady Mellor3ed46202019-03-26 20:22:35 -0700633
634 // Add the suppress notif bubble
Mady Mellor78133512020-01-31 08:45:52 -0800635 mEntryListener.onPendingEntryAdded(mRow.getEntry());
Mady Mellor8d25b202019-06-25 13:59:28 -0700636 mBubbleController.updateBubble(mRow.getEntry());
Mady Mellor3ed46202019-03-26 20:22:35 -0700637
Mady Mellorce23c462019-06-17 17:30:07 -0700638 // Notif should be suppressed because we were foreground
Ned Burns00b4b2d2019-10-17 22:09:27 -0400639 assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500640 mRow.getEntry()));
Mady Mellorb25f9062019-12-09 12:12:57 -0800641 // Dot + flyout is hidden because notif is suppressed
642 assertFalse(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showDot());
643 assertFalse(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showFlyout());
Mady Mellor3ed46202019-03-26 20:22:35 -0700644
645 // # of bubbles should change
646 verify(mBubbleStateChangeListener).onHasBubblesChanged(true /* hasBubbles */);
Joshua Tsujibe60a582020-03-23 17:17:26 -0400647
648 assertFalse(mSysUiStateBubblesExpanded);
Mady Mellor3ed46202019-03-26 20:22:35 -0700649 }
Mady Mellore80930e2019-03-21 16:00:45 -0700650
651 @Test
Mady Mellorb25f9062019-12-09 12:12:57 -0800652 public void testSuppressNotif_onUpdateNotif() {
653 mBubbleController.updateBubble(mRow.getEntry());
654
655 // Should not be suppressed
656 assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500657 mRow.getEntry()));
Mady Mellorb25f9062019-12-09 12:12:57 -0800658 // Should show dot
659 assertTrue(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showDot());
660
661 // Update to suppress notif
662 setMetadataFlags(mRow.getEntry(),
663 Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION, true /* enableFlag */);
664 mBubbleController.updateBubble(mRow.getEntry());
665
666 // Notif should be suppressed
667 assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500668 mRow.getEntry()));
Mady Mellorb25f9062019-12-09 12:12:57 -0800669 // Dot + flyout is hidden because notif is suppressed
670 assertFalse(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showDot());
671 assertFalse(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showFlyout());
672
673 // # of bubbles should change
674 verify(mBubbleStateChangeListener).onHasBubblesChanged(true /* hasBubbles */);
Joshua Tsujibe60a582020-03-23 17:17:26 -0400675
676 assertFalse(mSysUiStateBubblesExpanded);
Mady Mellorb25f9062019-12-09 12:12:57 -0800677 }
678
Mady Mellorb25f9062019-12-09 12:12:57 -0800679 @Test
Mark Renouffec45da2019-03-13 13:24:27 -0400680 public void testExpandStackAndSelectBubble_removedFirst() {
Ned Burns00b4b2d2019-10-17 22:09:27 -0400681 final String key = mRow.getEntry().getKey();
Mark Renouffec45da2019-03-13 13:24:27 -0400682
Mady Mellor78133512020-01-31 08:45:52 -0800683 mEntryListener.onPendingEntryAdded(mRow.getEntry());
Mark Renouff97ed462019-04-05 13:46:24 -0400684 mBubbleController.updateBubble(mRow.getEntry());
Mark Renouffec45da2019-03-13 13:24:27 -0400685
Mark Renouffec45da2019-03-13 13:24:27 -0400686 // Simulate notification cancellation.
Ned Burns00b4b2d2019-10-17 22:09:27 -0400687 mRemoveInterceptor.onNotificationRemoveRequested(
Evan Laird04373662020-01-24 17:37:39 -0500688 mRow.getEntry().getKey(), mRow.getEntry(), REASON_APP_CANCEL);
Mark Renouffec45da2019-03-13 13:24:27 -0400689
690 mBubbleController.expandStackAndSelectBubble(key);
Joshua Tsujibe60a582020-03-23 17:17:26 -0400691
692 assertTrue(mSysUiStateBubblesExpanded);
Mark Renouffec45da2019-03-13 13:24:27 -0400693 }
694
695 @Test
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800696 public void testMarkNewNotificationAsShowInShade() {
Mady Mellor78133512020-01-31 08:45:52 -0800697 mEntryListener.onPendingEntryAdded(mRow.getEntry());
Ned Burns00b4b2d2019-10-17 22:09:27 -0400698 assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500699 mRow.getEntry()));
Mady Mellorb8aaf972019-11-26 10:28:00 -0800700
701 mTestableLooper.processAllMessages();
702 assertTrue(mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()).showDot());
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800703 }
704
Mark Renouf08bc42a2019-03-07 13:01:59 -0500705 @Test
Mady Mellorfc02cc32019-04-01 14:47:55 -0700706 public void testAddNotif_notBubble() {
Mady Mellor78133512020-01-31 08:45:52 -0800707 mEntryListener.onPendingEntryAdded(mNonBubbleNotifRow.getEntry());
Mady Mellorfc02cc32019-04-01 14:47:55 -0700708 mEntryListener.onPreEntryUpdated(mNonBubbleNotifRow.getEntry());
709
710 verify(mBubbleStateChangeListener, never()).onHasBubblesChanged(anyBoolean());
711 assertThat(mBubbleController.hasBubbles()).isFalse();
712 }
713
714 @Test
Mark Renouf08bc42a2019-03-07 13:01:59 -0500715 public void testDeleteIntent_removeBubble_aged() throws PendingIntent.CanceledException {
Mark Renouff97ed462019-04-05 13:46:24 -0400716 mBubbleController.updateBubble(mRow.getEntry());
Beverlya53fb0d2020-01-29 15:26:13 -0500717 mBubbleController.removeBubble(mRow.getEntry(), BubbleController.DISMISS_AGED);
Mark Renouf08bc42a2019-03-07 13:01:59 -0500718 verify(mDeleteIntent, never()).send();
719 }
720
721 @Test
722 public void testDeleteIntent_removeBubble_user() throws PendingIntent.CanceledException {
Mark Renouff97ed462019-04-05 13:46:24 -0400723 mBubbleController.updateBubble(mRow.getEntry());
Ned Burns00b4b2d2019-10-17 22:09:27 -0400724 mBubbleController.removeBubble(
Beverlya53fb0d2020-01-29 15:26:13 -0500725 mRow.getEntry(), BubbleController.DISMISS_USER_GESTURE);
Mark Renouf08bc42a2019-03-07 13:01:59 -0500726 verify(mDeleteIntent, times(1)).send();
727 }
728
729 @Test
730 public void testDeleteIntent_dismissStack() throws PendingIntent.CanceledException {
Mark Renouff97ed462019-04-05 13:46:24 -0400731 mBubbleController.updateBubble(mRow.getEntry());
732 mBubbleController.updateBubble(mRow2.getEntry());
Joshua Tsuji7dd88b02020-03-27 17:43:09 -0400733 mBubbleData.dismissAll(BubbleController.DISMISS_USER_GESTURE);
Mark Renouf08bc42a2019-03-07 13:01:59 -0500734 verify(mDeleteIntent, times(2)).send();
735 }
736
Mady Melloraa8fef22019-04-11 13:36:40 -0700737 @Test
738 public void testRemoveBubble_noLongerBubbleAfterUpdate()
739 throws PendingIntent.CanceledException {
740 mBubbleController.updateBubble(mRow.getEntry());
741 assertTrue(mBubbleController.hasBubbles());
742
Ned Burns00b4b2d2019-10-17 22:09:27 -0400743 mRow.getEntry().getSbn().getNotification().flags &= ~FLAG_BUBBLE;
Mady Melloraa8fef22019-04-11 13:36:40 -0700744 mEntryListener.onPreEntryUpdated(mRow.getEntry());
745
746 assertFalse(mBubbleController.hasBubbles());
747 verify(mDeleteIntent, never()).send();
748 }
749
Mady Mellorc2ff0112019-03-28 14:18:06 -0700750 @Test
751 public void testRemoveBubble_succeeds_appCancel() {
Mady Mellor78133512020-01-31 08:45:52 -0800752 mEntryListener.onPendingEntryAdded(mRow.getEntry());
Mady Mellorc2ff0112019-03-28 14:18:06 -0700753 mBubbleController.updateBubble(mRow.getEntry());
754
755 assertTrue(mBubbleController.hasBubbles());
756
757 boolean intercepted = mRemoveInterceptor.onNotificationRemoveRequested(
Evan Laird04373662020-01-24 17:37:39 -0500758 mRow.getEntry().getKey(), mRow.getEntry(), REASON_APP_CANCEL);
Mady Mellorc2ff0112019-03-28 14:18:06 -0700759
760 // Cancels always remove so no need to intercept
761 assertFalse(intercepted);
Beverlya53fb0d2020-01-29 15:26:13 -0500762 }
763
764 @Test
765 public void testRemoveBubble_entryListenerRemove() {
766 mEntryListener.onPendingEntryAdded(mRow.getEntry());
767 mBubbleController.updateBubble(mRow.getEntry());
768
769 assertTrue(mBubbleController.hasBubbles());
770
771 // Removes the notification
Julia Reynolds138111f2020-02-26 11:17:39 -0500772 mEntryListener.onEntryRemoved(mRow.getEntry(), null, false, REASON_APP_CANCEL);
Mady Mellorc2ff0112019-03-28 14:18:06 -0700773 assertFalse(mBubbleController.hasBubbles());
774 }
775
776 @Test
Beverlya53fb0d2020-01-29 15:26:13 -0500777 public void removeBubble_clearAllIntercepted() {
Mady Mellor78133512020-01-31 08:45:52 -0800778 mEntryListener.onPendingEntryAdded(mRow.getEntry());
Mady Mellorc2ff0112019-03-28 14:18:06 -0700779 mBubbleController.updateBubble(mRow.getEntry());
780
781 assertTrue(mBubbleController.hasBubbles());
Ned Burns00b4b2d2019-10-17 22:09:27 -0400782 assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500783 mRow.getEntry()));
Mady Mellorc2ff0112019-03-28 14:18:06 -0700784
785 boolean intercepted = mRemoveInterceptor.onNotificationRemoveRequested(
Evan Laird04373662020-01-24 17:37:39 -0500786 mRow.getEntry().getKey(), mRow.getEntry(), REASON_CANCEL_ALL);
Mady Mellorc2ff0112019-03-28 14:18:06 -0700787
788 // Intercept!
789 assertTrue(intercepted);
790 // Should update show in shade state
Ned Burns00b4b2d2019-10-17 22:09:27 -0400791 assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500792 mRow.getEntry()));
Mady Mellorc2ff0112019-03-28 14:18:06 -0700793 }
794
795 @Test
Beverlya53fb0d2020-01-29 15:26:13 -0500796 public void removeBubble_userDismissNotifIntercepted() {
Mady Mellor78133512020-01-31 08:45:52 -0800797 mEntryListener.onPendingEntryAdded(mRow.getEntry());
Mady Mellorc2ff0112019-03-28 14:18:06 -0700798 mBubbleController.updateBubble(mRow.getEntry());
799
800 assertTrue(mBubbleController.hasBubbles());
Ned Burns00b4b2d2019-10-17 22:09:27 -0400801 assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500802 mRow.getEntry()));
Mady Mellorc2ff0112019-03-28 14:18:06 -0700803
804 boolean intercepted = mRemoveInterceptor.onNotificationRemoveRequested(
Evan Laird04373662020-01-24 17:37:39 -0500805 mRow.getEntry().getKey(), mRow.getEntry(), REASON_CANCEL);
Mady Mellorc2ff0112019-03-28 14:18:06 -0700806
807 // Intercept!
808 assertTrue(intercepted);
809 // Should update show in shade state
Ned Burns00b4b2d2019-10-17 22:09:27 -0400810 assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500811 mRow.getEntry()));
Mady Mellorc2ff0112019-03-28 14:18:06 -0700812 }
813
814 @Test
815 public void removeBubble_succeeds_userDismissBubble_userDimissNotif() {
Mady Mellor78133512020-01-31 08:45:52 -0800816 mEntryListener.onPendingEntryAdded(mRow.getEntry());
Mady Mellorc2ff0112019-03-28 14:18:06 -0700817 mBubbleController.updateBubble(mRow.getEntry());
818
819 assertTrue(mBubbleController.hasBubbles());
Ned Burns00b4b2d2019-10-17 22:09:27 -0400820 assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500821 mRow.getEntry()));
Mady Mellorc2ff0112019-03-28 14:18:06 -0700822
823 // Dismiss the bubble
Ned Burns00b4b2d2019-10-17 22:09:27 -0400824 mBubbleController.removeBubble(
Beverlya53fb0d2020-01-29 15:26:13 -0500825 mRow.getEntry(), BubbleController.DISMISS_USER_GESTURE);
Mady Mellorc2ff0112019-03-28 14:18:06 -0700826 assertFalse(mBubbleController.hasBubbles());
827
828 // Dismiss the notification
829 boolean intercepted = mRemoveInterceptor.onNotificationRemoveRequested(
Evan Laird04373662020-01-24 17:37:39 -0500830 mRow.getEntry().getKey(), mRow.getEntry(), REASON_CANCEL);
Mady Mellorc2ff0112019-03-28 14:18:06 -0700831
832 // It's no longer a bubble so we shouldn't intercept
833 assertFalse(intercepted);
834 }
835
Mady Mellorf44b6832020-01-14 13:26:14 -0800836 @Test
837 public void testNotifyShadeSuppressionChange_notificationDismiss() {
838 BubbleController.NotificationSuppressionChangedListener listener =
839 mock(BubbleController.NotificationSuppressionChangedListener.class);
840 mBubbleData.setSuppressionChangedListener(listener);
841
Mady Mellor78133512020-01-31 08:45:52 -0800842 mEntryListener.onPendingEntryAdded(mRow.getEntry());
Mady Mellorf44b6832020-01-14 13:26:14 -0800843
844 assertTrue(mBubbleController.hasBubbles());
845 assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500846 mRow.getEntry()));
Mady Mellorf44b6832020-01-14 13:26:14 -0800847
Evan Laird04373662020-01-24 17:37:39 -0500848 mRemoveInterceptor.onNotificationRemoveRequested(
849 mRow.getEntry().getKey(), mRow.getEntry(), REASON_CANCEL);
Mady Mellorf44b6832020-01-14 13:26:14 -0800850
851 // Should update show in shade state
852 assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500853 mRow.getEntry()));
Mady Mellorf44b6832020-01-14 13:26:14 -0800854
855 // Should notify delegate that shade state changed
856 verify(listener).onBubbleNotificationSuppressionChange(
857 mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()));
858 }
859
860 @Test
861 public void testNotifyShadeSuppressionChange_bubbleExpanded() {
862 BubbleController.NotificationSuppressionChangedListener listener =
863 mock(BubbleController.NotificationSuppressionChangedListener.class);
864 mBubbleData.setSuppressionChangedListener(listener);
865
Mady Mellor78133512020-01-31 08:45:52 -0800866 mEntryListener.onPendingEntryAdded(mRow.getEntry());
Mady Mellorf44b6832020-01-14 13:26:14 -0800867
868 assertTrue(mBubbleController.hasBubbles());
869 assertFalse(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500870 mRow.getEntry()));
Mady Mellorf44b6832020-01-14 13:26:14 -0800871
872 mBubbleData.setExpanded(true);
873
874 // Once a bubble is expanded the notif is suppressed
875 assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade(
Beverlyed8aea22020-01-22 16:52:47 -0500876 mRow.getEntry()));
Mady Mellorf44b6832020-01-14 13:26:14 -0800877
878 // Should notify delegate that shade state changed
879 verify(listener).onBubbleNotificationSuppressionChange(
880 mBubbleData.getBubbleWithKey(mRow.getEntry().getKey()));
881 }
882
Beverlya53fb0d2020-01-29 15:26:13 -0500883 @Test
884 public void testBubbleSummaryDismissal_suppressesSummaryAndBubbleFromShade() throws Exception {
885 // GIVEN a group summary with a bubble child
886 ExpandableNotificationRow groupSummary = mNotificationTestHelper.createGroup(0);
887 ExpandableNotificationRow groupedBubble = mNotificationTestHelper.createBubbleInGroup();
888 mEntryListener.onPendingEntryAdded(groupedBubble.getEntry());
889 groupSummary.addChildNotification(groupedBubble);
890 assertTrue(mBubbleData.hasBubbleWithKey(groupedBubble.getEntry().getKey()));
891
892 // WHEN the summary is dismissed
893 mBubbleController.handleDismissalInterception(groupSummary.getEntry());
894
895 // THEN the summary and bubbled child are suppressed from the shade
896 assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade(
897 groupedBubble.getEntry()));
898 assertTrue(mBubbleData.isSummarySuppressed(groupSummary.getEntry().getSbn().getGroupKey()));
899 }
900
901 @Test
902 public void testAppRemovesSummary_removesAllBubbleChildren() throws Exception {
903 // GIVEN a group summary with a bubble child
904 ExpandableNotificationRow groupSummary = mNotificationTestHelper.createGroup(0);
905 ExpandableNotificationRow groupedBubble = mNotificationTestHelper.createBubbleInGroup();
906 mEntryListener.onPendingEntryAdded(groupedBubble.getEntry());
907 groupSummary.addChildNotification(groupedBubble);
908 assertTrue(mBubbleData.hasBubbleWithKey(groupedBubble.getEntry().getKey()));
909
910 // GIVEN the summary is dismissed
911 mBubbleController.handleDismissalInterception(groupSummary.getEntry());
912
913 // WHEN the summary is cancelled by the app
Julia Reynolds138111f2020-02-26 11:17:39 -0500914 mEntryListener.onEntryRemoved(groupSummary.getEntry(), null, false, REASON_APP_CANCEL);
Beverlya53fb0d2020-01-29 15:26:13 -0500915
916 // THEN the summary and its children are removed from bubble data
917 assertFalse(mBubbleData.hasBubbleWithKey(groupedBubble.getEntry().getKey()));
918 assertFalse(mBubbleData.isSummarySuppressed(
919 groupSummary.getEntry().getSbn().getGroupKey()));
920 }
921
922 @Test
923 public void testSummaryDismissal_marksBubblesHiddenFromShadeAndDismissesNonBubbledChildren()
924 throws Exception {
925 // GIVEN a group summary with two (non-bubble) children and one bubble child
926 ExpandableNotificationRow groupSummary = mNotificationTestHelper.createGroup(2);
927 ExpandableNotificationRow groupedBubble = mNotificationTestHelper.createBubbleInGroup();
928 mEntryListener.onPendingEntryAdded(groupedBubble.getEntry());
929 groupSummary.addChildNotification(groupedBubble);
930
931 // WHEN the summary is dismissed
932 mBubbleController.handleDismissalInterception(groupSummary.getEntry());
933
934 // THEN only the NON-bubble children are dismissed
Kevin Han43077f92020-02-28 12:51:53 -0800935 List<ExpandableNotificationRow> childrenRows = groupSummary.getAttachedChildren();
Beverlya53fb0d2020-01-29 15:26:13 -0500936 verify(mNotificationEntryManager, times(1)).performRemoveNotification(
937 childrenRows.get(0).getEntry().getSbn(), REASON_GROUP_SUMMARY_CANCELED);
938 verify(mNotificationEntryManager, times(1)).performRemoveNotification(
939 childrenRows.get(1).getEntry().getSbn(), REASON_GROUP_SUMMARY_CANCELED);
940 verify(mNotificationEntryManager, never()).performRemoveNotification(
941 eq(groupedBubble.getEntry().getSbn()), anyInt());
942
943 // THEN the bubble child is suppressed from the shade
944 assertTrue(mBubbleController.isBubbleNotificationSuppressedFromShade(
945 groupedBubble.getEntry()));
946
947 // THEN the summary is removed from GroupManager
948 verify(mNotificationGroupManager, times(1)).onEntryRemoved(groupSummary.getEntry());
949 }
950
Mady Mellore80930e2019-03-21 16:00:45 -0700951 /**
Aran Inkc4381c42020-02-06 13:11:53 -0500952 * Sets the bubble metadata flags for this entry. These ]flags are normally set by
Mady Mellor8d25b202019-06-25 13:59:28 -0700953 * NotificationManagerService when the notification is sent, however, these tests do not
954 * go through that path so we set them explicitly when testing.
955 */
956 private void setMetadataFlags(NotificationEntry entry, int flag, boolean enableFlag) {
957 Notification.BubbleMetadata bubbleMetadata =
Ned Burns00b4b2d2019-10-17 22:09:27 -0400958 entry.getSbn().getNotification().getBubbleMetadata();
Mady Mellor8d25b202019-06-25 13:59:28 -0700959 int flags = bubbleMetadata.getFlags();
960 if (enableFlag) {
961 flags |= flag;
962 } else {
963 flags &= ~flag;
964 }
965 bubbleMetadata.setFlags(flags);
966 }
Mady Mellorebdbbb92018-11-15 14:36:48 -0800967}