Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 20 | import android.service.notification.StatusBarNotification; |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 21 | import android.util.ArraySet; |
Selim Cinek | 04be389 | 2017-08-08 10:58:32 -0700 | [diff] [blame] | 22 | import android.util.Log; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 23 | |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 24 | import com.android.systemui.Dependency; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 25 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
| 26 | import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener; |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 27 | import com.android.systemui.statusbar.StatusBarState; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 28 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Evan Laird | 878c853 | 2018-10-15 15:54:29 -0400 | [diff] [blame] | 29 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 30 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 31 | import com.android.systemui.statusbar.policy.OnHeadsUpChangedListener; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 32 | |
Selim Cinek | 52941c5 | 2016-05-07 18:29:32 -0400 | [diff] [blame] | 33 | import java.io.FileDescriptor; |
| 34 | import java.io.PrintWriter; |
Selim Cinek | c0b14b0 | 2016-05-09 13:12:40 -0400 | [diff] [blame] | 35 | import java.util.ArrayList; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 36 | import java.util.HashMap; |
Selim Cinek | 52941c5 | 2016-05-07 18:29:32 -0400 | [diff] [blame] | 37 | import java.util.Map; |
Selim Cinek | f93bf3e | 2018-05-08 14:43:21 -0700 | [diff] [blame] | 38 | import java.util.Objects; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 39 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 40 | import javax.inject.Inject; |
| 41 | import javax.inject.Singleton; |
| 42 | |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 43 | /** |
| 44 | * A class to handle notifications and their corresponding groups. |
| 45 | */ |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 46 | @Singleton |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 47 | public class NotificationGroupManager implements OnHeadsUpChangedListener, StateListener { |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 48 | |
Selim Cinek | 04be389 | 2017-08-08 10:58:32 -0700 | [diff] [blame] | 49 | private static final String TAG = "NotificationGroupManager"; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 50 | private final HashMap<String, NotificationGroup> mGroupMap = new HashMap<>(); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 51 | private final ArraySet<OnGroupChangeListener> mListeners = new ArraySet<>(); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 52 | private int mBarState = -1; |
Selim Cinek | a6c0cef | 2016-03-18 11:42:25 -0700 | [diff] [blame] | 53 | private HashMap<String, StatusBarNotification> mIsolatedEntries = new HashMap<>(); |
Selim Cinek | 967ed2a | 2016-04-08 18:29:11 -0700 | [diff] [blame] | 54 | private HeadsUpManager mHeadsUpManager; |
Selim Cinek | 80c44dd | 2016-08-15 19:39:55 -0700 | [diff] [blame] | 55 | private boolean mIsUpdatingUnchangedGroup; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 56 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 57 | @Inject |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 58 | public NotificationGroupManager(StatusBarStateController statusBarStateController) { |
| 59 | statusBarStateController.addCallback(this); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 60 | } |
| 61 | |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 62 | /** |
| 63 | * Add a listener for changes to groups. |
| 64 | * |
| 65 | * @param listener listener to add |
| 66 | */ |
| 67 | public void addOnGroupChangeListener(OnGroupChangeListener listener) { |
| 68 | mListeners.add(listener); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | public boolean isGroupExpanded(StatusBarNotification sbn) { |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 72 | NotificationGroup group = mGroupMap.get(getGroupKey(sbn)); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 73 | if (group == null) { |
| 74 | return false; |
| 75 | } |
| 76 | return group.expanded; |
| 77 | } |
| 78 | |
| 79 | public void setGroupExpanded(StatusBarNotification sbn, boolean expanded) { |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 80 | NotificationGroup group = mGroupMap.get(getGroupKey(sbn)); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 81 | if (group == null) { |
| 82 | return; |
| 83 | } |
| 84 | setGroupExpanded(group, expanded); |
| 85 | } |
| 86 | |
| 87 | private void setGroupExpanded(NotificationGroup group, boolean expanded) { |
| 88 | group.expanded = expanded; |
| 89 | if (group.summary != null) { |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 90 | for (OnGroupChangeListener listener : mListeners) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 91 | listener.onGroupExpansionChanged(group.summary.getRow(), expanded); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 92 | } |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 96 | public void onEntryRemoved(NotificationEntry removed) { |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 97 | onEntryRemovedInternal(removed, removed.notification); |
Selim Cinek | 52941c5 | 2016-05-07 18:29:32 -0400 | [diff] [blame] | 98 | mIsolatedEntries.remove(removed.key); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /** |
| 102 | * An entry was removed. |
| 103 | * |
| 104 | * @param removed the removed entry |
| 105 | * @param sbn the notification the entry has, which doesn't need to be the same as it's internal |
| 106 | * notification |
| 107 | */ |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 108 | private void onEntryRemovedInternal(NotificationEntry removed, |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 109 | final StatusBarNotification sbn) { |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 110 | String groupKey = getGroupKey(sbn); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 111 | final NotificationGroup group = mGroupMap.get(groupKey); |
Selim Cinek | 0b4aeab | 2015-09-01 17:07:38 -0700 | [diff] [blame] | 112 | if (group == null) { |
| 113 | // When an app posts 2 different notifications as summary of the same group, then a |
| 114 | // cancellation of the first notification removes this group. |
| 115 | // This situation is not supported and we will not allow such notifications anymore in |
| 116 | // the close future. See b/23676310 for reference. |
| 117 | return; |
| 118 | } |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 119 | if (isGroupChild(sbn)) { |
Selim Cinek | 04be389 | 2017-08-08 10:58:32 -0700 | [diff] [blame] | 120 | group.children.remove(removed.key); |
Selim Cinek | e73ad21 | 2015-11-03 19:11:08 -0800 | [diff] [blame] | 121 | } else { |
| 122 | group.summary = null; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 123 | } |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 124 | updateSuppression(group); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 125 | if (group.children.isEmpty()) { |
| 126 | if (group.summary == null) { |
| 127 | mGroupMap.remove(groupKey); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 128 | for (OnGroupChangeListener listener : mListeners) { |
| 129 | listener.onGroupRemoved(group, groupKey); |
| 130 | } |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 135 | public void onEntryAdded(final NotificationEntry added) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 136 | if (added.isRowRemoved()) { |
Selim Cinek | 04be389 | 2017-08-08 10:58:32 -0700 | [diff] [blame] | 137 | added.setDebugThrowable(new Throwable()); |
| 138 | } |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 139 | final StatusBarNotification sbn = added.notification; |
| 140 | boolean isGroupChild = isGroupChild(sbn); |
| 141 | String groupKey = getGroupKey(sbn); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 142 | NotificationGroup group = mGroupMap.get(groupKey); |
| 143 | if (group == null) { |
| 144 | group = new NotificationGroup(); |
| 145 | mGroupMap.put(groupKey, group); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 146 | for (OnGroupChangeListener listener : mListeners) { |
| 147 | listener.onGroupCreated(group, groupKey); |
| 148 | } |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 149 | } |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 150 | if (isGroupChild) { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 151 | NotificationEntry existing = group.children.get(added.key); |
Selim Cinek | 04be389 | 2017-08-08 10:58:32 -0700 | [diff] [blame] | 152 | if (existing != null && existing != added) { |
| 153 | Throwable existingThrowable = existing.getDebugThrowable(); |
| 154 | Log.wtf(TAG, "Inconsistent entries found with the same key " + added.key |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 155 | + "existing removed: " + existing.isRowRemoved() |
Selim Cinek | 04be389 | 2017-08-08 10:58:32 -0700 | [diff] [blame] | 156 | + (existingThrowable != null |
| 157 | ? Log.getStackTraceString(existingThrowable) + "\n": "") |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 158 | + " added removed" + added.isRowRemoved() |
Selim Cinek | 04be389 | 2017-08-08 10:58:32 -0700 | [diff] [blame] | 159 | , new Throwable()); |
| 160 | } |
| 161 | group.children.put(added.key, added); |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 162 | updateSuppression(group); |
Selim Cinek | e73ad21 | 2015-11-03 19:11:08 -0800 | [diff] [blame] | 163 | } else { |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 164 | group.summary = added; |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 165 | group.expanded = added.areChildrenExpanded(); |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 166 | updateSuppression(group); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 167 | if (!group.children.isEmpty()) { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 168 | ArrayList<NotificationEntry> childrenCopy |
Selim Cinek | 04be389 | 2017-08-08 10:58:32 -0700 | [diff] [blame] | 169 | = new ArrayList<>(group.children.values()); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 170 | for (NotificationEntry child : childrenCopy) { |
Selim Cinek | 50e7467 | 2016-05-05 15:58:10 -0400 | [diff] [blame] | 171 | onEntryBecomingChild(child); |
| 172 | } |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 173 | for (OnGroupChangeListener listener : mListeners) { |
| 174 | listener.onGroupCreatedFromChildren(group); |
Selim Cinek | f93bf3e | 2018-05-08 14:43:21 -0700 | [diff] [blame] | 175 | } |
| 176 | } |
Selim Cinek | f93bf3e | 2018-05-08 14:43:21 -0700 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 180 | private void onEntryBecomingChild(NotificationEntry entry) { |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 181 | if (shouldIsolate(entry)) { |
| 182 | isolateNotification(entry); |
Selim Cinek | 50e7467 | 2016-05-05 15:58:10 -0400 | [diff] [blame] | 183 | } |
| 184 | } |
| 185 | |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 186 | private void updateSuppression(NotificationGroup group) { |
Selim Cinek | 80c44dd | 2016-08-15 19:39:55 -0700 | [diff] [blame] | 187 | if (group == null) { |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 188 | return; |
| 189 | } |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 190 | boolean prevSuppressed = group.suppressed; |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 191 | group.suppressed = group.summary != null && !group.expanded |
| 192 | && (group.children.size() == 1 |
| 193 | || (group.children.size() == 0 |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 194 | && group.summary.notification.getNotification().isGroupSummary() |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 195 | && hasIsolatedChildren(group))); |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 196 | if (prevSuppressed != group.suppressed) { |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 197 | for (OnGroupChangeListener listener : mListeners) { |
| 198 | if (!mIsUpdatingUnchangedGroup) { |
| 199 | listener.onGroupSuppressionChanged(group, group.suppressed); |
| 200 | listener.onGroupsChanged(); |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 201 | } |
Selim Cinek | 967ed2a | 2016-04-08 18:29:11 -0700 | [diff] [blame] | 202 | } |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 206 | private boolean hasIsolatedChildren(NotificationGroup group) { |
| 207 | return getNumberOfIsolatedChildren(group.summary.notification.getGroupKey()) != 0; |
| 208 | } |
| 209 | |
| 210 | private int getNumberOfIsolatedChildren(String groupKey) { |
| 211 | int count = 0; |
Selim Cinek | a6c0cef | 2016-03-18 11:42:25 -0700 | [diff] [blame] | 212 | for (StatusBarNotification sbn : mIsolatedEntries.values()) { |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 213 | if (sbn.getGroupKey().equals(groupKey) && isIsolated(sbn)) { |
| 214 | count++; |
| 215 | } |
| 216 | } |
| 217 | return count; |
| 218 | } |
| 219 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 220 | private NotificationEntry getIsolatedChild(String groupKey) { |
Selim Cinek | 967ed2a | 2016-04-08 18:29:11 -0700 | [diff] [blame] | 221 | for (StatusBarNotification sbn : mIsolatedEntries.values()) { |
| 222 | if (sbn.getGroupKey().equals(groupKey) && isIsolated(sbn)) { |
| 223 | return mGroupMap.get(sbn.getKey()).summary; |
| 224 | } |
| 225 | } |
| 226 | return null; |
| 227 | } |
| 228 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 229 | public void onEntryUpdated(NotificationEntry entry, |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 230 | StatusBarNotification oldNotification) { |
Selim Cinek | 68bdff1 | 2016-08-03 13:38:56 -0700 | [diff] [blame] | 231 | String oldKey = oldNotification.getGroupKey(); |
| 232 | String newKey = entry.notification.getGroupKey(); |
| 233 | boolean groupKeysChanged = !oldKey.equals(newKey); |
| 234 | boolean wasGroupChild = isGroupChild(oldNotification); |
| 235 | boolean isGroupChild = isGroupChild(entry.notification); |
Selim Cinek | 80c44dd | 2016-08-15 19:39:55 -0700 | [diff] [blame] | 236 | mIsUpdatingUnchangedGroup = !groupKeysChanged && wasGroupChild == isGroupChild; |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 237 | if (mGroupMap.get(getGroupKey(oldNotification)) != null) { |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 238 | onEntryRemovedInternal(entry, oldNotification); |
| 239 | } |
| 240 | onEntryAdded(entry); |
Selim Cinek | 80c44dd | 2016-08-15 19:39:55 -0700 | [diff] [blame] | 241 | mIsUpdatingUnchangedGroup = false; |
Selim Cinek | a6c0cef | 2016-03-18 11:42:25 -0700 | [diff] [blame] | 242 | if (isIsolated(entry.notification)) { |
| 243 | mIsolatedEntries.put(entry.key, entry.notification); |
Selim Cinek | 68bdff1 | 2016-08-03 13:38:56 -0700 | [diff] [blame] | 244 | if (groupKeysChanged) { |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 245 | updateSuppression(mGroupMap.get(oldKey)); |
| 246 | updateSuppression(mGroupMap.get(newKey)); |
| 247 | } |
Selim Cinek | 68bdff1 | 2016-08-03 13:38:56 -0700 | [diff] [blame] | 248 | } else if (!wasGroupChild && isGroupChild) { |
Selim Cinek | 50e7467 | 2016-05-05 15:58:10 -0400 | [diff] [blame] | 249 | onEntryBecomingChild(entry); |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 250 | } |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 251 | } |
| 252 | |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 253 | public boolean isSummaryOfSuppressedGroup(StatusBarNotification sbn) { |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 254 | return isGroupSuppressed(getGroupKey(sbn)) && sbn.getNotification().isGroupSummary(); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 255 | } |
| 256 | |
Selim Cinek | 53c4d3d | 2016-05-23 10:56:34 -0700 | [diff] [blame] | 257 | private boolean isOnlyChild(StatusBarNotification sbn) { |
Selim Cinek | 36b0223 | 2016-05-11 23:07:05 -0400 | [diff] [blame] | 258 | return !sbn.getNotification().isGroupSummary() |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 259 | && getTotalNumberOfChildren(sbn) == 1; |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Selim Cinek | 53c4d3d | 2016-05-23 10:56:34 -0700 | [diff] [blame] | 262 | public boolean isOnlyChildInGroup(StatusBarNotification sbn) { |
Selim Cinek | 88086e7 | 2016-06-17 21:01:32 -0700 | [diff] [blame] | 263 | if (!isOnlyChild(sbn)) { |
| 264 | return false; |
| 265 | } |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 266 | NotificationEntry logicalGroupSummary = getLogicalGroupSummary(sbn); |
Selim Cinek | 88086e7 | 2016-06-17 21:01:32 -0700 | [diff] [blame] | 267 | return logicalGroupSummary != null |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 268 | && !logicalGroupSummary.notification.equals(sbn); |
Selim Cinek | 53c4d3d | 2016-05-23 10:56:34 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 271 | private int getTotalNumberOfChildren(StatusBarNotification sbn) { |
Selim Cinek | 53c4d3d | 2016-05-23 10:56:34 -0700 | [diff] [blame] | 272 | int isolatedChildren = getNumberOfIsolatedChildren(sbn.getGroupKey()); |
| 273 | NotificationGroup group = mGroupMap.get(sbn.getGroupKey()); |
| 274 | int realChildren = group != null ? group.children.size() : 0; |
| 275 | return isolatedChildren + realChildren; |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | private boolean isGroupSuppressed(String groupKey) { |
| 279 | NotificationGroup group = mGroupMap.get(groupKey); |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 280 | return group != null && group.suppressed; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 281 | } |
| 282 | |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 283 | private void setStatusBarState(int newState) { |
Selim Cinek | 9c4c414 | 2015-12-04 16:44:56 -0800 | [diff] [blame] | 284 | mBarState = newState; |
| 285 | if (mBarState == StatusBarState.KEYGUARD) { |
Selim Cinek | 9184f9c | 2016-02-02 17:36:53 -0800 | [diff] [blame] | 286 | collapseAllGroups(); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | public void collapseAllGroups() { |
Selim Cinek | c0b14b0 | 2016-05-09 13:12:40 -0400 | [diff] [blame] | 291 | // Because notifications can become isolated when the group becomes suppressed it can |
| 292 | // lead to concurrent modifications while looping. We need to make a copy. |
| 293 | ArrayList<NotificationGroup> groupCopy = new ArrayList<>(mGroupMap.values()); |
| 294 | int size = groupCopy.size(); |
| 295 | for (int i = 0; i < size; i++) { |
| 296 | NotificationGroup group = groupCopy.get(i); |
Selim Cinek | 9184f9c | 2016-02-02 17:36:53 -0800 | [diff] [blame] | 297 | if (group.expanded) { |
| 298 | setGroupExpanded(group, false); |
Selim Cinek | 9c4c414 | 2015-12-04 16:44:56 -0800 | [diff] [blame] | 299 | } |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 300 | updateSuppression(group); |
Selim Cinek | 9c4c414 | 2015-12-04 16:44:56 -0800 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 304 | /** |
| 305 | * @return whether a given notification is a child in a group which has a summary |
| 306 | */ |
| 307 | public boolean isChildInGroupWithSummary(StatusBarNotification sbn) { |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 308 | if (!isGroupChild(sbn)) { |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 309 | return false; |
| 310 | } |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 311 | NotificationGroup group = mGroupMap.get(getGroupKey(sbn)); |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 312 | if (group == null || group.summary == null || group.suppressed) { |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 313 | return false; |
| 314 | } |
Selim Cinek | 3f19f60 | 2016-05-02 18:01:56 -0700 | [diff] [blame] | 315 | if (group.children.isEmpty()) { |
| 316 | // If the suppression of a group changes because the last child was removed, this can |
| 317 | // still be called temporarily because the child hasn't been fully removed yet. Let's |
| 318 | // make sure we still return false in that case. |
| 319 | return false; |
| 320 | } |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 321 | return true; |
| 322 | } |
| 323 | |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 324 | /** |
| 325 | * @return whether a given notification is a summary in a group which has children |
| 326 | */ |
| 327 | public boolean isSummaryOfGroup(StatusBarNotification sbn) { |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 328 | if (!isGroupSummary(sbn)) { |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 329 | return false; |
| 330 | } |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 331 | NotificationGroup group = mGroupMap.get(getGroupKey(sbn)); |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 332 | if (group == null || group.summary == null) { |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 333 | return false; |
| 334 | } |
Kevin | 96eed64 | 2018-09-05 18:53:33 -0700 | [diff] [blame] | 335 | return !group.children.isEmpty() && Objects.equals(group.summary.notification, sbn); |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 338 | /** |
| 339 | * Get the summary of a specified status bar notification. For isolated notification this return |
| 340 | * itself. |
| 341 | */ |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 342 | public NotificationEntry getGroupSummary(StatusBarNotification sbn) { |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 343 | return getGroupSummary(getGroupKey(sbn)); |
| 344 | } |
| 345 | |
| 346 | /** |
| 347 | * Similar to {@link #getGroupSummary(StatusBarNotification)} but doesn't get the visual summary |
| 348 | * but the logical summary, i.e when a child is isolated, it still returns the summary as if |
| 349 | * it wasn't isolated. |
| 350 | */ |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 351 | public NotificationEntry getLogicalGroupSummary(StatusBarNotification sbn) { |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 352 | return getGroupSummary(sbn.getGroupKey()); |
| 353 | } |
| 354 | |
| 355 | @Nullable |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 356 | private NotificationEntry getGroupSummary(String groupKey) { |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 357 | NotificationGroup group = mGroupMap.get(groupKey); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 358 | //TODO: see if this can become an Entry |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 359 | return group == null ? null |
| 360 | : group.summary == null ? null |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 361 | : group.summary; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 362 | } |
| 363 | |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 364 | /** |
| 365 | * Get the children that are logically in the summary's group, whether or not they are isolated. |
| 366 | * |
| 367 | * @param summary summary of a group |
| 368 | * @return list of the children |
| 369 | */ |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 370 | public ArrayList<NotificationEntry> getLogicalChildren(StatusBarNotification summary) { |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 371 | NotificationGroup group = mGroupMap.get(summary.getGroupKey()); |
| 372 | if (group == null) { |
| 373 | return null; |
| 374 | } |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 375 | ArrayList<NotificationEntry> children = new ArrayList<>(group.children.values()); |
| 376 | NotificationEntry isolatedChild = getIsolatedChild(summary.getGroupKey()); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 377 | if (isolatedChild != null) { |
| 378 | children.add(isolatedChild); |
| 379 | } |
| 380 | return children; |
| 381 | } |
| 382 | |
| 383 | /** |
| 384 | * Get the group key. May differ from the one in the notification due to the notification |
| 385 | * being temporarily isolated. |
| 386 | * |
| 387 | * @param sbn notification to check |
| 388 | * @return the key of the notification |
| 389 | */ |
| 390 | public String getGroupKey(StatusBarNotification sbn) { |
| 391 | if (isIsolated(sbn)) { |
| 392 | return sbn.getKey(); |
| 393 | } |
| 394 | return sbn.getGroupKey(); |
| 395 | } |
| 396 | |
Chris Wren | 698b170 | 2016-05-23 11:16:32 -0400 | [diff] [blame] | 397 | /** @return group expansion state after toggling. */ |
| 398 | public boolean toggleGroupExpansion(StatusBarNotification sbn) { |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 399 | NotificationGroup group = mGroupMap.get(getGroupKey(sbn)); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 400 | if (group == null) { |
Chris Wren | 698b170 | 2016-05-23 11:16:32 -0400 | [diff] [blame] | 401 | return false; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 402 | } |
| 403 | setGroupExpanded(group, !group.expanded); |
Chris Wren | 698b170 | 2016-05-23 11:16:32 -0400 | [diff] [blame] | 404 | return group.expanded; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 407 | private boolean isIsolated(StatusBarNotification sbn) { |
Selim Cinek | a6c0cef | 2016-03-18 11:42:25 -0700 | [diff] [blame] | 408 | return mIsolatedEntries.containsKey(sbn.getKey()); |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 409 | } |
| 410 | |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 411 | /** |
| 412 | * Whether a notification is visually a group summary. |
| 413 | * |
| 414 | * @param sbn notification to check |
| 415 | * @return true if it is visually a group summary |
| 416 | */ |
| 417 | public boolean isGroupSummary(StatusBarNotification sbn) { |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 418 | if (isIsolated(sbn)) { |
| 419 | return true; |
| 420 | } |
| 421 | return sbn.getNotification().isGroupSummary(); |
| 422 | } |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 423 | |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 424 | /** |
| 425 | * Whether a notification is visually a group child. |
| 426 | * |
| 427 | * @param sbn notification to check |
| 428 | * @return true if it is visually a group child |
| 429 | */ |
| 430 | public boolean isGroupChild(StatusBarNotification sbn) { |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 431 | if (isIsolated(sbn)) { |
| 432 | return false; |
| 433 | } |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 434 | return sbn.isGroup() && !sbn.getNotification().isGroupSummary(); |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 435 | } |
| 436 | |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 437 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 438 | public void onHeadsUpStateChanged(NotificationEntry entry, boolean isHeadsUp) { |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 439 | onAlertStateChanged(entry, isHeadsUp); |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 442 | private void onAlertStateChanged(NotificationEntry entry, boolean isAlerting) { |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 443 | if (isAlerting) { |
| 444 | if (shouldIsolate(entry)) { |
| 445 | isolateNotification(entry); |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 446 | } |
| 447 | } else { |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 448 | stopIsolatingNotification(entry); |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 449 | } |
| 450 | } |
| 451 | |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 452 | /** |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 453 | * Whether a notification that is normally part of a group should be temporarily isolated from |
| 454 | * the group and put in their own group visually. This generally happens when the notification |
| 455 | * is alerting. |
| 456 | * |
| 457 | * @param entry the notification to check |
| 458 | * @return true if the entry should be isolated |
| 459 | */ |
| 460 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 461 | private boolean shouldIsolate(NotificationEntry entry) { |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 462 | StatusBarNotification sbn = entry.notification; |
Selim Cinek | a6c0cef | 2016-03-18 11:42:25 -0700 | [diff] [blame] | 463 | NotificationGroup notificationGroup = mGroupMap.get(sbn.getGroupKey()); |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 464 | if (!sbn.isGroup() || sbn.getNotification().isGroupSummary()) { |
| 465 | return false; |
| 466 | } |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 467 | if (!mHeadsUpManager.isAlerting(entry.key)) { |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 468 | return false; |
| 469 | } |
| 470 | return (sbn.getNotification().fullScreenIntent != null |
| 471 | || notificationGroup == null |
| 472 | || !notificationGroup.expanded |
| 473 | || isGroupNotFullyVisible(notificationGroup)); |
| 474 | } |
| 475 | |
| 476 | /** |
| 477 | * Isolate a notification from its group so that it visually shows as its own group. |
| 478 | * |
| 479 | * @param entry the notification to isolate |
| 480 | */ |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 481 | private void isolateNotification(NotificationEntry entry) { |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 482 | StatusBarNotification sbn = entry.notification; |
| 483 | |
| 484 | // We will be isolated now, so lets update the groups |
| 485 | onEntryRemovedInternal(entry, entry.notification); |
| 486 | |
| 487 | mIsolatedEntries.put(sbn.getKey(), sbn); |
| 488 | |
| 489 | onEntryAdded(entry); |
| 490 | // We also need to update the suppression of the old group, because this call comes |
| 491 | // even before the groupManager knows about the notification at all. |
| 492 | // When the notification gets added afterwards it is already isolated and therefore |
| 493 | // it doesn't lead to an update. |
| 494 | updateSuppression(mGroupMap.get(entry.notification.getGroupKey())); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 495 | for (OnGroupChangeListener listener : mListeners) { |
| 496 | listener.onGroupsChanged(); |
| 497 | } |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | /** |
| 501 | * Stop isolating a notification and re-group it with its original logical group. |
| 502 | * |
| 503 | * @param entry the notification to un-isolate |
| 504 | */ |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 505 | private void stopIsolatingNotification(NotificationEntry entry) { |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 506 | StatusBarNotification sbn = entry.notification; |
| 507 | if (mIsolatedEntries.containsKey(sbn.getKey())) { |
| 508 | // not isolated anymore, we need to update the groups |
| 509 | onEntryRemovedInternal(entry, entry.notification); |
| 510 | mIsolatedEntries.remove(sbn.getKey()); |
| 511 | onEntryAdded(entry); |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 512 | for (OnGroupChangeListener listener : mListeners) { |
| 513 | listener.onGroupsChanged(); |
| 514 | } |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 515 | } |
Selim Cinek | a6c0cef | 2016-03-18 11:42:25 -0700 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | private boolean isGroupNotFullyVisible(NotificationGroup notificationGroup) { |
| 519 | return notificationGroup.summary == null |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 520 | || notificationGroup.summary.isGroupNotFullyVisible(); |
Selim Cinek | a6c0cef | 2016-03-18 11:42:25 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Selim Cinek | 967ed2a | 2016-04-08 18:29:11 -0700 | [diff] [blame] | 523 | public void setHeadsUpManager(HeadsUpManager headsUpManager) { |
| 524 | mHeadsUpManager = headsUpManager; |
| 525 | } |
| 526 | |
Selim Cinek | 52941c5 | 2016-05-07 18:29:32 -0400 | [diff] [blame] | 527 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 528 | pw.println("GroupManager state:"); |
| 529 | pw.println(" number of groups: " + mGroupMap.size()); |
| 530 | for (Map.Entry<String, NotificationGroup> entry : mGroupMap.entrySet()) { |
| 531 | pw.println("\n key: " + entry.getKey()); pw.println(entry.getValue()); |
| 532 | } |
| 533 | pw.println("\n isolated entries: " + mIsolatedEntries.size()); |
| 534 | for (Map.Entry<String, StatusBarNotification> entry : mIsolatedEntries.entrySet()) { |
| 535 | pw.print(" "); pw.print(entry.getKey()); |
| 536 | pw.print(", "); pw.println(entry.getValue()); |
| 537 | } |
| 538 | } |
| 539 | |
Evan Laird | 878c853 | 2018-10-15 15:54:29 -0400 | [diff] [blame] | 540 | @Override |
| 541 | public void onStateChanged(int newState) { |
| 542 | setStatusBarState(newState); |
| 543 | } |
| 544 | |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 545 | public static class NotificationGroup { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 546 | public final HashMap<String, NotificationEntry> children = new HashMap<>(); |
| 547 | public NotificationEntry summary; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 548 | public boolean expanded; |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 549 | /** |
| 550 | * Is this notification group suppressed, i.e its summary is hidden |
| 551 | */ |
| 552 | public boolean suppressed; |
Selim Cinek | 52941c5 | 2016-05-07 18:29:32 -0400 | [diff] [blame] | 553 | |
| 554 | @Override |
| 555 | public String toString() { |
Selim Cinek | 60ca787 | 2016-05-12 11:24:07 -0700 | [diff] [blame] | 556 | String result = " summary:\n " |
Selim Cinek | 04be389 | 2017-08-08 10:58:32 -0700 | [diff] [blame] | 557 | + (summary != null ? summary.notification : "null") |
| 558 | + (summary != null && summary.getDebugThrowable() != null |
| 559 | ? Log.getStackTraceString(summary.getDebugThrowable()) |
| 560 | : ""); |
Selim Cinek | 52941c5 | 2016-05-07 18:29:32 -0400 | [diff] [blame] | 561 | result += "\n children size: " + children.size(); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 562 | for (NotificationEntry child : children.values()) { |
Selim Cinek | 04be389 | 2017-08-08 10:58:32 -0700 | [diff] [blame] | 563 | result += "\n " + child.notification |
| 564 | + (child.getDebugThrowable() != null |
| 565 | ? Log.getStackTraceString(child.getDebugThrowable()) |
| 566 | : ""); |
Selim Cinek | 52941c5 | 2016-05-07 18:29:32 -0400 | [diff] [blame] | 567 | } |
| 568 | return result; |
| 569 | } |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | public interface OnGroupChangeListener { |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 573 | |
| 574 | /** |
| 575 | * A new group has been created. |
| 576 | * |
| 577 | * @param group the group that was created |
| 578 | * @param groupKey the group's key |
| 579 | */ |
| 580 | default void onGroupCreated(NotificationGroup group, String groupKey) {} |
| 581 | |
| 582 | /** |
| 583 | * A group has been removed. |
| 584 | * |
| 585 | * @param group the group that was removed |
| 586 | * @param groupKey the group's key |
| 587 | */ |
| 588 | default void onGroupRemoved(NotificationGroup group, String groupKey) {} |
| 589 | |
| 590 | /** |
| 591 | * The suppression of a group has changed. |
| 592 | * |
| 593 | * @param group the group that has changed |
| 594 | * @param suppressed true if the group is now suppressed, false o/w |
| 595 | */ |
| 596 | default void onGroupSuppressionChanged(NotificationGroup group, boolean suppressed) {} |
| 597 | |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 598 | /** |
| 599 | * The expansion of a group has changed. |
| 600 | * |
| 601 | * @param changedRow the row for which the expansion has changed, which is also the summary |
| 602 | * @param expanded a boolean indicating the new expanded state |
| 603 | */ |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 604 | default void onGroupExpansionChanged(ExpandableNotificationRow changedRow, |
| 605 | boolean expanded) {} |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 606 | |
| 607 | /** |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 608 | * A group of children just received a summary notification and should therefore become |
| 609 | * children of it. |
| 610 | * |
| 611 | * @param group the group created |
| 612 | */ |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 613 | default void onGroupCreatedFromChildren(NotificationGroup group) {} |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 614 | |
| 615 | /** |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 616 | * The groups have changed. This can happen if the isolation of a child has changes or if a |
| 617 | * group became suppressed / unsuppressed |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 618 | */ |
Kevin | 01a53cb | 2018-11-09 18:19:54 -0800 | [diff] [blame] | 619 | default void onGroupsChanged() {} |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 620 | } |
| 621 | } |