blob: 270b6edbe367ff1bc968cfb39509594122fc7351 [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())
Julia Reynoldse46bb372016-03-17 11:05:58 -0400218 && !sbn.getNotification().isGroupSummary()
Selim Cinek23c80342016-03-17 18:27:36 -0700219 && getTotalNumberOfChildren(sbn) == 1;
Selim Cinek2a739342016-03-17 10:28:55 -0700220 }
221
Selim Cinek23c80342016-03-17 18:27:36 -0700222 private int getTotalNumberOfChildren(StatusBarNotification sbn) {
223 return getNumberOfIsolatedChildren(sbn.getGroupKey())
224 + mGroupMap.get(sbn.getGroupKey()).children.size();
225 }
226
227 private boolean isGroupSuppressed(String groupKey) {
228 NotificationGroup group = mGroupMap.get(groupKey);
Selim Cinek2a739342016-03-17 10:28:55 -0700229 return group != null && group.suppressed;
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100230 }
231
Selim Cinek9c4c4142015-12-04 16:44:56 -0800232 public void setStatusBarState(int newState) {
233 if (mBarState == newState) {
234 return;
235 }
236 mBarState = newState;
237 if (mBarState == StatusBarState.KEYGUARD) {
Selim Cinek9184f9c2016-02-02 17:36:53 -0800238 collapseAllGroups();
239 }
240 }
241
242 public void collapseAllGroups() {
Selim Cinekc0b14b02016-05-09 13:12:40 -0400243 // Because notifications can become isolated when the group becomes suppressed it can
244 // lead to concurrent modifications while looping. We need to make a copy.
245 ArrayList<NotificationGroup> groupCopy = new ArrayList<>(mGroupMap.values());
246 int size = groupCopy.size();
247 for (int i = 0; i < size; i++) {
248 NotificationGroup group = groupCopy.get(i);
Selim Cinek9184f9c2016-02-02 17:36:53 -0800249 if (group.expanded) {
250 setGroupExpanded(group, false);
Selim Cinek9c4c4142015-12-04 16:44:56 -0800251 }
Selim Cinek2a739342016-03-17 10:28:55 -0700252 updateSuppression(group);
Selim Cinek9c4c4142015-12-04 16:44:56 -0800253 }
254 }
255
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100256 /**
257 * @return whether a given notification is a child in a group which has a summary
258 */
259 public boolean isChildInGroupWithSummary(StatusBarNotification sbn) {
Selim Cinekef5127e2015-12-21 16:55:58 -0800260 if (!isGroupChild(sbn)) {
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100261 return false;
262 }
Selim Cinekef5127e2015-12-21 16:55:58 -0800263 NotificationGroup group = mGroupMap.get(getGroupKey(sbn));
Selim Cinek2a739342016-03-17 10:28:55 -0700264 if (group == null || group.summary == null || group.suppressed) {
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100265 return false;
266 }
Selim Cinek3f19f602016-05-02 18:01:56 -0700267 if (group.children.isEmpty()) {
268 // If the suppression of a group changes because the last child was removed, this can
269 // still be called temporarily because the child hasn't been fully removed yet. Let's
270 // make sure we still return false in that case.
271 return false;
272 }
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100273 return true;
274 }
275
Selim Cinek263398f2015-10-21 17:40:23 -0700276 /**
277 * @return whether a given notification is a summary in a group which has children
278 */
279 public boolean isSummaryOfGroup(StatusBarNotification sbn) {
Selim Cinekef5127e2015-12-21 16:55:58 -0800280 if (!isGroupSummary(sbn)) {
Selim Cinek263398f2015-10-21 17:40:23 -0700281 return false;
282 }
Selim Cinekef5127e2015-12-21 16:55:58 -0800283 NotificationGroup group = mGroupMap.get(getGroupKey(sbn));
Selim Cinek263398f2015-10-21 17:40:23 -0700284 if (group == null) {
285 return false;
286 }
287 return !group.children.isEmpty();
288 }
289
Selim Cinek23c80342016-03-17 18:27:36 -0700290 /**
291 * Get the summary of a specified status bar notification. For isolated notification this return
292 * itself.
293 */
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100294 public ExpandableNotificationRow getGroupSummary(StatusBarNotification sbn) {
Selim Cinek23c80342016-03-17 18:27:36 -0700295 return getGroupSummary(getGroupKey(sbn));
296 }
297
298 /**
299 * Similar to {@link #getGroupSummary(StatusBarNotification)} but doesn't get the visual summary
300 * but the logical summary, i.e when a child is isolated, it still returns the summary as if
301 * it wasn't isolated.
302 */
303 public ExpandableNotificationRow getLogicalGroupSummary(
304 StatusBarNotification sbn) {
305 return getGroupSummary(sbn.getGroupKey());
306 }
307
308 @Nullable
309 private ExpandableNotificationRow getGroupSummary(String groupKey) {
310 NotificationGroup group = mGroupMap.get(groupKey);
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100311 return group == null ? null
312 : group.summary == null ? null
Selim Cinek23c80342016-03-17 18:27:36 -0700313 : group.summary.row;
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100314 }
315
Selim Cinek83bc7832015-10-22 13:26:54 -0700316 public void toggleGroupExpansion(StatusBarNotification sbn) {
Selim Cinekef5127e2015-12-21 16:55:58 -0800317 NotificationGroup group = mGroupMap.get(getGroupKey(sbn));
Selim Cinek83bc7832015-10-22 13:26:54 -0700318 if (group == null) {
319 return;
320 }
321 setGroupExpanded(group, !group.expanded);
322 }
323
Selim Cinekef5127e2015-12-21 16:55:58 -0800324 private boolean isIsolated(StatusBarNotification sbn) {
Selim Cineka6c0cef2016-03-18 11:42:25 -0700325 return mIsolatedEntries.containsKey(sbn.getKey());
Selim Cinekef5127e2015-12-21 16:55:58 -0800326 }
327
328 private boolean isGroupSummary(StatusBarNotification sbn) {
329 if (isIsolated(sbn)) {
330 return true;
331 }
332 return sbn.getNotification().isGroupSummary();
333 }
Julia Reynoldse46bb372016-03-17 11:05:58 -0400334
Selim Cinekef5127e2015-12-21 16:55:58 -0800335 private boolean isGroupChild(StatusBarNotification sbn) {
336 if (isIsolated(sbn)) {
337 return false;
338 }
Julia Reynoldse46bb372016-03-17 11:05:58 -0400339 return sbn.isGroup() && !sbn.getNotification().isGroupSummary();
Selim Cinekef5127e2015-12-21 16:55:58 -0800340 }
341
342 private String getGroupKey(StatusBarNotification sbn) {
343 if (isIsolated(sbn)) {
344 return sbn.getKey();
345 }
346 return sbn.getGroupKey();
347 }
348
349 @Override
350 public void onHeadsUpPinnedModeChanged(boolean inPinnedMode) {
351 }
352
353 @Override
354 public void onHeadsUpPinned(ExpandableNotificationRow headsUp) {
355 }
356
357 @Override
358 public void onHeadsUpUnPinned(ExpandableNotificationRow headsUp) {
359 }
360
361 @Override
362 public void onHeadsUpStateChanged(NotificationData.Entry entry, boolean isHeadsUp) {
363 final StatusBarNotification sbn = entry.notification;
364 if (entry.row.isHeadsUp()) {
Selim Cineka6c0cef2016-03-18 11:42:25 -0700365 if (shouldIsolate(sbn)) {
Selim Cinek23c80342016-03-17 18:27:36 -0700366 // We will be isolated now, so lets update the groups
367 onEntryRemovedInternal(entry, entry.notification);
Selim Cineka6c0cef2016-03-18 11:42:25 -0700368
369 mIsolatedEntries.put(sbn.getKey(), sbn);
370
Selim Cinek23c80342016-03-17 18:27:36 -0700371 onEntryAdded(entry);
372 // We also need to update the suppression of the old group, because this call comes
373 // even before the groupManager knows about the notification at all.
374 // When the notification gets added afterwards it is already isolated and therefore
375 // it doesn't lead to an update.
376 updateSuppression(mGroupMap.get(entry.notification.getGroupKey()));
377 mListener.onGroupsChanged();
Selim Cinek967ed2a2016-04-08 18:29:11 -0700378 } else {
379 handleSuppressedSummaryHeadsUpped(entry);
Selim Cinekef5127e2015-12-21 16:55:58 -0800380 }
381 } else {
Selim Cineka6c0cef2016-03-18 11:42:25 -0700382 if (mIsolatedEntries.containsKey(sbn.getKey())) {
383 // not isolated anymore, we need to update the groups
384 onEntryRemovedInternal(entry, entry.notification);
385 mIsolatedEntries.remove(sbn.getKey());
386 onEntryAdded(entry);
387 mListener.onGroupsChanged();
Selim Cinekef5127e2015-12-21 16:55:58 -0800388 }
389 }
390 }
391
Selim Cinek967ed2a2016-04-08 18:29:11 -0700392 private void handleSuppressedSummaryHeadsUpped(NotificationData.Entry entry) {
393 StatusBarNotification sbn = entry.notification;
394 if (!isGroupSuppressed(sbn.getGroupKey())
395 || !sbn.getNotification().isGroupSummary()
396 || !entry.row.isHeadsUp()) {
397 return;
398 }
399 // The parent of a suppressed group got huned, lets hun the child!
400 NotificationGroup notificationGroup = mGroupMap.get(sbn.getGroupKey());
401 if (notificationGroup != null) {
402 Iterator<NotificationData.Entry> iterator = notificationGroup.children.iterator();
403 NotificationData.Entry child = iterator.hasNext() ? iterator.next() : null;
404 if (child == null) {
405 child = getIsolatedChild(sbn.getGroupKey());
406 }
407 if (child != null) {
408 if (mHeadsUpManager.isHeadsUp(child.key)) {
409 mHeadsUpManager.updateNotification(child, true);
410 } else {
411 mHeadsUpManager.showNotification(child);
412 }
413 }
414 }
415 mHeadsUpManager.releaseImmediately(entry.key);
416 }
417
Selim Cineka6c0cef2016-03-18 11:42:25 -0700418 private boolean shouldIsolate(StatusBarNotification sbn) {
419 NotificationGroup notificationGroup = mGroupMap.get(sbn.getGroupKey());
Julia Reynoldse46bb372016-03-17 11:05:58 -0400420 return (sbn.isGroup() && !sbn.getNotification().isGroupSummary())
Selim Cineka6c0cef2016-03-18 11:42:25 -0700421 && (sbn.getNotification().fullScreenIntent != null
422 || notificationGroup == null
423 || !notificationGroup.expanded
424 || isGroupNotFullyVisible(notificationGroup));
425 }
426
427 private boolean isGroupNotFullyVisible(NotificationGroup notificationGroup) {
428 return notificationGroup.summary == null
429 || notificationGroup.summary.row.getClipTopOptimization() > 0
430 || notificationGroup.summary.row.getClipTopAmount() > 0
431 || notificationGroup.summary.row.getTranslationY() < 0;
432 }
433
Selim Cinek967ed2a2016-04-08 18:29:11 -0700434 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
435 mHeadsUpManager = headsUpManager;
436 }
437
Selim Cinek52941c52016-05-07 18:29:32 -0400438 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
439 pw.println("GroupManager state:");
440 pw.println(" number of groups: " + mGroupMap.size());
441 for (Map.Entry<String, NotificationGroup> entry : mGroupMap.entrySet()) {
442 pw.println("\n key: " + entry.getKey()); pw.println(entry.getValue());
443 }
444 pw.println("\n isolated entries: " + mIsolatedEntries.size());
445 for (Map.Entry<String, StatusBarNotification> entry : mIsolatedEntries.entrySet()) {
446 pw.print(" "); pw.print(entry.getKey());
447 pw.print(", "); pw.println(entry.getValue());
448 }
449 }
450
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100451 public static class NotificationGroup {
452 public final HashSet<NotificationData.Entry> children = new HashSet<>();
453 public NotificationData.Entry summary;
454 public boolean expanded;
Selim Cinek2a739342016-03-17 10:28:55 -0700455 /**
456 * Is this notification group suppressed, i.e its summary is hidden
457 */
458 public boolean suppressed;
Selim Cinek52941c52016-05-07 18:29:32 -0400459
460 @Override
461 public String toString() {
Selim Cinek60ca7872016-05-12 11:24:07 -0700462 String result = " summary:\n "
463 + (summary != null ? summary.notification : "null");
Selim Cinek52941c52016-05-07 18:29:32 -0400464 result += "\n children size: " + children.size();
465 for (NotificationData.Entry child : children) {
466 result += "\n " + child.notification;
467 }
468 return result;
469 }
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100470 }
471
472 public interface OnGroupChangeListener {
473 /**
474 * The expansion of a group has changed.
475 *
476 * @param changedRow the row for which the expansion has changed, which is also the summary
477 * @param expanded a boolean indicating the new expanded state
478 */
479 void onGroupExpansionChanged(ExpandableNotificationRow changedRow, boolean expanded);
480
481 /**
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100482 * A group of children just received a summary notification and should therefore become
483 * children of it.
484 *
485 * @param group the group created
486 */
487 void onGroupCreatedFromChildren(NotificationGroup group);
Selim Cinekef5127e2015-12-21 16:55:58 -0800488
489 /**
Selim Cinek2a739342016-03-17 10:28:55 -0700490 * The groups have changed. This can happen if the isolation of a child has changes or if a
491 * group became suppressed / unsuppressed
Selim Cinekef5127e2015-12-21 16:55:58 -0800492 */
Selim Cinek2a739342016-03-17 10:28:55 -0700493 void onGroupsChanged();
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100494 }
495}