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 android.content.Context; |
| 20 | import android.content.res.Resources; |
Lucas Dupin | 1601382 | 2018-05-17 18:00:16 -0700 | [diff] [blame] | 21 | import android.os.Trace; |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 22 | import android.os.UserHandle; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 23 | import android.util.Log; |
| 24 | import android.view.View; |
| 25 | import android.view.ViewGroup; |
| 26 | |
| 27 | import com.android.systemui.R; |
Selim Cinek | fdf8033 | 2019-03-07 17:29:55 -0800 | [diff] [blame] | 28 | import com.android.systemui.bubbles.BubbleData; |
Beverly | 8011091 | 2019-02-13 12:20:57 -0500 | [diff] [blame] | 29 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 30 | import com.android.systemui.statusbar.notification.DynamicPrivacyController; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 31 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 32 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 33 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 34 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
| 35 | import com.android.systemui.statusbar.notification.stack.NotificationListContainer; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 36 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 37 | import com.android.systemui.statusbar.phone.ShadeController; |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 38 | import com.android.systemui.util.Assert; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 39 | |
| 40 | import java.util.ArrayList; |
| 41 | import java.util.HashMap; |
| 42 | import java.util.List; |
| 43 | import java.util.Stack; |
| 44 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 45 | import javax.inject.Inject; |
| 46 | import javax.inject.Singleton; |
| 47 | |
Jason Monk | 09f4d37 | 2018-12-20 15:30:54 -0500 | [diff] [blame] | 48 | import dagger.Lazy; |
| 49 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 50 | /** |
| 51 | * NotificationViewHierarchyManager manages updating the view hierarchy of notification views based |
| 52 | * on their group structure. For example, if a notification becomes bundled with another, |
| 53 | * NotificationViewHierarchyManager will update the view hierarchy to reflect that. It also will |
| 54 | * tell NotificationListContainer which notifications to display, and inform it of changes to those |
| 55 | * notifications that might affect their display. |
| 56 | */ |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 57 | @Singleton |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 58 | public class NotificationViewHierarchyManager implements DynamicPrivacyController.Listener { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 59 | private static final String TAG = "NotificationViewHierarchyManager"; |
| 60 | |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 61 | //TODO: change this top <Entry, List<Entry>>? |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 62 | private final HashMap<ExpandableNotificationRow, List<ExpandableNotificationRow>> |
| 63 | mTmpChildOrderMap = new HashMap<>(); |
Eliot Courtney | 6c313d3 | 2017-12-14 19:57:51 +0900 | [diff] [blame] | 64 | |
| 65 | // Dependencies: |
Jason Monk | 09f4d37 | 2018-12-20 15:30:54 -0500 | [diff] [blame] | 66 | protected final NotificationLockscreenUserManager mLockscreenUserManager; |
| 67 | protected final NotificationGroupManager mGroupManager; |
| 68 | protected final VisualStabilityManager mVisualStabilityManager; |
Beverly | 8011091 | 2019-02-13 12:20:57 -0500 | [diff] [blame] | 69 | private final SysuiStatusBarStateController mStatusBarStateController; |
Jason Monk | 09f4d37 | 2018-12-20 15:30:54 -0500 | [diff] [blame] | 70 | private final NotificationEntryManager mEntryManager; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 71 | |
| 72 | // Lazy |
Jason Monk | 09f4d37 | 2018-12-20 15:30:54 -0500 | [diff] [blame] | 73 | private final Lazy<ShadeController> mShadeController; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * {@code true} if notifications not part of a group should by default be rendered in their |
| 77 | * expanded state. If {@code false}, then only the first notification will be expanded if |
| 78 | * possible. |
| 79 | */ |
| 80 | private final boolean mAlwaysExpandNonGroupedNotification; |
Selim Cinek | fdf8033 | 2019-03-07 17:29:55 -0800 | [diff] [blame] | 81 | private final BubbleData mBubbleData; |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 82 | private final DynamicPrivacyController mDynamicPrivacyController; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 83 | |
| 84 | private NotificationPresenter mPresenter; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 85 | private NotificationListContainer mListContainer; |
| 86 | |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 87 | // Used to help track down re-entrant calls to our update methods, which will cause bugs. |
| 88 | private boolean mPerformingUpdate; |
| 89 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 90 | @Inject |
Jason Monk | 09f4d37 | 2018-12-20 15:30:54 -0500 | [diff] [blame] | 91 | public NotificationViewHierarchyManager(Context context, |
| 92 | NotificationLockscreenUserManager notificationLockscreenUserManager, |
| 93 | NotificationGroupManager groupManager, |
| 94 | VisualStabilityManager visualStabilityManager, |
Beverly | 8011091 | 2019-02-13 12:20:57 -0500 | [diff] [blame] | 95 | StatusBarStateController statusBarStateController, |
Jason Monk | 09f4d37 | 2018-12-20 15:30:54 -0500 | [diff] [blame] | 96 | NotificationEntryManager notificationEntryManager, |
Selim Cinek | fdf8033 | 2019-03-07 17:29:55 -0800 | [diff] [blame] | 97 | Lazy<ShadeController> shadeController, |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 98 | BubbleData bubbleData, |
| 99 | DynamicPrivacyController privacyController) { |
Jason Monk | 09f4d37 | 2018-12-20 15:30:54 -0500 | [diff] [blame] | 100 | mLockscreenUserManager = notificationLockscreenUserManager; |
| 101 | mGroupManager = groupManager; |
| 102 | mVisualStabilityManager = visualStabilityManager; |
Beverly | 8011091 | 2019-02-13 12:20:57 -0500 | [diff] [blame] | 103 | mStatusBarStateController = (SysuiStatusBarStateController) statusBarStateController; |
Jason Monk | 09f4d37 | 2018-12-20 15:30:54 -0500 | [diff] [blame] | 104 | mEntryManager = notificationEntryManager; |
Jason Monk | 09f4d37 | 2018-12-20 15:30:54 -0500 | [diff] [blame] | 105 | mShadeController = shadeController; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 106 | Resources res = context.getResources(); |
| 107 | mAlwaysExpandNonGroupedNotification = |
| 108 | res.getBoolean(R.bool.config_alwaysExpandNonGroupedNotifications); |
Selim Cinek | fdf8033 | 2019-03-07 17:29:55 -0800 | [diff] [blame] | 109 | mBubbleData = bubbleData; |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 110 | mDynamicPrivacyController = privacyController; |
| 111 | privacyController.addListener(this); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | public void setUpWithPresenter(NotificationPresenter presenter, |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 115 | NotificationListContainer listContainer) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 116 | mPresenter = presenter; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 117 | mListContainer = listContainer; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Updates the visual representation of the notifications. |
| 122 | */ |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 123 | //TODO: Rewrite this to focus on Entries, or some other data object instead of views |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 124 | public void updateNotificationViews() { |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 125 | Assert.isMainThread(); |
| 126 | beginUpdate(); |
| 127 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 128 | ArrayList<NotificationEntry> activeNotifications = mEntryManager.getNotificationData() |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 129 | .getActiveNotifications(); |
| 130 | ArrayList<ExpandableNotificationRow> toShow = new ArrayList<>(activeNotifications.size()); |
| 131 | final int N = activeNotifications.size(); |
| 132 | for (int i = 0; i < N; i++) { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 133 | NotificationEntry ent = activeNotifications.get(i); |
Selim Cinek | fdf8033 | 2019-03-07 17:29:55 -0800 | [diff] [blame] | 134 | if (ent.isRowDismissed() || ent.isRowRemoved() |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 135 | || (mBubbleData.hasBubbleWithKey(ent.key) && !ent.showInShadeWhenBubble())) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 136 | // we don't want to update removed notifications because they could |
| 137 | // temporarily become children if they were isolated before. |
| 138 | continue; |
| 139 | } |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 140 | |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 141 | int userId = ent.notification.getUserId(); |
| 142 | |
| 143 | // Display public version of the notification if we need to redact. |
| 144 | // TODO: This area uses a lot of calls into NotificationLockscreenUserManager. |
| 145 | // We can probably move some of this code there. |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 146 | int currentUserId = mLockscreenUserManager.getCurrentUserId(); |
| 147 | boolean devicePublic = mLockscreenUserManager.isLockscreenPublicMode(currentUserId); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 148 | boolean userPublic = devicePublic |
| 149 | || mLockscreenUserManager.isLockscreenPublicMode(userId); |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 150 | if (userPublic && mDynamicPrivacyController.isDynamicallyUnlocked() |
| 151 | && (userId == currentUserId || userId == UserHandle.USER_ALL |
| 152 | || !mLockscreenUserManager.needsSeparateWorkChallenge(userId))) { |
| 153 | userPublic = false; |
| 154 | } |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 155 | boolean needsRedaction = mLockscreenUserManager.needsRedaction(ent); |
| 156 | boolean sensitive = userPublic && needsRedaction; |
| 157 | boolean deviceSensitive = devicePublic |
| 158 | && !mLockscreenUserManager.userAllowsPrivateNotificationsInPublic( |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 159 | currentUserId); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 160 | ent.getRow().setSensitive(sensitive, deviceSensitive); |
| 161 | ent.getRow().setNeedsRedaction(needsRedaction); |
| 162 | if (mGroupManager.isChildInGroupWithSummary(ent.notification)) { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 163 | NotificationEntry summary = mGroupManager.getGroupSummary(ent.notification); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 164 | List<ExpandableNotificationRow> orderedChildren = |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 165 | mTmpChildOrderMap.get(summary.getRow()); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 166 | if (orderedChildren == null) { |
| 167 | orderedChildren = new ArrayList<>(); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 168 | mTmpChildOrderMap.put(summary.getRow(), orderedChildren); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 169 | } |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 170 | orderedChildren.add(ent.getRow()); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 171 | } else { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 172 | toShow.add(ent.getRow()); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 173 | } |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 174 | } |
| 175 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 176 | ArrayList<ExpandableNotificationRow> viewsToRemove = new ArrayList<>(); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 177 | for (int i=0; i< mListContainer.getContainerChildCount(); i++) { |
| 178 | View child = mListContainer.getContainerChildAt(i); |
| 179 | if (!toShow.contains(child) && child instanceof ExpandableNotificationRow) { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 180 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 181 | |
| 182 | // Blocking helper is effectively a detached view. Don't bother removing it from the |
| 183 | // layout. |
| 184 | if (!row.isBlockingHelperShowing()) { |
| 185 | viewsToRemove.add((ExpandableNotificationRow) child); |
| 186 | } |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 190 | for (ExpandableNotificationRow viewToRemove : viewsToRemove) { |
| 191 | if (mGroupManager.isChildInGroupWithSummary(viewToRemove.getStatusBarNotification())) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 192 | // we are only transferring this notification to its parent, don't generate an |
| 193 | // animation |
| 194 | mListContainer.setChildTransferInProgress(true); |
| 195 | } |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 196 | if (viewToRemove.isSummaryWithChildren()) { |
| 197 | viewToRemove.removeAllChildren(); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 198 | } |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 199 | mListContainer.removeContainerView(viewToRemove); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 200 | mListContainer.setChildTransferInProgress(false); |
| 201 | } |
| 202 | |
| 203 | removeNotificationChildren(); |
| 204 | |
| 205 | for (int i = 0; i < toShow.size(); i++) { |
| 206 | View v = toShow.get(i); |
| 207 | if (v.getParent() == null) { |
| 208 | mVisualStabilityManager.notifyViewAddition(v); |
| 209 | mListContainer.addContainerView(v); |
Selim Cinek | fdf8033 | 2019-03-07 17:29:55 -0800 | [diff] [blame] | 210 | } else if (!mListContainer.containsView(v)) { |
| 211 | // the view is added somewhere else. Let's make sure |
| 212 | // the ordering works properly below, by excluding these |
| 213 | toShow.remove(v); |
| 214 | i--; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | |
| 218 | addNotificationChildrenAndSort(); |
| 219 | |
| 220 | // So after all this work notifications still aren't sorted correctly. |
| 221 | // Let's do that now by advancing through toShow and mListContainer in |
| 222 | // lock-step, making sure mListContainer matches what we see in toShow. |
| 223 | int j = 0; |
| 224 | for (int i = 0; i < mListContainer.getContainerChildCount(); i++) { |
| 225 | View child = mListContainer.getContainerChildAt(i); |
| 226 | if (!(child instanceof ExpandableNotificationRow)) { |
| 227 | // We don't care about non-notification views. |
| 228 | continue; |
| 229 | } |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 230 | if (((ExpandableNotificationRow) child).isBlockingHelperShowing()) { |
| 231 | // Don't count/reorder notifications that are showing the blocking helper! |
| 232 | continue; |
| 233 | } |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 234 | |
| 235 | ExpandableNotificationRow targetChild = toShow.get(j); |
| 236 | if (child != targetChild) { |
| 237 | // Oops, wrong notification at this position. Put the right one |
| 238 | // here and advance both lists. |
| 239 | if (mVisualStabilityManager.canReorderNotification(targetChild)) { |
| 240 | mListContainer.changeViewPosition(targetChild, i); |
| 241 | } else { |
| 242 | mVisualStabilityManager.addReorderingAllowedCallback(mEntryManager); |
| 243 | } |
| 244 | } |
| 245 | j++; |
| 246 | |
| 247 | } |
| 248 | |
| 249 | mVisualStabilityManager.onReorderingFinished(); |
| 250 | // clear the map again for the next usage |
| 251 | mTmpChildOrderMap.clear(); |
| 252 | |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 253 | updateRowStatesInternal(); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 254 | |
| 255 | mListContainer.onNotificationViewUpdateFinished(); |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 256 | |
| 257 | endUpdate(); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | private void addNotificationChildrenAndSort() { |
| 261 | // Let's now add all notification children which are missing |
| 262 | boolean orderChanged = false; |
| 263 | for (int i = 0; i < mListContainer.getContainerChildCount(); i++) { |
| 264 | View view = mListContainer.getContainerChildAt(i); |
| 265 | if (!(view instanceof ExpandableNotificationRow)) { |
| 266 | // We don't care about non-notification views. |
| 267 | continue; |
| 268 | } |
| 269 | |
| 270 | ExpandableNotificationRow parent = (ExpandableNotificationRow) view; |
| 271 | List<ExpandableNotificationRow> children = parent.getNotificationChildren(); |
| 272 | List<ExpandableNotificationRow> orderedChildren = mTmpChildOrderMap.get(parent); |
| 273 | |
| 274 | for (int childIndex = 0; orderedChildren != null && childIndex < orderedChildren.size(); |
| 275 | childIndex++) { |
| 276 | ExpandableNotificationRow childView = orderedChildren.get(childIndex); |
| 277 | if (children == null || !children.contains(childView)) { |
| 278 | if (childView.getParent() != null) { |
| 279 | Log.wtf(TAG, "trying to add a notification child that already has " + |
| 280 | "a parent. class:" + childView.getParent().getClass() + |
| 281 | "\n child: " + childView); |
| 282 | // This shouldn't happen. We can recover by removing it though. |
| 283 | ((ViewGroup) childView.getParent()).removeView(childView); |
| 284 | } |
| 285 | mVisualStabilityManager.notifyViewAddition(childView); |
| 286 | parent.addChildNotification(childView, childIndex); |
| 287 | mListContainer.notifyGroupChildAdded(childView); |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | // Finally after removing and adding has been performed we can apply the order. |
| 292 | orderChanged |= parent.applyChildOrder(orderedChildren, mVisualStabilityManager, |
| 293 | mEntryManager); |
| 294 | } |
| 295 | if (orderChanged) { |
| 296 | mListContainer.generateChildOrderChangedEvent(); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | private void removeNotificationChildren() { |
| 301 | // First let's remove all children which don't belong in the parents |
| 302 | ArrayList<ExpandableNotificationRow> toRemove = new ArrayList<>(); |
| 303 | for (int i = 0; i < mListContainer.getContainerChildCount(); i++) { |
| 304 | View view = mListContainer.getContainerChildAt(i); |
| 305 | if (!(view instanceof ExpandableNotificationRow)) { |
| 306 | // We don't care about non-notification views. |
| 307 | continue; |
| 308 | } |
| 309 | |
| 310 | ExpandableNotificationRow parent = (ExpandableNotificationRow) view; |
| 311 | List<ExpandableNotificationRow> children = parent.getNotificationChildren(); |
| 312 | List<ExpandableNotificationRow> orderedChildren = mTmpChildOrderMap.get(parent); |
| 313 | |
| 314 | if (children != null) { |
| 315 | toRemove.clear(); |
| 316 | for (ExpandableNotificationRow childRow : children) { |
| 317 | if ((orderedChildren == null |
| 318 | || !orderedChildren.contains(childRow)) |
| 319 | && !childRow.keepInParent()) { |
| 320 | toRemove.add(childRow); |
| 321 | } |
| 322 | } |
| 323 | for (ExpandableNotificationRow remove : toRemove) { |
| 324 | parent.removeChildNotification(remove); |
| 325 | if (mEntryManager.getNotificationData().get( |
| 326 | remove.getStatusBarNotification().getKey()) == null) { |
| 327 | // We only want to add an animation if the view is completely removed |
| 328 | // otherwise it's just a transfer |
| 329 | mListContainer.notifyGroupChildRemoved(remove, |
| 330 | parent.getChildrenContainer()); |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | /** |
| 338 | * Updates expanded, dimmed and locked states of notification rows. |
| 339 | */ |
| 340 | public void updateRowStates() { |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 341 | Assert.isMainThread(); |
| 342 | beginUpdate(); |
| 343 | updateRowStatesInternal(); |
| 344 | endUpdate(); |
| 345 | } |
| 346 | |
| 347 | private void updateRowStatesInternal() { |
Lucas Dupin | 1601382 | 2018-05-17 18:00:16 -0700 | [diff] [blame] | 348 | Trace.beginSection("NotificationViewHierarchyManager#updateRowStates"); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 349 | final int N = mListContainer.getContainerChildCount(); |
| 350 | |
| 351 | int visibleNotifications = 0; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 352 | boolean onKeyguard = mStatusBarStateController.getState() == StatusBarState.KEYGUARD; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 353 | int maxNotifications = -1; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 354 | if (onKeyguard) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 355 | maxNotifications = mPresenter.getMaxNotificationsWhileLocked(true /* recompute */); |
| 356 | } |
| 357 | mListContainer.setMaxDisplayedNotifications(maxNotifications); |
| 358 | Stack<ExpandableNotificationRow> stack = new Stack<>(); |
| 359 | for (int i = N - 1; i >= 0; i--) { |
| 360 | View child = mListContainer.getContainerChildAt(i); |
| 361 | if (!(child instanceof ExpandableNotificationRow)) { |
| 362 | continue; |
| 363 | } |
| 364 | stack.push((ExpandableNotificationRow) child); |
| 365 | } |
| 366 | while(!stack.isEmpty()) { |
| 367 | ExpandableNotificationRow row = stack.pop(); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 368 | NotificationEntry entry = row.getEntry(); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 369 | boolean isChildNotification = |
| 370 | mGroupManager.isChildInGroupWithSummary(entry.notification); |
| 371 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 372 | row.setOnKeyguard(onKeyguard); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 373 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 374 | if (!onKeyguard) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 375 | // If mAlwaysExpandNonGroupedNotification is false, then only expand the |
| 376 | // very first notification and if it's not a child of grouped notifications. |
| 377 | row.setSystemExpanded(mAlwaysExpandNonGroupedNotification |
| 378 | || (visibleNotifications == 0 && !isChildNotification |
| 379 | && !row.isLowPriority())); |
| 380 | } |
| 381 | |
Jason Monk | 09f4d37 | 2018-12-20 15:30:54 -0500 | [diff] [blame] | 382 | entry.getRow().setOnAmbient(mShadeController.get().isDozing()); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 383 | int userId = entry.notification.getUserId(); |
| 384 | boolean suppressedSummary = mGroupManager.isSummaryOfSuppressedGroup( |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 385 | entry.notification) && !entry.isRowRemoved(); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 386 | boolean showOnKeyguard = mLockscreenUserManager.shouldShowOnKeyguard(entry |
| 387 | .notification); |
Selim Cinek | 3bf2d20 | 2018-10-16 17:30:05 -0700 | [diff] [blame] | 388 | if (!showOnKeyguard) { |
| 389 | // min priority notifications should show if their summary is showing |
| 390 | if (mGroupManager.isChildInGroupWithSummary(entry.notification)) { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 391 | NotificationEntry summary = mGroupManager.getLogicalGroupSummary( |
Selim Cinek | 3bf2d20 | 2018-10-16 17:30:05 -0700 | [diff] [blame] | 392 | entry.notification); |
| 393 | if (summary != null && mLockscreenUserManager.shouldShowOnKeyguard( |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 394 | summary.notification)) { |
Selim Cinek | 3bf2d20 | 2018-10-16 17:30:05 -0700 | [diff] [blame] | 395 | showOnKeyguard = true; |
| 396 | } |
| 397 | } |
| 398 | } |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 399 | if (suppressedSummary |
Pavel Grafov | 6515263 | 2018-03-26 15:14:45 +0100 | [diff] [blame] | 400 | || mLockscreenUserManager.shouldHideNotifications(userId) |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 401 | || (onKeyguard && !showOnKeyguard)) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 402 | entry.getRow().setVisibility(View.GONE); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 403 | } else { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 404 | boolean wasGone = entry.getRow().getVisibility() == View.GONE; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 405 | if (wasGone) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 406 | entry.getRow().setVisibility(View.VISIBLE); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 407 | } |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 408 | if (!isChildNotification && !entry.getRow().isRemoved()) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 409 | if (wasGone) { |
| 410 | // notify the scroller of a child addition |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 411 | mListContainer.generateAddAnimation(entry.getRow(), |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 412 | !showOnKeyguard /* fromMoreCard */); |
| 413 | } |
| 414 | visibleNotifications++; |
| 415 | } |
| 416 | } |
| 417 | if (row.isSummaryWithChildren()) { |
| 418 | List<ExpandableNotificationRow> notificationChildren = |
| 419 | row.getNotificationChildren(); |
| 420 | int size = notificationChildren.size(); |
| 421 | for (int i = size - 1; i >= 0; i--) { |
| 422 | stack.push(notificationChildren.get(i)); |
| 423 | } |
| 424 | } |
Dan Sandler | 83b70a0 | 2018-01-24 23:20:18 -0500 | [diff] [blame] | 425 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 426 | row.showAppOpsIcons(entry.mActiveAppOps); |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 427 | row.setLastAudiblyAlertedMs(entry.lastAudiblyAlertedMs); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 428 | } |
| 429 | |
Lucas Dupin | 1601382 | 2018-05-17 18:00:16 -0700 | [diff] [blame] | 430 | Trace.beginSection("NotificationPresenter#onUpdateRowStates"); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 431 | mPresenter.onUpdateRowStates(); |
Lucas Dupin | 1601382 | 2018-05-17 18:00:16 -0700 | [diff] [blame] | 432 | Trace.endSection(); |
| 433 | Trace.endSection(); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 434 | } |
Selim Cinek | 6f0a62a | 2019-04-09 18:40:12 -0700 | [diff] [blame] | 435 | |
| 436 | @Override |
| 437 | public void onDynamicPrivacyChanged() { |
| 438 | updateNotificationViews(); |
| 439 | } |
Ned Burns | d4a69f7 | 2019-06-19 19:49:19 -0400 | [diff] [blame] | 440 | |
| 441 | private void beginUpdate() { |
| 442 | if (mPerformingUpdate) { |
| 443 | throw new IllegalStateException("Re-entrant code during update."); |
| 444 | } |
| 445 | mPerformingUpdate = true; |
| 446 | } |
| 447 | |
| 448 | private void endUpdate() { |
| 449 | if (!mPerformingUpdate) { |
| 450 | throw new IllegalStateException("Manager state has become desynced."); |
| 451 | } |
| 452 | mPerformingUpdate = false; |
| 453 | } |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 454 | } |