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