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