Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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; |
| 18 | |
| 19 | import static junit.framework.Assert.assertTrue; |
| 20 | |
| 21 | import static org.junit.Assert.assertEquals; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 22 | import static org.mockito.ArgumentMatchers.any; |
Jason Monk | 09f4d37 | 2018-12-20 15:30:54 -0500 | [diff] [blame] | 23 | import static org.mockito.Mockito.mock; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 24 | import static org.mockito.Mockito.spy; |
| 25 | import static org.mockito.Mockito.times; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 26 | import static org.mockito.Mockito.verify; |
| 27 | import static org.mockito.Mockito.when; |
| 28 | |
| 29 | import android.support.test.filters.SmallTest; |
| 30 | import android.testing.AndroidTestingRunner; |
| 31 | import android.testing.TestableLooper; |
| 32 | import android.view.View; |
| 33 | import android.view.ViewGroup; |
| 34 | import android.widget.LinearLayout; |
| 35 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 36 | import com.android.systemui.Dependency; |
| 37 | import com.android.systemui.InitController; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 38 | import com.android.systemui.SysuiTestCase; |
| 39 | import com.android.systemui.plugins.statusbar.NotificationSwipeActionHelper; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 40 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 41 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 42 | import com.android.systemui.statusbar.notification.collection.NotificationData; |
| 43 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 44 | import com.android.systemui.statusbar.notification.logging.NotificationLogger; |
| 45 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
| 46 | import com.android.systemui.statusbar.notification.row.ExpandableView; |
| 47 | import com.android.systemui.statusbar.notification.stack.NotificationListContainer; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 48 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 49 | import com.android.systemui.statusbar.phone.ShadeController; |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 50 | import com.android.systemui.util.Assert; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 51 | |
| 52 | import com.google.android.collect.Lists; |
| 53 | |
| 54 | import org.junit.Before; |
| 55 | import org.junit.Test; |
| 56 | import org.junit.runner.RunWith; |
| 57 | import org.mockito.Mock; |
| 58 | import org.mockito.MockitoAnnotations; |
| 59 | import org.mockito.Spy; |
| 60 | |
| 61 | import java.util.List; |
| 62 | |
| 63 | @SmallTest |
| 64 | @RunWith(AndroidTestingRunner.class) |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 65 | @TestableLooper.RunWithLooper |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 66 | public class NotificationViewHierarchyManagerTest extends SysuiTestCase { |
| 67 | @Mock private NotificationPresenter mPresenter; |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 68 | @Mock private NotificationData mNotificationData; |
| 69 | @Spy private FakeListContainer mListContainer = new FakeListContainer(); |
| 70 | |
| 71 | // Dependency mocks: |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 72 | @Mock private NotificationEntryManager mEntryManager; |
| 73 | @Mock private NotificationLockscreenUserManager mLockscreenUserManager; |
| 74 | @Mock private NotificationGroupManager mGroupManager; |
| 75 | @Mock private VisualStabilityManager mVisualStabilityManager; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 76 | @Mock private ShadeController mShadeController; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 77 | |
| 78 | private NotificationViewHierarchyManager mViewHierarchyManager; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 79 | private NotificationTestHelper mHelper; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 80 | |
| 81 | @Before |
| 82 | public void setUp() { |
| 83 | MockitoAnnotations.initMocks(this); |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 84 | Assert.sMainLooper = TestableLooper.get(this).getLooper(); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 85 | mDependency.injectTestDependency(NotificationEntryManager.class, mEntryManager); |
| 86 | mDependency.injectTestDependency(NotificationLockscreenUserManager.class, |
| 87 | mLockscreenUserManager); |
| 88 | mDependency.injectTestDependency(NotificationGroupManager.class, mGroupManager); |
| 89 | mDependency.injectTestDependency(VisualStabilityManager.class, mVisualStabilityManager); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 90 | mDependency.injectTestDependency(ShadeController.class, mShadeController); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 91 | |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 92 | mHelper = new NotificationTestHelper(mContext); |
| 93 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 94 | when(mEntryManager.getNotificationData()).thenReturn(mNotificationData); |
| 95 | |
Jason Monk | 09f4d37 | 2018-12-20 15:30:54 -0500 | [diff] [blame] | 96 | mViewHierarchyManager = new NotificationViewHierarchyManager(mContext, |
| 97 | mLockscreenUserManager, mGroupManager, mVisualStabilityManager, |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 98 | mock(StatusBarStateControllerImpl.class), mEntryManager, |
Jason Monk | 09f4d37 | 2018-12-20 15:30:54 -0500 | [diff] [blame] | 99 | () -> mShadeController); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 100 | Dependency.get(InitController.class).executePostInitTasks(); |
| 101 | mViewHierarchyManager.setUpWithPresenter(mPresenter, mListContainer); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 102 | } |
| 103 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 104 | private NotificationEntry createEntry() throws Exception { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 105 | ExpandableNotificationRow row = mHelper.createRow(); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 106 | NotificationEntry entry = new NotificationEntry(row.getStatusBarNotification()); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 107 | entry.setRow(row); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 108 | return entry; |
| 109 | } |
| 110 | |
| 111 | @Test |
| 112 | public void testNotificationsBecomingBundled() throws Exception { |
| 113 | // Tests 3 top level notifications becoming a single bundled notification with |entry0| as |
| 114 | // the summary. |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 115 | NotificationEntry entry0 = createEntry(); |
| 116 | NotificationEntry entry1 = createEntry(); |
| 117 | NotificationEntry entry2 = createEntry(); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 118 | |
| 119 | // Set up the prior state to look like three top level notifications. |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 120 | mListContainer.addContainerView(entry0.getRow()); |
| 121 | mListContainer.addContainerView(entry1.getRow()); |
| 122 | mListContainer.addContainerView(entry2.getRow()); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 123 | when(mNotificationData.getActiveNotifications()).thenReturn( |
| 124 | Lists.newArrayList(entry0, entry1, entry2)); |
| 125 | |
| 126 | // Set up group manager to report that they should be bundled now. |
| 127 | when(mGroupManager.isChildInGroupWithSummary(entry0.notification)).thenReturn(false); |
| 128 | when(mGroupManager.isChildInGroupWithSummary(entry1.notification)).thenReturn(true); |
| 129 | when(mGroupManager.isChildInGroupWithSummary(entry2.notification)).thenReturn(true); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 130 | when(mGroupManager.getGroupSummary(entry1.notification)).thenReturn(entry0); |
| 131 | when(mGroupManager.getGroupSummary(entry2.notification)).thenReturn(entry0); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 132 | |
| 133 | // Run updateNotifications - the view hierarchy should be reorganized. |
| 134 | mViewHierarchyManager.updateNotificationViews(); |
| 135 | |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 136 | verify(mListContainer).notifyGroupChildAdded(entry1.getRow()); |
| 137 | verify(mListContainer).notifyGroupChildAdded(entry2.getRow()); |
| 138 | assertTrue(Lists.newArrayList(entry0.getRow()).equals(mListContainer.mRows)); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | @Test |
| 142 | public void testNotificationsBecomingUnbundled() throws Exception { |
| 143 | // Tests a bundled notification becoming three top level notifications. |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 144 | NotificationEntry entry0 = createEntry(); |
| 145 | NotificationEntry entry1 = createEntry(); |
| 146 | NotificationEntry entry2 = createEntry(); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 147 | entry0.getRow().addChildNotification(entry1.getRow()); |
| 148 | entry0.getRow().addChildNotification(entry2.getRow()); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 149 | |
| 150 | // Set up the prior state to look like one top level notification. |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 151 | mListContainer.addContainerView(entry0.getRow()); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 152 | when(mNotificationData.getActiveNotifications()).thenReturn( |
| 153 | Lists.newArrayList(entry0, entry1, entry2)); |
| 154 | |
| 155 | // Set up group manager to report that they should not be bundled now. |
| 156 | when(mGroupManager.isChildInGroupWithSummary(entry0.notification)).thenReturn(false); |
| 157 | when(mGroupManager.isChildInGroupWithSummary(entry1.notification)).thenReturn(false); |
| 158 | when(mGroupManager.isChildInGroupWithSummary(entry2.notification)).thenReturn(false); |
| 159 | |
| 160 | // Run updateNotifications - the view hierarchy should be reorganized. |
| 161 | mViewHierarchyManager.updateNotificationViews(); |
| 162 | |
| 163 | verify(mListContainer).notifyGroupChildRemoved( |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 164 | entry1.getRow(), entry0.getRow().getChildrenContainer()); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 165 | verify(mListContainer).notifyGroupChildRemoved( |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 166 | entry2.getRow(), entry0.getRow().getChildrenContainer()); |
| 167 | assertTrue( |
| 168 | Lists.newArrayList(entry0.getRow(), entry1.getRow(), entry2.getRow()) |
| 169 | .equals(mListContainer.mRows)); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | @Test |
| 173 | public void testNotificationsBecomingSuppressed() throws Exception { |
| 174 | // Tests two top level notifications becoming a suppressed summary and a child. |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 175 | NotificationEntry entry0 = createEntry(); |
| 176 | NotificationEntry entry1 = createEntry(); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 177 | entry0.getRow().addChildNotification(entry1.getRow()); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 178 | |
| 179 | // Set up the prior state to look like a top level notification. |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 180 | mListContainer.addContainerView(entry0.getRow()); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 181 | when(mNotificationData.getActiveNotifications()).thenReturn( |
| 182 | Lists.newArrayList(entry0, entry1)); |
| 183 | |
| 184 | // Set up group manager to report a suppressed summary now. |
| 185 | when(mGroupManager.isChildInGroupWithSummary(entry0.notification)).thenReturn(false); |
| 186 | when(mGroupManager.isChildInGroupWithSummary(entry1.notification)).thenReturn(false); |
| 187 | when(mGroupManager.isSummaryOfSuppressedGroup(entry0.notification)).thenReturn(true); |
| 188 | |
| 189 | // Run updateNotifications - the view hierarchy should be reorganized. |
| 190 | mViewHierarchyManager.updateNotificationViews(); |
| 191 | |
| 192 | verify(mListContainer).notifyGroupChildRemoved( |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 193 | entry1.getRow(), entry0.getRow().getChildrenContainer()); |
| 194 | assertTrue(Lists.newArrayList(entry0.getRow(), entry1.getRow()).equals(mListContainer.mRows)); |
| 195 | assertEquals(View.GONE, entry0.getRow().getVisibility()); |
| 196 | assertEquals(View.VISIBLE, entry1.getRow().getVisibility()); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 197 | } |
| 198 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 199 | @Test |
| 200 | public void testUpdateNotificationViews_appOps() throws Exception { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 201 | NotificationEntry entry0 = createEntry(); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 202 | entry0.setRow(spy(entry0.getRow())); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 203 | when(mNotificationData.getActiveNotifications()).thenReturn( |
| 204 | Lists.newArrayList(entry0)); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 205 | mListContainer.addContainerView(entry0.getRow()); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 206 | |
| 207 | mViewHierarchyManager.updateNotificationViews(); |
| 208 | |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 209 | verify(entry0.getRow(), times(1)).showAppOpsIcons(any()); |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 210 | } |
| 211 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 212 | private class FakeListContainer implements NotificationListContainer { |
| 213 | final LinearLayout mLayout = new LinearLayout(mContext); |
| 214 | final List<View> mRows = Lists.newArrayList(); |
| 215 | |
| 216 | @Override |
| 217 | public void setChildTransferInProgress(boolean childTransferInProgress) {} |
| 218 | |
| 219 | @Override |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 220 | public void changeViewPosition(ExpandableView child, int newIndex) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 221 | mRows.remove(child); |
| 222 | mRows.add(newIndex, child); |
| 223 | } |
| 224 | |
| 225 | @Override |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 226 | public void notifyGroupChildAdded(ExpandableView row) {} |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 227 | |
| 228 | @Override |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 229 | public void notifyGroupChildRemoved(ExpandableView row, ViewGroup childrenContainer) {} |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 230 | |
| 231 | @Override |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 232 | public void generateAddAnimation(ExpandableView child, boolean fromMoreCard) {} |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 233 | |
| 234 | @Override |
| 235 | public void generateChildOrderChangedEvent() {} |
| 236 | |
| 237 | @Override |
Aaron Heuckroth | cd944dc | 2018-10-01 16:31:08 -0400 | [diff] [blame] | 238 | public void onReset(ExpandableView view) {} |
| 239 | |
| 240 | @Override |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 241 | public int getContainerChildCount() { |
| 242 | return mRows.size(); |
| 243 | } |
| 244 | |
| 245 | @Override |
| 246 | public View getContainerChildAt(int i) { |
| 247 | return mRows.get(i); |
| 248 | } |
| 249 | |
| 250 | @Override |
| 251 | public void removeContainerView(View v) { |
| 252 | mLayout.removeView(v); |
| 253 | mRows.remove(v); |
| 254 | } |
| 255 | |
| 256 | @Override |
| 257 | public void addContainerView(View v) { |
| 258 | mLayout.addView(v); |
| 259 | mRows.add(v); |
| 260 | } |
| 261 | |
| 262 | @Override |
| 263 | public void setMaxDisplayedNotifications(int maxNotifications) {} |
| 264 | |
| 265 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 266 | public ViewGroup getViewParentForNotification(NotificationEntry entry) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 267 | return null; |
| 268 | } |
| 269 | |
| 270 | @Override |
| 271 | public void onHeightChanged(ExpandableView view, boolean animate) {} |
| 272 | |
| 273 | @Override |
| 274 | public void resetExposedMenuView(boolean animate, boolean force) {} |
| 275 | |
| 276 | @Override |
| 277 | public NotificationSwipeActionHelper getSwipeActionHelper() { |
| 278 | return null; |
| 279 | } |
| 280 | |
| 281 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 282 | public void cleanUpViewStateForEntry(NotificationEntry entry) { } |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 283 | |
| 284 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 285 | public boolean isInVisibleLocation(NotificationEntry entry) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 286 | return true; |
| 287 | } |
| 288 | |
| 289 | @Override |
| 290 | public void setChildLocationsChangedListener( |
| 291 | NotificationLogger.OnChildLocationsChangedListener listener) {} |
| 292 | |
| 293 | @Override |
| 294 | public boolean hasPulsingNotifications() { |
| 295 | return false; |
| 296 | } |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 297 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 298 | } |
| 299 | } |