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