blob: 4204f684a6328880a8802ac09e019c10638fff37 [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;
Matt Pietal5a19cb62019-10-30 12:31:07 -040042import com.android.systemui.util.Utils;
Eliot Courtney2b4c3a02017-11-27 13:27:46 +090043
44import java.util.ArrayList;
45import java.util.HashMap;
46import java.util.List;
47import java.util.Stack;
48
Jason Monk27d01a622018-12-10 15:57:09 -050049import javax.inject.Inject;
50import javax.inject.Singleton;
51
Jason Monk09f4d372018-12-20 15:30:54 -050052import dagger.Lazy;
53
Eliot Courtney2b4c3a02017-11-27 13:27:46 +090054/**
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 Monk27d01a622018-12-10 15:57:09 -050061@Singleton
Selim Cinek6f0a62a2019-04-09 18:40:12 -070062public class NotificationViewHierarchyManager implements DynamicPrivacyController.Listener {
Eliot Courtney2b4c3a02017-11-27 13:27:46 +090063 private static final String TAG = "NotificationViewHierarchyManager";
64
Ned Burnsb3b4bd32019-06-27 19:36:58 -040065 private final Handler mHandler;
66
Evan Laird94492852018-10-25 13:43:01 -040067 //TODO: change this top <Entry, List<Entry>>?
Eliot Courtney2b4c3a02017-11-27 13:27:46 +090068 private final HashMap<ExpandableNotificationRow, List<ExpandableNotificationRow>>
69 mTmpChildOrderMap = new HashMap<>();
Eliot Courtney6c313d32017-12-14 19:57:51 +090070
71 // Dependencies:
Jason Monk09f4d372018-12-20 15:30:54 -050072 protected final NotificationLockscreenUserManager mLockscreenUserManager;
73 protected final NotificationGroupManager mGroupManager;
74 protected final VisualStabilityManager mVisualStabilityManager;
Beverly80110912019-02-13 12:20:57 -050075 private final SysuiStatusBarStateController mStatusBarStateController;
Jason Monk09f4d372018-12-20 15:30:54 -050076 private final NotificationEntryManager mEntryManager;
Jason Monk297c04e2018-08-23 17:16:59 -040077
78 // Lazy
Jason Monk09f4d372018-12-20 15:30:54 -050079 private final Lazy<ShadeController> mShadeController;
Eliot Courtney2b4c3a02017-11-27 13:27:46 +090080
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 Mellorce23c462019-06-17 17:30:07 -070087 private final BubbleController mBubbleController;
Selim Cinek6f0a62a2019-04-09 18:40:12 -070088 private final DynamicPrivacyController mDynamicPrivacyController;
Selim Cinekb0fada62019-06-17 19:03:59 -070089 private final KeyguardBypassController mBypassController;
Beth Thibodeau07d20c32019-10-16 13:45:56 -040090 private final Context mContext;
Eliot Courtney2b4c3a02017-11-27 13:27:46 +090091
92 private NotificationPresenter mPresenter;
Eliot Courtney2b4c3a02017-11-27 13:27:46 +090093 private NotificationListContainer mListContainer;
94
Ned Burnsd4a69f72019-06-19 19:49:19 -040095 // Used to help track down re-entrant calls to our update methods, which will cause bugs.
96 private boolean mPerformingUpdate;
Ned Burnsb3b4bd32019-06-27 19:36:58 -040097 // Hack to get around re-entrant call in onDynamicPrivacyChanged() until we can track down
98 // the problem.
99 private boolean mIsHandleDynamicPrivacyChangeScheduled;
Ned Burnsd4a69f72019-06-19 19:49:19 -0400100
Jason Monk27d01a622018-12-10 15:57:09 -0500101 @Inject
Dave Mankofff4736812019-10-18 17:25:50 -0400102 public NotificationViewHierarchyManager(Context context, @MainHandler Handler mainHandler,
Jason Monk09f4d372018-12-20 15:30:54 -0500103 NotificationLockscreenUserManager notificationLockscreenUserManager,
104 NotificationGroupManager groupManager,
105 VisualStabilityManager visualStabilityManager,
Beverly80110912019-02-13 12:20:57 -0500106 StatusBarStateController statusBarStateController,
Jason Monk09f4d372018-12-20 15:30:54 -0500107 NotificationEntryManager notificationEntryManager,
Selim Cinekfdf80332019-03-07 17:29:55 -0800108 Lazy<ShadeController> shadeController,
Selim Cinekb0fada62019-06-17 19:03:59 -0700109 KeyguardBypassController bypassController,
Mady Mellorce23c462019-06-17 17:30:07 -0700110 BubbleController bubbleController,
Selim Cinek6f0a62a2019-04-09 18:40:12 -0700111 DynamicPrivacyController privacyController) {
Beth Thibodeau07d20c32019-10-16 13:45:56 -0400112 mContext = context;
Ned Burnsb3b4bd32019-06-27 19:36:58 -0400113 mHandler = mainHandler;
Jason Monk09f4d372018-12-20 15:30:54 -0500114 mLockscreenUserManager = notificationLockscreenUserManager;
Selim Cinekb0fada62019-06-17 19:03:59 -0700115 mBypassController = bypassController;
Jason Monk09f4d372018-12-20 15:30:54 -0500116 mGroupManager = groupManager;
117 mVisualStabilityManager = visualStabilityManager;
Beverly80110912019-02-13 12:20:57 -0500118 mStatusBarStateController = (SysuiStatusBarStateController) statusBarStateController;
Jason Monk09f4d372018-12-20 15:30:54 -0500119 mEntryManager = notificationEntryManager;
Jason Monk09f4d372018-12-20 15:30:54 -0500120 mShadeController = shadeController;
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900121 Resources res = context.getResources();
122 mAlwaysExpandNonGroupedNotification =
123 res.getBoolean(R.bool.config_alwaysExpandNonGroupedNotifications);
Mady Mellorce23c462019-06-17 17:30:07 -0700124 mBubbleController = bubbleController;
Selim Cinek6f0a62a2019-04-09 18:40:12 -0700125 mDynamicPrivacyController = privacyController;
126 privacyController.addListener(this);
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900127 }
128
129 public void setUpWithPresenter(NotificationPresenter presenter,
Jason Monk297c04e2018-08-23 17:16:59 -0400130 NotificationListContainer listContainer) {
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900131 mPresenter = presenter;
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900132 mListContainer = listContainer;
133 }
134
135 /**
136 * Updates the visual representation of the notifications.
137 */
Evan Laird94492852018-10-25 13:43:01 -0400138 //TODO: Rewrite this to focus on Entries, or some other data object instead of views
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900139 public void updateNotificationViews() {
Ned Burnsd4a69f72019-06-19 19:49:19 -0400140 Assert.isMainThread();
141 beginUpdate();
142
Evan Laird181de622019-10-24 09:53:02 -0400143 List<NotificationEntry> activeNotifications = mEntryManager.getVisibleNotifications();
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900144 ArrayList<ExpandableNotificationRow> toShow = new ArrayList<>(activeNotifications.size());
145 final int N = activeNotifications.size();
146 for (int i = 0; i < N; i++) {
Ned Burnsf81c4c42019-01-07 14:10:43 -0500147 NotificationEntry ent = activeNotifications.get(i);
Matt Pietal5a19cb62019-10-30 12:31:07 -0400148 boolean hideMedia = Utils.useQsMediaPlayer(mContext);
Selim Cinekfdf80332019-03-07 17:29:55 -0800149 if (ent.isRowDismissed() || ent.isRowRemoved()
Beth Thibodeau07d20c32019-10-16 13:45:56 -0400150 || (ent.isMediaNotification() && hideMedia)
Ned Burns00b4b2d2019-10-17 22:09:27 -0400151 || mBubbleController.isBubbleNotificationSuppressedFromShade(ent.getKey())) {
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900152 // we don't want to update removed notifications because they could
153 // temporarily become children if they were isolated before.
154 continue;
155 }
Mady Mellor5549dd22018-11-06 18:07:34 -0800156
Ned Burns00b4b2d2019-10-17 22:09:27 -0400157 int userId = ent.getSbn().getUserId();
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900158
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 Cinek6f0a62a2019-04-09 18:40:12 -0700162 int currentUserId = mLockscreenUserManager.getCurrentUserId();
163 boolean devicePublic = mLockscreenUserManager.isLockscreenPublicMode(currentUserId);
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900164 boolean userPublic = devicePublic
165 || mLockscreenUserManager.isLockscreenPublicMode(userId);
Selim Cinek6f0a62a2019-04-09 18:40:12 -0700166 if (userPublic && mDynamicPrivacyController.isDynamicallyUnlocked()
167 && (userId == currentUserId || userId == UserHandle.USER_ALL
168 || !mLockscreenUserManager.needsSeparateWorkChallenge(userId))) {
169 userPublic = false;
170 }
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900171 boolean needsRedaction = mLockscreenUserManager.needsRedaction(ent);
172 boolean sensitive = userPublic && needsRedaction;
173 boolean deviceSensitive = devicePublic
174 && !mLockscreenUserManager.userAllowsPrivateNotificationsInPublic(
Selim Cinek6f0a62a2019-04-09 18:40:12 -0700175 currentUserId);
Selim Cinekb2c5dc52019-06-24 15:46:52 -0700176 ent.setSensitive(sensitive, deviceSensitive);
Evan Laird94492852018-10-25 13:43:01 -0400177 ent.getRow().setNeedsRedaction(needsRedaction);
Ned Burns00b4b2d2019-10-17 22:09:27 -0400178 if (mGroupManager.isChildInGroupWithSummary(ent.getSbn())) {
179 NotificationEntry summary = mGroupManager.getGroupSummary(ent.getSbn());
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900180 List<ExpandableNotificationRow> orderedChildren =
Evan Laird94492852018-10-25 13:43:01 -0400181 mTmpChildOrderMap.get(summary.getRow());
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900182 if (orderedChildren == null) {
183 orderedChildren = new ArrayList<>();
Evan Laird94492852018-10-25 13:43:01 -0400184 mTmpChildOrderMap.put(summary.getRow(), orderedChildren);
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900185 }
Evan Laird94492852018-10-25 13:43:01 -0400186 orderedChildren.add(ent.getRow());
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900187 } else {
Evan Laird94492852018-10-25 13:43:01 -0400188 toShow.add(ent.getRow());
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900189 }
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900190 }
191
Rohan Shah524cf7b2018-03-15 14:40:02 -0700192 ArrayList<ExpandableNotificationRow> viewsToRemove = new ArrayList<>();
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900193 for (int i=0; i< mListContainer.getContainerChildCount(); i++) {
194 View child = mListContainer.getContainerChildAt(i);
195 if (!toShow.contains(child) && child instanceof ExpandableNotificationRow) {
Rohan Shah524cf7b2018-03-15 14:40:02 -0700196 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 Courtney2b4c3a02017-11-27 13:27:46 +0900203 }
204 }
205
Rohan Shah524cf7b2018-03-15 14:40:02 -0700206 for (ExpandableNotificationRow viewToRemove : viewsToRemove) {
Ned Burns1c2b85a42019-11-14 15:37:03 -0500207 if (mGroupManager.isChildInGroupWithSummary(viewToRemove.getEntry().getSbn())) {
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900208 // we are only transferring this notification to its parent, don't generate an
209 // animation
210 mListContainer.setChildTransferInProgress(true);
211 }
Rohan Shah524cf7b2018-03-15 14:40:02 -0700212 if (viewToRemove.isSummaryWithChildren()) {
213 viewToRemove.removeAllChildren();
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900214 }
Rohan Shah524cf7b2018-03-15 14:40:02 -0700215 mListContainer.removeContainerView(viewToRemove);
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900216 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 Cinekfdf80332019-03-07 17:29:55 -0800226 } 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 Courtney2b4c3a02017-11-27 13:27:46 +0900231 }
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 Shah524cf7b2018-03-15 14:40:02 -0700246 if (((ExpandableNotificationRow) child).isBlockingHelperShowing()) {
247 // Don't count/reorder notifications that are showing the blocking helper!
248 continue;
249 }
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900250
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 Burnsd4a69f72019-06-19 19:49:19 -0400269 updateRowStatesInternal();
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900270
271 mListContainer.onNotificationViewUpdateFinished();
Ned Burnsd4a69f72019-06-19 19:49:19 -0400272
273 endUpdate();
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900274 }
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 Laird181de622019-10-24 09:53:02 -0400341 if (mEntryManager.getActiveNotificationUnfiltered(
Ned Burns1c2b85a42019-11-14 15:37:03 -0500342 remove.getEntry().getSbn().getKey()) == null) {
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900343 // 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 Burnsd4a69f72019-06-19 19:49:19 -0400357 Assert.isMainThread();
358 beginUpdate();
359 updateRowStatesInternal();
360 endUpdate();
361 }
362
363 private void updateRowStatesInternal() {
Lucas Dupin16013822018-05-17 18:00:16 -0700364 Trace.beginSection("NotificationViewHierarchyManager#updateRowStates");
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900365 final int N = mListContainer.getContainerChildCount();
366
367 int visibleNotifications = 0;
Jason Monk297c04e2018-08-23 17:16:59 -0400368 boolean onKeyguard = mStatusBarStateController.getState() == StatusBarState.KEYGUARD;
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900369 int maxNotifications = -1;
Selim Cinekb0fada62019-06-17 19:03:59 -0700370 if (onKeyguard && !mBypassController.getBypassEnabled()) {
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900371 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 Burnsf81c4c42019-01-07 14:10:43 -0500384 NotificationEntry entry = row.getEntry();
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900385 boolean isChildNotification =
Ned Burns00b4b2d2019-10-17 22:09:27 -0400386 mGroupManager.isChildInGroupWithSummary(entry.getSbn());
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900387
Jason Monk297c04e2018-08-23 17:16:59 -0400388 row.setOnKeyguard(onKeyguard);
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900389
Jason Monk297c04e2018-08-23 17:16:59 -0400390 if (!onKeyguard) {
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900391 // 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 Burns00b4b2d2019-10-17 22:09:27 -0400398 int userId = entry.getSbn().getUserId();
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900399 boolean suppressedSummary = mGroupManager.isSummaryOfSuppressedGroup(
Ned Burns00b4b2d2019-10-17 22:09:27 -0400400 entry.getSbn()) && !entry.isRowRemoved();
Ned Burns8c1b7632019-07-19 14:26:15 -0400401 boolean showOnKeyguard = mLockscreenUserManager.shouldShowOnKeyguard(entry);
Selim Cinek3bf2d202018-10-16 17:30:05 -0700402 if (!showOnKeyguard) {
403 // min priority notifications should show if their summary is showing
Ned Burns00b4b2d2019-10-17 22:09:27 -0400404 if (mGroupManager.isChildInGroupWithSummary(entry.getSbn())) {
Ned Burnsf81c4c42019-01-07 14:10:43 -0500405 NotificationEntry summary = mGroupManager.getLogicalGroupSummary(
Ned Burns00b4b2d2019-10-17 22:09:27 -0400406 entry.getSbn());
Ned Burns8c1b7632019-07-19 14:26:15 -0400407 if (summary != null && mLockscreenUserManager.shouldShowOnKeyguard(summary)) {
Selim Cinek3bf2d202018-10-16 17:30:05 -0700408 showOnKeyguard = true;
409 }
410 }
411 }
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900412 if (suppressedSummary
Pavel Grafov65152632018-03-26 15:14:45 +0100413 || mLockscreenUserManager.shouldHideNotifications(userId)
Jason Monk297c04e2018-08-23 17:16:59 -0400414 || (onKeyguard && !showOnKeyguard)) {
Evan Laird94492852018-10-25 13:43:01 -0400415 entry.getRow().setVisibility(View.GONE);
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900416 } else {
Evan Laird94492852018-10-25 13:43:01 -0400417 boolean wasGone = entry.getRow().getVisibility() == View.GONE;
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900418 if (wasGone) {
Evan Laird94492852018-10-25 13:43:01 -0400419 entry.getRow().setVisibility(View.VISIBLE);
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900420 }
Evan Laird94492852018-10-25 13:43:01 -0400421 if (!isChildNotification && !entry.getRow().isRemoved()) {
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900422 if (wasGone) {
423 // notify the scroller of a child addition
Evan Laird94492852018-10-25 13:43:01 -0400424 mListContainer.generateAddAnimation(entry.getRow(),
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900425 !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 Sandler83b70a02018-01-24 23:20:18 -0500438
Julia Reynoldsfc640012018-02-21 12:25:27 -0500439 row.showAppOpsIcons(entry.mActiveAppOps);
Ned Burns60e94592019-09-06 14:47:25 -0400440 row.setLastAudiblyAlertedMs(entry.getLastAudiblyAlertedMs());
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900441 }
442
Lucas Dupin16013822018-05-17 18:00:16 -0700443 Trace.beginSection("NotificationPresenter#onUpdateRowStates");
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900444 mPresenter.onUpdateRowStates();
Lucas Dupin16013822018-05-17 18:00:16 -0700445 Trace.endSection();
446 Trace.endSection();
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900447 }
Selim Cinek6f0a62a2019-04-09 18:40:12 -0700448
449 @Override
450 public void onDynamicPrivacyChanged() {
Ned Burnsb3b4bd32019-06-27 19:36:58 -0400451 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 Cinek6f0a62a2019-04-09 18:40:12 -0700465 updateNotificationViews();
466 }
Ned Burnsd4a69f72019-06-19 19:49:19 -0400467
468 private void beginUpdate() {
469 if (mPerformingUpdate) {
Ned Burnsbddd3f12019-06-28 12:54:25 -0400470 Log.wtf(TAG, "Re-entrant code during update", new Exception());
Ned Burnsd4a69f72019-06-19 19:49:19 -0400471 }
472 mPerformingUpdate = true;
473 }
474
475 private void endUpdate() {
476 if (!mPerformingUpdate) {
Ned Burnsbddd3f12019-06-28 12:54:25 -0400477 Log.wtf(TAG, "Manager state has become desynced", new Exception());
Ned Burnsd4a69f72019-06-19 19:49:19 -0400478 }
479 mPerformingUpdate = false;
480 }
Eliot Courtney2b4c3a02017-11-27 13:27:46 +0900481}