Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
Julia Reynolds | 138111f | 2020-02-26 11:17:39 -0500 | [diff] [blame] | 19 | import static com.android.systemui.statusbar.notification.NotificationEntryManager.UNDEFINED_DISMISS_REASON; |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 20 | import static com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.FLAG_CONTENT_VIEW_HEADS_UP; |
| 21 | |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 22 | import static org.junit.Assert.assertFalse; |
| 23 | import static org.junit.Assert.assertTrue; |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 24 | import static org.mockito.ArgumentMatchers.any; |
| 25 | import static org.mockito.ArgumentMatchers.eq; |
Kevin | 4b8bbda | 2018-11-19 14:36:31 -0800 | [diff] [blame] | 26 | import static org.mockito.Mockito.doReturn; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 27 | import static org.mockito.Mockito.mock; |
Kevin | 4b8bbda | 2018-11-19 14:36:31 -0800 | [diff] [blame] | 28 | import static org.mockito.Mockito.spy; |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 29 | import static org.mockito.Mockito.verify; |
| 30 | import static org.mockito.Mockito.when; |
| 31 | |
| 32 | import android.app.Notification; |
Kevin | 4b8bbda | 2018-11-19 14:36:31 -0800 | [diff] [blame] | 33 | import android.service.notification.StatusBarNotification; |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 34 | import android.testing.AndroidTestingRunner; |
| 35 | import android.testing.TestableLooper; |
| 36 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 37 | import androidx.test.filters.SmallTest; |
| 38 | |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 39 | import com.android.systemui.SysuiTestCase; |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 40 | import com.android.systemui.bubbles.BubbleController; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 41 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Gus Prevas | d65c2db | 2018-12-18 17:13:38 -0500 | [diff] [blame] | 42 | import com.android.systemui.statusbar.notification.NotificationEntryListener; |
Ned Burns | 3d6b396 | 2018-12-07 21:26:00 -0500 | [diff] [blame] | 43 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 44 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Steve Elliott | d38a70f | 2020-05-11 14:01:08 -0400 | [diff] [blame] | 45 | import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier; |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 46 | import com.android.systemui.statusbar.notification.row.NotifBindPipeline.BindCallback; |
| 47 | import com.android.systemui.statusbar.notification.row.RowContentBindParams; |
| 48 | import com.android.systemui.statusbar.notification.row.RowContentBindStage; |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 49 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
| 50 | |
| 51 | import org.junit.Before; |
| 52 | import org.junit.Rule; |
| 53 | import org.junit.Test; |
| 54 | import org.junit.runner.RunWith; |
Ned Burns | 3d6b396 | 2018-12-07 21:26:00 -0500 | [diff] [blame] | 55 | import org.mockito.ArgumentCaptor; |
| 56 | import org.mockito.Captor; |
| 57 | import org.mockito.Mock; |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 58 | import org.mockito.MockitoAnnotations; |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 59 | import org.mockito.junit.MockitoJUnit; |
| 60 | import org.mockito.junit.MockitoRule; |
| 61 | |
| 62 | import java.util.HashMap; |
| 63 | |
| 64 | @SmallTest |
| 65 | @RunWith(AndroidTestingRunner.class) |
| 66 | @TestableLooper.RunWithLooper |
| 67 | public class NotificationGroupAlertTransferHelperTest extends SysuiTestCase { |
Ned Burns | 3d6b396 | 2018-12-07 21:26:00 -0500 | [diff] [blame] | 68 | @Rule public MockitoRule rule = MockitoJUnit.rule(); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 69 | |
| 70 | private NotificationGroupAlertTransferHelper mGroupAlertTransferHelper; |
| 71 | private NotificationGroupManager mGroupManager; |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 72 | private HeadsUpManager mHeadsUpManager; |
Ned Burns | 3d6b396 | 2018-12-07 21:26:00 -0500 | [diff] [blame] | 73 | @Mock private NotificationEntryManager mNotificationEntryManager; |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 74 | @Mock private RowContentBindStage mBindStage; |
| 75 | @Captor private ArgumentCaptor<NotificationEntryListener> mListenerCaptor; |
Gus Prevas | d65c2db | 2018-12-18 17:13:38 -0500 | [diff] [blame] | 76 | private NotificationEntryListener mNotificationEntryListener; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 77 | private final HashMap<String, NotificationEntry> mPendingEntries = new HashMap<>(); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 78 | private final NotificationGroupTestHelper mGroupTestHelper = |
| 79 | new NotificationGroupTestHelper(mContext); |
| 80 | |
| 81 | |
| 82 | @Before |
| 83 | public void setup() { |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 84 | MockitoAnnotations.initMocks(this); |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 85 | mDependency.injectMockDependency(BubbleController.class); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 86 | mHeadsUpManager = new HeadsUpManager(mContext) {}; |
| 87 | |
Ned Burns | 3d6b396 | 2018-12-07 21:26:00 -0500 | [diff] [blame] | 88 | when(mNotificationEntryManager.getPendingNotificationsIterator()) |
| 89 | .thenReturn(mPendingEntries.values()); |
| 90 | |
Steve Elliott | d38a70f | 2020-05-11 14:01:08 -0400 | [diff] [blame] | 91 | mGroupManager = new NotificationGroupManager( |
| 92 | mock(StatusBarStateController.class), |
| 93 | () -> mock(PeopleNotificationIdentifier.class)); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 94 | mDependency.injectTestDependency(NotificationGroupManager.class, mGroupManager); |
| 95 | mGroupManager.setHeadsUpManager(mHeadsUpManager); |
| 96 | |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 97 | when(mBindStage.getStageParams(any())).thenReturn(new RowContentBindParams()); |
| 98 | |
| 99 | mGroupAlertTransferHelper = new NotificationGroupAlertTransferHelper(mBindStage); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 100 | mGroupAlertTransferHelper.setHeadsUpManager(mHeadsUpManager); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 101 | |
Ned Burns | 3d6b396 | 2018-12-07 21:26:00 -0500 | [diff] [blame] | 102 | mGroupAlertTransferHelper.bind(mNotificationEntryManager, mGroupManager); |
Gus Prevas | d65c2db | 2018-12-18 17:13:38 -0500 | [diff] [blame] | 103 | verify(mNotificationEntryManager).addNotificationEntryListener(mListenerCaptor.capture()); |
| 104 | mNotificationEntryListener = mListenerCaptor.getValue(); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 105 | mHeadsUpManager.addListener(mGroupAlertTransferHelper); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | @Test |
| 109 | public void testSuppressedSummaryHeadsUpTransfersToChild() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 110 | NotificationEntry summaryEntry = mGroupTestHelper.createSummaryNotification(); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 111 | mHeadsUpManager.showNotification(summaryEntry); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 112 | NotificationEntry childEntry = mGroupTestHelper.createChildNotification(); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 113 | |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 114 | RowContentBindParams params = new RowContentBindParams(); |
| 115 | params.requireContentViews(FLAG_CONTENT_VIEW_HEADS_UP); |
| 116 | when(mBindStage.getStageParams(eq(childEntry))).thenReturn(params); |
| 117 | |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 118 | // Summary will be suppressed because there is only one child. |
| 119 | mGroupManager.onEntryAdded(summaryEntry); |
| 120 | mGroupManager.onEntryAdded(childEntry); |
| 121 | |
| 122 | // A suppressed summary should transfer its alert state to the child. |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 123 | assertFalse(mHeadsUpManager.isAlerting(summaryEntry.getKey())); |
| 124 | assertTrue(mHeadsUpManager.isAlerting(childEntry.getKey())); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | @Test |
| 128 | public void testSuppressedSummaryHeadsUpTransfersToChildButBackAgain() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 129 | NotificationEntry summaryEntry = |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 130 | mGroupTestHelper.createSummaryNotification(Notification.GROUP_ALERT_SUMMARY); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 131 | NotificationEntry childEntry = |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 132 | mGroupTestHelper.createChildNotification(Notification.GROUP_ALERT_SUMMARY); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 133 | NotificationEntry childEntry2 = |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 134 | mGroupTestHelper.createChildNotification(Notification.GROUP_ALERT_SUMMARY); |
| 135 | mHeadsUpManager.showNotification(summaryEntry); |
| 136 | // Trigger a transfer of alert state from summary to child. |
| 137 | mGroupManager.onEntryAdded(summaryEntry); |
| 138 | mGroupManager.onEntryAdded(childEntry); |
| 139 | |
| 140 | // Add second child notification so that summary is no longer suppressed. |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 141 | mPendingEntries.put(childEntry2.getKey(), childEntry2); |
Gus Prevas | d65c2db | 2018-12-18 17:13:38 -0500 | [diff] [blame] | 142 | mNotificationEntryListener.onPendingEntryAdded(childEntry2); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 143 | mGroupManager.onEntryAdded(childEntry2); |
| 144 | |
| 145 | // The alert state should transfer back to the summary as there is now more than one |
| 146 | // child and the summary should no longer be suppressed. |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 147 | assertTrue(mHeadsUpManager.isAlerting(summaryEntry.getKey())); |
| 148 | assertFalse(mHeadsUpManager.isAlerting(childEntry.getKey())); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | @Test |
| 152 | public void testSuppressedSummaryHeadsUpDoesntTransferBackOnDozingChanged() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 153 | NotificationEntry summaryEntry = |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 154 | mGroupTestHelper.createSummaryNotification(Notification.GROUP_ALERT_SUMMARY); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 155 | NotificationEntry childEntry = |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 156 | mGroupTestHelper.createChildNotification(Notification.GROUP_ALERT_SUMMARY); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 157 | NotificationEntry childEntry2 = |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 158 | mGroupTestHelper.createChildNotification(Notification.GROUP_ALERT_SUMMARY); |
| 159 | mHeadsUpManager.showNotification(summaryEntry); |
| 160 | // Trigger a transfer of alert state from summary to child. |
| 161 | mGroupManager.onEntryAdded(summaryEntry); |
| 162 | mGroupManager.onEntryAdded(childEntry); |
| 163 | |
| 164 | // Set dozing to true. |
| 165 | mGroupAlertTransferHelper.onDozingChanged(true); |
| 166 | |
| 167 | // Add second child notification so that summary is no longer suppressed. |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 168 | mPendingEntries.put(childEntry2.getKey(), childEntry2); |
Gus Prevas | d65c2db | 2018-12-18 17:13:38 -0500 | [diff] [blame] | 169 | mNotificationEntryListener.onPendingEntryAdded(childEntry2); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 170 | mGroupManager.onEntryAdded(childEntry2); |
| 171 | |
| 172 | // Dozing changed so no reason to re-alert summary. |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 173 | assertFalse(mHeadsUpManager.isAlerting(summaryEntry.getKey())); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | @Test |
| 177 | public void testSuppressedSummaryHeadsUpTransferDoesNotAlertChildIfUninflated() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 178 | NotificationEntry summaryEntry = mGroupTestHelper.createSummaryNotification(); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 179 | mHeadsUpManager.showNotification(summaryEntry); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 180 | NotificationEntry childEntry = mGroupTestHelper.createChildNotification(); |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 181 | RowContentBindParams params = new RowContentBindParams(); |
| 182 | when(mBindStage.getStageParams(eq(childEntry))).thenReturn(params); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 183 | |
| 184 | mGroupManager.onEntryAdded(summaryEntry); |
| 185 | mGroupManager.onEntryAdded(childEntry); |
| 186 | |
| 187 | // Alert is immediately removed from summary, but we do not show child yet either as its |
| 188 | // content is not inflated. |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 189 | assertFalse(mHeadsUpManager.isAlerting(summaryEntry.getKey())); |
| 190 | assertFalse(mHeadsUpManager.isAlerting(childEntry.getKey())); |
Kevin | 4b8bbda | 2018-11-19 14:36:31 -0800 | [diff] [blame] | 191 | assertTrue(mGroupAlertTransferHelper.isAlertTransferPending(childEntry)); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | @Test |
| 195 | public void testSuppressedSummaryHeadsUpTransferAlertsChildOnInflation() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 196 | NotificationEntry summaryEntry = mGroupTestHelper.createSummaryNotification(); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 197 | mHeadsUpManager.showNotification(summaryEntry); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 198 | NotificationEntry childEntry = mGroupTestHelper.createChildNotification(); |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 199 | RowContentBindParams params = new RowContentBindParams(); |
| 200 | when(mBindStage.getStageParams(eq(childEntry))).thenReturn(params); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 201 | |
| 202 | mGroupManager.onEntryAdded(summaryEntry); |
| 203 | mGroupManager.onEntryAdded(childEntry); |
| 204 | |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 205 | // Child entry finishes its inflation. |
| 206 | ArgumentCaptor<BindCallback> callbackCaptor = ArgumentCaptor.forClass(BindCallback.class); |
| 207 | verify(mBindStage).requestRebind(eq(childEntry), callbackCaptor.capture()); |
| 208 | callbackCaptor.getValue().onBindFinished(childEntry); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 209 | |
| 210 | // Alert is immediately removed from summary, and we show child as its content is inflated. |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 211 | assertFalse(mHeadsUpManager.isAlerting(summaryEntry.getKey())); |
| 212 | assertTrue(mHeadsUpManager.isAlerting(childEntry.getKey())); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | @Test |
| 216 | public void testSuppressedSummaryHeadsUpTransferBackAbortsChildInflation() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 217 | NotificationEntry summaryEntry = |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 218 | mGroupTestHelper.createSummaryNotification(Notification.GROUP_ALERT_SUMMARY); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 219 | NotificationEntry childEntry = |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 220 | mGroupTestHelper.createChildNotification(Notification.GROUP_ALERT_SUMMARY); |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 221 | RowContentBindParams params = new RowContentBindParams(); |
| 222 | when(mBindStage.getStageParams(eq(childEntry))).thenReturn(params); |
| 223 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 224 | NotificationEntry childEntry2 = |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 225 | mGroupTestHelper.createChildNotification(Notification.GROUP_ALERT_SUMMARY); |
| 226 | mHeadsUpManager.showNotification(summaryEntry); |
| 227 | // Trigger a transfer of alert state from summary to child. |
| 228 | mGroupManager.onEntryAdded(summaryEntry); |
| 229 | mGroupManager.onEntryAdded(childEntry); |
| 230 | |
| 231 | // Add second child notification so that summary is no longer suppressed. |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 232 | mPendingEntries.put(childEntry2.getKey(), childEntry2); |
Gus Prevas | d65c2db | 2018-12-18 17:13:38 -0500 | [diff] [blame] | 233 | mNotificationEntryListener.onPendingEntryAdded(childEntry2); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 234 | mGroupManager.onEntryAdded(childEntry2); |
| 235 | |
| 236 | // Child entry finishes its inflation. |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 237 | ArgumentCaptor<BindCallback> callbackCaptor = ArgumentCaptor.forClass(BindCallback.class); |
| 238 | verify(mBindStage).requestRebind(eq(childEntry), callbackCaptor.capture()); |
| 239 | callbackCaptor.getValue().onBindFinished(childEntry); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 240 | |
Kevin Han | 273bb0d | 2020-03-20 10:44:40 -0700 | [diff] [blame] | 241 | assertTrue((params.getContentViews() & FLAG_CONTENT_VIEW_HEADS_UP) == 0); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 242 | assertFalse(mHeadsUpManager.isAlerting(childEntry.getKey())); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 243 | } |
Kevin | 4b8bbda | 2018-11-19 14:36:31 -0800 | [diff] [blame] | 244 | |
| 245 | @Test |
| 246 | public void testCleanUpPendingAlertInfo() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 247 | NotificationEntry summaryEntry = |
Kevin | 4b8bbda | 2018-11-19 14:36:31 -0800 | [diff] [blame] | 248 | mGroupTestHelper.createSummaryNotification(Notification.GROUP_ALERT_SUMMARY); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 249 | NotificationEntry childEntry = |
Kevin | 4b8bbda | 2018-11-19 14:36:31 -0800 | [diff] [blame] | 250 | mGroupTestHelper.createChildNotification(Notification.GROUP_ALERT_SUMMARY); |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 251 | RowContentBindParams params = new RowContentBindParams(); |
| 252 | when(mBindStage.getStageParams(eq(childEntry))).thenReturn(params); |
| 253 | |
Kevin | 4b8bbda | 2018-11-19 14:36:31 -0800 | [diff] [blame] | 254 | mHeadsUpManager.showNotification(summaryEntry); |
| 255 | // Trigger a transfer of alert state from summary to child. |
| 256 | mGroupManager.onEntryAdded(summaryEntry); |
| 257 | mGroupManager.onEntryAdded(childEntry); |
| 258 | |
Julia Reynolds | 138111f | 2020-02-26 11:17:39 -0500 | [diff] [blame] | 259 | mNotificationEntryListener.onEntryRemoved( |
| 260 | childEntry, null, false, UNDEFINED_DISMISS_REASON); |
Kevin | 4b8bbda | 2018-11-19 14:36:31 -0800 | [diff] [blame] | 261 | |
| 262 | assertFalse(mGroupAlertTransferHelper.isAlertTransferPending(childEntry)); |
| 263 | } |
| 264 | |
| 265 | @Test |
| 266 | public void testUpdateGroupChangeDoesNotTransfer() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 267 | NotificationEntry summaryEntry = |
Kevin | 4b8bbda | 2018-11-19 14:36:31 -0800 | [diff] [blame] | 268 | mGroupTestHelper.createSummaryNotification(Notification.GROUP_ALERT_SUMMARY); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 269 | NotificationEntry childEntry = |
Kevin | 4b8bbda | 2018-11-19 14:36:31 -0800 | [diff] [blame] | 270 | mGroupTestHelper.createChildNotification(Notification.GROUP_ALERT_SUMMARY); |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 271 | RowContentBindParams params = new RowContentBindParams(); |
| 272 | when(mBindStage.getStageParams(eq(childEntry))).thenReturn(params); |
| 273 | |
Kevin | 4b8bbda | 2018-11-19 14:36:31 -0800 | [diff] [blame] | 274 | mHeadsUpManager.showNotification(summaryEntry); |
| 275 | // Trigger a transfer of alert state from summary to child. |
| 276 | mGroupManager.onEntryAdded(summaryEntry); |
| 277 | mGroupManager.onEntryAdded(childEntry); |
| 278 | |
| 279 | // Notify that entry changed groups. |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 280 | StatusBarNotification oldNotification = childEntry.getSbn(); |
| 281 | StatusBarNotification newSbn = spy(childEntry.getSbn().clone()); |
Kevin | 4b8bbda | 2018-11-19 14:36:31 -0800 | [diff] [blame] | 282 | doReturn("other_group").when(newSbn).getGroupKey(); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 283 | childEntry.setSbn(newSbn); |
Kevin | 4b8bbda | 2018-11-19 14:36:31 -0800 | [diff] [blame] | 284 | mGroupManager.onEntryUpdated(childEntry, oldNotification); |
| 285 | |
| 286 | assertFalse(mGroupAlertTransferHelper.isAlertTransferPending(childEntry)); |
| 287 | } |
| 288 | |
| 289 | @Test |
| 290 | public void testUpdateChildToSummaryDoesNotTransfer() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 291 | NotificationEntry summaryEntry = |
Kevin | 4b8bbda | 2018-11-19 14:36:31 -0800 | [diff] [blame] | 292 | mGroupTestHelper.createSummaryNotification(Notification.GROUP_ALERT_SUMMARY); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 293 | NotificationEntry childEntry = |
Ned Burns | ae90a9e | 2019-08-26 17:11:26 -0400 | [diff] [blame] | 294 | mGroupTestHelper.createChildNotification(Notification.GROUP_ALERT_SUMMARY, 47); |
Kevin Han | 933dc7c | 2020-01-29 11:17:46 -0800 | [diff] [blame] | 295 | RowContentBindParams params = new RowContentBindParams(); |
| 296 | when(mBindStage.getStageParams(eq(childEntry))).thenReturn(params); |
| 297 | |
Kevin | 4b8bbda | 2018-11-19 14:36:31 -0800 | [diff] [blame] | 298 | mHeadsUpManager.showNotification(summaryEntry); |
| 299 | // Trigger a transfer of alert state from summary to child. |
| 300 | mGroupManager.onEntryAdded(summaryEntry); |
| 301 | mGroupManager.onEntryAdded(childEntry); |
| 302 | |
| 303 | // Update that child to a summary. |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 304 | StatusBarNotification oldNotification = childEntry.getSbn(); |
| 305 | childEntry.setSbn( |
Ned Burns | ae90a9e | 2019-08-26 17:11:26 -0400 | [diff] [blame] | 306 | mGroupTestHelper.createSummaryNotification( |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 307 | Notification.GROUP_ALERT_SUMMARY, 47).getSbn()); |
Kevin | 4b8bbda | 2018-11-19 14:36:31 -0800 | [diff] [blame] | 308 | mGroupManager.onEntryUpdated(childEntry, oldNotification); |
| 309 | |
| 310 | assertFalse(mGroupAlertTransferHelper.isAlertTransferPending(childEntry)); |
| 311 | } |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 312 | } |