blob: 7e016bb000adf3df2c8f6fe3020f063de2f0c8cb [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 Mellorca0c24c2019-05-16 16:14:32 -070019import static android.content.pm.ActivityInfo.DOCUMENT_LAUNCH_ALWAYS;
Mady Mellorc2ff0112019-03-28 14:18:06 -070020import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL;
21import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL_ALL;
22import static android.service.notification.NotificationListenerService.REASON_CANCEL;
23import static android.service.notification.NotificationListenerService.REASON_CANCEL_ALL;
Mady Mellor390bff42019-04-05 15:09:01 -070024import static android.view.Display.DEFAULT_DISPLAY;
25import static android.view.Display.INVALID_DISPLAY;
Mady Mellord1c78b262018-11-06 18:04:40 -080026import static android.view.View.INVISIBLE;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080027import static android.view.View.VISIBLE;
Joshua Tsujib1a796b2019-01-16 15:43:12 -080028import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080029
Mady Mellor3f2efdb2018-11-21 11:30:45 -080030import static com.android.systemui.statusbar.StatusBarState.SHADE;
Mady Mellor1a4e86f2019-05-03 16:07:23 -070031import static com.android.systemui.statusbar.notification.NotificationEntryManager.UNDEFINED_DISMISS_REASON;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080032
Mark Renoufba5ab512019-05-02 15:21:01 -040033import static java.lang.annotation.ElementType.FIELD;
34import static java.lang.annotation.ElementType.LOCAL_VARIABLE;
35import static java.lang.annotation.ElementType.PARAMETER;
Mark Renouf08bc42a2019-03-07 13:01:59 -050036import static java.lang.annotation.RetentionPolicy.SOURCE;
37
Mady Mellorb4991e62019-01-10 15:14:51 -080038import android.annotation.Nullable;
Mady Mellore80930e2019-03-21 16:00:45 -070039import android.app.ActivityManager;
Mark Renoufc808f062019-02-07 15:20:37 -050040import android.app.ActivityManager.RunningTaskInfo;
Mark Renoufcecc77b2019-01-30 16:32:24 -050041import android.app.ActivityTaskManager;
42import android.app.IActivityTaskManager;
Mady Mellor5549dd22018-11-06 18:07:34 -080043import android.app.Notification;
Mady Mellor66efd5e2019-05-15 13:38:11 -070044import android.app.NotificationManager;
Mady Mellorca0c24c2019-05-16 16:14:32 -070045import android.app.PendingIntent;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080046import android.content.Context;
Mady Mellorca0c24c2019-05-16 16:14:32 -070047import android.content.pm.ActivityInfo;
Joshua Tsujia19515f2019-02-13 18:02:29 -050048import android.content.pm.ParceledListSlice;
Joshua Tsujif418f9e2019-04-04 17:09:53 -040049import android.content.res.Configuration;
Mady Mellord1c78b262018-11-06 18:04:40 -080050import android.graphics.Rect;
Mark Renoufcecc77b2019-01-30 16:32:24 -050051import android.os.RemoteException;
Mady Mellorb4991e62019-01-10 15:14:51 -080052import android.os.ServiceManager;
Mady Mellorceced172018-11-27 11:18:39 -080053import android.provider.Settings;
Mady Mellor5549dd22018-11-06 18:07:34 -080054import android.service.notification.StatusBarNotification;
Mark Renouf9ba6cea2019-04-17 11:53:50 -040055import android.util.Log;
Mark Renoufcecc77b2019-01-30 16:32:24 -050056import android.view.Display;
Joshua Tsujia19515f2019-02-13 18:02:29 -050057import android.view.IPinnedStackController;
58import android.view.IPinnedStackListener;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080059import android.view.ViewGroup;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080060import android.widget.FrameLayout;
61
Mark Renouf08bc42a2019-03-07 13:01:59 -050062import androidx.annotation.IntDef;
Mark Renouf658c6bc2019-01-30 10:26:54 -050063import androidx.annotation.MainThread;
64
Mady Mellorebdbbb92018-11-15 14:36:48 -080065import com.android.internal.annotations.VisibleForTesting;
Mady Mellora54e9fa2019-04-18 13:26:18 -070066import com.android.internal.statusbar.IStatusBarService;
Ned Burns01e38212019-01-03 16:32:52 -050067import com.android.systemui.Dependency;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080068import com.android.systemui.R;
Beverly8fdb5332019-02-04 14:29:49 -050069import com.android.systemui.plugins.statusbar.StatusBarStateController;
Mark Renoufcecc77b2019-01-30 16:32:24 -050070import com.android.systemui.shared.system.ActivityManagerWrapper;
71import com.android.systemui.shared.system.TaskStackChangeListener;
Joshua Tsujia19515f2019-02-13 18:02:29 -050072import com.android.systemui.shared.system.WindowManagerWrapper;
Mady Mellorc2ff0112019-03-28 14:18:06 -070073import com.android.systemui.statusbar.NotificationRemoveInterceptor;
Ned Burns01e38212019-01-03 16:32:52 -050074import com.android.systemui.statusbar.notification.NotificationEntryListener;
75import com.android.systemui.statusbar.notification.NotificationEntryManager;
Mady Mellor3f2efdb2018-11-21 11:30:45 -080076import com.android.systemui.statusbar.notification.NotificationInterruptionStateProvider;
Ned Burnsf81c4c42019-01-07 14:10:43 -050077import com.android.systemui.statusbar.notification.collection.NotificationEntry;
Ned Burns1a5e22f2019-02-14 15:11:52 -050078import com.android.systemui.statusbar.notification.row.NotificationContentInflater.InflationFlag;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080079import com.android.systemui.statusbar.phone.StatusBarWindowController;
Lyn Hanf1c9b8b2019-03-14 16:49:48 -070080import com.android.systemui.statusbar.policy.ConfigurationController;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080081
Mark Renouf08bc42a2019-03-07 13:01:59 -050082import java.lang.annotation.Retention;
Mark Renoufba5ab512019-05-02 15:21:01 -040083import java.lang.annotation.Target;
Mady Mellore80930e2019-03-21 16:00:45 -070084import java.util.List;
Mark Renouf08bc42a2019-03-07 13:01:59 -050085
Jason Monk27d01a622018-12-10 15:57:09 -050086import javax.inject.Inject;
87import javax.inject.Singleton;
88
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080089/**
90 * Bubbles are a special type of content that can "float" on top of other apps or System UI.
91 * Bubbles can be expanded to show more content.
92 *
93 * The controller manages addition, removal, and visible state of bubbles on screen.
94 */
Jason Monk27d01a622018-12-10 15:57:09 -050095@Singleton
Mark Renouf71a3af62019-04-08 15:02:54 -040096public class BubbleController implements ConfigurationController.ConfigurationListener {
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080097
98 private static final String TAG = "BubbleController";
Mark Renoufba5ab512019-05-02 15:21:01 -040099 private static final boolean DEBUG = false;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800100
Mark Renouf08bc42a2019-03-07 13:01:59 -0500101 @Retention(SOURCE)
102 @IntDef({DISMISS_USER_GESTURE, DISMISS_AGED, DISMISS_TASK_FINISHED, DISMISS_BLOCKED,
Mady Melloraa8fef22019-04-11 13:36:40 -0700103 DISMISS_NOTIF_CANCEL, DISMISS_ACCESSIBILITY_ACTION, DISMISS_NO_LONGER_BUBBLE})
Mark Renoufba5ab512019-05-02 15:21:01 -0400104 @Target({FIELD, LOCAL_VARIABLE, PARAMETER})
Mark Renouf08bc42a2019-03-07 13:01:59 -0500105 @interface DismissReason {}
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700106
Mark Renouf08bc42a2019-03-07 13:01:59 -0500107 static final int DISMISS_USER_GESTURE = 1;
108 static final int DISMISS_AGED = 2;
109 static final int DISMISS_TASK_FINISHED = 3;
110 static final int DISMISS_BLOCKED = 4;
111 static final int DISMISS_NOTIF_CANCEL = 5;
112 static final int DISMISS_ACCESSIBILITY_ACTION = 6;
Mady Melloraa8fef22019-04-11 13:36:40 -0700113 static final int DISMISS_NO_LONGER_BUBBLE = 7;
Mark Renouf08bc42a2019-03-07 13:01:59 -0500114
Joshua Tsuji4accf5982019-04-22 17:36:11 -0400115 public static final int MAX_BUBBLES = 5; // TODO: actually enforce this
Joshua Tsuji25a4b7b2019-03-22 14:11:06 -0400116
Mady Mellor5549dd22018-11-06 18:07:34 -0800117 // Enables some subset of notifs to automatically become bubbles
Mady Mellorca0c24c2019-05-16 16:14:32 -0700118 public static final boolean DEBUG_ENABLE_AUTO_BUBBLE = false;
Mady Mellor5549dd22018-11-06 18:07:34 -0800119
Mady Mellor44ee2fe2019-01-30 17:51:16 -0800120 /** Flag to enable or disable the entire feature */
Mady Mellorf6e3ac02019-01-29 10:37:52 -0800121 private static final String ENABLE_BUBBLES = "experiment_enable_bubbles";
Mady Mellor44ee2fe2019-01-30 17:51:16 -0800122 /** Auto bubble flags set whether different notif types should be presented as a bubble */
Mady Mellorceced172018-11-27 11:18:39 -0800123 private static final String ENABLE_AUTO_BUBBLE_MESSAGES = "experiment_autobubble_messaging";
124 private static final String ENABLE_AUTO_BUBBLE_ONGOING = "experiment_autobubble_ongoing";
125 private static final String ENABLE_AUTO_BUBBLE_ALL = "experiment_autobubble_all";
Mady Mellor44ee2fe2019-01-30 17:51:16 -0800126
127 /** Use an activityView for an auto-bubbled notifs if it has an appropriate content intent */
Mark Renouf89b1a4a2018-12-04 14:59:45 -0500128 private static final String ENABLE_BUBBLE_CONTENT_INTENT = "experiment_bubble_content_intent";
Mady Mellorceced172018-11-27 11:18:39 -0800129
Joshua Tsuji010c2b12019-02-25 18:11:25 -0500130 private static final String BUBBLE_STIFFNESS = "experiment_bubble_stiffness";
131 private static final String BUBBLE_BOUNCINESS = "experiment_bubble_bounciness";
132
Ned Burns01e38212019-01-03 16:32:52 -0500133 private final Context mContext;
134 private final NotificationEntryManager mNotificationEntryManager;
Mark Renoufcecc77b2019-01-30 16:32:24 -0500135 private final IActivityTaskManager mActivityTaskManager;
136 private final BubbleTaskStackListener mTaskStackListener;
Mady Mellord1c78b262018-11-06 18:04:40 -0800137 private BubbleStateChangeListener mStateChangeListener;
Mady Mellorcd9b1302018-11-06 18:08:04 -0800138 private BubbleExpandListener mExpandListener;
Issei Suzukic0387542019-03-08 17:31:14 +0100139 @Nullable private BubbleStackView.SurfaceSynchronizer mSurfaceSynchronizer;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800140
Mady Mellor3dff9e62019-02-05 18:12:53 -0800141 private BubbleData mBubbleData;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800142 private BubbleStackView mStackView;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800143
144 // Bubbles get added to the status bar view
Ned Burns01e38212019-01-03 16:32:52 -0500145 private final StatusBarWindowController mStatusBarWindowController;
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800146 private StatusBarStateListener mStatusBarStateListener;
147
Mady Melloraa8fef22019-04-11 13:36:40 -0700148 private final NotificationInterruptionStateProvider mNotificationInterruptionStateProvider;
Mady Mellora54e9fa2019-04-18 13:26:18 -0700149 private IStatusBarService mBarService;
Mady Mellorb4991e62019-01-10 15:14:51 -0800150
Mady Mellord1c78b262018-11-06 18:04:40 -0800151 // Used for determining view rect for touch interaction
152 private Rect mTempRect = new Rect();
153
Joshua Tsujif418f9e2019-04-04 17:09:53 -0400154 /** Last known orientation, used to detect orientation changes in {@link #onConfigChanged}. */
155 private int mOrientation = Configuration.ORIENTATION_UNDEFINED;
156
Mady Mellor5549dd22018-11-06 18:07:34 -0800157 /**
Mady Mellord1c78b262018-11-06 18:04:40 -0800158 * Listener to be notified when some states of the bubbles change.
159 */
160 public interface BubbleStateChangeListener {
161 /**
162 * Called when the stack has bubbles or no longer has bubbles.
163 */
164 void onHasBubblesChanged(boolean hasBubbles);
165 }
166
Mady Mellorcd9b1302018-11-06 18:08:04 -0800167 /**
168 * Listener to find out about stack expansion / collapse events.
169 */
170 public interface BubbleExpandListener {
171 /**
172 * Called when the expansion state of the bubble stack changes.
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700173 *
Mady Mellorcd9b1302018-11-06 18:08:04 -0800174 * @param isExpanding whether it's expanding or collapsing
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800175 * @param key the notification key associated with bubble being expanded
Mady Mellorcd9b1302018-11-06 18:08:04 -0800176 */
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800177 void onBubbleExpandChanged(boolean isExpanding, String key);
178 }
179
180 /**
181 * Listens for the current state of the status bar and updates the visibility state
182 * of bubbles as needed.
183 */
184 private class StatusBarStateListener implements StatusBarStateController.StateListener {
185 private int mState;
186 /**
187 * Returns the current status bar state.
188 */
189 public int getCurrentState() {
190 return mState;
191 }
192
193 @Override
194 public void onStateChanged(int newState) {
195 mState = newState;
Mark Renouf71a3af62019-04-08 15:02:54 -0400196 boolean shouldCollapse = (mState != SHADE);
197 if (shouldCollapse) {
198 collapseStack();
199 }
Lyn Han6c40fe72019-05-08 14:06:33 -0700200 updateStack();
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800201 }
Mady Mellorcd9b1302018-11-06 18:08:04 -0800202 }
203
Jason Monk27d01a622018-12-10 15:57:09 -0500204 @Inject
Mady Mellorcfd06c12019-02-13 14:32:12 -0800205 public BubbleController(Context context, StatusBarWindowController statusBarWindowController,
Mady Melloraa8fef22019-04-11 13:36:40 -0700206 BubbleData data, ConfigurationController configurationController,
Josh Tsuji890a7952019-05-18 01:55:47 +0000207 NotificationInterruptionStateProvider interruptionStateProvider) {
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700208 this(context, statusBarWindowController, data, null /* synchronizer */,
Josh Tsuji890a7952019-05-18 01:55:47 +0000209 configurationController, interruptionStateProvider);
Issei Suzukic0387542019-03-08 17:31:14 +0100210 }
211
212 public BubbleController(Context context, StatusBarWindowController statusBarWindowController,
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700213 BubbleData data, @Nullable BubbleStackView.SurfaceSynchronizer synchronizer,
Mady Melloraa8fef22019-04-11 13:36:40 -0700214 ConfigurationController configurationController,
Josh Tsuji890a7952019-05-18 01:55:47 +0000215 NotificationInterruptionStateProvider interruptionStateProvider) {
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800216 mContext = context;
Mady Melloraa8fef22019-04-11 13:36:40 -0700217 mNotificationInterruptionStateProvider = interruptionStateProvider;
218
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700219 configurationController.addCallback(this /* configurationListener */);
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800220
Mark Renouf9ba6cea2019-04-17 11:53:50 -0400221 mBubbleData = data;
222 mBubbleData.setListener(mBubbleDataListener);
223
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800224 mNotificationEntryManager = Dependency.get(NotificationEntryManager.class);
Ned Burns01e38212019-01-03 16:32:52 -0500225 mNotificationEntryManager.addNotificationEntryListener(mEntryListener);
Mady Mellorc2ff0112019-03-28 14:18:06 -0700226 mNotificationEntryManager.setNotificationRemoveInterceptor(mRemoveInterceptor);
Mady Mellorb4991e62019-01-10 15:14:51 -0800227
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800228 mStatusBarWindowController = statusBarWindowController;
229 mStatusBarStateListener = new StatusBarStateListener();
230 Dependency.get(StatusBarStateController.class).addCallback(mStatusBarStateListener);
Mark Renoufcecc77b2019-01-30 16:32:24 -0500231
232 mActivityTaskManager = ActivityTaskManager.getService();
233 mTaskStackListener = new BubbleTaskStackListener();
234 ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener);
Mady Mellor3dff9e62019-02-05 18:12:53 -0800235
Joshua Tsujia19515f2019-02-13 18:02:29 -0500236 try {
237 WindowManagerWrapper.getInstance().addPinnedStackListener(new BubblesImeListener());
238 } catch (RemoteException e) {
239 e.printStackTrace();
240 }
Issei Suzukic0387542019-03-08 17:31:14 +0100241 mSurfaceSynchronizer = synchronizer;
Mady Mellora54e9fa2019-04-18 13:26:18 -0700242
243 mBarService = IStatusBarService.Stub.asInterface(
244 ServiceManager.getService(Context.STATUS_BAR_SERVICE));
Mady Mellor5549dd22018-11-06 18:07:34 -0800245 }
246
Mark Renouf8b6a3c62019-04-09 10:17:40 -0400247 /**
248 * BubbleStackView is lazily created by this method the first time a Bubble is added. This
249 * method initializes the stack view and adds it to the StatusBar just above the scrim.
250 */
251 private void ensureStackViewCreated() {
252 if (mStackView == null) {
253 mStackView = new BubbleStackView(mContext, mBubbleData, mSurfaceSynchronizer);
254 ViewGroup sbv = mStatusBarWindowController.getStatusBarView();
255 // TODO(b/130237686): When you expand the shade on top of expanded bubble, there is no
256 // scrim between bubble and the shade
257 int bubblePosition = sbv.indexOfChild(sbv.findViewById(R.id.scrim_behind)) + 1;
258 sbv.addView(mStackView, bubblePosition,
259 new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
260 if (mExpandListener != null) {
261 mStackView.setExpandListener(mExpandListener);
262 }
Mark Renouf8b6a3c62019-04-09 10:17:40 -0400263 }
264 }
265
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700266 @Override
267 public void onUiModeChanged() {
268 if (mStackView != null) {
Lyn Han02cca812019-04-02 16:27:32 -0700269 mStackView.onThemeChanged();
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700270 }
271 }
272
273 @Override
274 public void onOverlayChanged() {
275 if (mStackView != null) {
Lyn Han02cca812019-04-02 16:27:32 -0700276 mStackView.onThemeChanged();
Lyn Hanf1c9b8b2019-03-14 16:49:48 -0700277 }
278 }
279
Joshua Tsujif418f9e2019-04-04 17:09:53 -0400280 @Override
281 public void onConfigChanged(Configuration newConfig) {
282 if (mStackView != null && newConfig != null && newConfig.orientation != mOrientation) {
283 mStackView.onOrientationChanged();
284 mOrientation = newConfig.orientation;
285 }
286 }
287
Mady Mellor5549dd22018-11-06 18:07:34 -0800288 /**
Mady Mellord1c78b262018-11-06 18:04:40 -0800289 * Set a listener to be notified when some states of the bubbles change.
290 */
291 public void setBubbleStateChangeListener(BubbleStateChangeListener listener) {
292 mStateChangeListener = listener;
293 }
294
295 /**
Mady Mellorcd9b1302018-11-06 18:08:04 -0800296 * Set a listener to be notified of bubble expand events.
297 */
298 public void setExpandListener(BubbleExpandListener listener) {
Issei Suzukiac9fcb72019-02-04 17:45:57 +0100299 mExpandListener = ((isExpanding, key) -> {
300 if (listener != null) {
301 listener.onBubbleExpandChanged(isExpanding, key);
302 }
303 mStatusBarWindowController.setBubbleExpanded(isExpanding);
304 });
Mady Mellorcd9b1302018-11-06 18:08:04 -0800305 if (mStackView != null) {
306 mStackView.setExpandListener(mExpandListener);
307 }
308 }
309
310 /**
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800311 * Whether or not there are bubbles present, regardless of them being visible on the
312 * screen (e.g. if on AOD).
313 */
314 public boolean hasBubbles() {
Mady Mellor3dff9e62019-02-05 18:12:53 -0800315 if (mStackView == null) {
316 return false;
317 }
Mark Renouf71a3af62019-04-08 15:02:54 -0400318 return mBubbleData.hasBubbles();
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800319 }
320
321 /**
322 * Whether the stack of bubbles is expanded or not.
323 */
324 public boolean isStackExpanded() {
Mark Renouf71a3af62019-04-08 15:02:54 -0400325 return mBubbleData.isExpanded();
326 }
327
328 /**
329 * Tell the stack of bubbles to expand.
330 */
331 public void expandStack() {
332 mBubbleData.setExpanded(true);
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800333 }
334
335 /**
336 * Tell the stack of bubbles to collapse.
337 */
338 public void collapseStack() {
Mark Renouf71a3af62019-04-08 15:02:54 -0400339 mBubbleData.setExpanded(false /* expanded */);
340 }
341
342 void selectBubble(Bubble bubble) {
343 mBubbleData.setSelectedBubble(bubble);
344 }
345
346 @VisibleForTesting
347 void selectBubble(String key) {
348 Bubble bubble = mBubbleData.getBubbleWithKey(key);
349 selectBubble(bubble);
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800350 }
351
352 /**
Mark Renouffec45da2019-03-13 13:24:27 -0400353 * Request the stack expand if needed, then select the specified Bubble as current.
354 *
355 * @param notificationKey the notification key for the bubble to be selected
356 */
357 public void expandStackAndSelectBubble(String notificationKey) {
Mark Renouf71a3af62019-04-08 15:02:54 -0400358 Bubble bubble = mBubbleData.getBubbleWithKey(notificationKey);
359 if (bubble != null) {
360 mBubbleData.setSelectedBubble(bubble);
361 mBubbleData.setExpanded(true);
Mark Renouffec45da2019-03-13 13:24:27 -0400362 }
363 }
364
365 /**
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800366 * Tell the stack of bubbles to be dismissed, this will remove all of the bubbles in the stack.
367 */
Mark Renouf08bc42a2019-03-07 13:01:59 -0500368 void dismissStack(@DismissReason int reason) {
Mark Renouf71a3af62019-04-08 15:02:54 -0400369 mBubbleData.dismissAll(reason);
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800370 }
371
372 /**
Mark Renouf041d7262019-02-06 12:09:41 -0500373 * Directs a back gesture at the bubble stack. When opened, the current expanded bubble
374 * is forwarded a back key down/up pair.
375 */
376 public void performBackPressIfNeeded() {
377 if (mStackView != null) {
378 mStackView.performBackPressIfNeeded();
379 }
380 }
381
382 /**
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800383 * Adds or updates a bubble associated with the provided notification entry.
384 *
Mark Renouf8b6a3c62019-04-09 10:17:40 -0400385 * @param notif the notification associated with this bubble.
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800386 */
Mark Renouff97ed462019-04-05 13:46:24 -0400387 void updateBubble(NotificationEntry notif) {
Mady Mellor66efd5e2019-05-15 13:38:11 -0700388 // If this is an interruptive notif, mark that it's interrupted
389 if (notif.importance >= NotificationManager.IMPORTANCE_HIGH) {
390 notif.setInterruption();
391 }
Mark Renouf71a3af62019-04-08 15:02:54 -0400392 mBubbleData.notificationEntryUpdated(notif);
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800393 }
394
395 /**
396 * Removes the bubble associated with the {@param uri}.
Mark Renouf658c6bc2019-01-30 10:26:54 -0500397 * <p>
398 * Must be called from the main thread.
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800399 */
Mark Renouf658c6bc2019-01-30 10:26:54 -0500400 @MainThread
Mark Renouf08bc42a2019-03-07 13:01:59 -0500401 void removeBubble(String key, int reason) {
Mark Renouf71a3af62019-04-08 15:02:54 -0400402 // TEMP: refactor to change this to pass entry
403 Bubble bubble = mBubbleData.getBubbleWithKey(key);
404 if (bubble != null) {
405 mBubbleData.notificationEntryRemoved(bubble.entry, reason);
Mady Mellore8e07712019-01-23 12:45:33 -0800406 }
407 }
408
Ned Burns01e38212019-01-03 16:32:52 -0500409 @SuppressWarnings("FieldCanBeLocal")
Mady Mellorc2ff0112019-03-28 14:18:06 -0700410 private final NotificationRemoveInterceptor mRemoveInterceptor =
411 new NotificationRemoveInterceptor() {
412 @Override
413 public boolean onNotificationRemoveRequested(String key, int reason) {
414 if (!mBubbleData.hasBubbleWithKey(key)) {
415 return false;
416 }
417 NotificationEntry entry = mBubbleData.getBubbleWithKey(key).entry;
418
419 final boolean isClearAll = reason == REASON_CANCEL_ALL;
420 final boolean isUserDimiss = reason == REASON_CANCEL;
421 final boolean isAppCancel = reason == REASON_APP_CANCEL
422 || reason == REASON_APP_CANCEL_ALL;
423
424 // Need to check for !appCancel here because the notification may have
425 // previously been dismissed & entry.isRowDismissed would still be true
426 boolean userRemovedNotif = (entry.isRowDismissed() && !isAppCancel)
427 || isClearAll || isUserDimiss;
428
429 // The bubble notification sticks around in the data as long as the bubble is
430 // not dismissed and the app hasn't cancelled the notification.
431 boolean bubbleExtended = entry.isBubble() && !entry.isBubbleDismissed()
432 && userRemovedNotif;
433 if (bubbleExtended) {
434 entry.setShowInShadeWhenBubble(false);
435 if (mStackView != null) {
436 mStackView.updateDotVisibility(entry.key);
437 }
438 mNotificationEntryManager.updateNotifications();
439 return true;
440 } else if (!userRemovedNotif && !entry.isBubbleDismissed()) {
441 // This wasn't a user removal so we should remove the bubble as well
442 mBubbleData.notificationEntryRemoved(entry, DISMISS_NOTIF_CANCEL);
443 return false;
444 }
445 return false;
446 }
447 };
448
449 @SuppressWarnings("FieldCanBeLocal")
Ned Burns01e38212019-01-03 16:32:52 -0500450 private final NotificationEntryListener mEntryListener = new NotificationEntryListener() {
451 @Override
Ned Burnsf81c4c42019-01-07 14:10:43 -0500452 public void onPendingEntryAdded(NotificationEntry entry) {
Mady Mellorf6e3ac02019-01-29 10:37:52 -0800453 if (!areBubblesEnabled(mContext)) {
454 return;
455 }
Mady Mellorca0c24c2019-05-16 16:14:32 -0700456 if (mNotificationInterruptionStateProvider.shouldBubbleUp(entry)
457 && canLaunchInActivityView(mContext, entry)) {
Mady Mellor8a1f0252019-04-01 11:31:34 -0700458 updateShowInShadeForSuppressNotification(entry);
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800459 }
460 }
461
462 @Override
Ned Burns1a5e22f2019-02-14 15:11:52 -0500463 public void onEntryInflated(NotificationEntry entry, @InflationFlag int inflatedFlags) {
Mady Mellorf6e3ac02019-01-29 10:37:52 -0800464 if (!areBubblesEnabled(mContext)) {
465 return;
466 }
Mady Mellorca0c24c2019-05-16 16:14:32 -0700467 if (mNotificationInterruptionStateProvider.shouldBubbleUp(entry)
468 && canLaunchInActivityView(mContext, entry)) {
Mark Renouff97ed462019-04-05 13:46:24 -0400469 updateBubble(entry);
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800470 }
471 }
472
473 @Override
474 public void onPreEntryUpdated(NotificationEntry entry) {
Mady Mellorf6e3ac02019-01-29 10:37:52 -0800475 if (!areBubblesEnabled(mContext)) {
476 return;
477 }
Mady Mellorca0c24c2019-05-16 16:14:32 -0700478 boolean shouldBubble = mNotificationInterruptionStateProvider.shouldBubbleUp(entry)
479 && canLaunchInActivityView(mContext, entry);
Mady Melloraa8fef22019-04-11 13:36:40 -0700480 if (!shouldBubble && mBubbleData.hasBubbleWithKey(entry.key)) {
481 // It was previously a bubble but no longer a bubble -- lets remove it
482 removeBubble(entry.key, DISMISS_NO_LONGER_BUBBLE);
Mady Mellorff40e012019-05-03 15:34:41 -0700483 } else if (shouldBubble) {
Mady Mellor8a1f0252019-04-01 11:31:34 -0700484 updateShowInShadeForSuppressNotification(entry);
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800485 entry.setBubbleDismissed(false); // updates come back as bubbles even if dismissed
Mark Renouff97ed462019-04-05 13:46:24 -0400486 updateBubble(entry);
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800487 }
488 }
Ned Burns01e38212019-01-03 16:32:52 -0500489 };
490
Mark Renouf71a3af62019-04-08 15:02:54 -0400491 @SuppressWarnings("FieldCanBeLocal")
Mark Renouf3bc5b362019-04-05 14:37:59 -0400492 private final BubbleData.Listener mBubbleDataListener = new BubbleData.Listener() {
Mark Renouf71a3af62019-04-08 15:02:54 -0400493
Mark Renouf3bc5b362019-04-05 14:37:59 -0400494 @Override
495 public void onBubbleAdded(Bubble bubble) {
Mark Renouf71a3af62019-04-08 15:02:54 -0400496 ensureStackViewCreated();
497 mStackView.addBubble(bubble);
Mark Renouf3bc5b362019-04-05 14:37:59 -0400498 }
499
500 @Override
Mady Mellorc2ff0112019-03-28 14:18:06 -0700501 public void onBubbleRemoved(Bubble bubble, @DismissReason int reason) {
Mark Renouf71a3af62019-04-08 15:02:54 -0400502 if (mStackView != null) {
503 mStackView.removeBubble(bubble);
504 }
Mady Mellorc2ff0112019-03-28 14:18:06 -0700505 if (!mBubbleData.hasBubbleWithKey(bubble.getKey())
506 && !bubble.entry.showInShadeWhenBubble()) {
507 // The bubble is gone & the notification is gone, time to actually remove it
508 mNotificationEntryManager.performRemoveNotification(bubble.entry.notification,
Mady Mellor1a4e86f2019-05-03 16:07:23 -0700509 UNDEFINED_DISMISS_REASON);
Mady Mellora54e9fa2019-04-18 13:26:18 -0700510 } else {
511 // The notification is still in the shade but we've removed the bubble so
512 // lets make sure NoMan knows it's not a bubble anymore
513 try {
514 mBarService.onNotificationBubbleChanged(bubble.getKey(), false /* isBubble */);
515 } catch (RemoteException e) {
516 // Bad things have happened
517 }
518 }
Mark Renouf3bc5b362019-04-05 14:37:59 -0400519 }
520
521 public void onBubbleUpdated(Bubble bubble) {
Mark Renouf71a3af62019-04-08 15:02:54 -0400522 if (mStackView != null) {
523 mStackView.updateBubble(bubble);
524 }
Mark Renouf3bc5b362019-04-05 14:37:59 -0400525 }
526
527 @Override
528 public void onOrderChanged(List<Bubble> bubbles) {
Mark Renoufba5ab512019-05-02 15:21:01 -0400529 if (mStackView != null) {
530 mStackView.updateBubbleOrder(bubbles);
531 }
Mark Renouf3bc5b362019-04-05 14:37:59 -0400532 }
533
534 @Override
Mark Renouf9ba6cea2019-04-17 11:53:50 -0400535 public void onSelectionChanged(@Nullable Bubble selectedBubble) {
Mark Renouf71a3af62019-04-08 15:02:54 -0400536 if (mStackView != null) {
537 mStackView.setSelectedBubble(selectedBubble);
538 }
Mark Renouf3bc5b362019-04-05 14:37:59 -0400539 }
540
541 @Override
542 public void onExpandedChanged(boolean expanded) {
Mark Renouf71a3af62019-04-08 15:02:54 -0400543 if (mStackView != null) {
544 mStackView.setExpanded(expanded);
545 }
Mark Renouf3bc5b362019-04-05 14:37:59 -0400546 }
547
Lyn Han6c40fe72019-05-08 14:06:33 -0700548 // Runs on state change.
Mark Renouf3bc5b362019-04-05 14:37:59 -0400549 @Override
Mark Renouf3bc5b362019-04-05 14:37:59 -0400550 public void apply() {
Mark Renouf71a3af62019-04-08 15:02:54 -0400551 mNotificationEntryManager.updateNotifications();
Lyn Han6c40fe72019-05-08 14:06:33 -0700552 updateStack();
Mark Renouf9ba6cea2019-04-17 11:53:50 -0400553
554 if (DEBUG) {
555 Log.d(TAG, "[BubbleData]");
556 Log.d(TAG, formatBubblesString(mBubbleData.getBubbles(),
557 mBubbleData.getSelectedBubble()));
558
559 if (mStackView != null) {
560 Log.d(TAG, "[BubbleStackView]");
561 Log.d(TAG, formatBubblesString(mStackView.getBubblesOnScreen(),
562 mStackView.getExpandedBubble()));
563 }
564 }
Mark Renouf3bc5b362019-04-05 14:37:59 -0400565 }
566 };
567
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800568 /**
Lyn Han6c40fe72019-05-08 14:06:33 -0700569 * Updates the visibility of the bubbles based on current state.
570 * Does not un-bubble, just hides or un-hides. Notifies any
571 * {@link BubbleStateChangeListener}s of visibility changes.
572 * Updates stack description for TalkBack focus.
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800573 */
Lyn Han6c40fe72019-05-08 14:06:33 -0700574 public void updateStack() {
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800575 if (mStackView == null) {
576 return;
Mady Mellord1c78b262018-11-06 18:04:40 -0800577 }
Mady Mellor3f2efdb2018-11-21 11:30:45 -0800578 if (mStatusBarStateListener.getCurrentState() == SHADE && hasBubbles()) {
579 // Bubbles only appear in unlocked shade
580 mStackView.setVisibility(hasBubbles() ? VISIBLE : INVISIBLE);
581 } else if (mStackView != null) {
582 mStackView.setVisibility(INVISIBLE);
Mady Mellor5549dd22018-11-06 18:07:34 -0800583 }
Lyn Han6c40fe72019-05-08 14:06:33 -0700584
585 // Let listeners know if bubble state changed.
586 boolean hadBubbles = mStatusBarWindowController.getBubblesShowing();
587 boolean hasBubblesShowing = hasBubbles() && mStackView.getVisibility() == VISIBLE;
588 mStatusBarWindowController.setBubblesShowing(hasBubblesShowing);
589 if (mStateChangeListener != null && hadBubbles != hasBubblesShowing) {
590 mStateChangeListener.onHasBubblesChanged(hasBubblesShowing);
591 }
592
593 mStackView.updateContentDescription();
Mady Mellord1c78b262018-11-06 18:04:40 -0800594 }
595
596 /**
597 * Rect indicating the touchable region for the bubble stack / expanded stack.
598 */
599 public Rect getTouchableRegion() {
600 if (mStackView == null || mStackView.getVisibility() != VISIBLE) {
601 return null;
602 }
603 mStackView.getBoundsOnScreen(mTempRect);
604 return mTempRect;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800605 }
606
Mady Mellor390bff42019-04-05 15:09:01 -0700607 /**
608 * The display id of the expanded view, if the stack is expanded and not occluded by the
609 * status bar, otherwise returns {@link Display#INVALID_DISPLAY}.
610 */
611 public int getExpandedDisplayId(Context context) {
Joel Galenson4071ddb2019-04-18 13:30:45 -0700612 if (mStackView == null) {
613 return INVALID_DISPLAY;
614 }
Mady Mellor390bff42019-04-05 15:09:01 -0700615 boolean defaultDisplay = context.getDisplay() != null
616 && context.getDisplay().getDisplayId() == DEFAULT_DISPLAY;
617 Bubble b = mStackView.getExpandedBubble();
618 if (defaultDisplay && b != null && isStackExpanded()
619 && !mStatusBarWindowController.getPanelExpanded()) {
620 return b.expandedView.getVirtualDisplayId();
621 }
622 return INVALID_DISPLAY;
623 }
624
Mady Mellorf6e3ac02019-01-29 10:37:52 -0800625 @VisibleForTesting
626 BubbleStackView getStackView() {
627 return mStackView;
628 }
629
Mady Mellor5549dd22018-11-06 18:07:34 -0800630 /**
Mady Mellorf6e3ac02019-01-29 10:37:52 -0800631 * Whether the notification should automatically bubble or not. Gated by secure settings flags.
Mady Mellor5549dd22018-11-06 18:07:34 -0800632 */
Mady Mellor9bad2242019-01-28 11:21:51 -0800633 @VisibleForTesting
Mady Mellorf6e3ac02019-01-29 10:37:52 -0800634 protected boolean shouldAutoBubbleForFlags(Context context, NotificationEntry entry) {
Mady Mellorceced172018-11-27 11:18:39 -0800635 if (entry.isBubbleDismissed()) {
Mady Mellor5549dd22018-11-06 18:07:34 -0800636 return false;
637 }
Mady Mellorb4991e62019-01-10 15:14:51 -0800638 StatusBarNotification n = entry.notification;
Mady Mellorceced172018-11-27 11:18:39 -0800639
640 boolean autoBubbleMessages = shouldAutoBubbleMessages(context) || DEBUG_ENABLE_AUTO_BUBBLE;
641 boolean autoBubbleOngoing = shouldAutoBubbleOngoing(context) || DEBUG_ENABLE_AUTO_BUBBLE;
642 boolean autoBubbleAll = shouldAutoBubbleAll(context) || DEBUG_ENABLE_AUTO_BUBBLE;
643
Mady Mellor5549dd22018-11-06 18:07:34 -0800644 boolean hasRemoteInput = false;
645 if (n.getNotification().actions != null) {
646 for (Notification.Action action : n.getNotification().actions) {
647 if (action.getRemoteInputs() != null) {
648 hasRemoteInput = true;
649 break;
650 }
651 }
652 }
Mady Mellor711f9562018-12-05 14:53:46 -0800653 boolean isCall = Notification.CATEGORY_CALL.equals(n.getNotification().category)
654 && n.isOngoing();
655 boolean isMusic = n.getNotification().hasMediaSession();
656 boolean isImportantOngoing = isMusic || isCall;
Mady Mellorceced172018-11-27 11:18:39 -0800657
Mady Mellor5549dd22018-11-06 18:07:34 -0800658 Class<? extends Notification.Style> style = n.getNotification().getNotificationStyle();
Mady Mellore3175372018-12-04 17:05:11 -0800659 boolean isMessageType = Notification.CATEGORY_MESSAGE.equals(n.getNotification().category);
660 boolean isMessageStyle = Notification.MessagingStyle.class.equals(style);
Mady Mellorf6e3ac02019-01-29 10:37:52 -0800661 return (((isMessageType && hasRemoteInput) || isMessageStyle) && autoBubbleMessages)
Mady Mellor711f9562018-12-05 14:53:46 -0800662 || (isImportantOngoing && autoBubbleOngoing)
Mady Mellorceced172018-11-27 11:18:39 -0800663 || autoBubbleAll;
664 }
665
Mady Mellor8a1f0252019-04-01 11:31:34 -0700666 private void updateShowInShadeForSuppressNotification(NotificationEntry entry) {
667 boolean suppressNotification = entry.getBubbleMetadata() != null
Mady Mellorc529d6d2019-04-16 14:22:52 -0700668 && entry.getBubbleMetadata().isNotificationSuppressed()
Steven Wu8ba8ca92019-04-11 10:47:42 -0400669 && isForegroundApp(mContext, entry.notification.getPackageName());
Mady Mellor8a1f0252019-04-01 11:31:34 -0700670 entry.setShowInShadeWhenBubble(!suppressNotification);
671 }
672
Mark Renouf9ba6cea2019-04-17 11:53:50 -0400673 static String formatBubblesString(List<Bubble> bubbles, Bubble selected) {
674 StringBuilder sb = new StringBuilder();
675 for (Bubble bubble : bubbles) {
676 if (bubble == null) {
677 sb.append(" <null> !!!!!\n");
678 } else {
679 boolean isSelected = (bubble == selected);
680 sb.append(String.format("%s Bubble{act=%12d, ongoing=%d, key=%s}\n",
681 ((isSelected) ? "->" : " "),
682 bubble.getLastActivity(),
683 (bubble.isOngoing() ? 1 : 0),
684 bubble.getKey()));
685 }
686 }
687 return sb.toString();
688 }
689
Mady Mellore80930e2019-03-21 16:00:45 -0700690 /**
691 * Return true if the applications with the package name is running in foreground.
692 *
Steven Wu8ba8ca92019-04-11 10:47:42 -0400693 * @param context application context.
Mady Mellore80930e2019-03-21 16:00:45 -0700694 * @param pkgName application package name.
695 */
Steven Wu8ba8ca92019-04-11 10:47:42 -0400696 public static boolean isForegroundApp(Context context, String pkgName) {
697 ActivityManager am = context.getSystemService(ActivityManager.class);
Mady Mellore80930e2019-03-21 16:00:45 -0700698 List<RunningTaskInfo> tasks = am.getRunningTasks(1 /* maxNum */);
699 return !tasks.isEmpty() && pkgName.equals(tasks.get(0).topActivity.getPackageName());
700 }
701
Mark Renoufcecc77b2019-01-30 16:32:24 -0500702 /**
703 * This task stack listener is responsible for responding to tasks moved to the front
704 * which are on the default (main) display. When this happens, expanded bubbles must be
705 * collapsed so the user may interact with the app which was just moved to the front.
706 * <p>
707 * This listener is registered with SystemUI's ActivityManagerWrapper which dispatches
708 * these calls via a main thread Handler.
709 */
710 @MainThread
711 private class BubbleTaskStackListener extends TaskStackChangeListener {
712
Mark Renoufcecc77b2019-01-30 16:32:24 -0500713 @Override
Mark Renoufc808f062019-02-07 15:20:37 -0500714 public void onTaskMovedToFront(RunningTaskInfo taskInfo) {
715 if (mStackView != null && taskInfo.displayId == Display.DEFAULT_DISPLAY) {
Mark Renouf71a3af62019-04-08 15:02:54 -0400716 mBubbleData.setExpanded(false);
Mark Renoufcecc77b2019-01-30 16:32:24 -0500717 }
718 }
719
Mark Renoufcecc77b2019-01-30 16:32:24 -0500720 @Override
Mark Renoufa12e8762019-03-07 15:43:01 -0500721 public void onActivityLaunchOnSecondaryDisplayRerouted() {
Mark Renoufcecc77b2019-01-30 16:32:24 -0500722 if (mStackView != null) {
Mark Renouf71a3af62019-04-08 15:02:54 -0400723 mBubbleData.setExpanded(false);
Mark Renoufcecc77b2019-01-30 16:32:24 -0500724 }
725 }
Mark Renouf446251d2019-04-26 10:22:41 -0400726
727 @Override
728 public void onBackPressedOnTaskRoot(RunningTaskInfo taskInfo) {
729 if (mStackView != null && taskInfo.displayId == getExpandedDisplayId(mContext)) {
730 mBubbleData.setExpanded(false);
731 }
732 }
Mark Renoufcecc77b2019-01-30 16:32:24 -0500733 }
734
Mady Mellorceced172018-11-27 11:18:39 -0800735 private static boolean shouldAutoBubbleMessages(Context context) {
736 return Settings.Secure.getInt(context.getContentResolver(),
737 ENABLE_AUTO_BUBBLE_MESSAGES, 0) != 0;
738 }
739
740 private static boolean shouldAutoBubbleOngoing(Context context) {
741 return Settings.Secure.getInt(context.getContentResolver(),
742 ENABLE_AUTO_BUBBLE_ONGOING, 0) != 0;
743 }
744
745 private static boolean shouldAutoBubbleAll(Context context) {
746 return Settings.Secure.getInt(context.getContentResolver(),
747 ENABLE_AUTO_BUBBLE_ALL, 0) != 0;
Mady Mellor5549dd22018-11-06 18:07:34 -0800748 }
Mark Renouf89b1a4a2018-12-04 14:59:45 -0500749
Mady Mellor3dff9e62019-02-05 18:12:53 -0800750 static boolean shouldUseContentIntent(Context context) {
Mark Renouf89b1a4a2018-12-04 14:59:45 -0500751 return Settings.Secure.getInt(context.getContentResolver(),
752 ENABLE_BUBBLE_CONTENT_INTENT, 0) != 0;
753 }
Mady Mellorf6e3ac02019-01-29 10:37:52 -0800754
755 private static boolean areBubblesEnabled(Context context) {
756 return Settings.Secure.getInt(context.getContentResolver(),
757 ENABLE_BUBBLES, 1) != 0;
758 }
Joshua Tsujia19515f2019-02-13 18:02:29 -0500759
Joshua Tsuji010c2b12019-02-25 18:11:25 -0500760 /** Default stiffness to use for bubble physics animations. */
761 public static int getBubbleStiffness(Context context, int defaultStiffness) {
762 return Settings.Secure.getInt(
763 context.getContentResolver(), BUBBLE_STIFFNESS, defaultStiffness);
764 }
765
766 /** Default bounciness/damping ratio to use for bubble physics animations. */
767 public static float getBubbleBounciness(Context context, float defaultBounciness) {
768 return Settings.Secure.getInt(
769 context.getContentResolver(),
770 BUBBLE_BOUNCINESS,
771 (int) (defaultBounciness * 100)) / 100f;
772 }
773
Mady Mellorca0c24c2019-05-16 16:14:32 -0700774 /**
775 * Whether an intent is properly configured to display in an {@link android.app.ActivityView}.
776 *
777 * Keep checks in sync with NotificationManagerService#canLaunchInActivityView. Typically
778 * that should filter out any invalid bubbles, but should protect SysUI side just in case.
779 *
780 * @param context the context to use.
781 * @param entry the entry to bubble.
782 */
783 static boolean canLaunchInActivityView(Context context, NotificationEntry entry) {
784 PendingIntent intent = entry.getBubbleMetadata() != null
785 ? entry.getBubbleMetadata().getIntent()
786 : null;
787 if (intent == null) {
788 Log.w(TAG, "Unable to create bubble -- no intent");
789 return false;
790 }
791 ActivityInfo info =
792 intent.getIntent().resolveActivityInfo(context.getPackageManager(), 0);
793 if (info == null) {
794 Log.w(TAG, "Unable to send as bubble -- couldn't find activity info for intent: "
795 + intent);
796 return false;
797 }
798 if (!ActivityInfo.isResizeableMode(info.resizeMode)) {
799 Log.w(TAG, "Unable to send as bubble -- activity is not resizable for intent: "
800 + intent);
801 return false;
802 }
803 if (info.documentLaunchMode != DOCUMENT_LAUNCH_ALWAYS) {
804 Log.w(TAG, "Unable to send as bubble -- activity is not documentLaunchMode=always "
805 + "for intent: " + intent);
806 return false;
807 }
808 if ((info.flags & ActivityInfo.FLAG_ALLOW_EMBEDDED) == 0) {
809 Log.w(TAG, "Unable to send as bubble -- activity is not embeddable for intent: "
810 + intent);
811 return false;
812 }
813 return true;
814 }
815
Joshua Tsujia19515f2019-02-13 18:02:29 -0500816 /** PinnedStackListener that dispatches IME visibility updates to the stack. */
817 private class BubblesImeListener extends IPinnedStackListener.Stub {
818
819 @Override
820 public void onListenerRegistered(IPinnedStackController controller) throws RemoteException {
821 }
822
823 @Override
824 public void onMovementBoundsChanged(Rect insetBounds, Rect normalBounds,
825 Rect animatingBounds, boolean fromImeAdjustment, boolean fromShelfAdjustment,
826 int displayRotation) throws RemoteException {}
827
828 @Override
Joshua Tsujid9422832019-03-05 13:32:37 -0500829 public void onImeVisibilityChanged(boolean imeVisible, int imeHeight) {
830 if (mStackView != null && mStackView.getBubbleCount() > 0) {
831 mStackView.post(() -> mStackView.onImeVisibilityChanged(imeVisible, imeHeight));
Joshua Tsujia19515f2019-02-13 18:02:29 -0500832 }
833 }
834
835 @Override
836 public void onShelfVisibilityChanged(boolean shelfVisible, int shelfHeight)
837 throws RemoteException {}
838
839 @Override
840 public void onMinimizedStateChanged(boolean isMinimized) throws RemoteException {}
841
842 @Override
843 public void onActionsChanged(ParceledListSlice actions) throws RemoteException {}
844 }
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800845}