blob: 6471c71d423c9990a066c88cd76ed5273c944b22 [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;
Joshua Tsujidd4d9f92019-05-13 13:57:38 -040020import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_BADGE;
21import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST;
22import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK;
Mady Mellorca0c24c2019-05-16 16:14:32 -070023import static android.content.pm.ActivityInfo.DOCUMENT_LAUNCH_ALWAYS;
Mady Mellorc2ff0112019-03-28 14:18:06 -070024import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL;
25import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL_ALL;
26import static android.service.notification.NotificationListenerService.REASON_CANCEL;
27import static android.service.notification.NotificationListenerService.REASON_CANCEL_ALL;
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 Tsujib1a796b2019-01-16 15:43:12 -080032import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
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
Mark Renoufc808f062019-02-07 15:20:37 -050045import android.app.ActivityManager.RunningTaskInfo;
Mady Mellor66efd5e2019-05-15 13:38:11 -070046import android.app.NotificationManager;
Mady Mellorca0c24c2019-05-16 16:14:32 -070047import android.app.PendingIntent;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080048import android.content.Context;
Mady Mellorca0c24c2019-05-16 16:14:32 -070049import android.content.pm.ActivityInfo;
Joshua Tsujia19515f2019-02-13 18:02:29 -050050import android.content.pm.ParceledListSlice;
Joshua Tsujif418f9e2019-04-04 17:09:53 -040051import android.content.res.Configuration;
Mady Mellord1c78b262018-11-06 18:04:40 -080052import android.graphics.Rect;
Mark Renoufcecc77b2019-01-30 16:32:24 -050053import android.os.RemoteException;
Mady Mellorb4991e62019-01-10 15:14:51 -080054import android.os.ServiceManager;
Mady Mellorceced172018-11-27 11:18:39 -080055import android.provider.Settings;
Mark Renoufbbcf07f2019-05-09 10:42:43 -040056import android.service.notification.NotificationListenerService.RankingMap;
Joshua Tsujidd4d9f92019-05-13 13:57:38 -040057import android.service.notification.ZenModeConfig;
Mark Renouf9ba6cea2019-04-17 11:53:50 -040058import android.util.Log;
Mark Renouf82a40e62019-05-23 16:16:24 -040059import android.util.Pair;
Mark Renoufcecc77b2019-01-30 16:32:24 -050060import android.view.Display;
Joshua Tsujia19515f2019-02-13 18:02:29 -050061import android.view.IPinnedStackController;
62import android.view.IPinnedStackListener;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080063import android.view.ViewGroup;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080064import android.widget.FrameLayout;
65
Mark Renouf08bc42a2019-03-07 13:01:59 -050066import androidx.annotation.IntDef;
Mark Renouf658c6bc2019-01-30 10:26:54 -050067import androidx.annotation.MainThread;
Joshua Tsujic650a142019-05-22 11:31:19 -040068import androidx.annotation.Nullable;
Mark Renouf658c6bc2019-01-30 10:26:54 -050069
Mady Mellorebdbbb92018-11-15 14:36:48 -080070import com.android.internal.annotations.VisibleForTesting;
Mady Mellora54e9fa2019-04-18 13:26:18 -070071import com.android.internal.statusbar.IStatusBarService;
Ned Burns01e38212019-01-03 16:32:52 -050072import com.android.systemui.Dependency;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080073import com.android.systemui.R;
Beverly8fdb5332019-02-04 14:29:49 -050074import com.android.systemui.plugins.statusbar.StatusBarStateController;
Mark Renoufcecc77b2019-01-30 16:32:24 -050075import com.android.systemui.shared.system.ActivityManagerWrapper;
76import com.android.systemui.shared.system.TaskStackChangeListener;
Joshua Tsujia19515f2019-02-13 18:02:29 -050077import com.android.systemui.shared.system.WindowManagerWrapper;
Mady Mellorc2ff0112019-03-28 14:18:06 -070078import com.android.systemui.statusbar.NotificationRemoveInterceptor;
Ned Burns01e38212019-01-03 16:32:52 -050079import com.android.systemui.statusbar.notification.NotificationEntryListener;
80import com.android.systemui.statusbar.notification.NotificationEntryManager;
Mady Mellor3f2efdb2018-11-21 11:30:45 -080081import com.android.systemui.statusbar.notification.NotificationInterruptionStateProvider;
Ned Burnsf81c4c42019-01-07 14:10:43 -050082import com.android.systemui.statusbar.notification.collection.NotificationEntry;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080083import com.android.systemui.statusbar.phone.StatusBarWindowController;
Lyn Hanf1c9b8b2019-03-14 16:49:48 -070084import com.android.systemui.statusbar.policy.ConfigurationController;
Joshua Tsujidd4d9f92019-05-13 13:57:38 -040085import com.android.systemui.statusbar.policy.ZenModeController;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080086
Mark Renouf08bc42a2019-03-07 13:01:59 -050087import java.lang.annotation.Retention;
Mark Renoufba5ab512019-05-02 15:21:01 -040088import java.lang.annotation.Target;
Mady Mellore80930e2019-03-21 16:00:45 -070089import java.util.List;
Mark Renouf08bc42a2019-03-07 13:01:59 -050090
Jason Monk27d01a622018-12-10 15:57:09 -050091import javax.inject.Inject;
92import javax.inject.Singleton;
93
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080094/**
95 * Bubbles are a special type of content that can "float" on top of other apps or System UI.
96 * Bubbles can be expanded to show more content.
97 *
98 * The controller manages addition, removal, and visible state of bubbles on screen.
99 */
Jason Monk27d01a622018-12-10 15:57:09 -0500100@Singleton
Mark Renouf71a3af62019-04-08 15:02:54 -0400101public class BubbleController implements ConfigurationController.ConfigurationListener {
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800102
Issei Suzukia8d07312019-06-07 12:56:19 +0200103 private static final String TAG = TAG_WITH_CLASS_NAME ? "BubbleController" : TAG_BUBBLES;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800104
Mark Renouf08bc42a2019-03-07 13:01:59 -0500105 @Retention(SOURCE)
106 @IntDef({DISMISS_USER_GESTURE, DISMISS_AGED, DISMISS_TASK_FINISHED, DISMISS_BLOCKED,
Mady Melloraa8fef22019-04-11 13:36:40 -0700107 DISMISS_NOTIF_CANCEL, DISMISS_ACCESSIBILITY_ACTION, DISMISS_NO_LONGER_BUBBLE})
Mark Renoufba5ab512019-05-02 15:21:01 -0400108 @Target({FIELD, LOCAL_VARIABLE, PARAMETER})
Mark Renouf08bc42a2019-03-07 13:01:59 -0500109 @interface DismissReason {}
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700110
Mark Renouf08bc42a2019-03-07 13:01:59 -0500111 static final int DISMISS_USER_GESTURE = 1;
112 static final int DISMISS_AGED = 2;
113 static final int DISMISS_TASK_FINISHED = 3;
114 static final int DISMISS_BLOCKED = 4;
115 static final int DISMISS_NOTIF_CANCEL = 5;
116 static final int DISMISS_ACCESSIBILITY_ACTION = 6;
Mady Melloraa8fef22019-04-11 13:36:40 -0700117 static final int DISMISS_NO_LONGER_BUBBLE = 7;
Mark Renouf08bc42a2019-03-07 13:01:59 -0500118
Joshua Tsuji4accf5982019-04-22 17:36:11 -0400119 public static final int MAX_BUBBLES = 5; // TODO: actually enforce this
Joshua Tsuji25a4b7b2019-03-22 14:11:06 -0400120
Mady Mellor44ee2fe2019-01-30 17:51:16 -0800121 /** Flag to enable or disable the entire feature */
Mady Mellorf6e3ac02019-01-29 10:37:52 -0800122 private static final String ENABLE_BUBBLES = "experiment_enable_bubbles";
Joshua Tsuji010c2b12019-02-25 18:11:25 -0500123
Ned Burns01e38212019-01-03 16:32:52 -0500124 private final Context mContext;
125 private final NotificationEntryManager mNotificationEntryManager;
Mark Renoufcecc77b2019-01-30 16:32:24 -0500126 private final BubbleTaskStackListener mTaskStackListener;
Mady Mellord1c78b262018-11-06 18:04:40 -0800127 private BubbleStateChangeListener mStateChangeListener;
Mady Mellorcd9b1302018-11-06 18:08:04 -0800128 private BubbleExpandListener mExpandListener;
Issei Suzukic0387542019-03-08 17:31:14 +0100129 @Nullable private BubbleStackView.SurfaceSynchronizer mSurfaceSynchronizer;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800130
Mady Mellor3dff9e62019-02-05 18:12:53 -0800131 private BubbleData mBubbleData;
Joshua Tsujic650a142019-05-22 11:31:19 -0400132 @Nullable private BubbleStackView mStackView;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800133
134 // Bubbles get added to the status bar view
Ned Burns01e38212019-01-03 16:32:52 -0500135 private final StatusBarWindowController mStatusBarWindowController;
Joshua Tsujidd4d9f92019-05-13 13:57:38 -0400136 private final ZenModeController mZenModeController;
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800137 private StatusBarStateListener mStatusBarStateListener;
138
Mady Melloraa8fef22019-04-11 13:36:40 -0700139 private final NotificationInterruptionStateProvider mNotificationInterruptionStateProvider;
Mady Mellora54e9fa2019-04-18 13:26:18 -0700140 private IStatusBarService mBarService;
Mady Mellorb4991e62019-01-10 15:14:51 -0800141
Mady Mellord1c78b262018-11-06 18:04:40 -0800142 // Used for determining view rect for touch interaction
143 private Rect mTempRect = new Rect();
144
Joshua Tsujif418f9e2019-04-04 17:09:53 -0400145 /** Last known orientation, used to detect orientation changes in {@link #onConfigChanged}. */
146 private int mOrientation = Configuration.ORIENTATION_UNDEFINED;
147
Mady Mellor5549dd22018-11-06 18:07:34 -0800148 /**
Mady Mellord1c78b262018-11-06 18:04:40 -0800149 * Listener to be notified when some states of the bubbles change.
150 */
151 public interface BubbleStateChangeListener {
152 /**
153 * Called when the stack has bubbles or no longer has bubbles.
154 */
155 void onHasBubblesChanged(boolean hasBubbles);
156 }
157
Mady Mellorcd9b1302018-11-06 18:08:04 -0800158 /**
159 * Listener to find out about stack expansion / collapse events.
160 */
161 public interface BubbleExpandListener {
162 /**
163 * Called when the expansion state of the bubble stack changes.
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700164 *
Mady Mellorcd9b1302018-11-06 18:08:04 -0800165 * @param isExpanding whether it's expanding or collapsing
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800166 * @param key the notification key associated with bubble being expanded
Mady Mellorcd9b1302018-11-06 18:08:04 -0800167 */
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800168 void onBubbleExpandChanged(boolean isExpanding, String key);
169 }
170
171 /**
172 * Listens for the current state of the status bar and updates the visibility state
173 * of bubbles as needed.
174 */
175 private class StatusBarStateListener implements StatusBarStateController.StateListener {
176 private int mState;
177 /**
178 * Returns the current status bar state.
179 */
180 public int getCurrentState() {
181 return mState;
182 }
183
184 @Override
185 public void onStateChanged(int newState) {
186 mState = newState;
Mark Renouf71a3af62019-04-08 15:02:54 -0400187 boolean shouldCollapse = (mState != SHADE);
188 if (shouldCollapse) {
189 collapseStack();
190 }
Lyn Han6c40fe72019-05-08 14:06:33 -0700191 updateStack();
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800192 }
Mady Mellorcd9b1302018-11-06 18:08:04 -0800193 }
194
Jason Monk27d01a622018-12-10 15:57:09 -0500195 @Inject
Mady Mellorcfd06c12019-02-13 14:32:12 -0800196 public BubbleController(Context context, StatusBarWindowController statusBarWindowController,
Mady Melloraa8fef22019-04-11 13:36:40 -0700197 BubbleData data, ConfigurationController configurationController,
Joshua Tsujidd4d9f92019-05-13 13:57:38 -0400198 NotificationInterruptionStateProvider interruptionStateProvider,
199 ZenModeController zenModeController) {
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700200 this(context, statusBarWindowController, data, null /* synchronizer */,
Joshua Tsujidd4d9f92019-05-13 13:57:38 -0400201 configurationController, interruptionStateProvider, zenModeController);
Issei Suzukic0387542019-03-08 17:31:14 +0100202 }
203
204 public BubbleController(Context context, StatusBarWindowController statusBarWindowController,
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700205 BubbleData data, @Nullable BubbleStackView.SurfaceSynchronizer synchronizer,
Mady Melloraa8fef22019-04-11 13:36:40 -0700206 ConfigurationController configurationController,
Joshua Tsujidd4d9f92019-05-13 13:57:38 -0400207 NotificationInterruptionStateProvider interruptionStateProvider,
208 ZenModeController zenModeController) {
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800209 mContext = context;
Mady Melloraa8fef22019-04-11 13:36:40 -0700210 mNotificationInterruptionStateProvider = interruptionStateProvider;
Joshua Tsujidd4d9f92019-05-13 13:57:38 -0400211 mZenModeController = zenModeController;
212 mZenModeController.addCallback(new ZenModeController.Callback() {
213 @Override
214 public void onZenChanged(int zen) {
215 updateStackViewForZenConfig();
216 }
217
218 @Override
219 public void onConfigChanged(ZenModeConfig config) {
220 updateStackViewForZenConfig();
221 }
222 });
Mady Melloraa8fef22019-04-11 13:36:40 -0700223
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700224 configurationController.addCallback(this /* configurationListener */);
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800225
Mark Renouf9ba6cea2019-04-17 11:53:50 -0400226 mBubbleData = data;
227 mBubbleData.setListener(mBubbleDataListener);
228
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800229 mNotificationEntryManager = Dependency.get(NotificationEntryManager.class);
Ned Burns01e38212019-01-03 16:32:52 -0500230 mNotificationEntryManager.addNotificationEntryListener(mEntryListener);
Mady Mellorc2ff0112019-03-28 14:18:06 -0700231 mNotificationEntryManager.setNotificationRemoveInterceptor(mRemoveInterceptor);
Mady Mellorb4991e62019-01-10 15:14:51 -0800232
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800233 mStatusBarWindowController = statusBarWindowController;
234 mStatusBarStateListener = new StatusBarStateListener();
235 Dependency.get(StatusBarStateController.class).addCallback(mStatusBarStateListener);
Mark Renoufcecc77b2019-01-30 16:32:24 -0500236
Mark Renoufcecc77b2019-01-30 16:32:24 -0500237 mTaskStackListener = new BubbleTaskStackListener();
238 ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener);
Mady Mellor3dff9e62019-02-05 18:12:53 -0800239
Joshua Tsujia19515f2019-02-13 18:02:29 -0500240 try {
241 WindowManagerWrapper.getInstance().addPinnedStackListener(new BubblesImeListener());
242 } catch (RemoteException e) {
243 e.printStackTrace();
244 }
Issei Suzukic0387542019-03-08 17:31:14 +0100245 mSurfaceSynchronizer = synchronizer;
Mady Mellora54e9fa2019-04-18 13:26:18 -0700246
247 mBarService = IStatusBarService.Stub.asInterface(
248 ServiceManager.getService(Context.STATUS_BAR_SERVICE));
Mady Mellor5549dd22018-11-06 18:07:34 -0800249 }
250
Mark Renouf8b6a3c62019-04-09 10:17:40 -0400251 /**
252 * BubbleStackView is lazily created by this method the first time a Bubble is added. This
253 * method initializes the stack view and adds it to the StatusBar just above the scrim.
254 */
255 private void ensureStackViewCreated() {
256 if (mStackView == null) {
257 mStackView = new BubbleStackView(mContext, mBubbleData, mSurfaceSynchronizer);
258 ViewGroup sbv = mStatusBarWindowController.getStatusBarView();
Lyn Hanbde48202019-05-29 19:18:29 -0700259 int bubbleScrimIndex = sbv.indexOfChild(sbv.findViewById(R.id.scrim_for_bubble));
260 int stackIndex = bubbleScrimIndex + 1; // Show stack above bubble scrim.
261 sbv.addView(mStackView, stackIndex,
Mark Renouf8b6a3c62019-04-09 10:17:40 -0400262 new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
263 if (mExpandListener != null) {
264 mStackView.setExpandListener(mExpandListener);
265 }
Joshua Tsujidd4d9f92019-05-13 13:57:38 -0400266
267 updateStackViewForZenConfig();
Mark Renouf8b6a3c62019-04-09 10:17:40 -0400268 }
269 }
270
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700271 @Override
272 public void onUiModeChanged() {
273 if (mStackView != null) {
Lyn Han02cca812019-04-02 16:27:32 -0700274 mStackView.onThemeChanged();
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700275 }
276 }
277
278 @Override
279 public void onOverlayChanged() {
280 if (mStackView != null) {
Lyn Han02cca812019-04-02 16:27:32 -0700281 mStackView.onThemeChanged();
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700282 }
283 }
284
Joshua Tsujif418f9e2019-04-04 17:09:53 -0400285 @Override
286 public void onConfigChanged(Configuration newConfig) {
287 if (mStackView != null && newConfig != null && newConfig.orientation != mOrientation) {
Joshua Tsujif418f9e2019-04-04 17:09:53 -0400288 mOrientation = newConfig.orientation;
Lyn Hanf4730312019-06-18 11:18:58 -0700289 mStackView.onOrientationChanged(newConfig.orientation);
Joshua Tsujif418f9e2019-04-04 17:09:53 -0400290 }
291 }
292
Mady Mellor5549dd22018-11-06 18:07:34 -0800293 /**
Mady Mellord1c78b262018-11-06 18:04:40 -0800294 * Set a listener to be notified when some states of the bubbles change.
295 */
296 public void setBubbleStateChangeListener(BubbleStateChangeListener listener) {
297 mStateChangeListener = listener;
298 }
299
300 /**
Mady Mellorcd9b1302018-11-06 18:08:04 -0800301 * Set a listener to be notified of bubble expand events.
302 */
303 public void setExpandListener(BubbleExpandListener listener) {
Issei Suzukiac9fcb72019-02-04 17:45:57 +0100304 mExpandListener = ((isExpanding, key) -> {
305 if (listener != null) {
306 listener.onBubbleExpandChanged(isExpanding, key);
307 }
308 mStatusBarWindowController.setBubbleExpanded(isExpanding);
309 });
Mady Mellorcd9b1302018-11-06 18:08:04 -0800310 if (mStackView != null) {
311 mStackView.setExpandListener(mExpandListener);
312 }
313 }
314
315 /**
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800316 * Whether or not there are bubbles present, regardless of them being visible on the
317 * screen (e.g. if on AOD).
318 */
319 public boolean hasBubbles() {
Mady Mellor3dff9e62019-02-05 18:12:53 -0800320 if (mStackView == null) {
321 return false;
322 }
Mark Renouf71a3af62019-04-08 15:02:54 -0400323 return mBubbleData.hasBubbles();
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800324 }
325
326 /**
327 * Whether the stack of bubbles is expanded or not.
328 */
329 public boolean isStackExpanded() {
Mark Renouf71a3af62019-04-08 15:02:54 -0400330 return mBubbleData.isExpanded();
331 }
332
333 /**
334 * Tell the stack of bubbles to expand.
335 */
336 public void expandStack() {
337 mBubbleData.setExpanded(true);
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800338 }
339
340 /**
341 * Tell the stack of bubbles to collapse.
342 */
343 public void collapseStack() {
Mark Renouf71a3af62019-04-08 15:02:54 -0400344 mBubbleData.setExpanded(false /* expanded */);
345 }
346
Mady Mellorce23c462019-06-17 17:30:07 -0700347 /**
348 * Whether (1) there is a bubble associated with the provided key and
349 * (2) if the notification for that bubble is hidden from the shade.
350 *
351 * False if there isn't a bubble or if the notification for that bubble appears in the shade.
352 */
353 public boolean isBubbleNotificationSuppressedFromShade(String key) {
354 return mBubbleData.hasBubbleWithKey(key)
355 && !mBubbleData.getBubbleWithKey(key).showInShadeWhenBubble();
356 }
357
Mark Renouf71a3af62019-04-08 15:02:54 -0400358 void selectBubble(Bubble bubble) {
359 mBubbleData.setSelectedBubble(bubble);
360 }
361
362 @VisibleForTesting
363 void selectBubble(String key) {
364 Bubble bubble = mBubbleData.getBubbleWithKey(key);
365 selectBubble(bubble);
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800366 }
367
368 /**
Mark Renouffec45da2019-03-13 13:24:27 -0400369 * Request the stack expand if needed, then select the specified Bubble as current.
370 *
371 * @param notificationKey the notification key for the bubble to be selected
372 */
373 public void expandStackAndSelectBubble(String notificationKey) {
Mark Renouf71a3af62019-04-08 15:02:54 -0400374 Bubble bubble = mBubbleData.getBubbleWithKey(notificationKey);
375 if (bubble != null) {
376 mBubbleData.setSelectedBubble(bubble);
377 mBubbleData.setExpanded(true);
Mark Renouffec45da2019-03-13 13:24:27 -0400378 }
379 }
380
381 /**
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800382 * Tell the stack of bubbles to be dismissed, this will remove all of the bubbles in the stack.
383 */
Mark Renouf08bc42a2019-03-07 13:01:59 -0500384 void dismissStack(@DismissReason int reason) {
Mark Renouf71a3af62019-04-08 15:02:54 -0400385 mBubbleData.dismissAll(reason);
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800386 }
387
388 /**
Mark Renouf041d7262019-02-06 12:09:41 -0500389 * Directs a back gesture at the bubble stack. When opened, the current expanded bubble
390 * is forwarded a back key down/up pair.
391 */
392 public void performBackPressIfNeeded() {
393 if (mStackView != null) {
394 mStackView.performBackPressIfNeeded();
395 }
396 }
397
398 /**
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800399 * Adds or updates a bubble associated with the provided notification entry.
400 *
Mark Renouf8b6a3c62019-04-09 10:17:40 -0400401 * @param notif the notification associated with this bubble.
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800402 */
Mark Renouff97ed462019-04-05 13:46:24 -0400403 void updateBubble(NotificationEntry notif) {
Mady Mellor66efd5e2019-05-15 13:38:11 -0700404 // If this is an interruptive notif, mark that it's interrupted
405 if (notif.importance >= NotificationManager.IMPORTANCE_HIGH) {
406 notif.setInterruption();
407 }
Mark Renouf71a3af62019-04-08 15:02:54 -0400408 mBubbleData.notificationEntryUpdated(notif);
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800409 }
410
411 /**
412 * Removes the bubble associated with the {@param uri}.
Mark Renouf658c6bc2019-01-30 10:26:54 -0500413 * <p>
414 * Must be called from the main thread.
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800415 */
Mark Renouf658c6bc2019-01-30 10:26:54 -0500416 @MainThread
Mark Renouf08bc42a2019-03-07 13:01:59 -0500417 void removeBubble(String key, int reason) {
Mark Renouf71a3af62019-04-08 15:02:54 -0400418 // TEMP: refactor to change this to pass entry
419 Bubble bubble = mBubbleData.getBubbleWithKey(key);
420 if (bubble != null) {
Mady Mellored99c272019-06-13 15:58:30 -0700421 mBubbleData.notificationEntryRemoved(bubble.getEntry(), reason);
Mady Mellore8e07712019-01-23 12:45:33 -0800422 }
423 }
424
Ned Burns01e38212019-01-03 16:32:52 -0500425 @SuppressWarnings("FieldCanBeLocal")
Mady Mellorc2ff0112019-03-28 14:18:06 -0700426 private final NotificationRemoveInterceptor mRemoveInterceptor =
427 new NotificationRemoveInterceptor() {
428 @Override
429 public boolean onNotificationRemoveRequested(String key, int reason) {
430 if (!mBubbleData.hasBubbleWithKey(key)) {
431 return false;
432 }
Mady Mellored99c272019-06-13 15:58:30 -0700433 Bubble bubble = mBubbleData.getBubbleWithKey(key);
434 NotificationEntry entry = bubble.getEntry();
Mady Mellorc2ff0112019-03-28 14:18:06 -0700435
436 final boolean isClearAll = reason == REASON_CANCEL_ALL;
437 final boolean isUserDimiss = reason == REASON_CANCEL;
438 final boolean isAppCancel = reason == REASON_APP_CANCEL
439 || reason == REASON_APP_CANCEL_ALL;
440
441 // Need to check for !appCancel here because the notification may have
442 // previously been dismissed & entry.isRowDismissed would still be true
443 boolean userRemovedNotif = (entry.isRowDismissed() && !isAppCancel)
444 || isClearAll || isUserDimiss;
445
446 // The bubble notification sticks around in the data as long as the bubble is
447 // not dismissed and the app hasn't cancelled the notification.
Mady Mellored99c272019-06-13 15:58:30 -0700448 boolean bubbleExtended = entry.isBubble() && !bubble.isRemoved()
Mady Mellorc2ff0112019-03-28 14:18:06 -0700449 && userRemovedNotif;
450 if (bubbleExtended) {
Mady Mellorce23c462019-06-17 17:30:07 -0700451 bubble.setShowInShadeWhenBubble(false);
Mady Mellorc2ff0112019-03-28 14:18:06 -0700452 if (mStackView != null) {
453 mStackView.updateDotVisibility(entry.key);
454 }
455 mNotificationEntryManager.updateNotifications();
456 return true;
Mady Mellored99c272019-06-13 15:58:30 -0700457 } else if (!userRemovedNotif && !bubble.isRemoved()) {
Mady Mellorc2ff0112019-03-28 14:18:06 -0700458 // This wasn't a user removal so we should remove the bubble as well
459 mBubbleData.notificationEntryRemoved(entry, DISMISS_NOTIF_CANCEL);
460 return false;
461 }
462 return false;
463 }
464 };
465
466 @SuppressWarnings("FieldCanBeLocal")
Ned Burns01e38212019-01-03 16:32:52 -0500467 private final NotificationEntryListener mEntryListener = new NotificationEntryListener() {
468 @Override
Ned Burnsf81c4c42019-01-07 14:10:43 -0500469 public void onPendingEntryAdded(NotificationEntry entry) {
Mady Mellorf6e3ac02019-01-29 10:37:52 -0800470 if (!areBubblesEnabled(mContext)) {
471 return;
472 }
Mady Mellorca0c24c2019-05-16 16:14:32 -0700473 if (mNotificationInterruptionStateProvider.shouldBubbleUp(entry)
474 && canLaunchInActivityView(mContext, entry)) {
Mark Renouff97ed462019-04-05 13:46:24 -0400475 updateBubble(entry);
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800476 }
477 }
478
479 @Override
480 public void onPreEntryUpdated(NotificationEntry entry) {
Mady Mellorf6e3ac02019-01-29 10:37:52 -0800481 if (!areBubblesEnabled(mContext)) {
482 return;
483 }
Mady Mellorca0c24c2019-05-16 16:14:32 -0700484 boolean shouldBubble = mNotificationInterruptionStateProvider.shouldBubbleUp(entry)
485 && canLaunchInActivityView(mContext, entry);
Mady Melloraa8fef22019-04-11 13:36:40 -0700486 if (!shouldBubble && mBubbleData.hasBubbleWithKey(entry.key)) {
487 // It was previously a bubble but no longer a bubble -- lets remove it
488 removeBubble(entry.key, DISMISS_NO_LONGER_BUBBLE);
Mady Mellorff40e012019-05-03 15:34:41 -0700489 } else if (shouldBubble) {
Mady Mellored99c272019-06-13 15:58:30 -0700490 Bubble b = mBubbleData.getBubbleWithKey(entry.key);
491 b.setRemoved(false); // updates come back as bubbles even if dismissed
Mark Renouff97ed462019-04-05 13:46:24 -0400492 updateBubble(entry);
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800493 }
494 }
Mark Renoufbbcf07f2019-05-09 10:42:43 -0400495
496 @Override
497 public void onNotificationRankingUpdated(RankingMap rankingMap) {
498 // Forward to BubbleData to block any bubbles which should no longer be shown
499 mBubbleData.notificationRankingUpdated(rankingMap);
500 }
Ned Burns01e38212019-01-03 16:32:52 -0500501 };
502
Mark Renouf71a3af62019-04-08 15:02:54 -0400503 @SuppressWarnings("FieldCanBeLocal")
Mark Renouf3bc5b362019-04-05 14:37:59 -0400504 private final BubbleData.Listener mBubbleDataListener = new BubbleData.Listener() {
Mark Renouf71a3af62019-04-08 15:02:54 -0400505
Mark Renouf3bc5b362019-04-05 14:37:59 -0400506 @Override
Mark Renouf82a40e62019-05-23 16:16:24 -0400507 public void applyUpdate(BubbleData.Update update) {
508 if (mStackView == null && update.addedBubble != null) {
509 // Lazy init stack view when the first bubble is added.
510 ensureStackViewCreated();
Mark Renouf71a3af62019-04-08 15:02:54 -0400511 }
Mark Renouf82a40e62019-05-23 16:16:24 -0400512
513 // If not yet initialized, ignore all other changes.
514 if (mStackView == null) {
515 return;
516 }
517
518 if (update.addedBubble != null) {
519 mStackView.addBubble(update.addedBubble);
520 }
521
522 // Collapsing? Do this first before remaining steps.
523 if (update.expandedChanged && !update.expanded) {
524 mStackView.setExpanded(false);
525 }
526
527 // Do removals, if any.
528 for (Pair<Bubble, Integer> removed : update.removedBubbles) {
529 final Bubble bubble = removed.first;
530 @DismissReason final int reason = removed.second;
531 mStackView.removeBubble(bubble);
532
533 if (!mBubbleData.hasBubbleWithKey(bubble.getKey())
Mady Mellor99a302602019-06-14 11:39:56 -0700534 && !bubble.showInShadeWhenBubble()) {
Mark Renouf82a40e62019-05-23 16:16:24 -0400535 // The bubble is gone & the notification is gone, time to actually remove it
Mady Mellored99c272019-06-13 15:58:30 -0700536 mNotificationEntryManager.performRemoveNotification(
537 bubble.getEntry().notification, UNDEFINED_DISMISS_REASON);
Mark Renouf82a40e62019-05-23 16:16:24 -0400538 } else {
Mady Mellor3a0a1b42019-05-23 06:40:21 -0700539 // Update the flag for SysUI
Mady Mellored99c272019-06-13 15:58:30 -0700540 bubble.getEntry().notification.getNotification().flags &= ~FLAG_BUBBLE;
Mady Mellor3a0a1b42019-05-23 06:40:21 -0700541
542 // Make sure NoMan knows it's not a bubble anymore so anyone querying it will
543 // get right result back
Mark Renouf82a40e62019-05-23 16:16:24 -0400544 try {
545 mBarService.onNotificationBubbleChanged(bubble.getKey(),
546 false /* isBubble */);
547 } catch (RemoteException e) {
548 // Bad things have happened
549 }
Mady Mellora54e9fa2019-04-18 13:26:18 -0700550 }
551 }
Mark Renouf3bc5b362019-04-05 14:37:59 -0400552
Mark Renouf82a40e62019-05-23 16:16:24 -0400553 if (update.updatedBubble != null) {
554 mStackView.updateBubble(update.updatedBubble);
Mark Renouf71a3af62019-04-08 15:02:54 -0400555 }
Mark Renouf3bc5b362019-04-05 14:37:59 -0400556
Mark Renouf82a40e62019-05-23 16:16:24 -0400557 if (update.orderChanged) {
558 mStackView.updateBubbleOrder(update.bubbles);
Mark Renoufba5ab512019-05-02 15:21:01 -0400559 }
Mark Renouf3bc5b362019-04-05 14:37:59 -0400560
Mark Renouf82a40e62019-05-23 16:16:24 -0400561 if (update.selectionChanged) {
562 mStackView.setSelectedBubble(update.selectedBubble);
Mark Renouf71a3af62019-04-08 15:02:54 -0400563 }
Mark Renouf3bc5b362019-04-05 14:37:59 -0400564
Mark Renouf82a40e62019-05-23 16:16:24 -0400565 // Expanding? Apply this last.
566 if (update.expandedChanged && update.expanded) {
567 mStackView.setExpanded(true);
Mark Renouf71a3af62019-04-08 15:02:54 -0400568 }
Mark Renouf3bc5b362019-04-05 14:37:59 -0400569
Mark Renouf71a3af62019-04-08 15:02:54 -0400570 mNotificationEntryManager.updateNotifications();
Lyn Han6c40fe72019-05-08 14:06:33 -0700571 updateStack();
Mark Renouf9ba6cea2019-04-17 11:53:50 -0400572
Issei Suzukia8d07312019-06-07 12:56:19 +0200573 if (DEBUG_BUBBLE_CONTROLLER) {
Mark Renouf9ba6cea2019-04-17 11:53:50 -0400574 Log.d(TAG, "[BubbleData]");
575 Log.d(TAG, formatBubblesString(mBubbleData.getBubbles(),
576 mBubbleData.getSelectedBubble()));
577
578 if (mStackView != null) {
579 Log.d(TAG, "[BubbleStackView]");
580 Log.d(TAG, formatBubblesString(mStackView.getBubblesOnScreen(),
581 mStackView.getExpandedBubble()));
582 }
583 }
Mark Renouf3bc5b362019-04-05 14:37:59 -0400584 }
585 };
586
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800587 /**
Joshua Tsujidd4d9f92019-05-13 13:57:38 -0400588 * Updates the stack view's suppression flags from the latest config from the zen (do not
589 * disturb) controller.
590 */
591 private void updateStackViewForZenConfig() {
592 final ZenModeConfig zenModeConfig = mZenModeController.getConfig();
593
594 if (zenModeConfig == null || mStackView == null) {
595 return;
596 }
597
598 final int suppressedEffects = zenModeConfig.suppressedVisualEffects;
599 final boolean hideNotificationDotsSelected =
600 (suppressedEffects & SUPPRESSED_EFFECT_BADGE) != 0;
601 final boolean dontPopNotifsOnScreenSelected =
602 (suppressedEffects & SUPPRESSED_EFFECT_PEEK) != 0;
603 final boolean hideFromPullDownShadeSelected =
604 (suppressedEffects & SUPPRESSED_EFFECT_NOTIFICATION_LIST) != 0;
605
606 final boolean dndEnabled = mZenModeController.getZen() != Settings.Global.ZEN_MODE_OFF;
607
608 mStackView.setSuppressNewDot(
609 dndEnabled && hideNotificationDotsSelected);
610 mStackView.setSuppressFlyout(
611 dndEnabled && (dontPopNotifsOnScreenSelected
612 || hideFromPullDownShadeSelected));
613 }
614
615 /**
616 * Lets any listeners know if bubble state has changed.
Lyn Han6c40fe72019-05-08 14:06:33 -0700617 * Updates the visibility of the bubbles based on current state.
618 * Does not un-bubble, just hides or un-hides. Notifies any
619 * {@link BubbleStateChangeListener}s of visibility changes.
620 * Updates stack description for TalkBack focus.
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800621 */
Lyn Han6c40fe72019-05-08 14:06:33 -0700622 public void updateStack() {
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800623 if (mStackView == null) {
624 return;
Mady Mellord1c78b262018-11-06 18:04:40 -0800625 }
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800626 if (mStatusBarStateListener.getCurrentState() == SHADE && hasBubbles()) {
627 // Bubbles only appear in unlocked shade
628 mStackView.setVisibility(hasBubbles() ? VISIBLE : INVISIBLE);
629 } else if (mStackView != null) {
630 mStackView.setVisibility(INVISIBLE);
Mady Mellor5549dd22018-11-06 18:07:34 -0800631 }
Lyn Han6c40fe72019-05-08 14:06:33 -0700632
633 // Let listeners know if bubble state changed.
634 boolean hadBubbles = mStatusBarWindowController.getBubblesShowing();
635 boolean hasBubblesShowing = hasBubbles() && mStackView.getVisibility() == VISIBLE;
636 mStatusBarWindowController.setBubblesShowing(hasBubblesShowing);
637 if (mStateChangeListener != null && hadBubbles != hasBubblesShowing) {
638 mStateChangeListener.onHasBubblesChanged(hasBubblesShowing);
639 }
640
641 mStackView.updateContentDescription();
Mady Mellord1c78b262018-11-06 18:04:40 -0800642 }
643
644 /**
645 * Rect indicating the touchable region for the bubble stack / expanded stack.
646 */
647 public Rect getTouchableRegion() {
648 if (mStackView == null || mStackView.getVisibility() != VISIBLE) {
649 return null;
650 }
651 mStackView.getBoundsOnScreen(mTempRect);
652 return mTempRect;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800653 }
654
Mady Mellor390bff42019-04-05 15:09:01 -0700655 /**
656 * The display id of the expanded view, if the stack is expanded and not occluded by the
657 * status bar, otherwise returns {@link Display#INVALID_DISPLAY}.
658 */
659 public int getExpandedDisplayId(Context context) {
Issei Suzukicac2a502019-04-16 16:52:50 +0200660 final Bubble bubble = getExpandedBubble(context);
661 return bubble != null ? bubble.getDisplayId() : INVALID_DISPLAY;
662 }
663
664 @Nullable
665 private Bubble getExpandedBubble(Context context) {
Joel Galenson4071ddb2019-04-18 13:30:45 -0700666 if (mStackView == null) {
Issei Suzukicac2a502019-04-16 16:52:50 +0200667 return null;
Joel Galenson4071ddb2019-04-18 13:30:45 -0700668 }
Issei Suzukicac2a502019-04-16 16:52:50 +0200669 final boolean defaultDisplay = context.getDisplay() != null
Mady Mellor390bff42019-04-05 15:09:01 -0700670 && context.getDisplay().getDisplayId() == DEFAULT_DISPLAY;
Issei Suzukicac2a502019-04-16 16:52:50 +0200671 final Bubble expandedBubble = mStackView.getExpandedBubble();
672 if (defaultDisplay && expandedBubble != null && isStackExpanded()
Mady Mellor390bff42019-04-05 15:09:01 -0700673 && !mStatusBarWindowController.getPanelExpanded()) {
Issei Suzukicac2a502019-04-16 16:52:50 +0200674 return expandedBubble;
Mady Mellor390bff42019-04-05 15:09:01 -0700675 }
Issei Suzukicac2a502019-04-16 16:52:50 +0200676 return null;
Mady Mellor390bff42019-04-05 15:09:01 -0700677 }
678
Mady Mellorf6e3ac02019-01-29 10:37:52 -0800679 @VisibleForTesting
680 BubbleStackView getStackView() {
681 return mStackView;
682 }
683
Mark Renouf9ba6cea2019-04-17 11:53:50 -0400684 static String formatBubblesString(List<Bubble> bubbles, Bubble selected) {
685 StringBuilder sb = new StringBuilder();
686 for (Bubble bubble : bubbles) {
687 if (bubble == null) {
688 sb.append(" <null> !!!!!\n");
689 } else {
690 boolean isSelected = (bubble == selected);
691 sb.append(String.format("%s Bubble{act=%12d, ongoing=%d, key=%s}\n",
692 ((isSelected) ? "->" : " "),
693 bubble.getLastActivity(),
694 (bubble.isOngoing() ? 1 : 0),
695 bubble.getKey()));
696 }
697 }
698 return sb.toString();
699 }
700
Mady Mellore80930e2019-03-21 16:00:45 -0700701 /**
Mark Renoufcecc77b2019-01-30 16:32:24 -0500702 * This task stack listener is responsible for responding to tasks moved to the front
703 * which are on the default (main) display. When this happens, expanded bubbles must be
704 * collapsed so the user may interact with the app which was just moved to the front.
705 * <p>
706 * This listener is registered with SystemUI's ActivityManagerWrapper which dispatches
707 * these calls via a main thread Handler.
708 */
709 @MainThread
710 private class BubbleTaskStackListener extends TaskStackChangeListener {
711
Mark Renoufcecc77b2019-01-30 16:32:24 -0500712 @Override
Mark Renoufc808f062019-02-07 15:20:37 -0500713 public void onTaskMovedToFront(RunningTaskInfo taskInfo) {
714 if (mStackView != null && taskInfo.displayId == Display.DEFAULT_DISPLAY) {
Mark Renouf71a3af62019-04-08 15:02:54 -0400715 mBubbleData.setExpanded(false);
Mark Renoufcecc77b2019-01-30 16:32:24 -0500716 }
717 }
718
Mark Renoufcecc77b2019-01-30 16:32:24 -0500719 @Override
Mark Renoufa12e8762019-03-07 15:43:01 -0500720 public void onActivityLaunchOnSecondaryDisplayRerouted() {
Mark Renoufcecc77b2019-01-30 16:32:24 -0500721 if (mStackView != null) {
Mark Renouf71a3af62019-04-08 15:02:54 -0400722 mBubbleData.setExpanded(false);
Mark Renoufcecc77b2019-01-30 16:32:24 -0500723 }
724 }
Mark Renouf446251d2019-04-26 10:22:41 -0400725
726 @Override
727 public void onBackPressedOnTaskRoot(RunningTaskInfo taskInfo) {
728 if (mStackView != null && taskInfo.displayId == getExpandedDisplayId(mContext)) {
729 mBubbleData.setExpanded(false);
730 }
731 }
Issei Suzukicac2a502019-04-16 16:52:50 +0200732
733 @Override
734 public void onSingleTaskDisplayDrawn(int displayId) {
735 final Bubble expandedBubble = getExpandedBubble(mContext);
736 if (expandedBubble != null && expandedBubble.getDisplayId() == displayId) {
737 expandedBubble.setContentVisibility(true);
738 }
739 }
Issei Suzuki734bc942019-06-05 13:59:52 +0200740
741 @Override
742 public void onSingleTaskDisplayEmpty(int displayId) {
743 final Bubble expandedBubble = getExpandedBubble(mContext);
744 if (expandedBubble == null) {
745 return;
746 }
747 if (expandedBubble.getDisplayId() == displayId) {
748 mBubbleData.setExpanded(false);
749 }
Mady Mellored99c272019-06-13 15:58:30 -0700750 if (expandedBubble.getExpandedView() != null) {
751 expandedBubble.getExpandedView().notifyDisplayEmpty();
Issei Suzuki734bc942019-06-05 13:59:52 +0200752 }
753 }
Mark Renoufcecc77b2019-01-30 16:32:24 -0500754 }
755
Mady Mellorf6e3ac02019-01-29 10:37:52 -0800756 private static boolean areBubblesEnabled(Context context) {
757 return Settings.Secure.getInt(context.getContentResolver(),
758 ENABLE_BUBBLES, 1) != 0;
759 }
Joshua Tsujia19515f2019-02-13 18:02:29 -0500760
Mady Mellorca0c24c2019-05-16 16:14:32 -0700761 /**
762 * Whether an intent is properly configured to display in an {@link android.app.ActivityView}.
763 *
764 * Keep checks in sync with NotificationManagerService#canLaunchInActivityView. Typically
765 * that should filter out any invalid bubbles, but should protect SysUI side just in case.
766 *
767 * @param context the context to use.
768 * @param entry the entry to bubble.
769 */
770 static boolean canLaunchInActivityView(Context context, NotificationEntry entry) {
771 PendingIntent intent = entry.getBubbleMetadata() != null
772 ? entry.getBubbleMetadata().getIntent()
773 : null;
774 if (intent == null) {
775 Log.w(TAG, "Unable to create bubble -- no intent");
776 return false;
777 }
778 ActivityInfo info =
779 intent.getIntent().resolveActivityInfo(context.getPackageManager(), 0);
780 if (info == null) {
781 Log.w(TAG, "Unable to send as bubble -- couldn't find activity info for intent: "
782 + intent);
783 return false;
784 }
785 if (!ActivityInfo.isResizeableMode(info.resizeMode)) {
786 Log.w(TAG, "Unable to send as bubble -- activity is not resizable for intent: "
787 + intent);
788 return false;
789 }
790 if (info.documentLaunchMode != DOCUMENT_LAUNCH_ALWAYS) {
791 Log.w(TAG, "Unable to send as bubble -- activity is not documentLaunchMode=always "
792 + "for intent: " + intent);
793 return false;
794 }
795 if ((info.flags & ActivityInfo.FLAG_ALLOW_EMBEDDED) == 0) {
796 Log.w(TAG, "Unable to send as bubble -- activity is not embeddable for intent: "
797 + intent);
798 return false;
799 }
800 return true;
801 }
802
Joshua Tsujia19515f2019-02-13 18:02:29 -0500803 /** PinnedStackListener that dispatches IME visibility updates to the stack. */
804 private class BubblesImeListener extends IPinnedStackListener.Stub {
805
806 @Override
807 public void onListenerRegistered(IPinnedStackController controller) throws RemoteException {
808 }
809
810 @Override
811 public void onMovementBoundsChanged(Rect insetBounds, Rect normalBounds,
812 Rect animatingBounds, boolean fromImeAdjustment, boolean fromShelfAdjustment,
813 int displayRotation) throws RemoteException {}
814
815 @Override
Joshua Tsujid9422832019-03-05 13:32:37 -0500816 public void onImeVisibilityChanged(boolean imeVisible, int imeHeight) {
817 if (mStackView != null && mStackView.getBubbleCount() > 0) {
818 mStackView.post(() -> mStackView.onImeVisibilityChanged(imeVisible, imeHeight));
Joshua Tsujia19515f2019-02-13 18:02:29 -0500819 }
820 }
821
822 @Override
823 public void onShelfVisibilityChanged(boolean shelfVisible, int shelfHeight)
824 throws RemoteException {}
825
826 @Override
827 public void onMinimizedStateChanged(boolean isMinimized) throws RemoteException {}
828
829 @Override
830 public void onActionsChanged(ParceledListSlice actions) throws RemoteException {}
831 }
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800832}