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