blob: 7a9b2645374b5fd4dd26ef82c5f4d808cb01840f [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 Cinek36b02232016-05-11 23:07:05 -0400218 && isOnlyChildInGroup(sbn);
219 }
220
221 public boolean isOnlyChildInGroup(StatusBarNotification sbn) {
222 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 Cinek23c80342016-03-17 18:27:36 -0700226 private int getTotalNumberOfChildren(StatusBarNotification sbn) {
227 return getNumberOfIsolatedChildren(sbn.getGroupKey())
228 + mGroupMap.get(sbn.getGroupKey()).children.size();
229 }
230
231 private boolean isGroupSuppressed(String groupKey) {
232 NotificationGroup group = mGroupMap.get(groupKey);
Selim Cinek2a739342016-03-17 10:28:55 -0700233 return group != null && group.suppressed;
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100234 }
235
Selim Cinek9c4c4142015-12-04 16:44:56 -0800236 public void setStatusBarState(int newState) {
237 if (mBarState == newState) {
238 return;
239 }
240 mBarState = newState;
241 if (mBarState == StatusBarState.KEYGUARD) {
Selim Cinek9184f9c2016-02-02 17:36:53 -0800242 collapseAllGroups();
243 }
244 }
245
246 public void collapseAllGroups() {
Selim Cinekc0b14b02016-05-09 13:12:40 -0400247 // Because notifications can become isolated when the group becomes suppressed it can
248 // lead to concurrent modifications while looping. We need to make a copy.
249 ArrayList<NotificationGroup> groupCopy = new ArrayList<>(mGroupMap.values());
250 int size = groupCopy.size();
251 for (int i = 0; i < size; i++) {
252 NotificationGroup group = groupCopy.get(i);
Selim Cinek9184f9c2016-02-02 17:36:53 -0800253 if (group.expanded) {
254 setGroupExpanded(group, false);
Selim Cinek9c4c4142015-12-04 16:44:56 -0800255 }
Selim Cinek2a739342016-03-17 10:28:55 -0700256 updateSuppression(group);
Selim Cinek9c4c4142015-12-04 16:44:56 -0800257 }
258 }
259
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100260 /**
261 * @return whether a given notification is a child in a group which has a summary
262 */
263 public boolean isChildInGroupWithSummary(StatusBarNotification sbn) {
Selim Cinekef5127e2015-12-21 16:55:58 -0800264 if (!isGroupChild(sbn)) {
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100265 return false;
266 }
Selim Cinekef5127e2015-12-21 16:55:58 -0800267 NotificationGroup group = mGroupMap.get(getGroupKey(sbn));
Selim Cinek2a739342016-03-17 10:28:55 -0700268 if (group == null || group.summary == null || group.suppressed) {
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100269 return false;
270 }
Selim Cinek3f19f602016-05-02 18:01:56 -0700271 if (group.children.isEmpty()) {
272 // If the suppression of a group changes because the last child was removed, this can
273 // still be called temporarily because the child hasn't been fully removed yet. Let's
274 // make sure we still return false in that case.
275 return false;
276 }
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100277 return true;
278 }
279
Selim Cinek263398f2015-10-21 17:40:23 -0700280 /**
281 * @return whether a given notification is a summary in a group which has children
282 */
283 public boolean isSummaryOfGroup(StatusBarNotification sbn) {
Selim Cinekef5127e2015-12-21 16:55:58 -0800284 if (!isGroupSummary(sbn)) {
Selim Cinek263398f2015-10-21 17:40:23 -0700285 return false;
286 }
Selim Cinekef5127e2015-12-21 16:55:58 -0800287 NotificationGroup group = mGroupMap.get(getGroupKey(sbn));
Selim Cinek263398f2015-10-21 17:40:23 -0700288 if (group == null) {
289 return false;
290 }
291 return !group.children.isEmpty();
292 }
293
Selim Cinek23c80342016-03-17 18:27:36 -0700294 /**
295 * Get the summary of a specified status bar notification. For isolated notification this return
296 * itself.
297 */
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100298 public ExpandableNotificationRow getGroupSummary(StatusBarNotification sbn) {
Selim Cinek23c80342016-03-17 18:27:36 -0700299 return getGroupSummary(getGroupKey(sbn));
300 }
301
302 /**
303 * Similar to {@link #getGroupSummary(StatusBarNotification)} but doesn't get the visual summary
304 * but the logical summary, i.e when a child is isolated, it still returns the summary as if
305 * it wasn't isolated.
306 */
307 public ExpandableNotificationRow getLogicalGroupSummary(
308 StatusBarNotification sbn) {
309 return getGroupSummary(sbn.getGroupKey());
310 }
311
312 @Nullable
313 private ExpandableNotificationRow getGroupSummary(String groupKey) {
314 NotificationGroup group = mGroupMap.get(groupKey);
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100315 return group == null ? null
316 : group.summary == null ? null
Selim Cinek23c80342016-03-17 18:27:36 -0700317 : group.summary.row;
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100318 }
319
Selim Cinek83bc7832015-10-22 13:26:54 -0700320 public void toggleGroupExpansion(StatusBarNotification sbn) {
Selim Cinekef5127e2015-12-21 16:55:58 -0800321 NotificationGroup group = mGroupMap.get(getGroupKey(sbn));
Selim Cinek83bc7832015-10-22 13:26:54 -0700322 if (group == null) {
323 return;
324 }
325 setGroupExpanded(group, !group.expanded);
326 }
327
Selim Cinekef5127e2015-12-21 16:55:58 -0800328 private boolean isIsolated(StatusBarNotification sbn) {
Selim Cineka6c0cef2016-03-18 11:42:25 -0700329 return mIsolatedEntries.containsKey(sbn.getKey());
Selim Cinekef5127e2015-12-21 16:55:58 -0800330 }
331
332 private boolean isGroupSummary(StatusBarNotification sbn) {
333 if (isIsolated(sbn)) {
334 return true;
335 }
336 return sbn.getNotification().isGroupSummary();
337 }
Julia Reynoldse46bb372016-03-17 11:05:58 -0400338
Selim Cinekef5127e2015-12-21 16:55:58 -0800339 private boolean isGroupChild(StatusBarNotification sbn) {
340 if (isIsolated(sbn)) {
341 return false;
342 }
Julia Reynoldse46bb372016-03-17 11:05:58 -0400343 return sbn.isGroup() && !sbn.getNotification().isGroupSummary();
Selim Cinekef5127e2015-12-21 16:55:58 -0800344 }
345
346 private String getGroupKey(StatusBarNotification sbn) {
347 if (isIsolated(sbn)) {
348 return sbn.getKey();
349 }
350 return sbn.getGroupKey();
351 }
352
353 @Override
354 public void onHeadsUpPinnedModeChanged(boolean inPinnedMode) {
355 }
356
357 @Override
358 public void onHeadsUpPinned(ExpandableNotificationRow headsUp) {
359 }
360
361 @Override
362 public void onHeadsUpUnPinned(ExpandableNotificationRow headsUp) {
363 }
364
365 @Override
366 public void onHeadsUpStateChanged(NotificationData.Entry entry, boolean isHeadsUp) {
367 final StatusBarNotification sbn = entry.notification;
368 if (entry.row.isHeadsUp()) {
Selim Cineka6c0cef2016-03-18 11:42:25 -0700369 if (shouldIsolate(sbn)) {
Selim Cinek23c80342016-03-17 18:27:36 -0700370 // We will be isolated now, so lets update the groups
371 onEntryRemovedInternal(entry, entry.notification);
Selim Cineka6c0cef2016-03-18 11:42:25 -0700372
373 mIsolatedEntries.put(sbn.getKey(), sbn);
374
Selim Cinek23c80342016-03-17 18:27:36 -0700375 onEntryAdded(entry);
376 // We also need to update the suppression of the old group, because this call comes
377 // even before the groupManager knows about the notification at all.
378 // When the notification gets added afterwards it is already isolated and therefore
379 // it doesn't lead to an update.
380 updateSuppression(mGroupMap.get(entry.notification.getGroupKey()));
381 mListener.onGroupsChanged();
Selim Cinek967ed2a2016-04-08 18:29:11 -0700382 } else {
383 handleSuppressedSummaryHeadsUpped(entry);
Selim Cinekef5127e2015-12-21 16:55:58 -0800384 }
385 } else {
Selim Cineka6c0cef2016-03-18 11:42:25 -0700386 if (mIsolatedEntries.containsKey(sbn.getKey())) {
387 // not isolated anymore, we need to update the groups
388 onEntryRemovedInternal(entry, entry.notification);
389 mIsolatedEntries.remove(sbn.getKey());
390 onEntryAdded(entry);
391 mListener.onGroupsChanged();
Selim Cinekef5127e2015-12-21 16:55:58 -0800392 }
393 }
394 }
395
Selim Cinek967ed2a2016-04-08 18:29:11 -0700396 private void handleSuppressedSummaryHeadsUpped(NotificationData.Entry entry) {
397 StatusBarNotification sbn = entry.notification;
398 if (!isGroupSuppressed(sbn.getGroupKey())
399 || !sbn.getNotification().isGroupSummary()
400 || !entry.row.isHeadsUp()) {
401 return;
402 }
403 // The parent of a suppressed group got huned, lets hun the child!
404 NotificationGroup notificationGroup = mGroupMap.get(sbn.getGroupKey());
405 if (notificationGroup != null) {
406 Iterator<NotificationData.Entry> iterator = notificationGroup.children.iterator();
407 NotificationData.Entry child = iterator.hasNext() ? iterator.next() : null;
408 if (child == null) {
409 child = getIsolatedChild(sbn.getGroupKey());
410 }
411 if (child != null) {
412 if (mHeadsUpManager.isHeadsUp(child.key)) {
413 mHeadsUpManager.updateNotification(child, true);
414 } else {
415 mHeadsUpManager.showNotification(child);
416 }
417 }
418 }
419 mHeadsUpManager.releaseImmediately(entry.key);
420 }
421
Selim Cineka6c0cef2016-03-18 11:42:25 -0700422 private boolean shouldIsolate(StatusBarNotification sbn) {
423 NotificationGroup notificationGroup = mGroupMap.get(sbn.getGroupKey());
Julia Reynoldse46bb372016-03-17 11:05:58 -0400424 return (sbn.isGroup() && !sbn.getNotification().isGroupSummary())
Selim Cineka6c0cef2016-03-18 11:42:25 -0700425 && (sbn.getNotification().fullScreenIntent != null
426 || notificationGroup == null
427 || !notificationGroup.expanded
428 || isGroupNotFullyVisible(notificationGroup));
429 }
430
431 private boolean isGroupNotFullyVisible(NotificationGroup notificationGroup) {
432 return notificationGroup.summary == null
433 || notificationGroup.summary.row.getClipTopOptimization() > 0
434 || notificationGroup.summary.row.getClipTopAmount() > 0
435 || notificationGroup.summary.row.getTranslationY() < 0;
436 }
437
Selim Cinek967ed2a2016-04-08 18:29:11 -0700438 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
439 mHeadsUpManager = headsUpManager;
440 }
441
Selim Cinek52941c52016-05-07 18:29:32 -0400442 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
443 pw.println("GroupManager state:");
444 pw.println(" number of groups: " + mGroupMap.size());
445 for (Map.Entry<String, NotificationGroup> entry : mGroupMap.entrySet()) {
446 pw.println("\n key: " + entry.getKey()); pw.println(entry.getValue());
447 }
448 pw.println("\n isolated entries: " + mIsolatedEntries.size());
449 for (Map.Entry<String, StatusBarNotification> entry : mIsolatedEntries.entrySet()) {
450 pw.print(" "); pw.print(entry.getKey());
451 pw.print(", "); pw.println(entry.getValue());
452 }
453 }
454
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100455 public static class NotificationGroup {
456 public final HashSet<NotificationData.Entry> children = new HashSet<>();
457 public NotificationData.Entry summary;
458 public boolean expanded;
Selim Cinek2a739342016-03-17 10:28:55 -0700459 /**
460 * Is this notification group suppressed, i.e its summary is hidden
461 */
462 public boolean suppressed;
Selim Cinek52941c52016-05-07 18:29:32 -0400463
464 @Override
465 public String toString() {
Selim Cinek60ca7872016-05-12 11:24:07 -0700466 String result = " summary:\n "
467 + (summary != null ? summary.notification : "null");
Selim Cinek52941c52016-05-07 18:29:32 -0400468 result += "\n children size: " + children.size();
469 for (NotificationData.Entry child : children) {
470 result += "\n " + child.notification;
471 }
472 return result;
473 }
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100474 }
475
476 public interface OnGroupChangeListener {
477 /**
478 * The expansion of a group has changed.
479 *
480 * @param changedRow the row for which the expansion has changed, which is also the summary
481 * @param expanded a boolean indicating the new expanded state
482 */
483 void onGroupExpansionChanged(ExpandableNotificationRow changedRow, boolean expanded);
484
485 /**
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100486 * A group of children just received a summary notification and should therefore become
487 * children of it.
488 *
489 * @param group the group created
490 */
491 void onGroupCreatedFromChildren(NotificationGroup group);
Selim Cinekef5127e2015-12-21 16:55:58 -0800492
493 /**
Selim Cinek2a739342016-03-17 10:28:55 -0700494 * The groups have changed. This can happen if the isolation of a child has changes or if a
495 * group became suppressed / unsuppressed
Selim Cinekef5127e2015-12-21 16:55:58 -0800496 */
Selim Cinek2a739342016-03-17 10:28:55 -0700497 void onGroupsChanged();
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100498 }
499}