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