blob: 79ee4b85f887800728a07a33a7089e8839b8ec69 [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 Mellord1c78b262018-11-06 18:04:40 -080019import static android.view.View.INVISIBLE;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080020import static android.view.View.VISIBLE;
21import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
22
23import static com.android.systemui.bubbles.BubbleMovementHelper.EDGE_OVERLAP;
24
Mady Mellorb4991e62019-01-10 15:14:51 -080025import android.annotation.Nullable;
26import android.app.INotificationManager;
Mady Mellor5549dd22018-11-06 18:07:34 -080027import android.app.Notification;
Mark Renouf89b1a4a2018-12-04 14:59:45 -050028import android.app.PendingIntent;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080029import android.content.Context;
Mark Renouf89b1a4a2018-12-04 14:59:45 -050030import android.content.pm.ActivityInfo;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080031import android.graphics.Point;
Mady Mellord1c78b262018-11-06 18:04:40 -080032import android.graphics.Rect;
Mady Mellorb4991e62019-01-10 15:14:51 -080033import android.os.RemoteException;
34import android.os.ServiceManager;
Mady Mellorceced172018-11-27 11:18:39 -080035import android.provider.Settings;
Mady Mellor5549dd22018-11-06 18:07:34 -080036import android.service.notification.StatusBarNotification;
Mark Renouf89b1a4a2018-12-04 14:59:45 -050037import android.util.Log;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080038import android.view.ViewGroup;
39import android.view.WindowManager;
40import android.widget.FrameLayout;
41
Mady Mellorebdbbb92018-11-15 14:36:48 -080042import com.android.internal.annotations.VisibleForTesting;
Ned Burns01e38212019-01-03 16:32:52 -050043import com.android.systemui.Dependency;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080044import com.android.systemui.R;
Ned Burns01e38212019-01-03 16:32:52 -050045import com.android.systemui.statusbar.notification.NotificationEntryListener;
46import com.android.systemui.statusbar.notification.NotificationEntryManager;
Ned Burnsf81c4c42019-01-07 14:10:43 -050047import com.android.systemui.statusbar.notification.collection.NotificationEntry;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080048import com.android.systemui.statusbar.phone.StatusBarWindowController;
49
Mady Mellor5549dd22018-11-06 18:07:34 -080050import java.util.ArrayList;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080051import java.util.HashMap;
52import java.util.Map;
53
Jason Monk27d01a622018-12-10 15:57:09 -050054import javax.inject.Inject;
55import javax.inject.Singleton;
56
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080057/**
58 * Bubbles are a special type of content that can "float" on top of other apps or System UI.
59 * Bubbles can be expanded to show more content.
60 *
61 * The controller manages addition, removal, and visible state of bubbles on screen.
62 */
Jason Monk27d01a622018-12-10 15:57:09 -050063@Singleton
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080064public class BubbleController {
65 private static final int MAX_BUBBLES = 5; // TODO: actually enforce this
66
67 private static final String TAG = "BubbleController";
68
Mady Mellor5549dd22018-11-06 18:07:34 -080069 // Enables some subset of notifs to automatically become bubbles
Ned Burns01e38212019-01-03 16:32:52 -050070 private static final boolean DEBUG_ENABLE_AUTO_BUBBLE = false;
Mady Mellor5549dd22018-11-06 18:07:34 -080071 // When a bubble is dismissed, recreate it as a notification
Ned Burns01e38212019-01-03 16:32:52 -050072 private static final boolean DEBUG_DEMOTE_TO_NOTIF = false;
Mady Mellor5549dd22018-11-06 18:07:34 -080073
Mady Mellorceced172018-11-27 11:18:39 -080074 // Secure settings
75 private static final String ENABLE_AUTO_BUBBLE_MESSAGES = "experiment_autobubble_messaging";
76 private static final String ENABLE_AUTO_BUBBLE_ONGOING = "experiment_autobubble_ongoing";
77 private static final String ENABLE_AUTO_BUBBLE_ALL = "experiment_autobubble_all";
Mark Renouf89b1a4a2018-12-04 14:59:45 -050078 private static final String ENABLE_BUBBLE_ACTIVITY_VIEW = "experiment_bubble_activity_view";
79 private static final String ENABLE_BUBBLE_CONTENT_INTENT = "experiment_bubble_content_intent";
Mady Mellorceced172018-11-27 11:18:39 -080080
Ned Burns01e38212019-01-03 16:32:52 -050081 private final Context mContext;
82 private final NotificationEntryManager mNotificationEntryManager;
Mady Mellord1c78b262018-11-06 18:04:40 -080083 private BubbleStateChangeListener mStateChangeListener;
Mady Mellorcd9b1302018-11-06 18:08:04 -080084 private BubbleExpandListener mExpandListener;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080085
Ned Burns01e38212019-01-03 16:32:52 -050086 private final Map<String, BubbleView> mBubbles = new HashMap<>();
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080087 private BubbleStackView mStackView;
Ned Burns01e38212019-01-03 16:32:52 -050088 private final Point mDisplaySize;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080089
90 // Bubbles get added to the status bar view
Ned Burns01e38212019-01-03 16:32:52 -050091 private final StatusBarWindowController mStatusBarWindowController;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -080092
Mady Mellorb4991e62019-01-10 15:14:51 -080093 private INotificationManager mNotificationManagerService;
94
Mady Mellord1c78b262018-11-06 18:04:40 -080095 // Used for determining view rect for touch interaction
96 private Rect mTempRect = new Rect();
97
Mady Mellor5549dd22018-11-06 18:07:34 -080098 /**
Mady Mellord1c78b262018-11-06 18:04:40 -080099 * Listener to be notified when some states of the bubbles change.
100 */
101 public interface BubbleStateChangeListener {
102 /**
103 * Called when the stack has bubbles or no longer has bubbles.
104 */
105 void onHasBubblesChanged(boolean hasBubbles);
106 }
107
Mady Mellorcd9b1302018-11-06 18:08:04 -0800108 /**
109 * Listener to find out about stack expansion / collapse events.
110 */
111 public interface BubbleExpandListener {
112 /**
113 * Called when the expansion state of the bubble stack changes.
114 *
115 * @param isExpanding whether it's expanding or collapsing
116 * @param amount fraction of how expanded or collapsed it is, 1 being fully, 0 at the start
117 */
118 void onBubbleExpandChanged(boolean isExpanding, float amount);
119 }
120
Jason Monk27d01a622018-12-10 15:57:09 -0500121 @Inject
Jason Monk92d5c242018-12-21 14:37:34 -0500122 public BubbleController(Context context, StatusBarWindowController statusBarWindowController) {
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800123 mContext = context;
Ned Burns01e38212019-01-03 16:32:52 -0500124 mNotificationEntryManager = Dependency.get(NotificationEntryManager.class);
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800125 WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
126 mDisplaySize = new Point();
127 wm.getDefaultDisplay().getSize(mDisplaySize);
Jason Monk92d5c242018-12-21 14:37:34 -0500128 mStatusBarWindowController = statusBarWindowController;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800129
Ned Burns01e38212019-01-03 16:32:52 -0500130 mNotificationEntryManager.addNotificationEntryListener(mEntryListener);
Mady Mellorb4991e62019-01-10 15:14:51 -0800131
132 try {
133 mNotificationManagerService = INotificationManager.Stub.asInterface(
134 ServiceManager.getServiceOrThrow(Context.NOTIFICATION_SERVICE));
135 } catch (ServiceManager.ServiceNotFoundException e) {
136 e.printStackTrace();
137 }
Mady Mellor5549dd22018-11-06 18:07:34 -0800138 }
139
140 /**
Mady Mellord1c78b262018-11-06 18:04:40 -0800141 * Set a listener to be notified when some states of the bubbles change.
142 */
143 public void setBubbleStateChangeListener(BubbleStateChangeListener listener) {
144 mStateChangeListener = listener;
145 }
146
147 /**
Mady Mellorcd9b1302018-11-06 18:08:04 -0800148 * Set a listener to be notified of bubble expand events.
149 */
150 public void setExpandListener(BubbleExpandListener listener) {
151 mExpandListener = listener;
152 if (mStackView != null) {
153 mStackView.setExpandListener(mExpandListener);
154 }
155 }
156
157 /**
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800158 * Whether or not there are bubbles present, regardless of them being visible on the
159 * screen (e.g. if on AOD).
160 */
161 public boolean hasBubbles() {
162 return mBubbles.size() > 0;
163 }
164
165 /**
166 * Whether the stack of bubbles is expanded or not.
167 */
168 public boolean isStackExpanded() {
169 return mStackView != null && mStackView.isExpanded();
170 }
171
172 /**
173 * Tell the stack of bubbles to collapse.
174 */
175 public void collapseStack() {
176 if (mStackView != null) {
177 mStackView.animateExpansion(false);
178 }
179 }
180
181 /**
182 * Tell the stack of bubbles to be dismissed, this will remove all of the bubbles in the stack.
183 */
Ned Burns01e38212019-01-03 16:32:52 -0500184 void dismissStack() {
Mady Mellord1c78b262018-11-06 18:04:40 -0800185 if (mStackView == null) {
186 return;
187 }
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800188 Point startPoint = getStartPoint(mStackView.getStackWidth(), mDisplaySize);
189 // Reset the position of the stack (TODO - or should we save / respect last user position?)
190 mStackView.setPosition(startPoint.x, startPoint.y);
191 for (String key: mBubbles.keySet()) {
192 removeBubble(key);
193 }
Ned Burns01e38212019-01-03 16:32:52 -0500194 mNotificationEntryManager.updateNotifications();
Mady Mellord1c78b262018-11-06 18:04:40 -0800195 updateBubblesShowing();
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800196 }
197
198 /**
199 * Adds a bubble associated with the provided notification entry or updates it if it exists.
200 */
Ned Burnsf81c4c42019-01-07 14:10:43 -0500201 public void addBubble(NotificationEntry notif) {
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800202 if (mBubbles.containsKey(notif.key)) {
203 // It's an update
204 BubbleView bubble = mBubbles.get(notif.key);
205 mStackView.updateBubble(bubble, notif);
206 } else {
207 // It's new
208 BubbleView bubble = new BubbleView(mContext);
209 bubble.setNotif(notif);
Mark Renouf89b1a4a2018-12-04 14:59:45 -0500210 if (shouldUseActivityView(mContext)) {
211 bubble.setAppOverlayIntent(getAppOverlayIntent(notif));
212 }
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800213 mBubbles.put(bubble.getKey(), bubble);
214
Mady Mellord1c78b262018-11-06 18:04:40 -0800215 boolean setPosition = mStackView != null && mStackView.getVisibility() != VISIBLE;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800216 if (mStackView == null) {
217 setPosition = true;
218 mStackView = new BubbleStackView(mContext);
Mady Mellord1c78b262018-11-06 18:04:40 -0800219 ViewGroup sbv = mStatusBarWindowController.getStatusBarView();
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800220 // XXX: Bug when you expand the shade on top of expanded bubble, there is no scrim
221 // between bubble and the shade
222 int bubblePosition = sbv.indexOfChild(sbv.findViewById(R.id.scrim_behind)) + 1;
223 sbv.addView(mStackView, bubblePosition,
224 new FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
Mady Mellorcd9b1302018-11-06 18:08:04 -0800225 if (mExpandListener != null) {
226 mStackView.setExpandListener(mExpandListener);
227 }
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800228 }
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800229 mStackView.addBubble(bubble);
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800230 if (setPosition) {
231 // Need to add the bubble to the stack before we can know the width
232 Point startPoint = getStartPoint(mStackView.getStackWidth(), mDisplaySize);
233 mStackView.setPosition(startPoint.x, startPoint.y);
Mady Mellord1c78b262018-11-06 18:04:40 -0800234 mStackView.setVisibility(VISIBLE);
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800235 }
Mady Mellord1c78b262018-11-06 18:04:40 -0800236 updateBubblesShowing();
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800237 }
238 }
239
Mark Renouf89b1a4a2018-12-04 14:59:45 -0500240 @Nullable
241 private PendingIntent getAppOverlayIntent(NotificationEntry notif) {
242 Notification notification = notif.notification.getNotification();
243 if (canLaunchInActivityView(notification.getAppOverlayIntent())) {
244 return notification.getAppOverlayIntent();
245 } else if (shouldUseContentIntent(mContext)
246 && canLaunchInActivityView(notification.contentIntent)) {
247 Log.d(TAG, "[addBubble " + notif.key
248 + "]: No appOverlayIntent, using contentIntent.");
249 return notification.contentIntent;
250 }
251 Log.d(TAG, "[addBubble " + notif.key + "]: No supported intent for ActivityView.");
252 return null;
253 }
254
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800255 /**
256 * Removes the bubble associated with the {@param uri}.
257 */
Ned Burns01e38212019-01-03 16:32:52 -0500258 void removeBubble(String key) {
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800259 BubbleView bv = mBubbles.get(key);
Mady Mellord1c78b262018-11-06 18:04:40 -0800260 if (mStackView != null && bv != null) {
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800261 mStackView.removeBubble(bv);
Mark Renouf89b1a4a2018-12-04 14:59:45 -0500262 bv.destroyActivityView(mStackView);
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800263 bv.getEntry().setBubbleDismissed(true);
264 }
Ned Burns01e38212019-01-03 16:32:52 -0500265
Ned Burnsf81c4c42019-01-07 14:10:43 -0500266 NotificationEntry entry = mNotificationEntryManager.getNotificationData().get(key);
Ned Burns01e38212019-01-03 16:32:52 -0500267 if (entry != null) {
268 entry.setBubbleDismissed(true);
269 if (!DEBUG_DEMOTE_TO_NOTIF) {
270 mNotificationEntryManager.performRemoveNotification(entry.notification);
271 }
Mady Mellor5549dd22018-11-06 18:07:34 -0800272 }
Ned Burns01e38212019-01-03 16:32:52 -0500273 mNotificationEntryManager.updateNotifications();
274
Mady Mellord1c78b262018-11-06 18:04:40 -0800275 updateBubblesShowing();
276 }
277
Ned Burns01e38212019-01-03 16:32:52 -0500278 @SuppressWarnings("FieldCanBeLocal")
279 private final NotificationEntryListener mEntryListener = new NotificationEntryListener() {
280 @Override
Ned Burnsf81c4c42019-01-07 14:10:43 -0500281 public void onPendingEntryAdded(NotificationEntry entry) {
Mady Mellorb4991e62019-01-10 15:14:51 -0800282 if (shouldAutoBubble(mContext, entry) || shouldBubble(entry)) {
Ned Burns01e38212019-01-03 16:32:52 -0500283 entry.setIsBubble(true);
284 }
285 }
286 };
287
Mady Mellord1c78b262018-11-06 18:04:40 -0800288 private void updateBubblesShowing() {
289 boolean hasBubblesShowing = false;
290 for (BubbleView bv : mBubbles.values()) {
291 if (!bv.getEntry().isBubbleDismissed()) {
292 hasBubblesShowing = true;
293 break;
294 }
295 }
296 boolean hadBubbles = mStatusBarWindowController.getBubblesShowing();
297 mStatusBarWindowController.setBubblesShowing(hasBubblesShowing);
298 if (mStackView != null && !hasBubblesShowing) {
299 mStackView.setVisibility(INVISIBLE);
300 }
301 if (mStateChangeListener != null && hadBubbles != hasBubblesShowing) {
302 mStateChangeListener.onHasBubblesChanged(hasBubblesShowing);
303 }
Mady Mellor5549dd22018-11-06 18:07:34 -0800304 }
305
306 /**
307 * Sets the visibility of the bubbles, doesn't un-bubble them, just changes visibility.
308 */
309 public void updateVisibility(boolean visible) {
310 if (mStackView == null) {
311 return;
312 }
313 ArrayList<BubbleView> viewsToRemove = new ArrayList<>();
314 for (BubbleView bv : mBubbles.values()) {
Ned Burnsf81c4c42019-01-07 14:10:43 -0500315 NotificationEntry entry = bv.getEntry();
Mady Mellor5549dd22018-11-06 18:07:34 -0800316 if (entry != null) {
Evan Laird94492852018-10-25 13:43:01 -0400317 if (entry.isRowRemoved() || entry.isBubbleDismissed() || entry.isRowDismissed()) {
Mady Mellor5549dd22018-11-06 18:07:34 -0800318 viewsToRemove.add(bv);
319 }
320 }
321 }
Mark Renouf89b1a4a2018-12-04 14:59:45 -0500322 for (BubbleView bubbleView : viewsToRemove) {
323 mBubbles.remove(bubbleView.getKey());
324 mStackView.removeBubble(bubbleView);
325 bubbleView.destroyActivityView(mStackView);
Mady Mellor5549dd22018-11-06 18:07:34 -0800326 }
327 if (mStackView != null) {
Mady Mellord1c78b262018-11-06 18:04:40 -0800328 mStackView.setVisibility(visible ? VISIBLE : INVISIBLE);
329 if (!visible) {
330 collapseStack();
331 }
Mady Mellor5549dd22018-11-06 18:07:34 -0800332 }
Mady Mellord1c78b262018-11-06 18:04:40 -0800333 updateBubblesShowing();
334 }
335
336 /**
337 * Rect indicating the touchable region for the bubble stack / expanded stack.
338 */
339 public Rect getTouchableRegion() {
340 if (mStackView == null || mStackView.getVisibility() != VISIBLE) {
341 return null;
342 }
343 mStackView.getBoundsOnScreen(mTempRect);
344 return mTempRect;
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800345 }
346
Mark Renouf89b1a4a2018-12-04 14:59:45 -0500347 private boolean canLaunchInActivityView(PendingIntent intent) {
348 if (intent == null) {
349 return false;
350 }
351 ActivityInfo info =
352 intent.getIntent().resolveActivityInfo(mContext.getPackageManager(), 0);
353 return info != null
354 && ActivityInfo.isResizeableMode(info.resizeMode)
355 && (info.flags & ActivityInfo.FLAG_ALLOW_EMBEDDED) != 0;
356 }
357
Mady Mellorebdbbb92018-11-15 14:36:48 -0800358 @VisibleForTesting
Ned Burns01e38212019-01-03 16:32:52 -0500359 BubbleStackView getStackView() {
Mady Mellorebdbbb92018-11-15 14:36:48 -0800360 return mStackView;
361 }
362
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800363 // TODO: factor in PIP location / maybe last place user had it
364 /**
365 * Gets an appropriate starting point to position the bubble stack.
366 */
Ned Burns01e38212019-01-03 16:32:52 -0500367 private static Point getStartPoint(int size, Point displaySize) {
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800368 final int x = displaySize.x - size + EDGE_OVERLAP;
369 final int y = displaySize.y / 4;
370 return new Point(x, y);
371 }
372
373 /**
374 * Gets an appropriate position for the bubble when the stack is expanded.
375 */
Ned Burns01e38212019-01-03 16:32:52 -0500376 static Point getExpandPoint(BubbleStackView view, int size, Point displaySize) {
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800377 // Same place for now..
378 return new Point(EDGE_OVERLAP, size);
379 }
380
Mady Mellor5549dd22018-11-06 18:07:34 -0800381 /**
Mady Mellorb4991e62019-01-10 15:14:51 -0800382 * Whether the notification has been developer configured to bubble and is allowed by the user.
383 */
384 private boolean shouldBubble(NotificationEntry entry) {
385 StatusBarNotification n = entry.notification;
386 boolean canAppOverlay = false;
387 try {
388 canAppOverlay = mNotificationManagerService.areAppOverlaysAllowedForPackage(
389 n.getPackageName(), n.getUid());
390 } catch (RemoteException e) {
391 Log.w(TAG, "Error calling NoMan to determine if app can overlay", e);
392 }
393
394 boolean canChannelOverlay = mNotificationEntryManager.getNotificationData().getChannel(
395 entry.key).canOverlayApps();
396 boolean hasOverlayIntent = n.getNotification().getAppOverlayIntent() != null;
397 return hasOverlayIntent && canChannelOverlay && canAppOverlay;
398 }
399
400 /**
Mady Mellor5549dd22018-11-06 18:07:34 -0800401 * Whether the notification should bubble or not.
402 */
Mady Mellorb4991e62019-01-10 15:14:51 -0800403 private boolean shouldAutoBubble(Context context, NotificationEntry entry) {
Mady Mellorceced172018-11-27 11:18:39 -0800404 if (entry.isBubbleDismissed()) {
Mady Mellor5549dd22018-11-06 18:07:34 -0800405 return false;
406 }
Mady Mellorb4991e62019-01-10 15:14:51 -0800407 StatusBarNotification n = entry.notification;
Mady Mellorceced172018-11-27 11:18:39 -0800408
409 boolean autoBubbleMessages = shouldAutoBubbleMessages(context) || DEBUG_ENABLE_AUTO_BUBBLE;
410 boolean autoBubbleOngoing = shouldAutoBubbleOngoing(context) || DEBUG_ENABLE_AUTO_BUBBLE;
411 boolean autoBubbleAll = shouldAutoBubbleAll(context) || DEBUG_ENABLE_AUTO_BUBBLE;
412
Mady Mellor5549dd22018-11-06 18:07:34 -0800413 boolean hasRemoteInput = false;
414 if (n.getNotification().actions != null) {
415 for (Notification.Action action : n.getNotification().actions) {
416 if (action.getRemoteInputs() != null) {
417 hasRemoteInput = true;
418 break;
419 }
420 }
421 }
Mady Mellor711f9562018-12-05 14:53:46 -0800422 boolean isCall = Notification.CATEGORY_CALL.equals(n.getNotification().category)
423 && n.isOngoing();
424 boolean isMusic = n.getNotification().hasMediaSession();
425 boolean isImportantOngoing = isMusic || isCall;
Mady Mellorceced172018-11-27 11:18:39 -0800426
Mady Mellor5549dd22018-11-06 18:07:34 -0800427 Class<? extends Notification.Style> style = n.getNotification().getNotificationStyle();
Mady Mellore3175372018-12-04 17:05:11 -0800428 boolean isMessageType = Notification.CATEGORY_MESSAGE.equals(n.getNotification().category);
429 boolean isMessageStyle = Notification.MessagingStyle.class.equals(style);
430 return (((isMessageType && hasRemoteInput) || isMessageStyle) && autoBubbleMessages)
Mady Mellor711f9562018-12-05 14:53:46 -0800431 || (isImportantOngoing && autoBubbleOngoing)
Mady Mellorceced172018-11-27 11:18:39 -0800432 || autoBubbleAll;
433 }
434
435 private static boolean shouldAutoBubbleMessages(Context context) {
436 return Settings.Secure.getInt(context.getContentResolver(),
437 ENABLE_AUTO_BUBBLE_MESSAGES, 0) != 0;
438 }
439
440 private static boolean shouldAutoBubbleOngoing(Context context) {
441 return Settings.Secure.getInt(context.getContentResolver(),
442 ENABLE_AUTO_BUBBLE_ONGOING, 0) != 0;
443 }
444
445 private static boolean shouldAutoBubbleAll(Context context) {
446 return Settings.Secure.getInt(context.getContentResolver(),
447 ENABLE_AUTO_BUBBLE_ALL, 0) != 0;
Mady Mellor5549dd22018-11-06 18:07:34 -0800448 }
Mark Renouf89b1a4a2018-12-04 14:59:45 -0500449
450 private static boolean shouldUseActivityView(Context context) {
451 return Settings.Secure.getInt(context.getContentResolver(),
452 ENABLE_BUBBLE_ACTIVITY_VIEW, 0) != 0;
453 }
454
455 private static boolean shouldUseContentIntent(Context context) {
456 return Settings.Secure.getInt(context.getContentResolver(),
457 ENABLE_BUBBLE_CONTENT_INTENT, 0) != 0;
458 }
Mady Mellorc3d6f7d2018-11-07 09:36:56 -0800459}