blob: 9ecff18d2d111d7b031d7bd29181baceaa93a82e [file] [log] [blame]
Selim Cinek25fd4e2b2015-02-20 17:46:07 +01001/*
2 * Copyright (C) 2015 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.phone;
18
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010019import android.service.notification.StatusBarNotification;
Selim Cinek23c80342016-03-17 18:27:36 -070020import android.support.annotation.Nullable;
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010021
22import com.android.systemui.statusbar.ExpandableNotificationRow;
23import com.android.systemui.statusbar.NotificationData;
Selim Cinek9c4c4142015-12-04 16:44:56 -080024import com.android.systemui.statusbar.StatusBarState;
Selim Cinekef5127e2015-12-21 16:55:58 -080025import com.android.systemui.statusbar.policy.HeadsUpManager;
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010026
Selim Cinek52941c52016-05-07 18:29:32 -040027import java.io.FileDescriptor;
28import java.io.PrintWriter;
Selim Cinekc0b14b02016-05-09 13:12:40 -040029import java.util.ArrayList;
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010030import java.util.HashMap;
31import java.util.HashSet;
Selim Cinek967ed2a2016-04-08 18:29:11 -070032import java.util.Iterator;
Selim Cinek52941c52016-05-07 18:29:32 -040033import java.util.Map;
Julia Reynoldse46bb372016-03-17 11:05:58 -040034import java.util.Objects;
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010035
36/**
37 * A class to handle notifications and their corresponding groups.
38 */
Selim Cinekef5127e2015-12-21 16:55:58 -080039public class NotificationGroupManager implements HeadsUpManager.OnHeadsUpChangedListener {
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010040
41 private final HashMap<String, NotificationGroup> mGroupMap = new HashMap<>();
42 private OnGroupChangeListener mListener;
43 private int mBarState = -1;
Selim Cineka6c0cef2016-03-18 11:42:25 -070044 private HashMap<String, StatusBarNotification> mIsolatedEntries = new HashMap<>();
Selim Cinek967ed2a2016-04-08 18:29:11 -070045 private HeadsUpManager mHeadsUpManager;
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010046
47 public void setOnGroupChangeListener(OnGroupChangeListener listener) {
48 mListener = listener;
49 }
50
51 public boolean isGroupExpanded(StatusBarNotification sbn) {
Selim Cinekef5127e2015-12-21 16:55:58 -080052 NotificationGroup group = mGroupMap.get(getGroupKey(sbn));
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010053 if (group == null) {
54 return false;
55 }
56 return group.expanded;
57 }
58
59 public void setGroupExpanded(StatusBarNotification sbn, boolean expanded) {
Selim Cinekef5127e2015-12-21 16:55:58 -080060 NotificationGroup group = mGroupMap.get(getGroupKey(sbn));
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010061 if (group == null) {
62 return;
63 }
64 setGroupExpanded(group, expanded);
65 }
66
67 private void setGroupExpanded(NotificationGroup group, boolean expanded) {
68 group.expanded = expanded;
69 if (group.summary != null) {
70 mListener.onGroupExpansionChanged(group.summary.row, expanded);
71 }
72 }
73
74 public void onEntryRemoved(NotificationData.Entry removed) {
75 onEntryRemovedInternal(removed, removed.notification);
Selim Cinek52941c52016-05-07 18:29:32 -040076 mIsolatedEntries.remove(removed.key);
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010077 }
78
79 /**
80 * An entry was removed.
81 *
82 * @param removed the removed entry
83 * @param sbn the notification the entry has, which doesn't need to be the same as it's internal
84 * notification
85 */
86 private void onEntryRemovedInternal(NotificationData.Entry removed,
87 final StatusBarNotification sbn) {
Selim Cinekef5127e2015-12-21 16:55:58 -080088 String groupKey = getGroupKey(sbn);
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010089 final NotificationGroup group = mGroupMap.get(groupKey);
Selim Cinek0b4aeab2015-09-01 17:07:38 -070090 if (group == null) {
91 // When an app posts 2 different notifications as summary of the same group, then a
92 // cancellation of the first notification removes this group.
93 // This situation is not supported and we will not allow such notifications anymore in
94 // the close future. See b/23676310 for reference.
95 return;
96 }
Selim Cinekef5127e2015-12-21 16:55:58 -080097 if (isGroupChild(sbn)) {
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010098 group.children.remove(removed);
Selim Cineke73ad212015-11-03 19:11:08 -080099 } else {
100 group.summary = null;
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100101 }
Selim Cinek2a739342016-03-17 10:28:55 -0700102 updateSuppression(group);
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100103 if (group.children.isEmpty()) {
104 if (group.summary == null) {
105 mGroupMap.remove(groupKey);
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100106 }
107 }
108 }
109
Selim Cinekef5127e2015-12-21 16:55:58 -0800110 public void onEntryAdded(final NotificationData.Entry added) {
111 final StatusBarNotification sbn = added.notification;
112 boolean isGroupChild = isGroupChild(sbn);
113 String groupKey = getGroupKey(sbn);
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100114 NotificationGroup group = mGroupMap.get(groupKey);
115 if (group == null) {
116 group = new NotificationGroup();
117 mGroupMap.put(groupKey, group);
118 }
Selim Cinekef5127e2015-12-21 16:55:58 -0800119 if (isGroupChild) {
Selim Cineke73ad212015-11-03 19:11:08 -0800120 group.children.add(added);
Selim Cinek2a739342016-03-17 10:28:55 -0700121 updateSuppression(group);
Selim Cineke73ad212015-11-03 19:11:08 -0800122 } else {
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100123 group.summary = added;
Selim Cinekb5605e52015-02-20 18:21:41 +0100124 group.expanded = added.row.areChildrenExpanded();
Selim Cinek2a739342016-03-17 10:28:55 -0700125 updateSuppression(group);
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100126 if (!group.children.isEmpty()) {
Selim Cinek50e74672016-05-05 15:58:10 -0400127 HashSet<NotificationData.Entry> childrenCopy =
128 (HashSet<NotificationData.Entry>) group.children.clone();
129 for (NotificationData.Entry child : childrenCopy) {
130 onEntryBecomingChild(child);
131 }
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100132 mListener.onGroupCreatedFromChildren(group);
133 }
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100134 }
135 }
136
Selim Cinek50e74672016-05-05 15:58:10 -0400137 private void onEntryBecomingChild(NotificationData.Entry entry) {
138 if (entry.row.isHeadsUp()) {
139 onHeadsUpStateChanged(entry, true);
140 }
141 }
142
Julia Reynoldse46bb372016-03-17 11:05:58 -0400143 public void onEntryBundlingUpdated(final NotificationData.Entry updated,
144 final String overrideGroupKey) {
145 final StatusBarNotification oldSbn = updated.notification.clone();
146 if (!Objects.equals(oldSbn.getOverrideGroupKey(), overrideGroupKey)) {
147 updated.notification.setOverrideGroupKey(overrideGroupKey);
148 onEntryUpdated(updated, oldSbn);
149 }
150 }
151
Selim Cinek2a739342016-03-17 10:28:55 -0700152 private void updateSuppression(NotificationGroup group) {
Selim Cinek23c80342016-03-17 18:27:36 -0700153 if (group == null) {
154 return;
155 }
Selim Cinek2a739342016-03-17 10:28:55 -0700156 boolean prevSuppressed = group.suppressed;
Selim Cinek23c80342016-03-17 18:27:36 -0700157 group.suppressed = group.summary != null && !group.expanded
158 && (group.children.size() == 1
159 || (group.children.size() == 0
Julia Reynoldse46bb372016-03-17 11:05:58 -0400160 && group.summary.notification.getNotification().isGroupSummary()
Selim Cinek23c80342016-03-17 18:27:36 -0700161 && hasIsolatedChildren(group)));
Selim Cinek2a739342016-03-17 10:28:55 -0700162 if (prevSuppressed != group.suppressed) {
Selim Cinek967ed2a2016-04-08 18:29:11 -0700163 if (group.suppressed) {
164 handleSuppressedSummaryHeadsUpped(group.summary);
165 }
Selim Cinek2a739342016-03-17 10:28:55 -0700166 mListener.onGroupsChanged();
167 }
168 }
169
Selim Cinek23c80342016-03-17 18:27:36 -0700170 private boolean hasIsolatedChildren(NotificationGroup group) {
171 return getNumberOfIsolatedChildren(group.summary.notification.getGroupKey()) != 0;
172 }
173
174 private int getNumberOfIsolatedChildren(String groupKey) {
175 int count = 0;
Selim Cineka6c0cef2016-03-18 11:42:25 -0700176 for (StatusBarNotification sbn : mIsolatedEntries.values()) {
Selim Cinek23c80342016-03-17 18:27:36 -0700177 if (sbn.getGroupKey().equals(groupKey) && isIsolated(sbn)) {
178 count++;
179 }
180 }
181 return count;
182 }
183
Selim Cinek967ed2a2016-04-08 18:29:11 -0700184 private NotificationData.Entry getIsolatedChild(String groupKey) {
185 for (StatusBarNotification sbn : mIsolatedEntries.values()) {
186 if (sbn.getGroupKey().equals(groupKey) && isIsolated(sbn)) {
187 return mGroupMap.get(sbn.getKey()).summary;
188 }
189 }
190 return null;
191 }
192
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100193 public void onEntryUpdated(NotificationData.Entry entry,
194 StatusBarNotification oldNotification) {
Selim Cinekef5127e2015-12-21 16:55:58 -0800195 if (mGroupMap.get(getGroupKey(oldNotification)) != null) {
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100196 onEntryRemovedInternal(entry, oldNotification);
197 }
198 onEntryAdded(entry);
Selim Cineka6c0cef2016-03-18 11:42:25 -0700199 if (isIsolated(entry.notification)) {
200 mIsolatedEntries.put(entry.key, entry.notification);
Selim Cinek23c80342016-03-17 18:27:36 -0700201 String oldKey = oldNotification.getGroupKey();
202 String newKey = entry.notification.getGroupKey();
203 if (!oldKey.equals(newKey)) {
204 updateSuppression(mGroupMap.get(oldKey));
205 updateSuppression(mGroupMap.get(newKey));
206 }
Selim Cinek50e74672016-05-05 15:58:10 -0400207 } else if (!isGroupChild(oldNotification) && isGroupChild(entry.notification)) {
208 onEntryBecomingChild(entry);
Selim Cinek23c80342016-03-17 18:27:36 -0700209 }
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100210 }
211
Selim Cinek2a739342016-03-17 10:28:55 -0700212 public boolean isSummaryOfSuppressedGroup(StatusBarNotification sbn) {
Selim Cinek23c80342016-03-17 18:27:36 -0700213 return isGroupSuppressed(getGroupKey(sbn)) && sbn.getNotification().isGroupSummary();
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100214 }
215
Selim Cinek23c80342016-03-17 18:27:36 -0700216 public boolean isOnlyChildInSuppressedGroup(StatusBarNotification sbn) {
217 return isGroupSuppressed(sbn.getGroupKey())
Selim Cinek53c4d3d2016-05-23 10:56:34 -0700218 && isOnlyChild(sbn);
Selim Cinek36b02232016-05-11 23:07:05 -0400219 }
220
Selim Cinek53c4d3d2016-05-23 10:56:34 -0700221 private boolean isOnlyChild(StatusBarNotification sbn) {
Selim Cinek36b02232016-05-11 23:07:05 -0400222 return !sbn.getNotification().isGroupSummary()
Selim Cinek23c80342016-03-17 18:27:36 -0700223 && getTotalNumberOfChildren(sbn) == 1;
Selim Cinek2a739342016-03-17 10:28:55 -0700224 }
225
Selim Cinek53c4d3d2016-05-23 10:56:34 -0700226 public boolean isOnlyChildInGroup(StatusBarNotification sbn) {
227 return isOnlyChild(sbn) && getLogicalGroupSummary(sbn) != null;
228 }
229
Selim Cinek23c80342016-03-17 18:27:36 -0700230 private int getTotalNumberOfChildren(StatusBarNotification sbn) {
Selim Cinek53c4d3d2016-05-23 10:56:34 -0700231 int isolatedChildren = getNumberOfIsolatedChildren(sbn.getGroupKey());
232 NotificationGroup group = mGroupMap.get(sbn.getGroupKey());
233 int realChildren = group != null ? group.children.size() : 0;
234 return isolatedChildren + realChildren;
Selim Cinek23c80342016-03-17 18:27:36 -0700235 }
236
237 private boolean isGroupSuppressed(String groupKey) {
238 NotificationGroup group = mGroupMap.get(groupKey);
Selim Cinek2a739342016-03-17 10:28:55 -0700239 return group != null && group.suppressed;
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100240 }
241
Selim Cinek9c4c4142015-12-04 16:44:56 -0800242 public void setStatusBarState(int newState) {
243 if (mBarState == newState) {
244 return;
245 }
246 mBarState = newState;
247 if (mBarState == StatusBarState.KEYGUARD) {
Selim Cinek9184f9c2016-02-02 17:36:53 -0800248 collapseAllGroups();
249 }
250 }
251
252 public void collapseAllGroups() {
Selim Cinekc0b14b02016-05-09 13:12:40 -0400253 // Because notifications can become isolated when the group becomes suppressed it can
254 // lead to concurrent modifications while looping. We need to make a copy.
255 ArrayList<NotificationGroup> groupCopy = new ArrayList<>(mGroupMap.values());
256 int size = groupCopy.size();
257 for (int i = 0; i < size; i++) {
258 NotificationGroup group = groupCopy.get(i);
Selim Cinek9184f9c2016-02-02 17:36:53 -0800259 if (group.expanded) {
260 setGroupExpanded(group, false);
Selim Cinek9c4c4142015-12-04 16:44:56 -0800261 }
Selim Cinek2a739342016-03-17 10:28:55 -0700262 updateSuppression(group);
Selim Cinek9c4c4142015-12-04 16:44:56 -0800263 }
264 }
265
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100266 /**
267 * @return whether a given notification is a child in a group which has a summary
268 */
269 public boolean isChildInGroupWithSummary(StatusBarNotification sbn) {
Selim Cinekef5127e2015-12-21 16:55:58 -0800270 if (!isGroupChild(sbn)) {
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100271 return false;
272 }
Selim Cinekef5127e2015-12-21 16:55:58 -0800273 NotificationGroup group = mGroupMap.get(getGroupKey(sbn));
Selim Cinek2a739342016-03-17 10:28:55 -0700274 if (group == null || group.summary == null || group.suppressed) {
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100275 return false;
276 }
Selim Cinek3f19f602016-05-02 18:01:56 -0700277 if (group.children.isEmpty()) {
278 // If the suppression of a group changes because the last child was removed, this can
279 // still be called temporarily because the child hasn't been fully removed yet. Let's
280 // make sure we still return false in that case.
281 return false;
282 }
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100283 return true;
284 }
285
Selim Cinek263398f2015-10-21 17:40:23 -0700286 /**
287 * @return whether a given notification is a summary in a group which has children
288 */
289 public boolean isSummaryOfGroup(StatusBarNotification sbn) {
Selim Cinekef5127e2015-12-21 16:55:58 -0800290 if (!isGroupSummary(sbn)) {
Selim Cinek263398f2015-10-21 17:40:23 -0700291 return false;
292 }
Selim Cinekef5127e2015-12-21 16:55:58 -0800293 NotificationGroup group = mGroupMap.get(getGroupKey(sbn));
Selim Cinek263398f2015-10-21 17:40:23 -0700294 if (group == null) {
295 return false;
296 }
297 return !group.children.isEmpty();
298 }
299
Selim Cinek23c80342016-03-17 18:27:36 -0700300 /**
301 * Get the summary of a specified status bar notification. For isolated notification this return
302 * itself.
303 */
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100304 public ExpandableNotificationRow getGroupSummary(StatusBarNotification sbn) {
Selim Cinek23c80342016-03-17 18:27:36 -0700305 return getGroupSummary(getGroupKey(sbn));
306 }
307
308 /**
309 * Similar to {@link #getGroupSummary(StatusBarNotification)} but doesn't get the visual summary
310 * but the logical summary, i.e when a child is isolated, it still returns the summary as if
311 * it wasn't isolated.
312 */
313 public ExpandableNotificationRow getLogicalGroupSummary(
314 StatusBarNotification sbn) {
315 return getGroupSummary(sbn.getGroupKey());
316 }
317
318 @Nullable
319 private ExpandableNotificationRow getGroupSummary(String groupKey) {
320 NotificationGroup group = mGroupMap.get(groupKey);
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100321 return group == null ? null
322 : group.summary == null ? null
Selim Cinek23c80342016-03-17 18:27:36 -0700323 : group.summary.row;
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100324 }
325
Chris Wren698b1702016-05-23 11:16:32 -0400326 /** @return group expansion state after toggling. */
327 public boolean toggleGroupExpansion(StatusBarNotification sbn) {
Selim Cinekef5127e2015-12-21 16:55:58 -0800328 NotificationGroup group = mGroupMap.get(getGroupKey(sbn));
Selim Cinek83bc7832015-10-22 13:26:54 -0700329 if (group == null) {
Chris Wren698b1702016-05-23 11:16:32 -0400330 return false;
Selim Cinek83bc7832015-10-22 13:26:54 -0700331 }
332 setGroupExpanded(group, !group.expanded);
Chris Wren698b1702016-05-23 11:16:32 -0400333 return group.expanded;
Selim Cinek83bc7832015-10-22 13:26:54 -0700334 }
335
Selim Cinekef5127e2015-12-21 16:55:58 -0800336 private boolean isIsolated(StatusBarNotification sbn) {
Selim Cineka6c0cef2016-03-18 11:42:25 -0700337 return mIsolatedEntries.containsKey(sbn.getKey());
Selim Cinekef5127e2015-12-21 16:55:58 -0800338 }
339
340 private boolean isGroupSummary(StatusBarNotification sbn) {
341 if (isIsolated(sbn)) {
342 return true;
343 }
344 return sbn.getNotification().isGroupSummary();
345 }
Julia Reynoldse46bb372016-03-17 11:05:58 -0400346
Selim Cinekef5127e2015-12-21 16:55:58 -0800347 private boolean isGroupChild(StatusBarNotification sbn) {
348 if (isIsolated(sbn)) {
349 return false;
350 }
Julia Reynoldse46bb372016-03-17 11:05:58 -0400351 return sbn.isGroup() && !sbn.getNotification().isGroupSummary();
Selim Cinekef5127e2015-12-21 16:55:58 -0800352 }
353
354 private String getGroupKey(StatusBarNotification sbn) {
355 if (isIsolated(sbn)) {
356 return sbn.getKey();
357 }
358 return sbn.getGroupKey();
359 }
360
361 @Override
362 public void onHeadsUpPinnedModeChanged(boolean inPinnedMode) {
363 }
364
365 @Override
366 public void onHeadsUpPinned(ExpandableNotificationRow headsUp) {
367 }
368
369 @Override
370 public void onHeadsUpUnPinned(ExpandableNotificationRow headsUp) {
371 }
372
373 @Override
374 public void onHeadsUpStateChanged(NotificationData.Entry entry, boolean isHeadsUp) {
375 final StatusBarNotification sbn = entry.notification;
376 if (entry.row.isHeadsUp()) {
Selim Cineka6c0cef2016-03-18 11:42:25 -0700377 if (shouldIsolate(sbn)) {
Selim Cinek23c80342016-03-17 18:27:36 -0700378 // We will be isolated now, so lets update the groups
379 onEntryRemovedInternal(entry, entry.notification);
Selim Cineka6c0cef2016-03-18 11:42:25 -0700380
381 mIsolatedEntries.put(sbn.getKey(), sbn);
382
Selim Cinek23c80342016-03-17 18:27:36 -0700383 onEntryAdded(entry);
384 // We also need to update the suppression of the old group, because this call comes
385 // even before the groupManager knows about the notification at all.
386 // When the notification gets added afterwards it is already isolated and therefore
387 // it doesn't lead to an update.
388 updateSuppression(mGroupMap.get(entry.notification.getGroupKey()));
389 mListener.onGroupsChanged();
Selim Cinek967ed2a2016-04-08 18:29:11 -0700390 } else {
391 handleSuppressedSummaryHeadsUpped(entry);
Selim Cinekef5127e2015-12-21 16:55:58 -0800392 }
393 } else {
Selim Cineka6c0cef2016-03-18 11:42:25 -0700394 if (mIsolatedEntries.containsKey(sbn.getKey())) {
395 // not isolated anymore, we need to update the groups
396 onEntryRemovedInternal(entry, entry.notification);
397 mIsolatedEntries.remove(sbn.getKey());
398 onEntryAdded(entry);
399 mListener.onGroupsChanged();
Selim Cinekef5127e2015-12-21 16:55:58 -0800400 }
401 }
402 }
403
Selim Cinek967ed2a2016-04-08 18:29:11 -0700404 private void handleSuppressedSummaryHeadsUpped(NotificationData.Entry entry) {
405 StatusBarNotification sbn = entry.notification;
406 if (!isGroupSuppressed(sbn.getGroupKey())
407 || !sbn.getNotification().isGroupSummary()
408 || !entry.row.isHeadsUp()) {
409 return;
410 }
411 // The parent of a suppressed group got huned, lets hun the child!
412 NotificationGroup notificationGroup = mGroupMap.get(sbn.getGroupKey());
413 if (notificationGroup != null) {
414 Iterator<NotificationData.Entry> iterator = notificationGroup.children.iterator();
415 NotificationData.Entry child = iterator.hasNext() ? iterator.next() : null;
416 if (child == null) {
417 child = getIsolatedChild(sbn.getGroupKey());
418 }
419 if (child != null) {
420 if (mHeadsUpManager.isHeadsUp(child.key)) {
421 mHeadsUpManager.updateNotification(child, true);
422 } else {
423 mHeadsUpManager.showNotification(child);
424 }
425 }
426 }
427 mHeadsUpManager.releaseImmediately(entry.key);
428 }
429
Selim Cineka6c0cef2016-03-18 11:42:25 -0700430 private boolean shouldIsolate(StatusBarNotification sbn) {
431 NotificationGroup notificationGroup = mGroupMap.get(sbn.getGroupKey());
Julia Reynoldse46bb372016-03-17 11:05:58 -0400432 return (sbn.isGroup() && !sbn.getNotification().isGroupSummary())
Selim Cineka6c0cef2016-03-18 11:42:25 -0700433 && (sbn.getNotification().fullScreenIntent != null
434 || notificationGroup == null
435 || !notificationGroup.expanded
436 || isGroupNotFullyVisible(notificationGroup));
437 }
438
439 private boolean isGroupNotFullyVisible(NotificationGroup notificationGroup) {
440 return notificationGroup.summary == null
Selim Cineka6c0cef2016-03-18 11:42:25 -0700441 || notificationGroup.summary.row.getClipTopAmount() > 0
442 || notificationGroup.summary.row.getTranslationY() < 0;
443 }
444
Selim Cinek967ed2a2016-04-08 18:29:11 -0700445 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
446 mHeadsUpManager = headsUpManager;
447 }
448
Selim Cinek52941c52016-05-07 18:29:32 -0400449 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
450 pw.println("GroupManager state:");
451 pw.println(" number of groups: " + mGroupMap.size());
452 for (Map.Entry<String, NotificationGroup> entry : mGroupMap.entrySet()) {
453 pw.println("\n key: " + entry.getKey()); pw.println(entry.getValue());
454 }
455 pw.println("\n isolated entries: " + mIsolatedEntries.size());
456 for (Map.Entry<String, StatusBarNotification> entry : mIsolatedEntries.entrySet()) {
457 pw.print(" "); pw.print(entry.getKey());
458 pw.print(", "); pw.println(entry.getValue());
459 }
460 }
461
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100462 public static class NotificationGroup {
463 public final HashSet<NotificationData.Entry> children = new HashSet<>();
464 public NotificationData.Entry summary;
465 public boolean expanded;
Selim Cinek2a739342016-03-17 10:28:55 -0700466 /**
467 * Is this notification group suppressed, i.e its summary is hidden
468 */
469 public boolean suppressed;
Selim Cinek52941c52016-05-07 18:29:32 -0400470
471 @Override
472 public String toString() {
Selim Cinek60ca7872016-05-12 11:24:07 -0700473 String result = " summary:\n "
474 + (summary != null ? summary.notification : "null");
Selim Cinek52941c52016-05-07 18:29:32 -0400475 result += "\n children size: " + children.size();
476 for (NotificationData.Entry child : children) {
477 result += "\n " + child.notification;
478 }
479 return result;
480 }
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100481 }
482
483 public interface OnGroupChangeListener {
484 /**
485 * The expansion of a group has changed.
486 *
487 * @param changedRow the row for which the expansion has changed, which is also the summary
488 * @param expanded a boolean indicating the new expanded state
489 */
490 void onGroupExpansionChanged(ExpandableNotificationRow changedRow, boolean expanded);
491
492 /**
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100493 * A group of children just received a summary notification and should therefore become
494 * children of it.
495 *
496 * @param group the group created
497 */
498 void onGroupCreatedFromChildren(NotificationGroup group);
Selim Cinekef5127e2015-12-21 16:55:58 -0800499
500 /**
Selim Cinek2a739342016-03-17 10:28:55 -0700501 * The groups have changed. This can happen if the isolation of a child has changes or if a
502 * group became suppressed / unsuppressed
Selim Cinekef5127e2015-12-21 16:55:58 -0800503 */
Selim Cinek2a739342016-03-17 10:28:55 -0700504 void onGroupsChanged();
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100505 }
506}