Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | package com.android.systemui.bubbles; |
| 17 | |
Joshua Tsuji | 0f390fb | 2020-04-28 15:20:10 -0400 | [diff] [blame] | 18 | import static com.android.internal.annotations.VisibleForTesting.Visibility.PACKAGE; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 19 | import static com.android.internal.annotations.VisibleForTesting.Visibility.PRIVATE; |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 20 | import static com.android.systemui.bubbles.BubbleDebugConfig.DEBUG_BUBBLE_DATA; |
| 21 | import static com.android.systemui.bubbles.BubbleDebugConfig.TAG_BUBBLES; |
| 22 | import static com.android.systemui.bubbles.BubbleDebugConfig.TAG_WITH_CLASS_NAME; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 23 | |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 24 | import static java.util.stream.Collectors.toList; |
| 25 | |
Pinyao Ting | 293b83d | 2020-05-06 17:10:56 -0700 | [diff] [blame] | 26 | import android.annotation.NonNull; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 27 | import android.app.Notification; |
| 28 | import android.app.PendingIntent; |
| 29 | import android.content.Context; |
Mark Renouf | bbcf07f | 2019-05-09 10:42:43 -0400 | [diff] [blame] | 30 | import android.service.notification.NotificationListenerService; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 31 | import android.util.Log; |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 32 | import android.util.Pair; |
Joshua Tsuji | 7dd88b0 | 2020-03-27 17:43:09 -0400 | [diff] [blame] | 33 | import android.view.View; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 34 | |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 35 | import androidx.annotation.Nullable; |
| 36 | |
Selim Cinek | fdf8033 | 2019-03-07 17:29:55 -0800 | [diff] [blame] | 37 | import com.android.internal.annotations.VisibleForTesting; |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 38 | import com.android.systemui.R; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 39 | import com.android.systemui.bubbles.BubbleController.DismissReason; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 40 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
| 41 | |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 42 | import java.io.FileDescriptor; |
| 43 | import java.io.PrintWriter; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 44 | import java.util.ArrayList; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 45 | import java.util.Collections; |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 46 | import java.util.Comparator; |
| 47 | import java.util.HashMap; |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 48 | import java.util.List; |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 49 | import java.util.Map; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 50 | import java.util.Objects; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 51 | |
Mady Mellor | cfd06c1 | 2019-02-13 14:32:12 -0800 | [diff] [blame] | 52 | import javax.inject.Inject; |
| 53 | import javax.inject.Singleton; |
| 54 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 55 | /** |
| 56 | * Keeps track of active bubbles. |
| 57 | */ |
Mady Mellor | cfd06c1 | 2019-02-13 14:32:12 -0800 | [diff] [blame] | 58 | @Singleton |
Selim Cinek | fdf8033 | 2019-03-07 17:29:55 -0800 | [diff] [blame] | 59 | public class BubbleData { |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 60 | |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 61 | private static final String TAG = TAG_WITH_CLASS_NAME ? "BubbleData" : TAG_BUBBLES; |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 62 | |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 63 | private static final Comparator<Bubble> BUBBLES_BY_SORT_KEY_DESCENDING = |
| 64 | Comparator.comparing(BubbleData::sortKey).reversed(); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 65 | |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 66 | private static final Comparator<Map.Entry<String, Long>> GROUPS_BY_MAX_SORT_KEY_DESCENDING = |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 67 | Comparator.<Map.Entry<String, Long>, Long>comparing(Map.Entry::getValue).reversed(); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 68 | |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 69 | /** Contains information about changes that have been made to the state of bubbles. */ |
| 70 | static final class Update { |
| 71 | boolean expandedChanged; |
| 72 | boolean selectionChanged; |
| 73 | boolean orderChanged; |
| 74 | boolean expanded; |
| 75 | @Nullable Bubble selectedBubble; |
| 76 | @Nullable Bubble addedBubble; |
| 77 | @Nullable Bubble updatedBubble; |
| 78 | // Pair with Bubble and @DismissReason Integer |
| 79 | final List<Pair<Bubble, Integer>> removedBubbles = new ArrayList<>(); |
| 80 | |
| 81 | // A read-only view of the bubbles list, changes there will be reflected here. |
| 82 | final List<Bubble> bubbles; |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 83 | final List<Bubble> overflowBubbles; |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 84 | |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 85 | private Update(List<Bubble> row, List<Bubble> overflow) { |
| 86 | bubbles = Collections.unmodifiableList(row); |
| 87 | overflowBubbles = Collections.unmodifiableList(overflow); |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | boolean anythingChanged() { |
| 91 | return expandedChanged |
| 92 | || selectionChanged |
| 93 | || addedBubble != null |
| 94 | || updatedBubble != null |
| 95 | || !removedBubbles.isEmpty() |
| 96 | || orderChanged; |
| 97 | } |
| 98 | |
Mady Mellor | 1d08202 | 2020-05-12 16:35:39 +0000 | [diff] [blame] | 99 | void bubbleRemoved(Bubble bubbleToRemove, @DismissReason int reason) { |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 100 | removedBubbles.add(new Pair<>(bubbleToRemove, reason)); |
| 101 | } |
| 102 | } |
| 103 | |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 104 | /** |
| 105 | * This interface reports changes to the state and appearance of bubbles which should be applied |
| 106 | * as necessary to the UI. |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 107 | */ |
| 108 | interface Listener { |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 109 | /** Reports changes have have occurred as a result of the most recent operation. */ |
| 110 | void applyUpdate(Update update); |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 111 | } |
| 112 | |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 113 | interface TimeSource { |
| 114 | long currentTimeMillis(); |
| 115 | } |
| 116 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 117 | private final Context mContext; |
Mady Mellor | 9ec3796 | 2020-01-10 10:21:03 -0800 | [diff] [blame] | 118 | /** Bubbles that are actively in the stack. */ |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 119 | private final List<Bubble> mBubbles; |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 120 | /** Bubbles that aged out to overflow. */ |
| 121 | private final List<Bubble> mOverflowBubbles; |
Mady Mellor | 9ec3796 | 2020-01-10 10:21:03 -0800 | [diff] [blame] | 122 | /** Bubbles that are being loaded but haven't been added to the stack just yet. */ |
| 123 | private final List<Bubble> mPendingBubbles; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 124 | private Bubble mSelectedBubble; |
Lyn Han | 89fb39d | 2020-04-07 11:51:07 -0700 | [diff] [blame] | 125 | private boolean mShowingOverflow; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 126 | private boolean mExpanded; |
Lyn Han | 3a7ce7a | 2019-12-10 18:16:35 -0800 | [diff] [blame] | 127 | private final int mMaxBubbles; |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 128 | private int mMaxOverflowBubbles; |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 129 | |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 130 | // State tracked during an operation -- keeps track of what listener events to dispatch. |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 131 | private Update mStateChange; |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 132 | |
Mark Renouf | bbcf07f | 2019-05-09 10:42:43 -0400 | [diff] [blame] | 133 | private NotificationListenerService.Ranking mTmpRanking; |
| 134 | |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 135 | private TimeSource mTimeSource = System::currentTimeMillis; |
| 136 | |
| 137 | @Nullable |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 138 | private Listener mListener; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 139 | |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 140 | @Nullable |
| 141 | private BubbleController.NotificationSuppressionChangedListener mSuppressionListener; |
| 142 | |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 143 | /** |
| 144 | * We track groups with summaries that aren't visibly displayed but still kept around because |
| 145 | * the bubble(s) associated with the summary still exist. |
| 146 | * |
| 147 | * The summary must be kept around so that developers can cancel it (and hence the bubbles |
| 148 | * associated with it). This list is used to check if the summary should be hidden from the |
| 149 | * shade. |
| 150 | * |
| 151 | * Key: group key of the NotificationEntry |
| 152 | * Value: key of the NotificationEntry |
| 153 | */ |
| 154 | private HashMap<String, String> mSuppressedGroupKeys = new HashMap<>(); |
| 155 | |
Mady Mellor | cfd06c1 | 2019-02-13 14:32:12 -0800 | [diff] [blame] | 156 | @Inject |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 157 | public BubbleData(Context context) { |
| 158 | mContext = context; |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 159 | mBubbles = new ArrayList<>(); |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 160 | mOverflowBubbles = new ArrayList<>(); |
Mady Mellor | 9ec3796 | 2020-01-10 10:21:03 -0800 | [diff] [blame] | 161 | mPendingBubbles = new ArrayList<>(); |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 162 | mStateChange = new Update(mBubbles, mOverflowBubbles); |
Lyn Han | 3a7ce7a | 2019-12-10 18:16:35 -0800 | [diff] [blame] | 163 | mMaxBubbles = mContext.getResources().getInteger(R.integer.bubbles_max_rendered); |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 164 | mMaxOverflowBubbles = mContext.getResources().getInteger(R.integer.bubbles_max_overflow); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 165 | } |
| 166 | |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 167 | public void setSuppressionChangedListener( |
| 168 | BubbleController.NotificationSuppressionChangedListener listener) { |
| 169 | mSuppressionListener = listener; |
| 170 | } |
| 171 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 172 | public boolean hasBubbles() { |
| 173 | return !mBubbles.isEmpty(); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 174 | } |
| 175 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 176 | public boolean isExpanded() { |
| 177 | return mExpanded; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 178 | } |
| 179 | |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 180 | public boolean hasAnyBubbleWithKey(String key) { |
| 181 | return hasBubbleInStackWithKey(key) || hasOverflowBubbleWithKey(key); |
| 182 | } |
| 183 | |
| 184 | public boolean hasBubbleInStackWithKey(String key) { |
| 185 | return getBubbleInStackWithKey(key) != null; |
| 186 | } |
| 187 | |
| 188 | public boolean hasOverflowBubbleWithKey(String key) { |
| 189 | return getOverflowBubbleWithKey(key) != null; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 190 | } |
| 191 | |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 192 | @Nullable |
| 193 | public Bubble getSelectedBubble() { |
| 194 | return mSelectedBubble; |
| 195 | } |
| 196 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 197 | public void setExpanded(boolean expanded) { |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 198 | if (DEBUG_BUBBLE_DATA) { |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 199 | Log.d(TAG, "setExpanded: " + expanded); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 200 | } |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 201 | setExpandedInternal(expanded); |
| 202 | dispatchPendingChanges(); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 203 | } |
| 204 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 205 | public void setSelectedBubble(Bubble bubble) { |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 206 | if (DEBUG_BUBBLE_DATA) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 207 | Log.d(TAG, "setSelectedBubble: " + bubble); |
| 208 | } |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 209 | setSelectedBubbleInternal(bubble); |
| 210 | dispatchPendingChanges(); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 211 | } |
| 212 | |
Lyn Han | 1e19d7f | 2020-02-05 19:10:58 -0800 | [diff] [blame] | 213 | public void promoteBubbleFromOverflow(Bubble bubble, BubbleStackView stack, |
| 214 | BubbleIconFactory factory) { |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 215 | if (DEBUG_BUBBLE_DATA) { |
| 216 | Log.d(TAG, "promoteBubbleFromOverflow: " + bubble); |
| 217 | } |
Lyn Han | 18cdc1c | 2020-03-18 19:12:42 -0700 | [diff] [blame] | 218 | moveOverflowBubbleToPending(bubble); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 219 | // Preserve new order for next repack, which sorts by last updated time. |
| 220 | bubble.markUpdatedAt(mTimeSource.currentTimeMillis()); |
Lyn Han | 1e19d7f | 2020-02-05 19:10:58 -0800 | [diff] [blame] | 221 | bubble.inflate( |
Lyn Han | 4438d9b | 2020-03-11 18:04:35 -0700 | [diff] [blame] | 222 | b -> { |
| 223 | notificationEntryUpdated(bubble, /* suppressFlyout */ |
| 224 | false, /* showInShade */ true); |
Lyn Han | 89274b4 | 2020-03-25 00:56:26 -0700 | [diff] [blame] | 225 | setSelectedBubble(bubble); |
Lyn Han | 4438d9b | 2020-03-11 18:04:35 -0700 | [diff] [blame] | 226 | }, |
Pinyao Ting | 293b83d | 2020-05-06 17:10:56 -0700 | [diff] [blame] | 227 | mContext, stack, factory, false /* skipInflation */); |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 228 | dispatchPendingChanges(); |
| 229 | } |
| 230 | |
Lyn Han | 89fb39d | 2020-04-07 11:51:07 -0700 | [diff] [blame] | 231 | void setShowingOverflow(boolean showingOverflow) { |
| 232 | mShowingOverflow = showingOverflow; |
| 233 | } |
| 234 | |
Lyn Han | 18cdc1c | 2020-03-18 19:12:42 -0700 | [diff] [blame] | 235 | private void moveOverflowBubbleToPending(Bubble b) { |
Lyn Han | 18cdc1c | 2020-03-18 19:12:42 -0700 | [diff] [blame] | 236 | mOverflowBubbles.remove(b); |
| 237 | mPendingBubbles.add(b); |
| 238 | } |
| 239 | |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 240 | /** |
| 241 | * Constructs a new bubble or returns an existing one. Does not add new bubbles to |
| 242 | * bubble data, must go through {@link #notificationEntryUpdated(Bubble, boolean, boolean)} |
| 243 | * for that. |
| 244 | */ |
| 245 | Bubble getOrCreateBubble(NotificationEntry entry) { |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 246 | String key = entry.getKey(); |
| 247 | Bubble bubble = getBubbleInStackWithKey(entry.getKey()); |
| 248 | if (bubble != null) { |
| 249 | bubble.setEntry(entry); |
| 250 | } else { |
| 251 | bubble = getOverflowBubbleWithKey(key); |
| 252 | if (bubble != null) { |
| 253 | moveOverflowBubbleToPending(bubble); |
| 254 | bubble.setEntry(entry); |
| 255 | return bubble; |
Lyn Han | bf1b3d6 | 2020-03-12 10:31:19 -0700 | [diff] [blame] | 256 | } |
Mady Mellor | 9ec3796 | 2020-01-10 10:21:03 -0800 | [diff] [blame] | 257 | // Check for it in pending |
| 258 | for (int i = 0; i < mPendingBubbles.size(); i++) { |
| 259 | Bubble b = mPendingBubbles.get(i); |
| 260 | if (b.getKey().equals(entry.getKey())) { |
Mady Mellor | e45ff86 | 2020-03-24 15:54:50 -0700 | [diff] [blame] | 261 | b.setEntry(entry); |
Mady Mellor | 9ec3796 | 2020-01-10 10:21:03 -0800 | [diff] [blame] | 262 | return b; |
| 263 | } |
| 264 | } |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 265 | bubble = new Bubble(entry, mSuppressionListener); |
Mady Mellor | 9ec3796 | 2020-01-10 10:21:03 -0800 | [diff] [blame] | 266 | mPendingBubbles.add(bubble); |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 267 | } |
| 268 | return bubble; |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * When this method is called it is expected that all info in the bubble has completed loading. |
| 273 | * @see Bubble#inflate(BubbleViewInfoTask.Callback, Context, |
| 274 | * BubbleStackView, BubbleIconFactory). |
| 275 | */ |
| 276 | void notificationEntryUpdated(Bubble bubble, boolean suppressFlyout, boolean showInShade) { |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 277 | if (DEBUG_BUBBLE_DATA) { |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 278 | Log.d(TAG, "notificationEntryUpdated: " + bubble); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 279 | } |
Mady Mellor | 9ec3796 | 2020-01-10 10:21:03 -0800 | [diff] [blame] | 280 | mPendingBubbles.remove(bubble); // No longer pending once we're here |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 281 | Bubble prevBubble = getBubbleInStackWithKey(bubble.getKey()); |
Pinyao Ting | 293b83d | 2020-05-06 17:10:56 -0700 | [diff] [blame] | 282 | suppressFlyout |= bubble.getEntry() == null |
| 283 | || !bubble.getEntry().getRanking().visuallyInterruptive(); |
Lyn Han | 405e0b7 | 2019-08-13 16:07:55 -0700 | [diff] [blame] | 284 | |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 285 | if (prevBubble == null) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 286 | // Create a new bubble |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 287 | bubble.setSuppressFlyout(suppressFlyout); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 288 | doAdd(bubble); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 289 | trim(); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 290 | } else { |
| 291 | // Updates an existing bubble |
Lyn Han | 405e0b7 | 2019-08-13 16:07:55 -0700 | [diff] [blame] | 292 | bubble.setSuppressFlyout(suppressFlyout); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 293 | doUpdate(bubble); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 294 | } |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 295 | if (bubble.shouldAutoExpand()) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 296 | setSelectedBubbleInternal(bubble); |
| 297 | if (!mExpanded) { |
| 298 | setExpandedInternal(true); |
| 299 | } |
| 300 | } else if (mSelectedBubble == null) { |
| 301 | setSelectedBubbleInternal(bubble); |
| 302 | } |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 303 | |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 304 | boolean isBubbleExpandedAndSelected = mExpanded && mSelectedBubble == bubble; |
| 305 | boolean suppress = isBubbleExpandedAndSelected || !showInShade || !bubble.showInShade(); |
| 306 | bubble.setSuppressNotification(suppress); |
Joshua Tsuji | 2ed260e | 2020-03-26 14:26:01 -0400 | [diff] [blame] | 307 | bubble.setShowDot(!isBubbleExpandedAndSelected /* show */); |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 308 | |
| 309 | dispatchPendingChanges(); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 310 | } |
| 311 | |
Pinyao Ting | 293b83d | 2020-05-06 17:10:56 -0700 | [diff] [blame] | 312 | /** |
| 313 | * Called when a notification associated with a bubble is removed. |
| 314 | */ |
| 315 | public void notificationEntryRemoved(String key, @DismissReason int reason) { |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 316 | if (DEBUG_BUBBLE_DATA) { |
Pinyao Ting | 293b83d | 2020-05-06 17:10:56 -0700 | [diff] [blame] | 317 | Log.d(TAG, "notificationEntryRemoved: key=" + key + " reason=" + reason); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 318 | } |
Pinyao Ting | 293b83d | 2020-05-06 17:10:56 -0700 | [diff] [blame] | 319 | doRemove(key, reason); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 320 | dispatchPendingChanges(); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 321 | } |
| 322 | |
Mark Renouf | bbcf07f | 2019-05-09 10:42:43 -0400 | [diff] [blame] | 323 | /** |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 324 | * Adds a group key indicating that the summary for this group should be suppressed. |
| 325 | * |
| 326 | * @param groupKey the group key of the group whose summary should be suppressed. |
| 327 | * @param notifKey the notification entry key of that summary. |
| 328 | */ |
| 329 | void addSummaryToSuppress(String groupKey, String notifKey) { |
| 330 | mSuppressedGroupKeys.put(groupKey, notifKey); |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * Retrieves the notif entry key of the summary associated with the provided group key. |
| 335 | * |
| 336 | * @param groupKey the group to look up |
| 337 | * @return the key for the {@link NotificationEntry} that is the summary of this group. |
| 338 | */ |
| 339 | String getSummaryKey(String groupKey) { |
| 340 | return mSuppressedGroupKeys.get(groupKey); |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | * Removes a group key indicating that summary for this group should no longer be suppressed. |
| 345 | */ |
| 346 | void removeSuppressedSummary(String groupKey) { |
| 347 | mSuppressedGroupKeys.remove(groupKey); |
| 348 | } |
| 349 | |
| 350 | /** |
| 351 | * Whether the summary for the provided group key is suppressed. |
| 352 | */ |
| 353 | boolean isSummarySuppressed(String groupKey) { |
| 354 | return mSuppressedGroupKeys.containsKey(groupKey); |
| 355 | } |
| 356 | |
| 357 | /** |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 358 | * Retrieves any bubbles that are part of the notification group represented by the provided |
| 359 | * group key. |
| 360 | */ |
| 361 | ArrayList<Bubble> getBubblesInGroup(@Nullable String groupKey) { |
| 362 | ArrayList<Bubble> bubbleChildren = new ArrayList<>(); |
| 363 | if (groupKey == null) { |
| 364 | return bubbleChildren; |
| 365 | } |
| 366 | for (Bubble b : mBubbles) { |
Pinyao Ting | 293b83d | 2020-05-06 17:10:56 -0700 | [diff] [blame] | 367 | if (b.getEntry() != null && groupKey.equals(b.getEntry().getSbn().getGroupKey())) { |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 368 | bubbleChildren.add(b); |
| 369 | } |
| 370 | } |
| 371 | return bubbleChildren; |
| 372 | } |
| 373 | |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 374 | private void doAdd(Bubble bubble) { |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 375 | if (DEBUG_BUBBLE_DATA) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 376 | Log.d(TAG, "doAdd: " + bubble); |
| 377 | } |
| 378 | int minInsertPoint = 0; |
| 379 | boolean newGroup = !hasBubbleWithGroupId(bubble.getGroupId()); |
| 380 | if (isExpanded()) { |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 381 | // first bubble of a group goes to the beginning, otherwise within the existing group |
| 382 | minInsertPoint = newGroup ? 0 : findFirstIndexForGroup(bubble.getGroupId()); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 383 | } |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 384 | if (insertBubble(minInsertPoint, bubble) < mBubbles.size() - 1) { |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 385 | mStateChange.orderChanged = true; |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 386 | } |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 387 | mStateChange.addedBubble = bubble; |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 388 | |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 389 | if (!isExpanded()) { |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 390 | mStateChange.orderChanged |= packGroup(findFirstIndexForGroup(bubble.getGroupId())); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 391 | // Top bubble becomes selected. |
| 392 | setSelectedBubbleInternal(mBubbles.get(0)); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 393 | } |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | private void trim() { |
Lyn Han | 3a7ce7a | 2019-12-10 18:16:35 -0800 | [diff] [blame] | 397 | if (mBubbles.size() > mMaxBubbles) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 398 | mBubbles.stream() |
| 399 | // sort oldest first (ascending lastActivity) |
| 400 | .sorted(Comparator.comparingLong(Bubble::getLastActivity)) |
| 401 | // skip the selected bubble |
| 402 | .filter((b) -> !b.equals(mSelectedBubble)) |
| 403 | .findFirst() |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 404 | .ifPresent((b) -> doRemove(b.getKey(), BubbleController.DISMISS_AGED)); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 405 | } |
| 406 | } |
| 407 | |
| 408 | private void doUpdate(Bubble bubble) { |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 409 | if (DEBUG_BUBBLE_DATA) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 410 | Log.d(TAG, "doUpdate: " + bubble); |
| 411 | } |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 412 | mStateChange.updatedBubble = bubble; |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 413 | if (!isExpanded()) { |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 414 | // while collapsed, update causes re-pack |
| 415 | int prevPos = mBubbles.indexOf(bubble); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 416 | mBubbles.remove(bubble); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 417 | int newPos = insertBubble(0, bubble); |
| 418 | if (prevPos != newPos) { |
| 419 | packGroup(newPos); |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 420 | mStateChange.orderChanged = true; |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 421 | } |
| 422 | setSelectedBubbleInternal(mBubbles.get(0)); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 423 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 424 | } |
| 425 | |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 426 | private void doRemove(String key, @DismissReason int reason) { |
Lyn Han | e139557 | 2020-03-23 15:48:54 -0700 | [diff] [blame] | 427 | if (DEBUG_BUBBLE_DATA) { |
| 428 | Log.d(TAG, "doRemove: " + key); |
| 429 | } |
Mady Mellor | 9ec3796 | 2020-01-10 10:21:03 -0800 | [diff] [blame] | 430 | // If it was pending remove it |
| 431 | for (int i = 0; i < mPendingBubbles.size(); i++) { |
| 432 | if (mPendingBubbles.get(i).getKey().equals(key)) { |
| 433 | mPendingBubbles.remove(mPendingBubbles.get(i)); |
| 434 | } |
| 435 | } |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 436 | int indexToRemove = indexForKey(key); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 437 | if (indexToRemove == -1) { |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 438 | if (hasOverflowBubbleWithKey(key) |
| 439 | && (reason == BubbleController.DISMISS_NOTIF_CANCEL |
| 440 | || reason == BubbleController.DISMISS_GROUP_CANCELLED |
| 441 | || reason == BubbleController.DISMISS_NO_LONGER_BUBBLE |
| 442 | || reason == BubbleController.DISMISS_BLOCKED)) { |
| 443 | |
| 444 | Bubble b = getOverflowBubbleWithKey(key); |
| 445 | if (DEBUG_BUBBLE_DATA) { |
| 446 | Log.d(TAG, "Cancel overflow bubble: " + b); |
| 447 | } |
Lyn Han | e4274be | 2020-04-24 17:55:36 -0700 | [diff] [blame] | 448 | mStateChange.bubbleRemoved(b, reason); |
Mady Mellor | 1d08202 | 2020-05-12 16:35:39 +0000 | [diff] [blame] | 449 | mOverflowBubbles.remove(b); |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 450 | } |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 451 | return; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 452 | } |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 453 | Bubble bubbleToRemove = mBubbles.get(indexToRemove); |
| 454 | if (mBubbles.size() == 1) { |
| 455 | // Going to become empty, handle specially. |
| 456 | setExpandedInternal(false); |
| 457 | setSelectedBubbleInternal(null); |
| 458 | } |
| 459 | if (indexToRemove < mBubbles.size() - 1) { |
| 460 | // Removing anything but the last bubble means positions will change. |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 461 | mStateChange.orderChanged = true; |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 462 | } |
| 463 | mBubbles.remove(indexToRemove); |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 464 | mStateChange.bubbleRemoved(bubbleToRemove, reason); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 465 | if (!isExpanded()) { |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 466 | mStateChange.orderChanged |= repackAll(); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 467 | } |
| 468 | |
Lyn Han | d698186 | 2020-02-18 18:01:43 -0800 | [diff] [blame] | 469 | overflowBubble(reason, bubbleToRemove); |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 470 | |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 471 | // Note: If mBubbles.isEmpty(), then mSelectedBubble is now null. |
| 472 | if (Objects.equals(mSelectedBubble, bubbleToRemove)) { |
| 473 | // Move selection to the new bubble at the same position. |
| 474 | int newIndex = Math.min(indexToRemove, mBubbles.size() - 1); |
| 475 | Bubble newSelected = mBubbles.get(newIndex); |
| 476 | setSelectedBubbleInternal(newSelected); |
| 477 | } |
Pinyao Ting | 293b83d | 2020-05-06 17:10:56 -0700 | [diff] [blame] | 478 | if (bubbleToRemove.getEntry() != null) { |
| 479 | maybeSendDeleteIntent(reason, bubbleToRemove.getEntry()); |
| 480 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 481 | } |
| 482 | |
Lyn Han | d698186 | 2020-02-18 18:01:43 -0800 | [diff] [blame] | 483 | void overflowBubble(@DismissReason int reason, Bubble bubble) { |
Lyn Han | 6cb4e5f | 2020-04-27 15:11:18 -0700 | [diff] [blame] | 484 | if (bubble.getPendingIntentCanceled() |
| 485 | || !(reason == BubbleController.DISMISS_AGED |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 486 | || reason == BubbleController.DISMISS_USER_GESTURE)) { |
| 487 | return; |
| 488 | } |
| 489 | if (DEBUG_BUBBLE_DATA) { |
| 490 | Log.d(TAG, "Overflowing: " + bubble); |
| 491 | } |
| 492 | mOverflowBubbles.add(0, bubble); |
| 493 | bubble.stopInflation(); |
| 494 | if (mOverflowBubbles.size() == mMaxOverflowBubbles + 1) { |
| 495 | // Remove oldest bubble. |
| 496 | Bubble oldest = mOverflowBubbles.get(mOverflowBubbles.size() - 1); |
Lyn Han | d698186 | 2020-02-18 18:01:43 -0800 | [diff] [blame] | 497 | if (DEBUG_BUBBLE_DATA) { |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 498 | Log.d(TAG, "Overflow full. Remove: " + oldest); |
Lyn Han | d698186 | 2020-02-18 18:01:43 -0800 | [diff] [blame] | 499 | } |
Lyn Han | e4274be | 2020-04-24 17:55:36 -0700 | [diff] [blame] | 500 | mStateChange.bubbleRemoved(oldest, BubbleController.DISMISS_OVERFLOW_MAX_REACHED); |
Mady Mellor | 1d08202 | 2020-05-12 16:35:39 +0000 | [diff] [blame] | 501 | mOverflowBubbles.remove(oldest); |
Lyn Han | d698186 | 2020-02-18 18:01:43 -0800 | [diff] [blame] | 502 | } |
| 503 | } |
| 504 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 505 | public void dismissAll(@DismissReason int reason) { |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 506 | if (DEBUG_BUBBLE_DATA) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 507 | Log.d(TAG, "dismissAll: reason=" + reason); |
| 508 | } |
| 509 | if (mBubbles.isEmpty()) { |
| 510 | return; |
| 511 | } |
| 512 | setExpandedInternal(false); |
| 513 | setSelectedBubbleInternal(null); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 514 | while (!mBubbles.isEmpty()) { |
Lyn Han | d698186 | 2020-02-18 18:01:43 -0800 | [diff] [blame] | 515 | doRemove(mBubbles.get(0).getKey(), reason); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 516 | } |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 517 | dispatchPendingChanges(); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 518 | } |
| 519 | |
Mady Mellor | ca184aae | 2019-09-17 16:07:12 -0700 | [diff] [blame] | 520 | /** |
| 521 | * Indicates that the provided display is no longer in use and should be cleaned up. |
| 522 | * |
| 523 | * @param displayId the id of the display to clean up. |
| 524 | */ |
| 525 | void notifyDisplayEmpty(int displayId) { |
| 526 | for (Bubble b : mBubbles) { |
| 527 | if (b.getDisplayId() == displayId) { |
| 528 | if (b.getExpandedView() != null) { |
| 529 | b.getExpandedView().notifyDisplayEmpty(); |
| 530 | } |
| 531 | return; |
| 532 | } |
| 533 | } |
| 534 | } |
| 535 | |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 536 | private void dispatchPendingChanges() { |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 537 | if (mListener != null && mStateChange.anythingChanged()) { |
| 538 | mListener.applyUpdate(mStateChange); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 539 | } |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 540 | mStateChange = new Update(mBubbles, mOverflowBubbles); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | /** |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 544 | * Requests a change to the selected bubble. |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 545 | * |
| 546 | * @param bubble the new selected bubble |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 547 | */ |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 548 | private void setSelectedBubbleInternal(@Nullable Bubble bubble) { |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 549 | if (DEBUG_BUBBLE_DATA) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 550 | Log.d(TAG, "setSelectedBubbleInternal: " + bubble); |
| 551 | } |
Lyn Han | 89fb39d | 2020-04-07 11:51:07 -0700 | [diff] [blame] | 552 | if (!mShowingOverflow && Objects.equals(bubble, mSelectedBubble)) { |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 553 | return; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 554 | } |
Lyn Han | 89fb39d | 2020-04-07 11:51:07 -0700 | [diff] [blame] | 555 | // Otherwise, if we are showing the overflow menu, return to the previously selected bubble. |
| 556 | |
Lyn Han | 1e19d7f | 2020-02-05 19:10:58 -0800 | [diff] [blame] | 557 | if (bubble != null && !mBubbles.contains(bubble) && !mOverflowBubbles.contains(bubble)) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 558 | Log.e(TAG, "Cannot select bubble which doesn't exist!" |
| 559 | + " (" + bubble + ") bubbles=" + mBubbles); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 560 | return; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 561 | } |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 562 | if (mExpanded && bubble != null) { |
Mady Mellor | 73310bc1 | 2019-05-01 20:47:49 -0700 | [diff] [blame] | 563 | bubble.markAsAccessedAt(mTimeSource.currentTimeMillis()); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 564 | } |
| 565 | mSelectedBubble = bubble; |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 566 | mStateChange.selectedBubble = bubble; |
| 567 | mStateChange.selectionChanged = true; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 568 | } |
| 569 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 570 | /** |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 571 | * Requests a change to the expanded state. |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 572 | * |
| 573 | * @param shouldExpand the new requested state |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 574 | */ |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 575 | private void setExpandedInternal(boolean shouldExpand) { |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 576 | if (DEBUG_BUBBLE_DATA) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 577 | Log.d(TAG, "setExpandedInternal: shouldExpand=" + shouldExpand); |
| 578 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 579 | if (mExpanded == shouldExpand) { |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 580 | return; |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 581 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 582 | if (shouldExpand) { |
| 583 | if (mBubbles.isEmpty()) { |
| 584 | Log.e(TAG, "Attempt to expand stack when empty!"); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 585 | return; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 586 | } |
| 587 | if (mSelectedBubble == null) { |
| 588 | Log.e(TAG, "Attempt to expand stack without selected bubble!"); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 589 | return; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 590 | } |
Lyn Han | b9be52d | 2020-03-31 22:13:34 -0700 | [diff] [blame] | 591 | mSelectedBubble.markUpdatedAt(mTimeSource.currentTimeMillis()); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 592 | mSelectedBubble.markAsAccessedAt(mTimeSource.currentTimeMillis()); |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 593 | mStateChange.orderChanged |= repackAll(); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 594 | } else if (!mBubbles.isEmpty()) { |
| 595 | // Apply ordering and grouping rules from expanded -> collapsed, then save |
| 596 | // the result. |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 597 | mStateChange.orderChanged |= repackAll(); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 598 | // Save the state which should be returned to when expanded (with no other changes) |
| 599 | |
Lyn Han | 89fb39d | 2020-04-07 11:51:07 -0700 | [diff] [blame] | 600 | if (mShowingOverflow) { |
| 601 | // Show previously selected bubble instead of overflow menu on next expansion. |
| 602 | setSelectedBubbleInternal(mSelectedBubble); |
| 603 | } |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 604 | if (mBubbles.indexOf(mSelectedBubble) > 0) { |
| 605 | // Move the selected bubble to the top while collapsed. |
| 606 | if (!mSelectedBubble.isOngoing() && mBubbles.get(0).isOngoing()) { |
| 607 | // The selected bubble cannot be raised to the first position because |
| 608 | // there is an ongoing bubble there. Instead, force the top ongoing bubble |
| 609 | // to become selected. |
| 610 | setSelectedBubbleInternal(mBubbles.get(0)); |
| 611 | } else { |
| 612 | // Raise the selected bubble (and it's group) up to the front so the selected |
| 613 | // bubble remains on top. |
| 614 | mBubbles.remove(mSelectedBubble); |
| 615 | mBubbles.add(0, mSelectedBubble); |
Mark Renouf | 6e4ddd7 | 2019-07-16 13:28:43 -0400 | [diff] [blame] | 616 | mStateChange.orderChanged |= packGroup(0); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 617 | } |
| 618 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 619 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 620 | mExpanded = shouldExpand; |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 621 | mStateChange.expanded = shouldExpand; |
| 622 | mStateChange.expandedChanged = true; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 623 | } |
| 624 | |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 625 | private static long sortKey(Bubble bubble) { |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 626 | long key = bubble.getLastUpdateTime(); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 627 | if (bubble.isOngoing()) { |
| 628 | // Set 2nd highest bit (signed long int), to partition between ongoing and regular |
| 629 | key |= 0x4000000000000000L; |
| 630 | } |
| 631 | return key; |
| 632 | } |
| 633 | |
| 634 | /** |
| 635 | * Locates and inserts the bubble into a sorted position. The is inserted |
| 636 | * based on sort key, groupId is not considered. A call to {@link #packGroup(int)} may be |
| 637 | * required to keep grouping intact. |
| 638 | * |
| 639 | * @param minPosition the first insert point to consider |
Lyn Han | 72f5090 | 2019-10-25 15:55:49 -0700 | [diff] [blame] | 640 | * @param newBubble the bubble to insert |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 641 | * @return the position where the bubble was inserted |
| 642 | */ |
| 643 | private int insertBubble(int minPosition, Bubble newBubble) { |
| 644 | long newBubbleSortKey = sortKey(newBubble); |
| 645 | String previousGroupId = null; |
| 646 | |
| 647 | for (int pos = minPosition; pos < mBubbles.size(); pos++) { |
| 648 | Bubble bubbleAtPos = mBubbles.get(pos); |
| 649 | String groupIdAtPos = bubbleAtPos.getGroupId(); |
| 650 | boolean atStartOfGroup = !groupIdAtPos.equals(previousGroupId); |
| 651 | |
| 652 | if (atStartOfGroup && newBubbleSortKey > sortKey(bubbleAtPos)) { |
| 653 | // Insert before the start of first group which has older bubbles. |
| 654 | mBubbles.add(pos, newBubble); |
| 655 | return pos; |
| 656 | } |
| 657 | previousGroupId = groupIdAtPos; |
| 658 | } |
| 659 | mBubbles.add(newBubble); |
| 660 | return mBubbles.size() - 1; |
| 661 | } |
| 662 | |
| 663 | private boolean hasBubbleWithGroupId(String groupId) { |
| 664 | return mBubbles.stream().anyMatch(b -> b.getGroupId().equals(groupId)); |
| 665 | } |
| 666 | |
| 667 | private int findFirstIndexForGroup(String appId) { |
| 668 | for (int i = 0; i < mBubbles.size(); i++) { |
| 669 | Bubble bubbleAtPos = mBubbles.get(i); |
| 670 | if (bubbleAtPos.getGroupId().equals(appId)) { |
| 671 | return i; |
| 672 | } |
| 673 | } |
| 674 | return 0; |
| 675 | } |
| 676 | |
| 677 | /** |
| 678 | * Starting at the given position, moves all bubbles with the same group id to follow. Bubbles |
| 679 | * at positions lower than {@code position} are unchanged. Relative order within the group |
| 680 | * unchanged. Relative order of any other bubbles are also unchanged. |
| 681 | * |
| 682 | * @param position the position of the first bubble for the group |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 683 | * @return true if the position of any bubbles has changed as a result |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 684 | */ |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 685 | private boolean packGroup(int position) { |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 686 | if (DEBUG_BUBBLE_DATA) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 687 | Log.d(TAG, "packGroup: position=" + position); |
| 688 | } |
| 689 | Bubble groupStart = mBubbles.get(position); |
| 690 | final String groupAppId = groupStart.getGroupId(); |
| 691 | List<Bubble> moving = new ArrayList<>(); |
| 692 | |
| 693 | // Walk backward, collect bubbles within the group |
| 694 | for (int i = mBubbles.size() - 1; i > position; i--) { |
| 695 | if (mBubbles.get(i).getGroupId().equals(groupAppId)) { |
| 696 | moving.add(0, mBubbles.get(i)); |
| 697 | } |
| 698 | } |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 699 | if (moving.isEmpty()) { |
| 700 | return false; |
| 701 | } |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 702 | mBubbles.removeAll(moving); |
| 703 | mBubbles.addAll(position + 1, moving); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 704 | return true; |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 705 | } |
| 706 | |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 707 | /** |
| 708 | * This applies a full sort and group pass to all existing bubbles. The bubbles are grouped |
Lyn Han | b9be52d | 2020-03-31 22:13:34 -0700 | [diff] [blame] | 709 | * by groupId. Each group is then sorted by the max(lastUpdated) time of its bubbles. Bubbles |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 710 | * within each group are then sorted by lastUpdated descending. |
| 711 | * |
| 712 | * @return true if the position of any bubbles changed as a result |
| 713 | */ |
| 714 | private boolean repackAll() { |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 715 | if (DEBUG_BUBBLE_DATA) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 716 | Log.d(TAG, "repackAll()"); |
| 717 | } |
| 718 | if (mBubbles.isEmpty()) { |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 719 | return false; |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 720 | } |
| 721 | Map<String, Long> groupLastActivity = new HashMap<>(); |
| 722 | for (Bubble bubble : mBubbles) { |
| 723 | long maxSortKeyForGroup = groupLastActivity.getOrDefault(bubble.getGroupId(), 0L); |
| 724 | long sortKeyForBubble = sortKey(bubble); |
| 725 | if (sortKeyForBubble > maxSortKeyForGroup) { |
| 726 | groupLastActivity.put(bubble.getGroupId(), sortKeyForBubble); |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | // Sort groups by their most recently active bubble |
| 731 | List<String> groupsByMostRecentActivity = |
| 732 | groupLastActivity.entrySet().stream() |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 733 | .sorted(GROUPS_BY_MAX_SORT_KEY_DESCENDING) |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 734 | .map(Map.Entry::getKey) |
| 735 | .collect(toList()); |
| 736 | |
| 737 | List<Bubble> repacked = new ArrayList<>(mBubbles.size()); |
| 738 | |
| 739 | // For each group, add bubbles, freshest to oldest |
| 740 | for (String appId : groupsByMostRecentActivity) { |
| 741 | mBubbles.stream() |
| 742 | .filter((b) -> b.getGroupId().equals(appId)) |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 743 | .sorted(BUBBLES_BY_SORT_KEY_DESCENDING) |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 744 | .forEachOrdered(repacked::add); |
| 745 | } |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 746 | if (repacked.equals(mBubbles)) { |
| 747 | return false; |
| 748 | } |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 749 | mBubbles.clear(); |
| 750 | mBubbles.addAll(repacked); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 751 | return true; |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 752 | } |
| 753 | |
Pinyao Ting | 293b83d | 2020-05-06 17:10:56 -0700 | [diff] [blame] | 754 | private void maybeSendDeleteIntent(@DismissReason int reason, |
| 755 | @NonNull final NotificationEntry entry) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 756 | if (reason == BubbleController.DISMISS_USER_GESTURE) { |
| 757 | Notification.BubbleMetadata bubbleMetadata = entry.getBubbleMetadata(); |
| 758 | PendingIntent deleteIntent = bubbleMetadata != null |
| 759 | ? bubbleMetadata.getDeleteIntent() |
| 760 | : null; |
| 761 | if (deleteIntent != null) { |
| 762 | try { |
| 763 | deleteIntent.send(); |
| 764 | } catch (PendingIntent.CanceledException e) { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 765 | Log.w(TAG, "Failed to send delete intent for bubble with key: " |
| 766 | + entry.getKey()); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 767 | } |
| 768 | } |
| 769 | } |
| 770 | } |
| 771 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 772 | private int indexForKey(String key) { |
| 773 | for (int i = 0; i < mBubbles.size(); i++) { |
| 774 | Bubble bubble = mBubbles.get(i); |
| 775 | if (bubble.getKey().equals(key)) { |
| 776 | return i; |
| 777 | } |
| 778 | } |
| 779 | return -1; |
| 780 | } |
| 781 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 782 | /** |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 783 | * The set of bubbles in row. |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 784 | */ |
Joshua Tsuji | 0f390fb | 2020-04-28 15:20:10 -0400 | [diff] [blame] | 785 | @VisibleForTesting(visibility = PACKAGE) |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 786 | public List<Bubble> getBubbles() { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 787 | return Collections.unmodifiableList(mBubbles); |
| 788 | } |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 789 | /** |
| 790 | * The set of bubbles in overflow. |
| 791 | */ |
| 792 | @VisibleForTesting(visibility = PRIVATE) |
| 793 | public List<Bubble> getOverflowBubbles() { |
| 794 | return Collections.unmodifiableList(mOverflowBubbles); |
| 795 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 796 | |
| 797 | @VisibleForTesting(visibility = PRIVATE) |
Joshua Tsuji | 7dd88b0 | 2020-03-27 17:43:09 -0400 | [diff] [blame] | 798 | @Nullable |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 799 | Bubble getAnyBubbleWithkey(String key) { |
| 800 | Bubble b = getBubbleInStackWithKey(key); |
| 801 | if (b == null) { |
| 802 | b = getOverflowBubbleWithKey(key); |
| 803 | } |
| 804 | return b; |
| 805 | } |
| 806 | |
| 807 | @VisibleForTesting(visibility = PRIVATE) |
| 808 | @Nullable |
| 809 | Bubble getBubbleInStackWithKey(String key) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 810 | for (int i = 0; i < mBubbles.size(); i++) { |
| 811 | Bubble bubble = mBubbles.get(i); |
| 812 | if (bubble.getKey().equals(key)) { |
| 813 | return bubble; |
| 814 | } |
| 815 | } |
| 816 | return null; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 817 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 818 | |
Joshua Tsuji | 7dd88b0 | 2020-03-27 17:43:09 -0400 | [diff] [blame] | 819 | @Nullable |
| 820 | Bubble getBubbleWithView(View view) { |
| 821 | for (int i = 0; i < mBubbles.size(); i++) { |
| 822 | Bubble bubble = mBubbles.get(i); |
| 823 | if (bubble.getIconView() != null && bubble.getIconView().equals(view)) { |
| 824 | return bubble; |
| 825 | } |
| 826 | } |
| 827 | return null; |
| 828 | } |
| 829 | |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 830 | @VisibleForTesting(visibility = PRIVATE) |
Lyn Han | 89274b4 | 2020-03-25 00:56:26 -0700 | [diff] [blame] | 831 | Bubble getOverflowBubbleWithKey(String key) { |
| 832 | for (int i = 0; i < mOverflowBubbles.size(); i++) { |
| 833 | Bubble bubble = mOverflowBubbles.get(i); |
| 834 | if (bubble.getKey().equals(key)) { |
| 835 | return bubble; |
| 836 | } |
| 837 | } |
| 838 | return null; |
| 839 | } |
| 840 | |
| 841 | @VisibleForTesting(visibility = PRIVATE) |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 842 | void setTimeSource(TimeSource timeSource) { |
| 843 | mTimeSource = timeSource; |
| 844 | } |
| 845 | |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 846 | public void setListener(Listener listener) { |
| 847 | mListener = listener; |
| 848 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 849 | |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 850 | /** |
Lyn Han | 2f6e89d | 2020-04-15 10:01:01 -0700 | [diff] [blame] | 851 | * Set maximum number of bubbles allowed in overflow. |
| 852 | * This method should only be used in tests, not in production. |
| 853 | */ |
| 854 | @VisibleForTesting |
| 855 | void setMaxOverflowBubbles(int maxOverflowBubbles) { |
| 856 | mMaxOverflowBubbles = maxOverflowBubbles; |
| 857 | } |
| 858 | |
| 859 | /** |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 860 | * Description of current bubble data state. |
| 861 | */ |
| 862 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Lyn Han | 72f5090 | 2019-10-25 15:55:49 -0700 | [diff] [blame] | 863 | pw.print("selected: "); |
| 864 | pw.println(mSelectedBubble != null |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 865 | ? mSelectedBubble.getKey() |
| 866 | : "null"); |
Lyn Han | 72f5090 | 2019-10-25 15:55:49 -0700 | [diff] [blame] | 867 | pw.print("expanded: "); |
| 868 | pw.println(mExpanded); |
| 869 | pw.print("count: "); |
| 870 | pw.println(mBubbles.size()); |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 871 | for (Bubble bubble : mBubbles) { |
| 872 | bubble.dump(fd, pw, args); |
| 873 | } |
Lyn Han | 72f5090 | 2019-10-25 15:55:49 -0700 | [diff] [blame] | 874 | pw.print("summaryKeys: "); |
| 875 | pw.println(mSuppressedGroupKeys.size()); |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 876 | for (String key : mSuppressedGroupKeys.keySet()) { |
| 877 | pw.println(" suppressing: " + key); |
| 878 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 879 | } |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 880 | } |