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