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