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