blob: 3b58e5352106e3f7e96356a8cf698b5d2e3e59dd [file] [log] [blame]
Mady Mellorc3d6f7d2018-11-07 09:36:56 -08001/*
2 * Copyright (C) 2018 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
17package com.android.systemui.bubbles;
18
Mady Mellor3a0a1b42019-05-23 06:40:21 -070019import static android.app.Notification.FLAG_BUBBLE;
Mady Mellor9adfe6a2020-03-30 17:23:26 -070020import static android.app.NotificationManager.BUBBLE_PREFERENCE_NONE;
21import static android.app.NotificationManager.BUBBLE_PREFERENCE_SELECTED;
Mady Mellorc2ff0112019-03-28 14:18:06 -070022import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL;
23import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL_ALL;
24import static android.service.notification.NotificationListenerService.REASON_CANCEL;
25import static android.service.notification.NotificationListenerService.REASON_CANCEL_ALL;
Mady Mellor22f2f072019-04-18 13:26:18 -070026import static android.service.notification.NotificationListenerService.REASON_CLICK;
27import static android.service.notification.NotificationListenerService.REASON_GROUP_SUMMARY_CANCELED;
Mady Mellor390bff42019-04-05 15:09:01 -070028import static android.view.Display.DEFAULT_DISPLAY;
29import static android.view.Display.INVALID_DISPLAY;
Mady Mellord1c78b262018-11-06 18:04:40 -080030import static android.view.View.INVISIBLE;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080031import static android.view.View.VISIBLE;
Joshua Tsujid9923e52020-04-29 15:33:01 -040032import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080033
Issei Suzukia8d07312019-06-07 12:56:19 +020034import static com.android.systemui.bubbles.BubbleDebugConfig.DEBUG_BUBBLE_CONTROLLER;
35import static com.android.systemui.bubbles.BubbleDebugConfig.TAG_BUBBLES;
36import static com.android.systemui.bubbles.BubbleDebugConfig.TAG_WITH_CLASS_NAME;
Mady Mellor3f2efdb2018-11-21 11:30:45 -080037import static com.android.systemui.statusbar.StatusBarState.SHADE;
Mady Mellor1a4e86f2019-05-03 16:07:23 -070038import static com.android.systemui.statusbar.notification.NotificationEntryManager.UNDEFINED_DISMISS_REASON;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080039
Mark Renoufba5ab512019-05-02 15:21:01 -040040import static java.lang.annotation.ElementType.FIELD;
41import static java.lang.annotation.ElementType.LOCAL_VARIABLE;
42import static java.lang.annotation.ElementType.PARAMETER;
Mark Renouf08bc42a2019-03-07 13:01:59 -050043import static java.lang.annotation.RetentionPolicy.SOURCE;
44
Pinyao Ting3c930612020-05-19 00:26:03 +000045import android.annotation.NonNull;
Mark Renoufc19b4732019-06-26 12:08:33 -040046import android.annotation.UserIdInt;
Mark Renoufc808f062019-02-07 15:20:37 -050047import android.app.ActivityManager.RunningTaskInfo;
Mady Mellor9adfe6a2020-03-30 17:23:26 -070048import android.app.INotificationManager;
49import android.app.Notification;
50import android.app.NotificationChannel;
Mady Mellor66efd5e2019-05-15 13:38:11 -070051import android.app.NotificationManager;
Mady Mellorca0c24c2019-05-16 16:14:32 -070052import android.app.PendingIntent;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080053import android.content.Context;
Mady Mellorca0c24c2019-05-16 16:14:32 -070054import android.content.pm.ActivityInfo;
Mady Mellorf3b9fab2019-11-13 17:27:32 -080055import android.content.pm.PackageManager;
Joshua Tsujif418f9e2019-04-04 17:09:53 -040056import android.content.res.Configuration;
Joshua Tsujid9923e52020-04-29 15:33:01 -040057import android.graphics.PixelFormat;
Mady Mellord1c78b262018-11-06 18:04:40 -080058import android.graphics.Rect;
Joshua Tsujid9923e52020-04-29 15:33:01 -040059import android.os.Binder;
Lyn Han6cb4e5f2020-04-27 15:11:18 -070060import android.os.Handler;
Mark Renoufcecc77b2019-01-30 16:32:24 -050061import android.os.RemoteException;
Mady Mellorb4991e62019-01-10 15:14:51 -080062import android.os.ServiceManager;
Mady Mellor56515c42020-02-18 17:58:36 -080063import android.service.notification.NotificationListenerService;
Mark Renoufbbcf07f2019-05-09 10:42:43 -040064import android.service.notification.NotificationListenerService.RankingMap;
Joshua Tsujidd4d9f92019-05-13 13:57:38 -040065import android.service.notification.ZenModeConfig;
Mark Renoufc19b4732019-06-26 12:08:33 -040066import android.util.ArraySet;
Mark Renouf9ba6cea2019-04-17 11:53:50 -040067import android.util.Log;
Mark Renouf82a40e62019-05-23 16:16:24 -040068import android.util.Pair;
Mark Renoufc19b4732019-06-26 12:08:33 -040069import android.util.SparseSetArray;
Mark Renoufcecc77b2019-01-30 16:32:24 -050070import android.view.Display;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080071import android.view.ViewGroup;
Joshua Tsujid9923e52020-04-29 15:33:01 -040072import android.view.WindowManager;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080073
Mark Renouf08bc42a2019-03-07 13:01:59 -050074import androidx.annotation.IntDef;
Mark Renouf658c6bc2019-01-30 10:26:54 -050075import androidx.annotation.MainThread;
Joshua Tsujic650a142019-05-22 11:31:19 -040076import androidx.annotation.Nullable;
Mark Renouf658c6bc2019-01-30 10:26:54 -050077
Mady Mellorebdbbb92018-11-15 14:36:48 -080078import com.android.internal.annotations.VisibleForTesting;
Mady Mellora54e9fa2019-04-18 13:26:18 -070079import com.android.internal.statusbar.IStatusBarService;
Beverlya53fb0d2020-01-29 15:26:13 -050080import com.android.internal.statusbar.NotificationVisibility;
Beverlya53fb0d2020-01-29 15:26:13 -050081import com.android.systemui.Dumpable;
Sergey Nikolaienkov5cb6e522020-02-10 17:33:00 +010082import com.android.systemui.bubbles.dagger.BubbleModule;
Ned Burnsaaeb44b2020-02-12 23:48:26 -050083import com.android.systemui.dump.DumpManager;
Joshua Tsujibe60a582020-03-23 17:17:26 -040084import com.android.systemui.model.SysUiState;
Beverly8fdb5332019-02-04 14:29:49 -050085import com.android.systemui.plugins.statusbar.StatusBarStateController;
Mark Renoufcecc77b2019-01-30 16:32:24 -050086import com.android.systemui.shared.system.ActivityManagerWrapper;
Hongwei Wang43a752b2019-09-17 20:20:30 +000087import com.android.systemui.shared.system.PinnedStackListenerForwarder;
Mark Renoufcecc77b2019-01-30 16:32:24 -050088import com.android.systemui.shared.system.TaskStackChangeListener;
Joshua Tsujia19515f2019-02-13 18:02:29 -050089import com.android.systemui.shared.system.WindowManagerWrapper;
Beverlya53fb0d2020-01-29 15:26:13 -050090import com.android.systemui.statusbar.FeatureFlags;
Mark Renoufc19b4732019-06-26 12:08:33 -040091import com.android.systemui.statusbar.NotificationLockscreenUserManager;
Mady Mellorc2ff0112019-03-28 14:18:06 -070092import com.android.systemui.statusbar.NotificationRemoveInterceptor;
Joshua Tsujid9923e52020-04-29 15:33:01 -040093import com.android.systemui.statusbar.ScrimView;
Mady Mellor9adfe6a2020-03-30 17:23:26 -070094import com.android.systemui.statusbar.notification.NotificationChannelHelper;
Ned Burns01e38212019-01-03 16:32:52 -050095import com.android.systemui.statusbar.notification.NotificationEntryListener;
96import com.android.systemui.statusbar.notification.NotificationEntryManager;
Beverlya53fb0d2020-01-29 15:26:13 -050097import com.android.systemui.statusbar.notification.collection.NotifCollection;
98import com.android.systemui.statusbar.notification.collection.NotifPipeline;
Ned Burnsf81c4c42019-01-07 14:10:43 -050099import com.android.systemui.statusbar.notification.collection.NotificationEntry;
Beverlya53fb0d2020-01-29 15:26:13 -0500100import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener;
Beverly Taid1e175c2020-03-10 16:37:04 +0000101import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProvider;
Mady Mellor22f2f072019-04-18 13:26:18 -0700102import com.android.systemui.statusbar.phone.NotificationGroupManager;
wilsonshihe8321942019-10-18 18:39:46 +0800103import com.android.systemui.statusbar.phone.NotificationShadeWindowController;
Joshua Tsujid9923e52020-04-29 15:33:01 -0400104import com.android.systemui.statusbar.phone.ScrimController;
Mady Mellor7f234902019-10-20 12:06:29 -0700105import com.android.systemui.statusbar.phone.ShadeController;
Mady Mellorf3b9fab2019-11-13 17:27:32 -0800106import com.android.systemui.statusbar.phone.StatusBar;
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700107import com.android.systemui.statusbar.policy.ConfigurationController;
Joshua Tsujidd4d9f92019-05-13 13:57:38 -0400108import com.android.systemui.statusbar.policy.ZenModeController;
Joshua Tsuji7155bf12020-02-13 16:14:29 -0500109import com.android.systemui.util.FloatingContentCoordinator;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800110
Mady Mellor70cba7bb2019-07-02 15:06:07 -0700111import java.io.FileDescriptor;
112import java.io.PrintWriter;
Mark Renouf08bc42a2019-03-07 13:01:59 -0500113import java.lang.annotation.Retention;
Mark Renoufba5ab512019-05-02 15:21:01 -0400114import java.lang.annotation.Target;
Mady Mellor22f2f072019-04-18 13:26:18 -0700115import java.util.ArrayList;
Lyn Hanb58c7562020-01-07 14:29:20 -0800116import java.util.List;
Pinyao Ting3c930612020-05-19 00:26:03 +0000117import java.util.Objects;
Mark Renouf08bc42a2019-03-07 13:01:59 -0500118
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800119/**
120 * Bubbles are a special type of content that can "float" on top of other apps or System UI.
121 * Bubbles can be expanded to show more content.
122 *
123 * The controller manages addition, removal, and visible state of bubbles on screen.
124 */
Beverlya53fb0d2020-01-29 15:26:13 -0500125public class BubbleController implements ConfigurationController.ConfigurationListener, Dumpable {
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800126
Issei Suzukia8d07312019-06-07 12:56:19 +0200127 private static final String TAG = TAG_WITH_CLASS_NAME ? "BubbleController" : TAG_BUBBLES;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800128
Mark Renouf08bc42a2019-03-07 13:01:59 -0500129 @Retention(SOURCE)
130 @IntDef({DISMISS_USER_GESTURE, DISMISS_AGED, DISMISS_TASK_FINISHED, DISMISS_BLOCKED,
Mark Renoufc19b4732019-06-26 12:08:33 -0400131 DISMISS_NOTIF_CANCEL, DISMISS_ACCESSIBILITY_ACTION, DISMISS_NO_LONGER_BUBBLE,
Lyn Han2f6e89d2020-04-15 10:01:01 -0700132 DISMISS_USER_CHANGED, DISMISS_GROUP_CANCELLED, DISMISS_INVALID_INTENT,
133 DISMISS_OVERFLOW_MAX_REACHED})
Mark Renoufba5ab512019-05-02 15:21:01 -0400134 @Target({FIELD, LOCAL_VARIABLE, PARAMETER})
Mark Renouf08bc42a2019-03-07 13:01:59 -0500135 @interface DismissReason {}
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700136
Mark Renouf08bc42a2019-03-07 13:01:59 -0500137 static final int DISMISS_USER_GESTURE = 1;
138 static final int DISMISS_AGED = 2;
139 static final int DISMISS_TASK_FINISHED = 3;
140 static final int DISMISS_BLOCKED = 4;
141 static final int DISMISS_NOTIF_CANCEL = 5;
142 static final int DISMISS_ACCESSIBILITY_ACTION = 6;
Mady Melloraa8fef22019-04-11 13:36:40 -0700143 static final int DISMISS_NO_LONGER_BUBBLE = 7;
Mark Renoufc19b4732019-06-26 12:08:33 -0400144 static final int DISMISS_USER_CHANGED = 8;
Mady Mellor22f2f072019-04-18 13:26:18 -0700145 static final int DISMISS_GROUP_CANCELLED = 9;
Mady Mellor8454ddf2019-08-15 11:16:23 -0700146 static final int DISMISS_INVALID_INTENT = 10;
Lyn Han2f6e89d2020-04-15 10:01:01 -0700147 static final int DISMISS_OVERFLOW_MAX_REACHED = 11;
Mark Renouf08bc42a2019-03-07 13:01:59 -0500148
Ned Burns01e38212019-01-03 16:32:52 -0500149 private final Context mContext;
150 private final NotificationEntryManager mNotificationEntryManager;
Beverlya53fb0d2020-01-29 15:26:13 -0500151 private final NotifPipeline mNotifPipeline;
Mark Renoufcecc77b2019-01-30 16:32:24 -0500152 private final BubbleTaskStackListener mTaskStackListener;
Mady Mellorcd9b1302018-11-06 18:08:04 -0800153 private BubbleExpandListener mExpandListener;
Issei Suzukic0387542019-03-08 17:31:14 +0100154 @Nullable private BubbleStackView.SurfaceSynchronizer mSurfaceSynchronizer;
Mady Mellor22f2f072019-04-18 13:26:18 -0700155 private final NotificationGroupManager mNotificationGroupManager;
Heemin Seogba6337f2019-12-10 15:34:37 -0800156 private final ShadeController mShadeController;
Joshua Tsuji7155bf12020-02-13 16:14:29 -0500157 private final FloatingContentCoordinator mFloatingContentCoordinator;
Pinyao Tingee191b12020-04-29 18:35:39 -0700158 private final BubbleDataRepository mDataRepository;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800159
Mady Mellor3dff9e62019-02-05 18:12:53 -0800160 private BubbleData mBubbleData;
Joshua Tsujid9923e52020-04-29 15:33:01 -0400161 private ScrimView mBubbleScrim;
Joshua Tsujic650a142019-05-22 11:31:19 -0400162 @Nullable private BubbleStackView mStackView;
Mady Mellor247ca2c2019-12-02 16:18:59 -0800163 private BubbleIconFactory mBubbleIconFactory;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800164
Mark Renoufc19b4732019-06-26 12:08:33 -0400165 // Tracks the id of the current (foreground) user.
166 private int mCurrentUserId;
167 // Saves notification keys of active bubbles when users are switched.
168 private final SparseSetArray<String> mSavedBubbleKeysPerUser;
169
Mady Mellor56515c42020-02-18 17:58:36 -0800170 // Used when ranking updates occur and we check if things should bubble / unbubble
171 private NotificationListenerService.Ranking mTmpRanking;
172
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800173 // Bubbles get added to the status bar view
wilsonshihe8321942019-10-18 18:39:46 +0800174 private final NotificationShadeWindowController mNotificationShadeWindowController;
Joshua Tsujidd4d9f92019-05-13 13:57:38 -0400175 private final ZenModeController mZenModeController;
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800176 private StatusBarStateListener mStatusBarStateListener;
Mady Mellor9adfe6a2020-03-30 17:23:26 -0700177 private INotificationManager mINotificationManager;
Aran Inkaa4dfa72019-11-18 16:49:07 -0500178
Lyn Hanb58c7562020-01-07 14:29:20 -0800179 // Callback that updates BubbleOverflowActivity on data change.
Mady Mellor1d082022020-05-12 16:35:39 +0000180 @Nullable private Runnable mOverflowCallback = null;
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800181
Beverly Taid1e175c2020-03-10 16:37:04 +0000182 private final NotificationInterruptStateProvider mNotificationInterruptStateProvider;
Mady Mellora54e9fa2019-04-18 13:26:18 -0700183 private IStatusBarService mBarService;
Joshua Tsujid9923e52020-04-29 15:33:01 -0400184 private WindowManager mWindowManager;
Joshua Tsujibe60a582020-03-23 17:17:26 -0400185 private SysUiState mSysUiState;
Mady Mellorb4991e62019-01-10 15:14:51 -0800186
Lyn Han6cb4e5f2020-04-27 15:11:18 -0700187 // Used to post to main UI thread
188 private Handler mHandler = new Handler();
189
Joshua Tsuji4395bbd2020-05-19 17:53:33 -0400190 /** LayoutParams used to add the BubbleStackView to the window manager. */
Joshua Tsujid9923e52020-04-29 15:33:01 -0400191 private WindowManager.LayoutParams mWmLayoutParams;
Joshua Tsuji4395bbd2020-05-19 17:53:33 -0400192 /** Whether or not the BubbleStackView has been added to the WindowManager. */
193 private boolean mAddedToWindowManager = false;
Joshua Tsujid9923e52020-04-29 15:33:01 -0400194
Mady Mellord1c78b262018-11-06 18:04:40 -0800195 // Used for determining view rect for touch interaction
196 private Rect mTempRect = new Rect();
197
Mark Renoufc19b4732019-06-26 12:08:33 -0400198 // Listens to user switch so bubbles can be saved and restored.
199 private final NotificationLockscreenUserManager mNotifUserManager;
200
Joshua Tsujif418f9e2019-04-04 17:09:53 -0400201 /** Last known orientation, used to detect orientation changes in {@link #onConfigChanged}. */
202 private int mOrientation = Configuration.ORIENTATION_UNDEFINED;
203
Lyn Hanb4b06132020-05-11 09:25:20 -0700204 /**
205 * Last known screen density, used to detect display size changes in {@link #onConfigChanged}.
206 */
207 private int mDensityDpi = Configuration.DENSITY_DPI_UNDEFINED;
208
Mady Mellor3df7ab02019-12-09 15:07:10 -0800209 private boolean mInflateSynchronously;
210
Beverlyed8aea22020-01-22 16:52:47 -0500211 // TODO (b/145659174): allow for multiple callbacks to support the "shadow" new notif pipeline
212 private final List<NotifCallback> mCallbacks = new ArrayList<>();
213
Mady Mellor5549dd22018-11-06 18:07:34 -0800214 /**
Mady Mellorcd9b1302018-11-06 18:08:04 -0800215 * Listener to find out about stack expansion / collapse events.
216 */
217 public interface BubbleExpandListener {
218 /**
219 * Called when the expansion state of the bubble stack changes.
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700220 *
Mady Mellorcd9b1302018-11-06 18:08:04 -0800221 * @param isExpanding whether it's expanding or collapsing
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800222 * @param key the notification key associated with bubble being expanded
Mady Mellorcd9b1302018-11-06 18:08:04 -0800223 */
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800224 void onBubbleExpandChanged(boolean isExpanding, String key);
225 }
226
227 /**
Mady Mellorf44b6832020-01-14 13:26:14 -0800228 * Listener to be notified when a bubbles' notification suppression state changes.
229 */
230 public interface NotificationSuppressionChangedListener {
231 /**
232 * Called when the notification suppression state of a bubble changes.
233 */
234 void onBubbleNotificationSuppressionChange(Bubble bubble);
Beverlyed8aea22020-01-22 16:52:47 -0500235 }
Mady Mellorf44b6832020-01-14 13:26:14 -0800236
Beverlyed8aea22020-01-22 16:52:47 -0500237 /**
238 * Callback for when the BubbleController wants to interact with the notification pipeline to:
239 * - Remove a previously bubbled notification
240 * - Update the notification shade since bubbled notification should/shouldn't be showing
241 */
242 public interface NotifCallback {
243 /**
Beverlya53fb0d2020-01-29 15:26:13 -0500244 * Called when a bubbled notification that was hidden from the shade is now being removed
245 * This can happen when an app cancels a bubbled notification or when the user dismisses a
246 * bubble.
Beverlyed8aea22020-01-22 16:52:47 -0500247 */
Pinyao Ting3c930612020-05-19 00:26:03 +0000248 void removeNotification(@NonNull NotificationEntry entry, int reason);
Beverlyed8aea22020-01-22 16:52:47 -0500249
250 /**
251 * Called when a bubbled notification has changed whether it should be
252 * filtered from the shade.
253 */
Pinyao Ting3c930612020-05-19 00:26:03 +0000254 void invalidateNotifications(@NonNull String reason);
Beverlyed8aea22020-01-22 16:52:47 -0500255
256 /**
257 * Called on a bubbled entry that has been removed when there are no longer
258 * bubbled entries in its group.
259 *
260 * Checks whether its group has any other (non-bubbled) children. If it doesn't,
261 * removes all remnants of the group's summary from the notification pipeline.
262 * TODO: (b/145659174) Only old pipeline needs this - delete post-migration.
263 */
Pinyao Ting3c930612020-05-19 00:26:03 +0000264 void maybeCancelSummary(@NonNull NotificationEntry entry);
Mady Mellorf44b6832020-01-14 13:26:14 -0800265 }
266
267 /**
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800268 * Listens for the current state of the status bar and updates the visibility state
269 * of bubbles as needed.
270 */
271 private class StatusBarStateListener implements StatusBarStateController.StateListener {
272 private int mState;
273 /**
274 * Returns the current status bar state.
275 */
276 public int getCurrentState() {
277 return mState;
278 }
279
280 @Override
281 public void onStateChanged(int newState) {
282 mState = newState;
Mark Renouf71a3af62019-04-08 15:02:54 -0400283 boolean shouldCollapse = (mState != SHADE);
284 if (shouldCollapse) {
285 collapseStack();
286 }
Lyn Han6c40fe72019-05-08 14:06:33 -0700287 updateStack();
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800288 }
Mady Mellorcd9b1302018-11-06 18:08:04 -0800289 }
290
Sergey Nikolaienkov5cb6e522020-02-10 17:33:00 +0100291 /**
292 * Injected constructor. See {@link BubbleModule}.
293 */
Mady Mellor7f234902019-10-20 12:06:29 -0700294 public BubbleController(Context context,
wilsonshihe8321942019-10-18 18:39:46 +0800295 NotificationShadeWindowController notificationShadeWindowController,
Mady Mellor7f234902019-10-20 12:06:29 -0700296 StatusBarStateController statusBarStateController,
Heemin Seogba6337f2019-12-10 15:34:37 -0800297 ShadeController shadeController,
Mady Mellor7f234902019-10-20 12:06:29 -0700298 BubbleData data,
299 @Nullable BubbleStackView.SurfaceSynchronizer synchronizer,
300 ConfigurationController configurationController,
Beverly Taid1e175c2020-03-10 16:37:04 +0000301 NotificationInterruptStateProvider interruptionStateProvider,
Mady Mellor7f234902019-10-20 12:06:29 -0700302 ZenModeController zenModeController,
303 NotificationLockscreenUserManager notifUserManager,
304 NotificationGroupManager groupManager,
Beverlya53fb0d2020-01-29 15:26:13 -0500305 NotificationEntryManager entryManager,
306 NotifPipeline notifPipeline,
307 FeatureFlags featureFlags,
Ned Burnsaaeb44b2020-02-12 23:48:26 -0500308 DumpManager dumpManager,
Joshua Tsujibe60a582020-03-23 17:17:26 -0400309 FloatingContentCoordinator floatingContentCoordinator,
Pinyao Tingee191b12020-04-29 18:35:39 -0700310 BubbleDataRepository dataRepository,
Mady Mellor9adfe6a2020-03-30 17:23:26 -0700311 SysUiState sysUiState,
Mady Mellor59a7b982020-05-11 15:19:59 -0700312 INotificationManager notificationManager,
313 WindowManager windowManager) {
Ned Burnsaaeb44b2020-02-12 23:48:26 -0500314 dumpManager.registerDumpable(TAG, this);
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800315 mContext = context;
Heemin Seogba6337f2019-12-10 15:34:37 -0800316 mShadeController = shadeController;
Beverly Taid1e175c2020-03-10 16:37:04 +0000317 mNotificationInterruptStateProvider = interruptionStateProvider;
Mark Renoufc19b4732019-06-26 12:08:33 -0400318 mNotifUserManager = notifUserManager;
Joshua Tsujidd4d9f92019-05-13 13:57:38 -0400319 mZenModeController = zenModeController;
Joshua Tsuji7155bf12020-02-13 16:14:29 -0500320 mFloatingContentCoordinator = floatingContentCoordinator;
Pinyao Tingee191b12020-04-29 18:35:39 -0700321 mDataRepository = dataRepository;
Mady Mellor9adfe6a2020-03-30 17:23:26 -0700322 mINotificationManager = notificationManager;
Joshua Tsujidd4d9f92019-05-13 13:57:38 -0400323 mZenModeController.addCallback(new ZenModeController.Callback() {
324 @Override
325 public void onZenChanged(int zen) {
Mady Mellorb8aaf972019-11-26 10:28:00 -0800326 for (Bubble b : mBubbleData.getBubbles()) {
Joshua Tsuji2ed260e2020-03-26 14:26:01 -0400327 b.setShowDot(b.showInShade());
Mady Mellordf48d0a2019-06-25 18:26:46 -0700328 }
Joshua Tsujidd4d9f92019-05-13 13:57:38 -0400329 }
330
331 @Override
332 public void onConfigChanged(ZenModeConfig config) {
Mady Mellorb8aaf972019-11-26 10:28:00 -0800333 for (Bubble b : mBubbleData.getBubbles()) {
Joshua Tsuji2ed260e2020-03-26 14:26:01 -0400334 b.setShowDot(b.showInShade());
Mady Mellordf48d0a2019-06-25 18:26:46 -0700335 }
Joshua Tsujidd4d9f92019-05-13 13:57:38 -0400336 }
337 });
Mady Melloraa8fef22019-04-11 13:36:40 -0700338
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700339 configurationController.addCallback(this /* configurationListener */);
Joshua Tsujibe60a582020-03-23 17:17:26 -0400340 mSysUiState = sysUiState;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800341
Mark Renouf9ba6cea2019-04-17 11:53:50 -0400342 mBubbleData = data;
343 mBubbleData.setListener(mBubbleDataListener);
Mady Mellorf44b6832020-01-14 13:26:14 -0800344 mBubbleData.setSuppressionChangedListener(new NotificationSuppressionChangedListener() {
345 @Override
346 public void onBubbleNotificationSuppressionChange(Bubble bubble) {
347 // Make sure NoMan knows it's not showing in the shade anymore so anyone querying it
348 // can tell.
349 try {
350 mBarService.onBubbleNotificationSuppressionChanged(bubble.getKey(),
351 !bubble.showInShade());
352 } catch (RemoteException e) {
353 // Bad things have happened
354 }
355 }
356 });
Mark Renouf9ba6cea2019-04-17 11:53:50 -0400357
Mady Mellor7f234902019-10-20 12:06:29 -0700358 mNotificationEntryManager = entryManager;
Mady Mellor22f2f072019-04-18 13:26:18 -0700359 mNotificationGroupManager = groupManager;
Beverlya53fb0d2020-01-29 15:26:13 -0500360 mNotifPipeline = notifPipeline;
361
362 if (!featureFlags.isNewNotifPipelineRenderingEnabled()) {
363 setupNEM();
364 } else {
365 setupNotifPipeline();
366 }
Mady Mellorb4991e62019-01-10 15:14:51 -0800367
wilsonshihe8321942019-10-18 18:39:46 +0800368 mNotificationShadeWindowController = notificationShadeWindowController;
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800369 mStatusBarStateListener = new StatusBarStateListener();
Mady Mellor7f234902019-10-20 12:06:29 -0700370 statusBarStateController.addCallback(mStatusBarStateListener);
Mark Renoufcecc77b2019-01-30 16:32:24 -0500371
Mark Renoufcecc77b2019-01-30 16:32:24 -0500372 mTaskStackListener = new BubbleTaskStackListener();
373 ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener);
Mady Mellor3dff9e62019-02-05 18:12:53 -0800374
Joshua Tsujia19515f2019-02-13 18:02:29 -0500375 try {
376 WindowManagerWrapper.getInstance().addPinnedStackListener(new BubblesImeListener());
377 } catch (RemoteException e) {
378 e.printStackTrace();
379 }
Issei Suzukic0387542019-03-08 17:31:14 +0100380 mSurfaceSynchronizer = synchronizer;
Mady Mellora54e9fa2019-04-18 13:26:18 -0700381
Mady Mellor59a7b982020-05-11 15:19:59 -0700382 mWindowManager = windowManager;
Mady Mellora54e9fa2019-04-18 13:26:18 -0700383 mBarService = IStatusBarService.Stub.asInterface(
384 ServiceManager.getService(Context.STATUS_BAR_SERVICE));
Mark Renoufc19b4732019-06-26 12:08:33 -0400385
Joshua Tsujid9923e52020-04-29 15:33:01 -0400386 mBubbleScrim = new ScrimView(mContext);
387
Mark Renoufc19b4732019-06-26 12:08:33 -0400388 mSavedBubbleKeysPerUser = new SparseSetArray<>();
389 mCurrentUserId = mNotifUserManager.getCurrentUserId();
390 mNotifUserManager.addUserChangedListener(
Steve Elliottb47f1c72019-12-19 12:39:26 -0500391 new NotificationLockscreenUserManager.UserChangedListener() {
392 @Override
393 public void onUserChanged(int newUserId) {
394 BubbleController.this.saveBubbles(mCurrentUserId);
395 mBubbleData.dismissAll(DISMISS_USER_CHANGED);
396 BubbleController.this.restoreBubbles(newUserId);
397 mCurrentUserId = newUserId;
398 }
Mark Renoufc19b4732019-06-26 12:08:33 -0400399 });
Mady Mellorff076eb2019-11-13 10:12:06 -0800400
Mady Mellor247ca2c2019-12-02 16:18:59 -0800401 mBubbleIconFactory = new BubbleIconFactory(context);
Mady Mellor5549dd22018-11-06 18:07:34 -0800402 }
403
Mark Renouf8b6a3c62019-04-09 10:17:40 -0400404 /**
Beverlyed8aea22020-01-22 16:52:47 -0500405 * See {@link NotifCallback}.
406 */
407 public void addNotifCallback(NotifCallback callback) {
408 mCallbacks.add(callback);
409 }
410
411 private void setupNEM() {
412 mNotificationEntryManager.addNotificationEntryListener(
413 new NotificationEntryListener() {
414 @Override
Mady Mellorf9439ab2020-01-30 16:06:53 -0800415 public void onPendingEntryAdded(NotificationEntry entry) {
Beverlyed8aea22020-01-22 16:52:47 -0500416 onEntryAdded(entry);
417 }
418
419 @Override
420 public void onPreEntryUpdated(NotificationEntry entry) {
421 onEntryUpdated(entry);
422 }
423
424 @Override
Beverlya53fb0d2020-01-29 15:26:13 -0500425 public void onEntryRemoved(
426 NotificationEntry entry,
427 @android.annotation.Nullable NotificationVisibility visibility,
Julia Reynolds138111f2020-02-26 11:17:39 -0500428 boolean removedByUser,
429 int reason) {
Beverlya53fb0d2020-01-29 15:26:13 -0500430 BubbleController.this.onEntryRemoved(entry);
431 }
432
433 @Override
Beverlyed8aea22020-01-22 16:52:47 -0500434 public void onNotificationRankingUpdated(RankingMap rankingMap) {
435 onRankingUpdated(rankingMap);
436 }
437 });
438
Evan Laird04373662020-01-24 17:37:39 -0500439 mNotificationEntryManager.addNotificationRemoveInterceptor(
Beverlyed8aea22020-01-22 16:52:47 -0500440 new NotificationRemoveInterceptor() {
441 @Override
Evan Laird04373662020-01-24 17:37:39 -0500442 public boolean onNotificationRemoveRequested(
Beverlya53fb0d2020-01-29 15:26:13 -0500443 String key,
444 NotificationEntry entry,
445 int dismissReason) {
446 final boolean isClearAll = dismissReason == REASON_CANCEL_ALL;
447 final boolean isUserDimiss = dismissReason == REASON_CANCEL
448 || dismissReason == REASON_CLICK;
449 final boolean isAppCancel = dismissReason == REASON_APP_CANCEL
450 || dismissReason == REASON_APP_CANCEL_ALL;
451 final boolean isSummaryCancel =
452 dismissReason == REASON_GROUP_SUMMARY_CANCELED;
453
454 // Need to check for !appCancel here because the notification may have
455 // previously been dismissed & entry.isRowDismissed would still be true
456 boolean userRemovedNotif =
457 (entry != null && entry.isRowDismissed() && !isAppCancel)
458 || isClearAll || isUserDimiss || isSummaryCancel;
459
Mady Mellordd6fe612020-04-15 11:47:55 -0700460 if (userRemovedNotif) {
Beverlya53fb0d2020-01-29 15:26:13 -0500461 return handleDismissalInterception(entry);
462 }
Beverlya53fb0d2020-01-29 15:26:13 -0500463 return false;
Beverlyed8aea22020-01-22 16:52:47 -0500464 }
465 });
466
467 mNotificationGroupManager.addOnGroupChangeListener(
468 new NotificationGroupManager.OnGroupChangeListener() {
469 @Override
470 public void onGroupSuppressionChanged(
471 NotificationGroupManager.NotificationGroup group,
472 boolean suppressed) {
473 // More notifications could be added causing summary to no longer
474 // be suppressed -- in this case need to remove the key.
475 final String groupKey = group.summary != null
476 ? group.summary.getSbn().getGroupKey()
477 : null;
478 if (!suppressed && groupKey != null
479 && mBubbleData.isSummarySuppressed(groupKey)) {
480 mBubbleData.removeSuppressedSummary(groupKey);
481 }
482 }
483 });
484
485 addNotifCallback(new NotifCallback() {
486 @Override
Neil Fullerb28e0562020-05-15 10:00:05 +0000487 public void removeNotification(NotificationEntry entry, int reason) {
Beverlyed8aea22020-01-22 16:52:47 -0500488 mNotificationEntryManager.performRemoveNotification(entry.getSbn(),
Beverlya53fb0d2020-01-29 15:26:13 -0500489 reason);
Beverlyed8aea22020-01-22 16:52:47 -0500490 }
491
492 @Override
Beverlya53fb0d2020-01-29 15:26:13 -0500493 public void invalidateNotifications(String reason) {
Beverlyed8aea22020-01-22 16:52:47 -0500494 mNotificationEntryManager.updateNotifications(reason);
495 }
496
497 @Override
Neil Fullerb28e0562020-05-15 10:00:05 +0000498 public void maybeCancelSummary(NotificationEntry entry) {
Beverlyed8aea22020-01-22 16:52:47 -0500499 // Check if removed bubble has an associated suppressed group summary that needs
500 // to be removed now.
Beverlya53fb0d2020-01-29 15:26:13 -0500501 final String groupKey = entry.getSbn().getGroupKey();
Beverlyed8aea22020-01-22 16:52:47 -0500502 if (mBubbleData.isSummarySuppressed(groupKey)) {
Beverlya53fb0d2020-01-29 15:26:13 -0500503 mBubbleData.removeSuppressedSummary(groupKey);
Beverlyed8aea22020-01-22 16:52:47 -0500504
505 final NotificationEntry summary =
506 mNotificationEntryManager.getActiveNotificationUnfiltered(
507 mBubbleData.getSummaryKey(groupKey));
Beverlya53fb0d2020-01-29 15:26:13 -0500508 if (summary != null) {
509 mNotificationEntryManager.performRemoveNotification(summary.getSbn(),
510 UNDEFINED_DISMISS_REASON);
511 }
Beverlyed8aea22020-01-22 16:52:47 -0500512 }
513
Beverlya53fb0d2020-01-29 15:26:13 -0500514 // Check if we still need to remove the summary from NoManGroup because the summary
515 // may not be in the mBubbleData.mSuppressedGroupKeys list and removed above.
516 // For example:
517 // 1. Bubbled notifications (group) is posted to shade and are visible bubbles
518 // 2. User expands bubbles so now their respective notifications in the shade are
519 // hidden, including the group summary
520 // 3. User removes all bubbles
521 // 4. We expect all the removed bubbles AND the summary (note: the summary was
522 // never added to the suppressedSummary list in BubbleData, so we add this check)
Beverlyed8aea22020-01-22 16:52:47 -0500523 NotificationEntry summary =
524 mNotificationGroupManager.getLogicalGroupSummary(entry.getSbn());
525 if (summary != null) {
526 ArrayList<NotificationEntry> summaryChildren =
527 mNotificationGroupManager.getLogicalChildren(summary.getSbn());
528 boolean isSummaryThisNotif = summary.getKey().equals(entry.getKey());
529 if (!isSummaryThisNotif && (summaryChildren == null
530 || summaryChildren.isEmpty())) {
531 mNotificationEntryManager.performRemoveNotification(summary.getSbn(),
532 UNDEFINED_DISMISS_REASON);
533 }
534 }
535 }
536 });
537 }
538
Beverlya53fb0d2020-01-29 15:26:13 -0500539 private void setupNotifPipeline() {
540 mNotifPipeline.addCollectionListener(new NotifCollectionListener() {
541 @Override
542 public void onEntryAdded(NotificationEntry entry) {
543 BubbleController.this.onEntryAdded(entry);
544 }
545
546 @Override
547 public void onEntryUpdated(NotificationEntry entry) {
548 BubbleController.this.onEntryUpdated(entry);
549 }
550
551 @Override
552 public void onRankingUpdate(RankingMap rankingMap) {
553 onRankingUpdated(rankingMap);
554 }
555
556 @Override
557 public void onEntryRemoved(NotificationEntry entry,
558 @NotifCollection.CancellationReason int reason) {
559 BubbleController.this.onEntryRemoved(entry);
560 }
561 });
562 }
563
Beverlyed8aea22020-01-22 16:52:47 -0500564 /**
Joshua Tsujid9923e52020-04-29 15:33:01 -0400565 * Returns the scrim drawn behind the bubble stack. This is managed by {@link ScrimController}
566 * since we want the scrim's appearance and behavior to be identical to that of the notification
567 * shade scrim.
568 */
569 public ScrimView getScrimForBubble() {
570 return mBubbleScrim;
571 }
572
573 /**
Mady Mellor3df7ab02019-12-09 15:07:10 -0800574 * Sets whether to perform inflation on the same thread as the caller. This method should only
575 * be used in tests, not in production.
576 */
577 @VisibleForTesting
578 void setInflateSynchronously(boolean inflateSynchronously) {
579 mInflateSynchronously = inflateSynchronously;
Mady Mellor5549dd22018-11-06 18:07:34 -0800580 }
581
Mady Mellor1d082022020-05-12 16:35:39 +0000582 void setOverflowCallback(Runnable updateOverflow) {
583 mOverflowCallback = updateOverflow;
Lyn Hanb58c7562020-01-07 14:29:20 -0800584 }
585
586 /**
587 * @return Bubbles for updating overflow.
588 */
589 List<Bubble> getOverflowBubbles() {
590 return mBubbleData.getOverflowBubbles();
591 }
592
Mark Renouf8b6a3c62019-04-09 10:17:40 -0400593 /**
594 * BubbleStackView is lazily created by this method the first time a Bubble is added. This
595 * method initializes the stack view and adds it to the StatusBar just above the scrim.
596 */
597 private void ensureStackViewCreated() {
598 if (mStackView == null) {
Joshua Tsuji7155bf12020-02-13 16:14:29 -0500599 mStackView = new BubbleStackView(
Joshua Tsujibe60a582020-03-23 17:17:26 -0400600 mContext, mBubbleData, mSurfaceSynchronizer, mFloatingContentCoordinator,
Joshua Tsuji4395bbd2020-05-19 17:53:33 -0400601 mSysUiState, mNotificationShadeWindowController, this::onAllBubblesAnimatedOut);
Joshua Tsujid9923e52020-04-29 15:33:01 -0400602 mStackView.addView(mBubbleScrim);
Mark Renouf8b6a3c62019-04-09 10:17:40 -0400603 if (mExpandListener != null) {
604 mStackView.setExpandListener(mExpandListener);
605 }
Joshua Tsuji6855cab2020-04-16 01:05:39 -0400606
607 mStackView.setUnbubbleConversationCallback(notificationEntry ->
608 onUserChangedBubble(notificationEntry, false /* shouldBubble */));
Mark Renouf8b6a3c62019-04-09 10:17:40 -0400609 }
Joshua Tsuji4395bbd2020-05-19 17:53:33 -0400610
611 addToWindowManagerMaybe();
Mark Renouf8b6a3c62019-04-09 10:17:40 -0400612 }
613
Joshua Tsuji4395bbd2020-05-19 17:53:33 -0400614 /** Adds the BubbleStackView to the WindowManager if it's not already there. */
615 private void addToWindowManagerMaybe() {
616 // If the stack is null, or already added, don't add it.
617 if (mStackView == null || mAddedToWindowManager) {
618 return;
619 }
620
Joshua Tsujid9923e52020-04-29 15:33:01 -0400621 mWmLayoutParams = new WindowManager.LayoutParams(
622 // Fill the screen so we can use translation animations to position the bubble
623 // stack. We'll use touchable regions to ignore touches that are not on the bubbles
624 // themselves.
625 ViewGroup.LayoutParams.MATCH_PARENT,
626 ViewGroup.LayoutParams.MATCH_PARENT,
Joshua Tsuji94d4c342020-05-04 14:00:24 -0400627 WindowManager.LayoutParams.TYPE_TRUSTED_APPLICATION_OVERLAY,
Joshua Tsujid9923e52020-04-29 15:33:01 -0400628 // Start not focusable - we'll become focusable when expanded so the ActivityView
629 // can use the IME.
630 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
631 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
632 PixelFormat.TRANSLUCENT);
633
634 mWmLayoutParams.setFitInsetsTypes(0);
635 mWmLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
636 mWmLayoutParams.token = new Binder();
637 mWmLayoutParams.setTitle("Bubbles!");
638 mWmLayoutParams.packageName = mContext.getPackageName();
639 mWmLayoutParams.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
640
Joshua Tsuji4395bbd2020-05-19 17:53:33 -0400641 try {
642 mAddedToWindowManager = true;
643 mWindowManager.addView(mStackView, mWmLayoutParams);
644 } catch (IllegalStateException e) {
645 // This means the stack has already been added. This shouldn't happen, since we keep
646 // track of that, but just in case, update the previously added view's layout params.
647 e.printStackTrace();
648 updateWmFlags();
649 }
Joshua Tsujid9923e52020-04-29 15:33:01 -0400650 }
651
Joshua Tsuji4395bbd2020-05-19 17:53:33 -0400652 /** Removes the BubbleStackView from the WindowManager if it's there. */
653 private void removeFromWindowManagerMaybe() {
654 if (!mAddedToWindowManager) {
655 return;
656 }
657
658 try {
659 mAddedToWindowManager = false;
660 mWindowManager.removeView(mStackView);
661 } catch (IllegalArgumentException e) {
662 // This means the stack has already been removed - it shouldn't happen, but ignore if it
663 // does, since we wanted it removed anyway.
664 e.printStackTrace();
665 }
666 }
667
668 /**
669 * Updates the BubbleStackView's WindowManager.LayoutParams, and updates the WindowManager with
670 * the new params if the stack has been added.
671 */
Joshua Tsujid9923e52020-04-29 15:33:01 -0400672 private void updateWmFlags() {
673 if (isStackExpanded()) {
674 // If we're expanded, we want to be focusable so that the ActivityView can receive focus
675 // and show the IME.
676 mWmLayoutParams.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
677 } else {
678 // If we're collapsed, we don't want to be able to receive focus. Doing so would
679 // preclude applications from using the IME since we are always above them.
680 mWmLayoutParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
681 }
682
Joshua Tsuji4395bbd2020-05-19 17:53:33 -0400683 if (mStackView != null && mAddedToWindowManager) {
684 try {
685 mWindowManager.updateViewLayout(mStackView, mWmLayoutParams);
686 } catch (IllegalArgumentException e) {
687 // If the stack is somehow not there, ignore the attempt to update it.
688 e.printStackTrace();
689 }
690 }
691 }
692
693 /**
694 * Called by the BubbleStackView and whenever all bubbles have animated out, and none have been
695 * added in the meantime.
696 */
697 private void onAllBubblesAnimatedOut() {
698 if (mStackView != null) {
699 mStackView.setVisibility(INVISIBLE);
700 removeFromWindowManagerMaybe();
701 }
Joshua Tsujid9923e52020-04-29 15:33:01 -0400702 }
703
Mark Renoufc19b4732019-06-26 12:08:33 -0400704 /**
705 * Records the notification key for any active bubbles. These are used to restore active
706 * bubbles when the user returns to the foreground.
707 *
708 * @param userId the id of the user
709 */
710 private void saveBubbles(@UserIdInt int userId) {
711 // First clear any existing keys that might be stored.
712 mSavedBubbleKeysPerUser.remove(userId);
713 // Add in all active bubbles for the current user.
714 for (Bubble bubble: mBubbleData.getBubbles()) {
715 mSavedBubbleKeysPerUser.add(userId, bubble.getKey());
716 }
717 }
718
719 /**
720 * Promotes existing notifications to Bubbles if they were previously bubbles.
721 *
722 * @param userId the id of the user
723 */
724 private void restoreBubbles(@UserIdInt int userId) {
Mark Renoufc19b4732019-06-26 12:08:33 -0400725 ArraySet<String> savedBubbleKeys = mSavedBubbleKeysPerUser.get(userId);
726 if (savedBubbleKeys == null) {
727 // There were no bubbles saved for this used.
728 return;
729 }
Evan Laird181de622019-10-24 09:53:02 -0400730 for (NotificationEntry e :
731 mNotificationEntryManager.getActiveNotificationsForCurrentUser()) {
Ned Burns00b4b2d2019-10-17 22:09:27 -0400732 if (savedBubbleKeys.contains(e.getKey())
Beverly Taid1e175c2020-03-10 16:37:04 +0000733 && mNotificationInterruptStateProvider.shouldBubbleUp(e)
Mady Mellor76343012020-05-13 11:02:50 -0700734 && e.isBubble()
Mark Renoufc19b4732019-06-26 12:08:33 -0400735 && canLaunchInActivityView(mContext, e)) {
Mady Mellor76343012020-05-13 11:02:50 -0700736 updateBubble(e, true /* suppressFlyout */, false /* showInShade */);
Mark Renoufc19b4732019-06-26 12:08:33 -0400737 }
738 }
739 // Finally, remove the entries for this user now that bubbles are restored.
740 mSavedBubbleKeysPerUser.remove(mCurrentUserId);
741 }
742
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700743 @Override
744 public void onUiModeChanged() {
Mady Mellor247ca2c2019-12-02 16:18:59 -0800745 updateForThemeChanges();
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700746 }
747
748 @Override
749 public void onOverlayChanged() {
Mady Mellor247ca2c2019-12-02 16:18:59 -0800750 updateForThemeChanges();
751 }
752
753 private void updateForThemeChanges() {
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700754 if (mStackView != null) {
Lyn Han02cca812019-04-02 16:27:32 -0700755 mStackView.onThemeChanged();
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700756 }
Mady Mellor3df7ab02019-12-09 15:07:10 -0800757 mBubbleIconFactory = new BubbleIconFactory(mContext);
Lyn Handa9a6a22020-04-24 13:21:43 -0700758 // Reload each bubble
Mady Mellor3df7ab02019-12-09 15:07:10 -0800759 for (Bubble b: mBubbleData.getBubbles()) {
Pinyao Ting3c930612020-05-19 00:26:03 +0000760 b.inflate(null /* callback */, mContext, mStackView, mBubbleIconFactory,
761 false /* skipInflation */);
Lyn Handa9a6a22020-04-24 13:21:43 -0700762 }
763 for (Bubble b: mBubbleData.getOverflowBubbles()) {
Pinyao Ting3c930612020-05-19 00:26:03 +0000764 b.inflate(null /* callback */, mContext, mStackView, mBubbleIconFactory,
765 false /* skipInflation */);
Mady Mellor3df7ab02019-12-09 15:07:10 -0800766 }
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700767 }
768
Joshua Tsujif418f9e2019-04-04 17:09:53 -0400769 @Override
770 public void onConfigChanged(Configuration newConfig) {
Lyn Hanb4b06132020-05-11 09:25:20 -0700771 if (mStackView != null && newConfig != null) {
772 if (newConfig.orientation != mOrientation) {
773 mOrientation = newConfig.orientation;
774 mStackView.onOrientationChanged(newConfig.orientation);
775 }
776 if (newConfig.densityDpi != mDensityDpi) {
777 mDensityDpi = newConfig.densityDpi;
778 mBubbleIconFactory = new BubbleIconFactory(mContext);
779 mStackView.onDisplaySizeChanged();
780 }
Joshua Tsujif418f9e2019-04-04 17:09:53 -0400781 }
782 }
783
Lyn Han79c78132020-05-20 20:05:23 -0700784 boolean inLandscape() {
785 return mOrientation == Configuration.ORIENTATION_LANDSCAPE;
786 }
787
Mady Mellor5549dd22018-11-06 18:07:34 -0800788 /**
Mady Mellorcd9b1302018-11-06 18:08:04 -0800789 * Set a listener to be notified of bubble expand events.
790 */
791 public void setExpandListener(BubbleExpandListener listener) {
Issei Suzukiac9fcb72019-02-04 17:45:57 +0100792 mExpandListener = ((isExpanding, key) -> {
793 if (listener != null) {
794 listener.onBubbleExpandChanged(isExpanding, key);
795 }
Joshua Tsujid9923e52020-04-29 15:33:01 -0400796
797 updateWmFlags();
Issei Suzukiac9fcb72019-02-04 17:45:57 +0100798 });
Mady Mellorcd9b1302018-11-06 18:08:04 -0800799 if (mStackView != null) {
800 mStackView.setExpandListener(mExpandListener);
801 }
802 }
803
804 /**
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800805 * Whether or not there are bubbles present, regardless of them being visible on the
806 * screen (e.g. if on AOD).
807 */
Joshua Tsujid9923e52020-04-29 15:33:01 -0400808 @VisibleForTesting
809 boolean hasBubbles() {
Mady Mellor3dff9e62019-02-05 18:12:53 -0800810 if (mStackView == null) {
811 return false;
812 }
Mark Renouf71a3af62019-04-08 15:02:54 -0400813 return mBubbleData.hasBubbles();
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800814 }
815
816 /**
817 * Whether the stack of bubbles is expanded or not.
818 */
819 public boolean isStackExpanded() {
Mark Renouf71a3af62019-04-08 15:02:54 -0400820 return mBubbleData.isExpanded();
821 }
822
823 /**
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800824 * Tell the stack of bubbles to collapse.
825 */
826 public void collapseStack() {
Mark Renouf71a3af62019-04-08 15:02:54 -0400827 mBubbleData.setExpanded(false /* expanded */);
828 }
829
Mady Mellorce23c462019-06-17 17:30:07 -0700830 /**
Mady Mellore28fe102019-07-09 15:33:32 -0700831 * True if either:
832 * (1) There is a bubble associated with the provided key and if its notification is hidden
833 * from the shade.
834 * (2) There is a group summary associated with the provided key that is hidden from the shade
835 * because it has been dismissed but still has child bubbles active.
Mady Mellorce23c462019-06-17 17:30:07 -0700836 *
Mady Mellore28fe102019-07-09 15:33:32 -0700837 * False otherwise.
Mady Mellorce23c462019-06-17 17:30:07 -0700838 */
Beverlyed8aea22020-01-22 16:52:47 -0500839 public boolean isBubbleNotificationSuppressedFromShade(NotificationEntry entry) {
840 String key = entry.getKey();
Lyn Han2f6e89d2020-04-15 10:01:01 -0700841 boolean isSuppressedBubble = (mBubbleData.hasAnyBubbleWithKey(key)
842 && !mBubbleData.getAnyBubbleWithkey(key).showInShade());
Beverlyed8aea22020-01-22 16:52:47 -0500843
844 String groupKey = entry.getSbn().getGroupKey();
Mady Mellore28fe102019-07-09 15:33:32 -0700845 boolean isSuppressedSummary = mBubbleData.isSummarySuppressed(groupKey);
Mady Mellore4348272019-07-29 17:43:36 -0700846 boolean isSummary = key.equals(mBubbleData.getSummaryKey(groupKey));
Lyn Han2f6e89d2020-04-15 10:01:01 -0700847 return (isSummary && isSuppressedSummary) || isSuppressedBubble;
Mady Mellorce23c462019-06-17 17:30:07 -0700848 }
849
Lyn Hanb58c7562020-01-07 14:29:20 -0800850 void promoteBubbleFromOverflow(Bubble bubble) {
Lyn Han1e19d7f2020-02-05 19:10:58 -0800851 bubble.setInflateSynchronously(mInflateSynchronously);
Pinyao Ting3c930612020-05-19 00:26:03 +0000852 setIsBubble(bubble, /* isBubble */ true);
Lyn Han1e19d7f2020-02-05 19:10:58 -0800853 mBubbleData.promoteBubbleFromOverflow(bubble, mStackView, mBubbleIconFactory);
Lyn Hanb58c7562020-01-07 14:29:20 -0800854 }
855
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800856 /**
Mark Renouffec45da2019-03-13 13:24:27 -0400857 * Request the stack expand if needed, then select the specified Bubble as current.
Mady Mellor76343012020-05-13 11:02:50 -0700858 * If no bubble exists for this entry, one is created.
Mark Renouffec45da2019-03-13 13:24:27 -0400859 *
Mady Mellor76343012020-05-13 11:02:50 -0700860 * @param entry the notification for the bubble to be selected
Mark Renouffec45da2019-03-13 13:24:27 -0400861 */
Mady Mellor76343012020-05-13 11:02:50 -0700862 public void expandStackAndSelectBubble(NotificationEntry entry) {
863 String key = entry.getKey();
864 Bubble bubble = mBubbleData.getBubbleInStackWithKey(key);
865 if (bubble != null) {
Mark Renouf71a3af62019-04-08 15:02:54 -0400866 mBubbleData.setSelectedBubble(bubble);
Mady Mellor76343012020-05-13 11:02:50 -0700867 } else {
868 bubble = mBubbleData.getOverflowBubbleWithKey(key);
869 if (bubble != null) {
870 promoteBubbleFromOverflow(bubble);
871 } else if (entry.canBubble()) {
872 // It can bubble but it's not -- it got aged out of the overflow before it
873 // was dismissed or opened, make it a bubble again.
874 setIsBubble(entry, true);
875 bubble.setShouldAutoExpand(true);
876 updateBubble(entry, true /* suppressFlyout */, false /* showInShade */);
877 }
Mark Renouffec45da2019-03-13 13:24:27 -0400878 }
Mady Mellor76343012020-05-13 11:02:50 -0700879
Lyn Han2f6e89d2020-04-15 10:01:01 -0700880 mBubbleData.setExpanded(true);
Mark Renouffec45da2019-03-13 13:24:27 -0400881 }
882
883 /**
Mark Renouf041d7262019-02-06 12:09:41 -0500884 * Directs a back gesture at the bubble stack. When opened, the current expanded bubble
885 * is forwarded a back key down/up pair.
886 */
887 public void performBackPressIfNeeded() {
888 if (mStackView != null) {
889 mStackView.performBackPressIfNeeded();
890 }
891 }
892
893 /**
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800894 * Adds or updates a bubble associated with the provided notification entry.
895 *
Mark Renouf8b6a3c62019-04-09 10:17:40 -0400896 * @param notif the notification associated with this bubble.
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800897 */
Mark Renouff97ed462019-04-05 13:46:24 -0400898 void updateBubble(NotificationEntry notif) {
Mady Mellor76343012020-05-13 11:02:50 -0700899 updateBubble(notif, false /* suppressFlyout */, true /* showInShade */);
Mady Mellor7f234902019-10-20 12:06:29 -0700900 }
901
Pinyao Ting3c930612020-05-19 00:26:03 +0000902 /**
903 * Fills the overflow bubbles by loading them from disk.
904 */
905 void loadOverflowBubblesFromDisk() {
906 if (!mBubbleData.getOverflowBubbles().isEmpty()) {
907 // we don't need to load overflow bubbles from disk if it is already in memory
908 return;
909 }
910 mDataRepository.loadBubbles((bubbles) -> {
911 bubbles.forEach(bubble -> {
912 if (mBubbleData.getBubbles().contains(bubble)) {
913 // if the bubble is already active, there's no need to push it to overflow
914 return;
915 }
916 bubble.inflate((b) -> mBubbleData.overflowBubble(DISMISS_AGED, bubble),
917 mContext, mStackView, mBubbleIconFactory, true /* skipInflation */);
918 });
919 return null;
920 });
921 }
922
Mady Mellor7f234902019-10-20 12:06:29 -0700923 void updateBubble(NotificationEntry notif, boolean suppressFlyout, boolean showInShade) {
Joshua Tsuji4395bbd2020-05-19 17:53:33 -0400924 // Lazy init stack view when a bubble is created
925 ensureStackViewCreated();
Mady Mellor66efd5e2019-05-15 13:38:11 -0700926 // If this is an interruptive notif, mark that it's interrupted
Ned Burns60e94592019-09-06 14:47:25 -0400927 if (notif.getImportance() >= NotificationManager.IMPORTANCE_HIGH) {
Mady Mellor66efd5e2019-05-15 13:38:11 -0700928 notif.setInterruption();
929 }
Mady Mellor3df7ab02019-12-09 15:07:10 -0800930 Bubble bubble = mBubbleData.getOrCreateBubble(notif);
931 bubble.setInflateSynchronously(mInflateSynchronously);
932 bubble.inflate(
Lyn Han6cb4e5f2020-04-27 15:11:18 -0700933 b -> {
Mady Mellor76343012020-05-13 11:02:50 -0700934 mBubbleData.notificationEntryUpdated(b, suppressFlyout,
935 showInShade);
Lyn Han6cb4e5f2020-04-27 15:11:18 -0700936 if (bubble.getBubbleIntent() == null) {
937 return;
938 }
939 bubble.getBubbleIntent().registerCancelListener(pendingIntent -> {
940 if (bubble.getWasAccessed()) {
941 bubble.setPendingIntentCanceled();
942 return;
943 }
944 mHandler.post(
Pinyao Ting3c930612020-05-19 00:26:03 +0000945 () -> removeBubble(bubble.getKey(),
Lyn Han6cb4e5f2020-04-27 15:11:18 -0700946 BubbleController.DISMISS_INVALID_INTENT));
947 });
948 },
Pinyao Ting3c930612020-05-19 00:26:03 +0000949 mContext, mStackView, mBubbleIconFactory, false /* skipInflation */);
Mady Mellor7f234902019-10-20 12:06:29 -0700950 }
951
952 /**
953 * Called when a user has indicated that an active notification should be shown as a bubble.
954 * <p>
955 * This method will collapse the shade, create the bubble without a flyout or dot, and suppress
956 * the notification from appearing in the shade.
957 *
Mady Mellor9adfe6a2020-03-30 17:23:26 -0700958 * @param entry the notification to change bubble state for.
959 * @param shouldBubble whether the notification should show as a bubble or not.
Mady Mellor7f234902019-10-20 12:06:29 -0700960 */
Pinyao Ting3c930612020-05-19 00:26:03 +0000961 public void onUserChangedBubble(@Nullable final NotificationEntry entry, boolean shouldBubble) {
962 if (entry == null) {
963 return;
964 }
Mady Mellor9adfe6a2020-03-30 17:23:26 -0700965 NotificationChannel channel = entry.getChannel();
966 final String appPkg = entry.getSbn().getPackageName();
967 final int appUid = entry.getSbn().getUid();
968 if (channel == null || appPkg == null) {
969 return;
Mady Mellorff076eb2019-11-13 10:12:06 -0800970 }
Mady Mellor7f234902019-10-20 12:06:29 -0700971
Mady Mellor9adfe6a2020-03-30 17:23:26 -0700972 // Update the state in NotificationManagerService
973 try {
974 int flags = Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION;
Mady Mellor0577cda2020-05-12 11:47:55 -0700975 flags |= Notification.BubbleMetadata.FLAG_AUTO_EXPAND_BUBBLE;
Mady Mellor9adfe6a2020-03-30 17:23:26 -0700976 mBarService.onNotificationBubbleChanged(entry.getKey(), shouldBubble, flags);
977 } catch (RemoteException e) {
Mady Mellorff076eb2019-11-13 10:12:06 -0800978 }
Mady Mellor9adfe6a2020-03-30 17:23:26 -0700979
980 // Change the settings
981 channel = NotificationChannelHelper.createConversationChannelIfNeeded(mContext,
982 mINotificationManager, entry, channel);
983 channel.setAllowBubbles(shouldBubble);
984 try {
985 int currentPref = mINotificationManager.getBubblePreferenceForPackage(appPkg, appUid);
986 if (shouldBubble && currentPref == BUBBLE_PREFERENCE_NONE) {
987 mINotificationManager.setBubblesAllowed(appPkg, appUid, BUBBLE_PREFERENCE_SELECTED);
988 }
989 mINotificationManager.updateNotificationChannelForPackage(appPkg, appUid, channel);
990 } catch (RemoteException e) {
991 Log.e(TAG, e.getMessage());
992 }
993
994 if (shouldBubble) {
995 mShadeController.collapsePanel(true);
996 if (entry.getRow() != null) {
997 entry.getRow().updateBubbleButton();
998 }
Mady Mellor3b86a4f2019-12-11 13:15:41 -0800999 }
Mady Mellorff076eb2019-11-13 10:12:06 -08001000 }
1001
1002 /**
Pinyao Ting3c930612020-05-19 00:26:03 +00001003 * Removes the bubble with the given key.
Mark Renouf658c6bc2019-01-30 10:26:54 -05001004 * <p>
1005 * Must be called from the main thread.
Mady Mellorc3d6f7d2018-11-07 09:36:56 -08001006 */
Mark Renouf658c6bc2019-01-30 10:26:54 -05001007 @MainThread
Pinyao Ting3c930612020-05-19 00:26:03 +00001008 void removeBubble(String key, int reason) {
1009 if (mBubbleData.hasAnyBubbleWithKey(key)) {
1010 mBubbleData.notificationEntryRemoved(key, reason);
Mady Mellore8e07712019-01-23 12:45:33 -08001011 }
1012 }
1013
Beverlyed8aea22020-01-22 16:52:47 -05001014 private void onEntryAdded(NotificationEntry entry) {
Beverly Taid1e175c2020-03-10 16:37:04 +00001015 if (mNotificationInterruptStateProvider.shouldBubbleUp(entry)
Mady Mellor76343012020-05-13 11:02:50 -07001016 && entry.isBubble()
Mady Mellordd6fe612020-04-15 11:47:55 -07001017 && canLaunchInActivityView(mContext, entry)) {
Beverlyed8aea22020-01-22 16:52:47 -05001018 updateBubble(entry);
Mady Mellor22f2f072019-04-18 13:26:18 -07001019 }
1020 }
1021
Beverlyed8aea22020-01-22 16:52:47 -05001022 private void onEntryUpdated(NotificationEntry entry) {
Mady Mellor76343012020-05-13 11:02:50 -07001023 // shouldBubbleUp checks canBubble & for bubble metadata
Beverly Taid1e175c2020-03-10 16:37:04 +00001024 boolean shouldBubble = mNotificationInterruptStateProvider.shouldBubbleUp(entry)
Mady Mellordd6fe612020-04-15 11:47:55 -07001025 && canLaunchInActivityView(mContext, entry);
Lyn Han2f6e89d2020-04-15 10:01:01 -07001026 if (!shouldBubble && mBubbleData.hasAnyBubbleWithKey(entry.getKey())) {
Beverlyed8aea22020-01-22 16:52:47 -05001027 // It was previously a bubble but no longer a bubble -- lets remove it
Pinyao Ting3c930612020-05-19 00:26:03 +00001028 removeBubble(entry.getKey(), DISMISS_NO_LONGER_BUBBLE);
Mady Mellor76343012020-05-13 11:02:50 -07001029 } else if (shouldBubble && entry.isBubble()) {
Beverlyed8aea22020-01-22 16:52:47 -05001030 updateBubble(entry);
Mady Mellor3f2efdb2018-11-21 11:30:45 -08001031 }
Beverlyed8aea22020-01-22 16:52:47 -05001032 }
Mady Mellor3f2efdb2018-11-21 11:30:45 -08001033
Beverlya53fb0d2020-01-29 15:26:13 -05001034 private void onEntryRemoved(NotificationEntry entry) {
1035 if (isSummaryOfBubbles(entry)) {
1036 final String groupKey = entry.getSbn().getGroupKey();
1037 mBubbleData.removeSuppressedSummary(groupKey);
1038
1039 // Remove any associated bubble children with the summary
1040 final List<Bubble> bubbleChildren = mBubbleData.getBubblesInGroup(groupKey);
1041 for (int i = 0; i < bubbleChildren.size(); i++) {
Pinyao Ting3c930612020-05-19 00:26:03 +00001042 removeBubble(bubbleChildren.get(i).getKey(), DISMISS_GROUP_CANCELLED);
Beverlya53fb0d2020-01-29 15:26:13 -05001043 }
1044 } else {
Pinyao Ting3c930612020-05-19 00:26:03 +00001045 removeBubble(entry.getKey(), DISMISS_NOTIF_CANCEL);
Beverlya53fb0d2020-01-29 15:26:13 -05001046 }
1047 }
1048
Mady Mellor56515c42020-02-18 17:58:36 -08001049 /**
1050 * Called when NotificationListener has received adjusted notification rank and reapplied
1051 * filtering and sorting. This is used to dismiss or create bubbles based on changes in
1052 * permissions on the notification channel or the global setting.
1053 *
1054 * @param rankingMap the updated ranking map from NotificationListenerService
1055 */
Beverlyed8aea22020-01-22 16:52:47 -05001056 private void onRankingUpdated(RankingMap rankingMap) {
Mady Mellor56515c42020-02-18 17:58:36 -08001057 if (mTmpRanking == null) {
1058 mTmpRanking = new NotificationListenerService.Ranking();
1059 }
1060 String[] orderedKeys = rankingMap.getOrderedKeys();
1061 for (int i = 0; i < orderedKeys.length; i++) {
1062 String key = orderedKeys[i];
1063 NotificationEntry entry = mNotificationEntryManager.getPendingOrActiveNotif(key);
1064 rankingMap.getRanking(key, mTmpRanking);
Lyn Han2f6e89d2020-04-15 10:01:01 -07001065 boolean isActiveBubble = mBubbleData.hasAnyBubbleWithKey(key);
Mady Mellore45ff862020-03-24 15:54:50 -07001066 if (isActiveBubble && !mTmpRanking.canBubble()) {
Pinyao Ting3c930612020-05-19 00:26:03 +00001067 mBubbleData.notificationEntryRemoved(entry.getKey(),
1068 BubbleController.DISMISS_BLOCKED);
Mady Mellore45ff862020-03-24 15:54:50 -07001069 } else if (entry != null && mTmpRanking.isBubble() && !isActiveBubble) {
Mady Mellor56515c42020-02-18 17:58:36 -08001070 entry.setFlagBubble(true);
1071 onEntryUpdated(entry);
1072 }
1073 }
Beverlyed8aea22020-01-22 16:52:47 -05001074 }
Ned Burns01e38212019-01-03 16:32:52 -05001075
Pinyao Ting3c930612020-05-19 00:26:03 +00001076 private void setIsBubble(@NonNull final NotificationEntry entry, final boolean isBubble) {
1077 Objects.requireNonNull(entry);
Lyn Han2f6e89d2020-04-15 10:01:01 -07001078 if (isBubble) {
Mady Mellor76343012020-05-13 11:02:50 -07001079 entry.getSbn().getNotification().flags |= FLAG_BUBBLE;
Lyn Han2f6e89d2020-04-15 10:01:01 -07001080 } else {
Mady Mellor76343012020-05-13 11:02:50 -07001081 entry.getSbn().getNotification().flags &= ~FLAG_BUBBLE;
Lyn Han2f6e89d2020-04-15 10:01:01 -07001082 }
1083 try {
Mady Mellor76343012020-05-13 11:02:50 -07001084 mBarService.onNotificationBubbleChanged(entry.getKey(), isBubble, 0);
Lyn Han2f6e89d2020-04-15 10:01:01 -07001085 } catch (RemoteException e) {
1086 // Bad things have happened
1087 }
1088 }
1089
Pinyao Ting3c930612020-05-19 00:26:03 +00001090 private void setIsBubble(@NonNull final Bubble b, final boolean isBubble) {
1091 Objects.requireNonNull(b);
1092 if (isBubble) {
1093 b.enable(FLAG_BUBBLE);
1094 } else {
1095 b.disable(FLAG_BUBBLE);
1096 }
1097 if (b.getEntry() != null) {
1098 setIsBubble(b.getEntry(), isBubble);
1099 } else {
1100 try {
1101 mBarService.onNotificationBubbleChanged(b.getKey(), isBubble, 0);
1102 } catch (RemoteException e) {
1103 // Bad things have happened
1104 }
1105 }
1106 }
1107
Mark Renouf71a3af62019-04-08 15:02:54 -04001108 @SuppressWarnings("FieldCanBeLocal")
Mark Renouf3bc5b362019-04-05 14:37:59 -04001109 private final BubbleData.Listener mBubbleDataListener = new BubbleData.Listener() {
Mark Renouf71a3af62019-04-08 15:02:54 -04001110
Mark Renouf3bc5b362019-04-05 14:37:59 -04001111 @Override
Mark Renouf82a40e62019-05-23 16:16:24 -04001112 public void applyUpdate(BubbleData.Update update) {
Pinyao Ting6a8fab02020-05-21 14:30:21 -07001113 // Lazy load overflow bubbles from disk
1114 loadOverflowBubblesFromDisk();
Lyn Hanb58c7562020-01-07 14:29:20 -08001115 // Update bubbles in overflow.
Mady Mellor1d082022020-05-12 16:35:39 +00001116 if (mOverflowCallback != null) {
1117 mOverflowCallback.run();
Lyn Hanb58c7562020-01-07 14:29:20 -08001118 }
1119
Mark Renouf82a40e62019-05-23 16:16:24 -04001120 // Collapsing? Do this first before remaining steps.
1121 if (update.expandedChanged && !update.expanded) {
1122 mStackView.setExpanded(false);
1123 }
1124
1125 // Do removals, if any.
Mady Mellor22f2f072019-04-18 13:26:18 -07001126 ArrayList<Pair<Bubble, Integer>> removedBubbles =
1127 new ArrayList<>(update.removedBubbles);
Pinyao Tingee191b12020-04-29 18:35:39 -07001128 ArrayList<Bubble> bubblesToBeRemovedFromRepository = new ArrayList<>();
Mady Mellor22f2f072019-04-18 13:26:18 -07001129 for (Pair<Bubble, Integer> removed : removedBubbles) {
Mark Renouf82a40e62019-05-23 16:16:24 -04001130 final Bubble bubble = removed.first;
1131 @DismissReason final int reason = removed.second;
1132 mStackView.removeBubble(bubble);
Lyn Han2f6e89d2020-04-15 10:01:01 -07001133
Mark Renoufc19b4732019-06-26 12:08:33 -04001134 // If the bubble is removed for user switching, leave the notification in place.
Lyn Han2f6e89d2020-04-15 10:01:01 -07001135 if (reason == DISMISS_USER_CHANGED) {
1136 continue;
1137 }
Pinyao Tingee191b12020-04-29 18:35:39 -07001138 if (reason == DISMISS_NOTIF_CANCEL) {
1139 bubblesToBeRemovedFromRepository.add(bubble);
1140 }
Lyn Han2f6e89d2020-04-15 10:01:01 -07001141 if (!mBubbleData.hasBubbleInStackWithKey(bubble.getKey())) {
1142 if (!mBubbleData.hasOverflowBubbleWithKey(bubble.getKey())
1143 && (!bubble.showInShade()
1144 || reason == DISMISS_NOTIF_CANCEL
Mady Mellor1d082022020-05-12 16:35:39 +00001145 || reason == DISMISS_GROUP_CANCELLED)) {
Beverlyed8aea22020-01-22 16:52:47 -05001146 // The bubble is now gone & the notification is hidden from the shade, so
1147 // time to actually remove it
1148 for (NotifCallback cb : mCallbacks) {
Pinyao Ting3c930612020-05-19 00:26:03 +00001149 if (bubble.getEntry() != null) {
1150 cb.removeNotification(bubble.getEntry(), REASON_CANCEL);
1151 }
Beverlyed8aea22020-01-22 16:52:47 -05001152 }
Mark Renoufc19b4732019-06-26 12:08:33 -04001153 } else {
Pinyao Ting3c930612020-05-19 00:26:03 +00001154 if (bubble.isBubble() && bubble.showInShade()) {
1155 setIsBubble(bubble, false /* isBubble */);
Lyn Han2f6e89d2020-04-15 10:01:01 -07001156 }
Pinyao Ting3c930612020-05-19 00:26:03 +00001157 if (bubble.getEntry() != null && bubble.getEntry().getRow() != null) {
Mady Mellor9adfe6a2020-03-30 17:23:26 -07001158 bubble.getEntry().getRow().updateBubbleButton();
1159 }
Mark Renouf82a40e62019-05-23 16:16:24 -04001160 }
Mady Mellor22f2f072019-04-18 13:26:18 -07001161
Lyn Han2f6e89d2020-04-15 10:01:01 -07001162 }
Pinyao Ting3c930612020-05-19 00:26:03 +00001163 if (bubble.getEntry() != null) {
1164 final String groupKey = bubble.getEntry().getSbn().getGroupKey();
1165 if (mBubbleData.getBubblesInGroup(groupKey).isEmpty()) {
1166 // Time to potentially remove the summary
1167 for (NotifCallback cb : mCallbacks) {
1168 cb.maybeCancelSummary(bubble.getEntry());
1169 }
Mady Mellor22f2f072019-04-18 13:26:18 -07001170 }
Mady Mellora54e9fa2019-04-18 13:26:18 -07001171 }
1172 }
Pinyao Tingee191b12020-04-29 18:35:39 -07001173 mDataRepository.removeBubbles(mCurrentUserId, bubblesToBeRemovedFromRepository);
Mark Renouf3bc5b362019-04-05 14:37:59 -04001174
Lyn Hanc47e1712020-01-28 21:43:34 -08001175 if (update.addedBubble != null) {
Pinyao Tingee191b12020-04-29 18:35:39 -07001176 mDataRepository.addBubble(mCurrentUserId, update.addedBubble);
Lyn Hanc47e1712020-01-28 21:43:34 -08001177 mStackView.addBubble(update.addedBubble);
Pinyao Tingee191b12020-04-29 18:35:39 -07001178
Lyn Hanc47e1712020-01-28 21:43:34 -08001179 }
1180
Mark Renouf82a40e62019-05-23 16:16:24 -04001181 if (update.updatedBubble != null) {
1182 mStackView.updateBubble(update.updatedBubble);
Mark Renouf71a3af62019-04-08 15:02:54 -04001183 }
Mark Renouf3bc5b362019-04-05 14:37:59 -04001184
Lyn Hanb58c7562020-01-07 14:29:20 -08001185 // At this point, the correct bubbles are inflated in the stack.
1186 // Make sure the order in bubble data is reflected in bubble row.
Mark Renouf82a40e62019-05-23 16:16:24 -04001187 if (update.orderChanged) {
Pinyao Tingee191b12020-04-29 18:35:39 -07001188 mDataRepository.addBubbles(mCurrentUserId, update.bubbles);
Mark Renouf82a40e62019-05-23 16:16:24 -04001189 mStackView.updateBubbleOrder(update.bubbles);
Mark Renoufba5ab512019-05-02 15:21:01 -04001190 }
Mark Renouf3bc5b362019-04-05 14:37:59 -04001191
Mark Renouf82a40e62019-05-23 16:16:24 -04001192 if (update.selectionChanged) {
1193 mStackView.setSelectedBubble(update.selectedBubble);
Pinyao Ting3c930612020-05-19 00:26:03 +00001194 if (update.selectedBubble != null && update.selectedBubble.getEntry() != null) {
Mady Mellor740d85d2019-07-09 15:26:47 -07001195 mNotificationGroupManager.updateSuppression(
1196 update.selectedBubble.getEntry());
1197 }
Mark Renouf71a3af62019-04-08 15:02:54 -04001198 }
Mark Renouf3bc5b362019-04-05 14:37:59 -04001199
Mark Renouf82a40e62019-05-23 16:16:24 -04001200 // Expanding? Apply this last.
1201 if (update.expandedChanged && update.expanded) {
1202 mStackView.setExpanded(true);
Mark Renouf71a3af62019-04-08 15:02:54 -04001203 }
Mark Renouf3bc5b362019-04-05 14:37:59 -04001204
Beverlyed8aea22020-01-22 16:52:47 -05001205 for (NotifCallback cb : mCallbacks) {
Beverlya53fb0d2020-01-29 15:26:13 -05001206 cb.invalidateNotifications("BubbleData.Listener.applyUpdate");
Beverlyed8aea22020-01-22 16:52:47 -05001207 }
Lyn Han6c40fe72019-05-08 14:06:33 -07001208 updateStack();
Mark Renouf9ba6cea2019-04-17 11:53:50 -04001209
Issei Suzukia8d07312019-06-07 12:56:19 +02001210 if (DEBUG_BUBBLE_CONTROLLER) {
Lyn Hanb58c7562020-01-07 14:29:20 -08001211 Log.d(TAG, "\n[BubbleData] bubbles:");
Lyn Han767d70e2019-12-10 18:02:23 -08001212 Log.d(TAG, BubbleDebugConfig.formatBubblesString(mBubbleData.getBubbles(),
Mark Renouf9ba6cea2019-04-17 11:53:50 -04001213 mBubbleData.getSelectedBubble()));
1214
1215 if (mStackView != null) {
Lyn Hanb58c7562020-01-07 14:29:20 -08001216 Log.d(TAG, "\n[BubbleStackView]");
Lyn Han767d70e2019-12-10 18:02:23 -08001217 Log.d(TAG, BubbleDebugConfig.formatBubblesString(mStackView.getBubblesOnScreen(),
Mark Renouf9ba6cea2019-04-17 11:53:50 -04001218 mStackView.getExpandedBubble()));
1219 }
Mady Mellor1d082022020-05-12 16:35:39 +00001220 Log.d(TAG, "\n[BubbleData] overflow:");
1221 Log.d(TAG, BubbleDebugConfig.formatBubblesString(mBubbleData.getOverflowBubbles(),
1222 null) + "\n");
Mark Renouf9ba6cea2019-04-17 11:53:50 -04001223 }
Mark Renouf3bc5b362019-04-05 14:37:59 -04001224 }
1225 };
1226
Mady Mellor3f2efdb2018-11-21 11:30:45 -08001227 /**
Beverlya53fb0d2020-01-29 15:26:13 -05001228 * We intercept notification entries (including group summaries) dismissed by the user when
1229 * there is an active bubble associated with it. We do this so that developers can still
1230 * cancel it (and hence the bubbles associated with it). However, these intercepted
1231 * notifications should then be hidden from the shade since the user has cancelled them, so we
1232 * {@link Bubble#setSuppressNotification}. For the case of suppressed summaries, we also add
1233 * {@link BubbleData#addSummaryToSuppress}.
Beverlyed8aea22020-01-22 16:52:47 -05001234 *
Mady Mellor91b31e62020-01-30 17:40:48 -08001235 * @return true if we want to intercept the dismissal of the entry, else false.
Beverlyed8aea22020-01-22 16:52:47 -05001236 */
Beverlya53fb0d2020-01-29 15:26:13 -05001237 public boolean handleDismissalInterception(NotificationEntry entry) {
Beverlyed8aea22020-01-22 16:52:47 -05001238 if (entry == null) {
1239 return false;
1240 }
Lyn Han2f6e89d2020-04-15 10:01:01 -07001241 if (isSummaryOfBubbles(entry)) {
Beverlya53fb0d2020-01-29 15:26:13 -05001242 handleSummaryDismissalInterception(entry);
Lyn Han2f6e89d2020-04-15 10:01:01 -07001243 } else {
1244 Bubble bubble = mBubbleData.getBubbleInStackWithKey(entry.getKey());
1245 if (bubble == null || !entry.isBubble()) {
1246 bubble = mBubbleData.getOverflowBubbleWithKey(entry.getKey());
1247 }
1248 if (bubble == null) {
1249 return false;
1250 }
Beverlyed8aea22020-01-22 16:52:47 -05001251 bubble.setSuppressNotification(true);
Joshua Tsuji2ed260e2020-03-26 14:26:01 -04001252 bubble.setShowDot(false /* show */);
Beverlyed8aea22020-01-22 16:52:47 -05001253 }
Beverlya53fb0d2020-01-29 15:26:13 -05001254 // Update the shade
1255 for (NotifCallback cb : mCallbacks) {
1256 cb.invalidateNotifications("BubbleController.handleDismissalInterception");
1257 }
1258 return true;
Beverlyed8aea22020-01-22 16:52:47 -05001259 }
1260
Beverlya53fb0d2020-01-29 15:26:13 -05001261 private boolean isSummaryOfBubbles(NotificationEntry entry) {
1262 if (entry == null) {
Beverlyed8aea22020-01-22 16:52:47 -05001263 return false;
1264 }
Beverlya53fb0d2020-01-29 15:26:13 -05001265
1266 String groupKey = entry.getSbn().getGroupKey();
1267 ArrayList<Bubble> bubbleChildren = mBubbleData.getBubblesInGroup(groupKey);
1268 boolean isSuppressedSummary = (mBubbleData.isSummarySuppressed(groupKey)
1269 && mBubbleData.getSummaryKey(groupKey).equals(entry.getKey()));
1270 boolean isSummary = entry.getSbn().getNotification().isGroupSummary();
1271 return (isSuppressedSummary || isSummary)
1272 && bubbleChildren != null
1273 && !bubbleChildren.isEmpty();
1274 }
1275
1276 private void handleSummaryDismissalInterception(NotificationEntry summary) {
1277 // current children in the row:
Kevin Han43077f92020-02-28 12:51:53 -08001278 final List<NotificationEntry> children = summary.getAttachedNotifChildren();
Beverlya53fb0d2020-01-29 15:26:13 -05001279 if (children != null) {
1280 for (int i = 0; i < children.size(); i++) {
1281 NotificationEntry child = children.get(i);
Lyn Han2f6e89d2020-04-15 10:01:01 -07001282 if (mBubbleData.hasAnyBubbleWithKey(child.getKey())) {
Beverlya53fb0d2020-01-29 15:26:13 -05001283 // Suppress the bubbled child
1284 // As far as group manager is concerned, once a child is no longer shown
1285 // in the shade, it is essentially removed.
Lyn Han2f6e89d2020-04-15 10:01:01 -07001286 Bubble bubbleChild = mBubbleData.getAnyBubbleWithkey(child.getKey());
Beverlya53fb0d2020-01-29 15:26:13 -05001287 mNotificationGroupManager.onEntryRemoved(bubbleChild.getEntry());
1288 bubbleChild.setSuppressNotification(true);
Joshua Tsuji2ed260e2020-03-26 14:26:01 -04001289 bubbleChild.setShowDot(false /* show */);
Beverlya53fb0d2020-01-29 15:26:13 -05001290 } else {
1291 // non-bubbled children can be removed
1292 for (NotifCallback cb : mCallbacks) {
1293 cb.removeNotification(child, REASON_GROUP_SUMMARY_CANCELED);
1294 }
1295 }
1296 }
1297 }
1298
1299 // And since all children are removed, remove the summary.
1300 mNotificationGroupManager.onEntryRemoved(summary);
1301
1302 // TODO: (b/145659174) remove references to mSuppressedGroupKeys once fully migrated
1303 mBubbleData.addSummaryToSuppress(summary.getSbn().getGroupKey(),
1304 summary.getKey());
Beverlyed8aea22020-01-22 16:52:47 -05001305 }
1306
1307 /**
Joshua Tsujidd4d9f92019-05-13 13:57:38 -04001308 * Lets any listeners know if bubble state has changed.
Lyn Han6c40fe72019-05-08 14:06:33 -07001309 * Updates the visibility of the bubbles based on current state.
Joshua Tsujid9923e52020-04-29 15:33:01 -04001310 * Does not un-bubble, just hides or un-hides.
Lyn Han6c40fe72019-05-08 14:06:33 -07001311 * Updates stack description for TalkBack focus.
Mady Mellor3f2efdb2018-11-21 11:30:45 -08001312 */
Lyn Han6c40fe72019-05-08 14:06:33 -07001313 public void updateStack() {
Mady Mellor3f2efdb2018-11-21 11:30:45 -08001314 if (mStackView == null) {
1315 return;
Mady Mellord1c78b262018-11-06 18:04:40 -08001316 }
Joshua Tsuji4395bbd2020-05-19 17:53:33 -04001317
1318 if (mStatusBarStateListener.getCurrentState() != SHADE) {
1319 // Bubbles don't appear over the locked shade.
Mady Mellor3f2efdb2018-11-21 11:30:45 -08001320 mStackView.setVisibility(INVISIBLE);
Joshua Tsuji4395bbd2020-05-19 17:53:33 -04001321 } else if (hasBubbles()) {
1322 // If we're unlocked, show the stack if we have bubbles. If we don't have bubbles, the
1323 // stack will be set to INVISIBLE in onAllBubblesAnimatedOut after the bubbles animate
1324 // out.
1325 mStackView.setVisibility(VISIBLE);
Mady Mellor5549dd22018-11-06 18:07:34 -08001326 }
Lyn Han6c40fe72019-05-08 14:06:33 -07001327
Lyn Han6c40fe72019-05-08 14:06:33 -07001328 mStackView.updateContentDescription();
Mady Mellord1c78b262018-11-06 18:04:40 -08001329 }
1330
1331 /**
Mady Mellor390bff42019-04-05 15:09:01 -07001332 * The display id of the expanded view, if the stack is expanded and not occluded by the
1333 * status bar, otherwise returns {@link Display#INVALID_DISPLAY}.
1334 */
1335 public int getExpandedDisplayId(Context context) {
Joel Galenson4071ddb2019-04-18 13:30:45 -07001336 if (mStackView == null) {
Lyn Han9f66c3b2020-03-05 23:59:29 -08001337 return INVALID_DISPLAY;
Joel Galenson4071ddb2019-04-18 13:30:45 -07001338 }
Issei Suzukicac2a502019-04-16 16:52:50 +02001339 final boolean defaultDisplay = context.getDisplay() != null
Mady Mellor390bff42019-04-05 15:09:01 -07001340 && context.getDisplay().getDisplayId() == DEFAULT_DISPLAY;
Lyn Han9f66c3b2020-03-05 23:59:29 -08001341 final BubbleViewProvider expandedViewProvider = mStackView.getExpandedBubble();
1342 if (defaultDisplay && expandedViewProvider != null && isStackExpanded()
wilsonshihe8321942019-10-18 18:39:46 +08001343 && !mNotificationShadeWindowController.getPanelExpanded()) {
Lyn Han9f66c3b2020-03-05 23:59:29 -08001344 return expandedViewProvider.getDisplayId();
Mady Mellor390bff42019-04-05 15:09:01 -07001345 }
Lyn Han9f66c3b2020-03-05 23:59:29 -08001346 return INVALID_DISPLAY;
Mady Mellor390bff42019-04-05 15:09:01 -07001347 }
1348
Mady Mellorf6e3ac02019-01-29 10:37:52 -08001349 @VisibleForTesting
1350 BubbleStackView getStackView() {
1351 return mStackView;
1352 }
1353
Mady Mellor70cba7bb2019-07-02 15:06:07 -07001354 /**
1355 * Description of current bubble state.
1356 */
1357 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
1358 pw.println("BubbleController state:");
1359 mBubbleData.dump(fd, pw, args);
1360 pw.println();
Joshua Tsuji395bcfe2019-07-02 19:23:23 -04001361 if (mStackView != null) {
1362 mStackView.dump(fd, pw, args);
1363 }
1364 pw.println();
Mady Mellor70cba7bb2019-07-02 15:06:07 -07001365 }
1366
Mady Mellore80930e2019-03-21 16:00:45 -07001367 /**
Mark Renoufcecc77b2019-01-30 16:32:24 -05001368 * This task stack listener is responsible for responding to tasks moved to the front
1369 * which are on the default (main) display. When this happens, expanded bubbles must be
1370 * collapsed so the user may interact with the app which was just moved to the front.
1371 * <p>
1372 * This listener is registered with SystemUI's ActivityManagerWrapper which dispatches
1373 * these calls via a main thread Handler.
1374 */
1375 @MainThread
1376 private class BubbleTaskStackListener extends TaskStackChangeListener {
1377
Mark Renoufcecc77b2019-01-30 16:32:24 -05001378 @Override
Mark Renoufc808f062019-02-07 15:20:37 -05001379 public void onTaskMovedToFront(RunningTaskInfo taskInfo) {
1380 if (mStackView != null && taskInfo.displayId == Display.DEFAULT_DISPLAY) {
Mady Mellor047e24e2019-08-05 11:35:40 -07001381 if (!mStackView.isExpansionAnimating()) {
1382 mBubbleData.setExpanded(false);
1383 }
Mark Renoufcecc77b2019-01-30 16:32:24 -05001384 }
1385 }
1386
Mark Renoufcecc77b2019-01-30 16:32:24 -05001387 @Override
Winson Chunge789ff62020-02-24 14:40:23 -08001388 public void onActivityRestartAttempt(RunningTaskInfo task, boolean homeTaskVisible,
Evan Rosky8d1c24e2020-04-23 09:21:16 -07001389 boolean clearedTask, boolean wasVisible) {
Winson Chunge789ff62020-02-24 14:40:23 -08001390 for (Bubble b : mBubbleData.getBubbles()) {
1391 if (b.getDisplayId() == task.displayId) {
Mady Mellor76343012020-05-13 11:02:50 -07001392 mBubbleData.setSelectedBubble(b);
1393 mBubbleData.setExpanded(true);
Winson Chunge789ff62020-02-24 14:40:23 -08001394 return;
1395 }
1396 }
1397 }
1398
1399 @Override
Mark Renoufa12e8762019-03-07 15:43:01 -05001400 public void onActivityLaunchOnSecondaryDisplayRerouted() {
Mark Renoufcecc77b2019-01-30 16:32:24 -05001401 if (mStackView != null) {
Mark Renouf71a3af62019-04-08 15:02:54 -04001402 mBubbleData.setExpanded(false);
Mark Renoufcecc77b2019-01-30 16:32:24 -05001403 }
1404 }
Mark Renouf446251d2019-04-26 10:22:41 -04001405
1406 @Override
1407 public void onBackPressedOnTaskRoot(RunningTaskInfo taskInfo) {
1408 if (mStackView != null && taskInfo.displayId == getExpandedDisplayId(mContext)) {
1409 mBubbleData.setExpanded(false);
1410 }
1411 }
Issei Suzukicac2a502019-04-16 16:52:50 +02001412
1413 @Override
1414 public void onSingleTaskDisplayDrawn(int displayId) {
Lyn Hana0bb02e2020-01-28 17:57:27 -08001415 if (mStackView == null) {
1416 return;
Issei Suzukicac2a502019-04-16 16:52:50 +02001417 }
Lyn Hana0bb02e2020-01-28 17:57:27 -08001418 mStackView.showExpandedViewContents(displayId);
Issei Suzukicac2a502019-04-16 16:52:50 +02001419 }
Issei Suzuki734bc942019-06-05 13:59:52 +02001420
1421 @Override
1422 public void onSingleTaskDisplayEmpty(int displayId) {
Lyn Han9f66c3b2020-03-05 23:59:29 -08001423 final BubbleViewProvider expandedBubble = mStackView != null
Mady Mellor5186b132019-09-16 17:55:48 -07001424 ? mStackView.getExpandedBubble()
1425 : null;
Mady Mellorca184aae2019-09-17 16:07:12 -07001426 int expandedId = expandedBubble != null ? expandedBubble.getDisplayId() : -1;
1427 if (mStackView != null && mStackView.isExpanded() && expandedId == displayId) {
Issei Suzuki734bc942019-06-05 13:59:52 +02001428 mBubbleData.setExpanded(false);
Issei Suzuki734bc942019-06-05 13:59:52 +02001429 }
Mady Mellorca184aae2019-09-17 16:07:12 -07001430 mBubbleData.notifyDisplayEmpty(displayId);
Issei Suzuki734bc942019-06-05 13:59:52 +02001431 }
Mark Renoufcecc77b2019-01-30 16:32:24 -05001432 }
1433
Mady Mellorca0c24c2019-05-16 16:14:32 -07001434 /**
1435 * Whether an intent is properly configured to display in an {@link android.app.ActivityView}.
1436 *
1437 * Keep checks in sync with NotificationManagerService#canLaunchInActivityView. Typically
1438 * that should filter out any invalid bubbles, but should protect SysUI side just in case.
1439 *
1440 * @param context the context to use.
1441 * @param entry the entry to bubble.
1442 */
1443 static boolean canLaunchInActivityView(Context context, NotificationEntry entry) {
1444 PendingIntent intent = entry.getBubbleMetadata() != null
Mady Melloraa9ce172020-03-17 10:34:20 -07001445 ? entry.getBubbleMetadata().getIntent()
Mady Mellorca0c24c2019-05-16 16:14:32 -07001446 : null;
Mady Mellor2ac2d3a2020-01-08 17:18:54 -08001447 if (entry.getBubbleMetadata() != null
1448 && entry.getBubbleMetadata().getShortcutId() != null) {
1449 return true;
1450 }
Mady Mellorca0c24c2019-05-16 16:14:32 -07001451 if (intent == null) {
Mady Mellor7f234902019-10-20 12:06:29 -07001452 Log.w(TAG, "Unable to create bubble -- no intent: " + entry.getKey());
Mady Mellorca0c24c2019-05-16 16:14:32 -07001453 return false;
1454 }
Mady Mellorf3b9fab2019-11-13 17:27:32 -08001455 PackageManager packageManager = StatusBar.getPackageManagerForUser(
1456 context, entry.getSbn().getUser().getIdentifier());
Mady Mellorca0c24c2019-05-16 16:14:32 -07001457 ActivityInfo info =
Mady Mellorf3b9fab2019-11-13 17:27:32 -08001458 intent.getIntent().resolveActivityInfo(packageManager, 0);
Mady Mellorca0c24c2019-05-16 16:14:32 -07001459 if (info == null) {
Mady Mellor7f234902019-10-20 12:06:29 -07001460 Log.w(TAG, "Unable to send as bubble, "
1461 + entry.getKey() + " couldn't find activity info for intent: "
Mady Mellorca0c24c2019-05-16 16:14:32 -07001462 + intent);
1463 return false;
1464 }
1465 if (!ActivityInfo.isResizeableMode(info.resizeMode)) {
Mady Mellor7f234902019-10-20 12:06:29 -07001466 Log.w(TAG, "Unable to send as bubble, "
1467 + entry.getKey() + " activity is not resizable for intent: "
Mady Mellorca0c24c2019-05-16 16:14:32 -07001468 + intent);
1469 return false;
1470 }
Mady Mellorca0c24c2019-05-16 16:14:32 -07001471 return true;
1472 }
1473
Joshua Tsujia19515f2019-02-13 18:02:29 -05001474 /** PinnedStackListener that dispatches IME visibility updates to the stack. */
Hongwei Wang43a752b2019-09-17 20:20:30 +00001475 private class BubblesImeListener extends PinnedStackListenerForwarder.PinnedStackListener {
Joshua Tsujia19515f2019-02-13 18:02:29 -05001476 @Override
Joshua Tsujid9422832019-03-05 13:32:37 -05001477 public void onImeVisibilityChanged(boolean imeVisible, int imeHeight) {
Joshua Tsujiff6b0f22020-03-09 14:55:19 -04001478 if (mStackView != null) {
Joshua Tsujid9422832019-03-05 13:32:37 -05001479 mStackView.post(() -> mStackView.onImeVisibilityChanged(imeVisible, imeHeight));
Joshua Tsujia19515f2019-02-13 18:02:29 -05001480 }
1481 }
Joshua Tsujia19515f2019-02-13 18:02:29 -05001482 }
Mady Mellorc3d6f7d2018-11-07 09:36:56 -08001483}