blob: 095ca54f3bb2b767d3b5217ab4a73f6e517c52b8 [file] [log] [blame]
Eliot Courtney2b4c3a02017-11-27 13:27:46 +09001/*
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
17package com.android.systemui.statusbar;
18
19import android.content.Context;
20import android.content.res.Resources;
Ned Burnsb3b4bd32019-06-27 19:36:58 -040021import android.os.Handler;
Lucas Dupin16013822018-05-17 18:00:16 -070022import android.os.Trace;
Selim Cinek6f0a62a2019-04-09 18:40:12 -070023import android.os.UserHandle;
Eliot Courtney2b4c3a02017-11-27 13:27:46 +090024import android.util.Log;
25import android.view.View;
26import android.view.ViewGroup;
27
28import com.android.systemui.R;
Mady Mellorce23c462019-06-17 17:30:07 -070029import com.android.systemui.bubbles.BubbleController;
Dave Mankofff4736812019-10-18 17:25:50 -040030import com.android.systemui.dagger.qualifiers.MainHandler;
Beverly80110912019-02-13 12:20:57 -050031import com.android.systemui.plugins.statusbar.StatusBarStateController;
Selim Cinek6f0a62a2019-04-09 18:40:12 -070032import com.android.systemui.statusbar.notification.DynamicPrivacyController;
Rohan Shah20790b82018-07-02 17:21:04 -070033import com.android.systemui.statusbar.notification.NotificationEntryManager;
Eliot Courtney2b4c3a02017-11-27 13:27:46 +090034import com.android.systemui.statusbar.notification.VisualStabilityManager;
Ned Burnsf81c4c42019-01-07 14:10:43 -050035import com.android.systemui.statusbar.notification.collection.NotificationEntry;
Rohan Shah20790b82018-07-02 17:21:04 -070036import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
37import com.android.systemui.statusbar.notification.stack.NotificationListContainer;
Selim Cinekb0fada62019-06-17 19:03:59 -070038import com.android.systemui.statusbar.phone.KeyguardBypassController;
Eliot Courtney2b4c3a02017-11-27 13:27:46 +090039import com.android.systemui.statusbar.phone.NotificationGroupManager;
Jason Monk297c04e2018-08-23 17:16:59 -040040import com.android.systemui.statusbar.phone.ShadeController;
Ned Burnsd4a69f72019-06-19 19:49:19 -040041import com.android.systemui.util.Assert;
Eliot Courtney2b4c3a02017-11-27 13:27:46 +090042
43import java.util.ArrayList;
44import java.util.HashMap;
45import java.util.List;
46import java.util.Stack;
47
Jason Monk27d01a622018-12-10 15:57:09 -050048import javax.inject.Inject;
49import javax.inject.Singleton;
50
Jason Monk09f4d372018-12-20 15:30:54 -050051import dagger.Lazy;
52
Eliot Courtney2b4c3a02017-11-27 13:27:46 +090053/**
54 * NotificationViewHierarchyManager manages updating the view hierarchy of notification views based
55 * on their group structure. For example, if a notification becomes bundled with another,
56 * NotificationViewHierarchyManager will update the view hierarchy to reflect that. It also will
57 * tell NotificationListContainer which notifications to display, and inform it of changes to those
58 * notifications that might affect their display.
59 */
Jason Monk27d01a622018-12-10 15:57:09 -050060@Singleton
Selim Cinek6f0a62a2019-04-09 18:40:12 -070061public class NotificationViewHierarchyManager implements DynamicPrivacyController.Listener {
Eliot Courtney2b4c3a02017-11-27 13:27:46 +090062 private static final String TAG = "NotificationViewHierarchyManager";
63
Ned Burnsb3b4bd32019-06-27 19:36:58 -040064 private final Handler mHandler;
65
Evan Laird94492852018-10-25 13:43:01 -040066 //TODO: change this top <Entry, List<Entry>>?
Eliot Courtney2b4c3a02017-11-27 13:27:46 +090067 private final HashMap<ExpandableNotificationRow, List<ExpandableNotificationRow>>
68 mTmpChildOrderMap = new HashMap<>();
Eliot Courtney6c313d32017-12-14 19:57:51 +090069
70 // Dependencies:
Jason Monk09f4d372018-12-20 15:30:54 -050071 protected final NotificationLockscreenUserManager mLockscreenUserManager;
72 protected final NotificationGroupManager mGroupManager;
73 protected final VisualStabilityManager mVisualStabilityManager;
Beverly80110912019-02-13 12:20:57 -050074 private final SysuiStatusBarStateController mStatusBarStateController;
Jason Monk09f4d372018-12-20 15:30:54 -050075 private final NotificationEntryManager mEntryManager;
Jason Monk297c04e2018-08-23 17:16:59 -040076
77 // Lazy
Jason Monk09f4d372018-12-20 15:30:54 -050078 private final Lazy<ShadeController> mShadeController;
Eliot Courtney2b4c3a02017-11-27 13:27:46 +090079
80 /**
81 * {@code true} if notifications not part of a group should by default be rendered in their
82 * expanded state. If {@code false}, then only the first notification will be expanded if
83 * possible.
84 */
85 private final boolean mAlwaysExpandNonGroupedNotification;
Mady Mellorce23c462019-06-17 17:30:07 -070086 private final BubbleController mBubbleController;
Selim Cinek6f0a62a2019-04-09 18:40:12 -070087 private final DynamicPrivacyController mDynamicPrivacyController;
Selim Cinekb0fada62019-06-17 19:03:59 -070088 private final KeyguardBypassController mBypassController;
Eliot Courtney2b4c3a02017-11-27 13:27:46 +090089
90 private NotificationPresenter mPresenter;
Eliot Courtney2b4c3a02017-11-27 13:27:46 +090091 private NotificationListContainer mListContainer;
92
Ned Burnsd4a69f72019-06-19 19:49:19 -040093 // Used to help track down re-entrant calls to our update methods, which will cause bugs.
94 private boolean mPerformingUpdate;
Ned Burnsb3b4bd32019-06-27 19:36:58 -040095 // Hack to get around re-entrant call in onDynamicPrivacyChanged() until we can track down
96 // the problem.
97 private boolean mIsHandleDynamicPrivacyChangeScheduled;
Ned Burnsd4a69f72019-06-19 19:49:19 -040098
Jason Monk27d01a622018-12-10 15:57:09 -050099 @Inject
Dave Mankofff4736812019-10-18 17:25:50 -0400100 public NotificationViewHierarchyManager(Context context, @MainHandler Handler mainHandler,
Jason Monk09f4d372018-12-20 15:30:54 -0500101 NotificationLockscreenUserManager notificationLockscreenUserManager,
102 NotificationGroupManager groupManager,
103 VisualStabilityManager visualStabilityManager,
Beverly80110912019-02-13 12:20:57 -0500104 StatusBarStateController statusBarStateController,
Jason Monk09f4d372018-12-20 15:30:54 -0500105 NotificationEntryManager notificationEntryManager,
Selim Cinekfdf80332019-03-07 17:29:55 -0800106 Lazy<ShadeController> shadeController,
Selim Cinekb0fada62019-06-17 19:03:59 -0700107 KeyguardBypassController bypassController,
Mady Mellorce23c462019-06-17 17:30:07 -0700108 BubbleController bubbleController,
Selim Cinek6f0a62a2019-04-09 18:40:12 -0700109 DynamicPrivacyController privacyController) {
Ned Burnsb3b4bd32019-06-27 19:36:58 -0400110 mHandler = mainHandler;
Jason Monk09f4d372018-12-20 15:30:54 -0500111 mLockscreenUserManager = notificationLockscreenUserManager;
Selim Cinekb0fada62019-06-17 19:03:59 -0700112 mBypassController = bypassController;
Jason Monk09f4d372018-12-20 15:30:54 -0500113 mGroupManager = groupManager;
114 mVisualStabilityManager = visualStabilityManager;
Beverly80110912019-02-13 12:20:57 -0500115 mStatusBarStateController = (SysuiStatusBarStateController) statusBarStateController;
Jason Monk09f4d372018-12-20 15:30:54 -0500116 mEntryManager = notificationEntryManager;
Jason Monk09f4d372018-12-20 15:30:54 -0500117 mShadeController = shadeController;
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900118 Resources res = context.getResources();
119 mAlwaysExpandNonGroupedNotification =
120 res.getBoolean(R.bool.config_alwaysExpandNonGroupedNotifications);
Mady Mellorce23c462019-06-17 17:30:07 -0700121 mBubbleController = bubbleController;
Selim Cinek6f0a62a2019-04-09 18:40:12 -0700122 mDynamicPrivacyController = privacyController;
123 privacyController.addListener(this);
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900124 }
125
126 public void setUpWithPresenter(NotificationPresenter presenter,
Jason Monk297c04e2018-08-23 17:16:59 -0400127 NotificationListContainer listContainer) {
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900128 mPresenter = presenter;
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900129 mListContainer = listContainer;
130 }
131
132 /**
133 * Updates the visual representation of the notifications.
134 */
Evan Laird94492852018-10-25 13:43:01 -0400135 //TODO: Rewrite this to focus on Entries, or some other data object instead of views
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900136 public void updateNotificationViews() {
Ned Burnsd4a69f72019-06-19 19:49:19 -0400137 Assert.isMainThread();
138 beginUpdate();
139
Ned Burnsf81c4c42019-01-07 14:10:43 -0500140 ArrayList<NotificationEntry> activeNotifications = mEntryManager.getNotificationData()
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900141 .getActiveNotifications();
142 ArrayList<ExpandableNotificationRow> toShow = new ArrayList<>(activeNotifications.size());
143 final int N = activeNotifications.size();
144 for (int i = 0; i < N; i++) {
Ned Burnsf81c4c42019-01-07 14:10:43 -0500145 NotificationEntry ent = activeNotifications.get(i);
Selim Cinekfdf80332019-03-07 17:29:55 -0800146 if (ent.isRowDismissed() || ent.isRowRemoved()
Ned Burns00b4b2d2019-10-17 22:09:27 -0400147 || mBubbleController.isBubbleNotificationSuppressedFromShade(ent.getKey())) {
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900148 // we don't want to update removed notifications because they could
149 // temporarily become children if they were isolated before.
150 continue;
151 }
Mady Mellor5549dd22018-11-06 18:07:34 -0800152
Ned Burns00b4b2d2019-10-17 22:09:27 -0400153 int userId = ent.getSbn().getUserId();
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900154
155 // Display public version of the notification if we need to redact.
156 // TODO: This area uses a lot of calls into NotificationLockscreenUserManager.
157 // We can probably move some of this code there.
Selim Cinek6f0a62a2019-04-09 18:40:12 -0700158 int currentUserId = mLockscreenUserManager.getCurrentUserId();
159 boolean devicePublic = mLockscreenUserManager.isLockscreenPublicMode(currentUserId);
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900160 boolean userPublic = devicePublic
161 || mLockscreenUserManager.isLockscreenPublicMode(userId);
Selim Cinek6f0a62a2019-04-09 18:40:12 -0700162 if (userPublic && mDynamicPrivacyController.isDynamicallyUnlocked()
163 && (userId == currentUserId || userId == UserHandle.USER_ALL
164 || !mLockscreenUserManager.needsSeparateWorkChallenge(userId))) {
165 userPublic = false;
166 }
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900167 boolean needsRedaction = mLockscreenUserManager.needsRedaction(ent);
168 boolean sensitive = userPublic && needsRedaction;
169 boolean deviceSensitive = devicePublic
170 && !mLockscreenUserManager.userAllowsPrivateNotificationsInPublic(
Selim Cinek6f0a62a2019-04-09 18:40:12 -0700171 currentUserId);
Selim Cinekb2c5dc52019-06-24 15:46:52 -0700172 ent.setSensitive(sensitive, deviceSensitive);
Evan Laird94492852018-10-25 13:43:01 -0400173 ent.getRow().setNeedsRedaction(needsRedaction);
Ned Burns00b4b2d2019-10-17 22:09:27 -0400174 if (mGroupManager.isChildInGroupWithSummary(ent.getSbn())) {
175 NotificationEntry summary = mGroupManager.getGroupSummary(ent.getSbn());
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900176 List<ExpandableNotificationRow> orderedChildren =
Evan Laird94492852018-10-25 13:43:01 -0400177 mTmpChildOrderMap.get(summary.getRow());
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900178 if (orderedChildren == null) {
179 orderedChildren = new ArrayList<>();
Evan Laird94492852018-10-25 13:43:01 -0400180 mTmpChildOrderMap.put(summary.getRow(), orderedChildren);
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900181 }
Evan Laird94492852018-10-25 13:43:01 -0400182 orderedChildren.add(ent.getRow());
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900183 } else {
Evan Laird94492852018-10-25 13:43:01 -0400184 toShow.add(ent.getRow());
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900185 }
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900186 }
187
Rohan Shah524cf7b2018-03-15 14:40:02 -0700188 ArrayList<ExpandableNotificationRow> viewsToRemove = new ArrayList<>();
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900189 for (int i=0; i< mListContainer.getContainerChildCount(); i++) {
190 View child = mListContainer.getContainerChildAt(i);
191 if (!toShow.contains(child) && child instanceof ExpandableNotificationRow) {
Rohan Shah524cf7b2018-03-15 14:40:02 -0700192 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
193
194 // Blocking helper is effectively a detached view. Don't bother removing it from the
195 // layout.
196 if (!row.isBlockingHelperShowing()) {
197 viewsToRemove.add((ExpandableNotificationRow) child);
198 }
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900199 }
200 }
201
Rohan Shah524cf7b2018-03-15 14:40:02 -0700202 for (ExpandableNotificationRow viewToRemove : viewsToRemove) {
203 if (mGroupManager.isChildInGroupWithSummary(viewToRemove.getStatusBarNotification())) {
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900204 // we are only transferring this notification to its parent, don't generate an
205 // animation
206 mListContainer.setChildTransferInProgress(true);
207 }
Rohan Shah524cf7b2018-03-15 14:40:02 -0700208 if (viewToRemove.isSummaryWithChildren()) {
209 viewToRemove.removeAllChildren();
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900210 }
Rohan Shah524cf7b2018-03-15 14:40:02 -0700211 mListContainer.removeContainerView(viewToRemove);
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900212 mListContainer.setChildTransferInProgress(false);
213 }
214
215 removeNotificationChildren();
216
217 for (int i = 0; i < toShow.size(); i++) {
218 View v = toShow.get(i);
219 if (v.getParent() == null) {
220 mVisualStabilityManager.notifyViewAddition(v);
221 mListContainer.addContainerView(v);
Selim Cinekfdf80332019-03-07 17:29:55 -0800222 } else if (!mListContainer.containsView(v)) {
223 // the view is added somewhere else. Let's make sure
224 // the ordering works properly below, by excluding these
225 toShow.remove(v);
226 i--;
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900227 }
228 }
229
230 addNotificationChildrenAndSort();
231
232 // So after all this work notifications still aren't sorted correctly.
233 // Let's do that now by advancing through toShow and mListContainer in
234 // lock-step, making sure mListContainer matches what we see in toShow.
235 int j = 0;
236 for (int i = 0; i < mListContainer.getContainerChildCount(); i++) {
237 View child = mListContainer.getContainerChildAt(i);
238 if (!(child instanceof ExpandableNotificationRow)) {
239 // We don't care about non-notification views.
240 continue;
241 }
Rohan Shah524cf7b2018-03-15 14:40:02 -0700242 if (((ExpandableNotificationRow) child).isBlockingHelperShowing()) {
243 // Don't count/reorder notifications that are showing the blocking helper!
244 continue;
245 }
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900246
247 ExpandableNotificationRow targetChild = toShow.get(j);
248 if (child != targetChild) {
249 // Oops, wrong notification at this position. Put the right one
250 // here and advance both lists.
251 if (mVisualStabilityManager.canReorderNotification(targetChild)) {
252 mListContainer.changeViewPosition(targetChild, i);
253 } else {
254 mVisualStabilityManager.addReorderingAllowedCallback(mEntryManager);
255 }
256 }
257 j++;
258
259 }
260
261 mVisualStabilityManager.onReorderingFinished();
262 // clear the map again for the next usage
263 mTmpChildOrderMap.clear();
264
Ned Burnsd4a69f72019-06-19 19:49:19 -0400265 updateRowStatesInternal();
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900266
267 mListContainer.onNotificationViewUpdateFinished();
Ned Burnsd4a69f72019-06-19 19:49:19 -0400268
269 endUpdate();
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900270 }
271
272 private void addNotificationChildrenAndSort() {
273 // Let's now add all notification children which are missing
274 boolean orderChanged = false;
275 for (int i = 0; i < mListContainer.getContainerChildCount(); i++) {
276 View view = mListContainer.getContainerChildAt(i);
277 if (!(view instanceof ExpandableNotificationRow)) {
278 // We don't care about non-notification views.
279 continue;
280 }
281
282 ExpandableNotificationRow parent = (ExpandableNotificationRow) view;
283 List<ExpandableNotificationRow> children = parent.getNotificationChildren();
284 List<ExpandableNotificationRow> orderedChildren = mTmpChildOrderMap.get(parent);
285
286 for (int childIndex = 0; orderedChildren != null && childIndex < orderedChildren.size();
287 childIndex++) {
288 ExpandableNotificationRow childView = orderedChildren.get(childIndex);
289 if (children == null || !children.contains(childView)) {
290 if (childView.getParent() != null) {
291 Log.wtf(TAG, "trying to add a notification child that already has " +
292 "a parent. class:" + childView.getParent().getClass() +
293 "\n child: " + childView);
294 // This shouldn't happen. We can recover by removing it though.
295 ((ViewGroup) childView.getParent()).removeView(childView);
296 }
297 mVisualStabilityManager.notifyViewAddition(childView);
298 parent.addChildNotification(childView, childIndex);
299 mListContainer.notifyGroupChildAdded(childView);
300 }
301 }
302
303 // Finally after removing and adding has been performed we can apply the order.
304 orderChanged |= parent.applyChildOrder(orderedChildren, mVisualStabilityManager,
305 mEntryManager);
306 }
307 if (orderChanged) {
308 mListContainer.generateChildOrderChangedEvent();
309 }
310 }
311
312 private void removeNotificationChildren() {
313 // First let's remove all children which don't belong in the parents
314 ArrayList<ExpandableNotificationRow> toRemove = new ArrayList<>();
315 for (int i = 0; i < mListContainer.getContainerChildCount(); i++) {
316 View view = mListContainer.getContainerChildAt(i);
317 if (!(view instanceof ExpandableNotificationRow)) {
318 // We don't care about non-notification views.
319 continue;
320 }
321
322 ExpandableNotificationRow parent = (ExpandableNotificationRow) view;
323 List<ExpandableNotificationRow> children = parent.getNotificationChildren();
324 List<ExpandableNotificationRow> orderedChildren = mTmpChildOrderMap.get(parent);
325
326 if (children != null) {
327 toRemove.clear();
328 for (ExpandableNotificationRow childRow : children) {
329 if ((orderedChildren == null
330 || !orderedChildren.contains(childRow))
331 && !childRow.keepInParent()) {
332 toRemove.add(childRow);
333 }
334 }
335 for (ExpandableNotificationRow remove : toRemove) {
336 parent.removeChildNotification(remove);
337 if (mEntryManager.getNotificationData().get(
338 remove.getStatusBarNotification().getKey()) == null) {
339 // We only want to add an animation if the view is completely removed
340 // otherwise it's just a transfer
341 mListContainer.notifyGroupChildRemoved(remove,
342 parent.getChildrenContainer());
343 }
344 }
345 }
346 }
347 }
348
349 /**
350 * Updates expanded, dimmed and locked states of notification rows.
351 */
352 public void updateRowStates() {
Ned Burnsd4a69f72019-06-19 19:49:19 -0400353 Assert.isMainThread();
354 beginUpdate();
355 updateRowStatesInternal();
356 endUpdate();
357 }
358
359 private void updateRowStatesInternal() {
Lucas Dupin16013822018-05-17 18:00:16 -0700360 Trace.beginSection("NotificationViewHierarchyManager#updateRowStates");
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900361 final int N = mListContainer.getContainerChildCount();
362
363 int visibleNotifications = 0;
Jason Monk297c04e2018-08-23 17:16:59 -0400364 boolean onKeyguard = mStatusBarStateController.getState() == StatusBarState.KEYGUARD;
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900365 int maxNotifications = -1;
Selim Cinekb0fada62019-06-17 19:03:59 -0700366 if (onKeyguard && !mBypassController.getBypassEnabled()) {
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900367 maxNotifications = mPresenter.getMaxNotificationsWhileLocked(true /* recompute */);
368 }
369 mListContainer.setMaxDisplayedNotifications(maxNotifications);
370 Stack<ExpandableNotificationRow> stack = new Stack<>();
371 for (int i = N - 1; i >= 0; i--) {
372 View child = mListContainer.getContainerChildAt(i);
373 if (!(child instanceof ExpandableNotificationRow)) {
374 continue;
375 }
376 stack.push((ExpandableNotificationRow) child);
377 }
378 while(!stack.isEmpty()) {
379 ExpandableNotificationRow row = stack.pop();
Ned Burnsf81c4c42019-01-07 14:10:43 -0500380 NotificationEntry entry = row.getEntry();
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900381 boolean isChildNotification =
Ned Burns00b4b2d2019-10-17 22:09:27 -0400382 mGroupManager.isChildInGroupWithSummary(entry.getSbn());
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900383
Jason Monk297c04e2018-08-23 17:16:59 -0400384 row.setOnKeyguard(onKeyguard);
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900385
Jason Monk297c04e2018-08-23 17:16:59 -0400386 if (!onKeyguard) {
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900387 // If mAlwaysExpandNonGroupedNotification is false, then only expand the
388 // very first notification and if it's not a child of grouped notifications.
389 row.setSystemExpanded(mAlwaysExpandNonGroupedNotification
390 || (visibleNotifications == 0 && !isChildNotification
391 && !row.isLowPriority()));
392 }
393
Ned Burns00b4b2d2019-10-17 22:09:27 -0400394 int userId = entry.getSbn().getUserId();
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900395 boolean suppressedSummary = mGroupManager.isSummaryOfSuppressedGroup(
Ned Burns00b4b2d2019-10-17 22:09:27 -0400396 entry.getSbn()) && !entry.isRowRemoved();
Ned Burns8c1b7632019-07-19 14:26:15 -0400397 boolean showOnKeyguard = mLockscreenUserManager.shouldShowOnKeyguard(entry);
Selim Cinek3bf2d202018-10-16 17:30:05 -0700398 if (!showOnKeyguard) {
399 // min priority notifications should show if their summary is showing
Ned Burns00b4b2d2019-10-17 22:09:27 -0400400 if (mGroupManager.isChildInGroupWithSummary(entry.getSbn())) {
Ned Burnsf81c4c42019-01-07 14:10:43 -0500401 NotificationEntry summary = mGroupManager.getLogicalGroupSummary(
Ned Burns00b4b2d2019-10-17 22:09:27 -0400402 entry.getSbn());
Ned Burns8c1b7632019-07-19 14:26:15 -0400403 if (summary != null && mLockscreenUserManager.shouldShowOnKeyguard(summary)) {
Selim Cinek3bf2d202018-10-16 17:30:05 -0700404 showOnKeyguard = true;
405 }
406 }
407 }
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900408 if (suppressedSummary
Pavel Grafov65152632018-03-26 15:14:45 +0100409 || mLockscreenUserManager.shouldHideNotifications(userId)
Jason Monk297c04e2018-08-23 17:16:59 -0400410 || (onKeyguard && !showOnKeyguard)) {
Evan Laird94492852018-10-25 13:43:01 -0400411 entry.getRow().setVisibility(View.GONE);
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900412 } else {
Evan Laird94492852018-10-25 13:43:01 -0400413 boolean wasGone = entry.getRow().getVisibility() == View.GONE;
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900414 if (wasGone) {
Evan Laird94492852018-10-25 13:43:01 -0400415 entry.getRow().setVisibility(View.VISIBLE);
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900416 }
Evan Laird94492852018-10-25 13:43:01 -0400417 if (!isChildNotification && !entry.getRow().isRemoved()) {
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900418 if (wasGone) {
419 // notify the scroller of a child addition
Evan Laird94492852018-10-25 13:43:01 -0400420 mListContainer.generateAddAnimation(entry.getRow(),
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900421 !showOnKeyguard /* fromMoreCard */);
422 }
423 visibleNotifications++;
424 }
425 }
426 if (row.isSummaryWithChildren()) {
427 List<ExpandableNotificationRow> notificationChildren =
428 row.getNotificationChildren();
429 int size = notificationChildren.size();
430 for (int i = size - 1; i >= 0; i--) {
431 stack.push(notificationChildren.get(i));
432 }
433 }
Dan Sandler83b70a02018-01-24 23:20:18 -0500434
Julia Reynoldsfc640012018-02-21 12:25:27 -0500435 row.showAppOpsIcons(entry.mActiveAppOps);
Ned Burns60e94592019-09-06 14:47:25 -0400436 row.setLastAudiblyAlertedMs(entry.getLastAudiblyAlertedMs());
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900437 }
438
Lucas Dupin16013822018-05-17 18:00:16 -0700439 Trace.beginSection("NotificationPresenter#onUpdateRowStates");
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900440 mPresenter.onUpdateRowStates();
Lucas Dupin16013822018-05-17 18:00:16 -0700441 Trace.endSection();
442 Trace.endSection();
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900443 }
Selim Cinek6f0a62a2019-04-09 18:40:12 -0700444
445 @Override
446 public void onDynamicPrivacyChanged() {
Ned Burnsb3b4bd32019-06-27 19:36:58 -0400447 if (mPerformingUpdate) {
448 Log.w(TAG, "onDynamicPrivacyChanged made a re-entrant call");
449 }
450 // This listener can be called from updateNotificationViews() via a convoluted listener
451 // chain, so we post here to prevent a re-entrant call. See b/136186188
452 // TODO: Refactor away the need for this
453 if (!mIsHandleDynamicPrivacyChangeScheduled) {
454 mIsHandleDynamicPrivacyChangeScheduled = true;
455 mHandler.post(this::onHandleDynamicPrivacyChanged);
456 }
457 }
458
459 private void onHandleDynamicPrivacyChanged() {
460 mIsHandleDynamicPrivacyChangeScheduled = false;
Selim Cinek6f0a62a2019-04-09 18:40:12 -0700461 updateNotificationViews();
462 }
Ned Burnsd4a69f72019-06-19 19:49:19 -0400463
464 private void beginUpdate() {
465 if (mPerformingUpdate) {
Ned Burnsbddd3f12019-06-28 12:54:25 -0400466 Log.wtf(TAG, "Re-entrant code during update", new Exception());
Ned Burnsd4a69f72019-06-19 19:49:19 -0400467 }
468 mPerformingUpdate = true;
469 }
470
471 private void endUpdate() {
472 if (!mPerformingUpdate) {
Ned Burnsbddd3f12019-06-28 12:54:25 -0400473 Log.wtf(TAG, "Manager state has become desynced", new Exception());
Ned Burnsd4a69f72019-06-19 19:49:19 -0400474 }
475 mPerformingUpdate = false;
476 }
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900477}