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