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