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