Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.bubbles; |
| 18 | |
Steven Wu | 552f63f | 2019-02-05 13:41:36 -0500 | [diff] [blame] | 19 | import static android.content.pm.ActivityInfo.DOCUMENT_LAUNCH_ALWAYS; |
| 20 | import static android.util.StatsLog.BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__ACTIVITY_INFO_MISSING; |
| 21 | import static android.util.StatsLog.BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__ACTIVITY_INFO_NOT_RESIZABLE; |
| 22 | import static android.util.StatsLog.BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__DOCUMENT_LAUNCH_NOT_ALWAYS; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 23 | import static android.view.View.INVISIBLE; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 24 | import static android.view.View.VISIBLE; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 25 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 26 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 27 | import static com.android.systemui.statusbar.StatusBarState.SHADE; |
| 28 | import static com.android.systemui.statusbar.notification.NotificationAlertingManager.alertAgain; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 29 | |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 30 | import android.annotation.Nullable; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 31 | import android.app.ActivityManager; |
| 32 | import android.app.ActivityTaskManager; |
| 33 | import android.app.IActivityTaskManager; |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 34 | import android.app.INotificationManager; |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 35 | import android.app.Notification; |
Mark Renouf | 89b1a4a | 2018-12-04 14:59:45 -0500 | [diff] [blame] | 36 | import android.app.PendingIntent; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 37 | import android.content.Context; |
Mark Renouf | 89b1a4a | 2018-12-04 14:59:45 -0500 | [diff] [blame] | 38 | import android.content.pm.ActivityInfo; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 39 | import android.graphics.Point; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 40 | import android.graphics.Rect; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 41 | import android.os.RemoteException; |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 42 | import android.os.ServiceManager; |
Mady Mellor | ceced17 | 2018-11-27 11:18:39 -0800 | [diff] [blame] | 43 | import android.provider.Settings; |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 44 | import android.service.notification.StatusBarNotification; |
Mark Renouf | 89b1a4a | 2018-12-04 14:59:45 -0500 | [diff] [blame] | 45 | import android.util.Log; |
Steven Wu | 552f63f | 2019-02-05 13:41:36 -0500 | [diff] [blame] | 46 | import android.util.StatsLog; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 47 | import android.view.Display; |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 48 | import android.view.LayoutInflater; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 49 | import android.view.ViewGroup; |
| 50 | import android.view.WindowManager; |
| 51 | import android.widget.FrameLayout; |
| 52 | |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 53 | import androidx.annotation.MainThread; |
| 54 | |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 55 | import com.android.internal.annotations.VisibleForTesting; |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 56 | import com.android.internal.statusbar.NotificationVisibility; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 57 | import com.android.systemui.Dependency; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 58 | import com.android.systemui.R; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 59 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 60 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
| 61 | import com.android.systemui.shared.system.TaskStackChangeListener; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 62 | import com.android.systemui.statusbar.notification.NotificationEntryListener; |
| 63 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 64 | import com.android.systemui.statusbar.notification.NotificationInterruptionStateProvider; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 65 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 66 | import com.android.systemui.statusbar.notification.row.NotificationInflater; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 67 | import com.android.systemui.statusbar.phone.StatusBarWindowController; |
| 68 | |
| 69 | import java.util.HashMap; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 70 | import java.util.List; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 71 | import java.util.Map; |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 72 | import java.util.Set; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 73 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 74 | import javax.inject.Inject; |
| 75 | import javax.inject.Singleton; |
| 76 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 77 | /** |
| 78 | * Bubbles are a special type of content that can "float" on top of other apps or System UI. |
| 79 | * Bubbles can be expanded to show more content. |
| 80 | * |
| 81 | * The controller manages addition, removal, and visible state of bubbles on screen. |
| 82 | */ |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 83 | @Singleton |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 84 | public class BubbleController implements BubbleExpandedView.OnBubbleBlockedListener { |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 85 | private static final int MAX_BUBBLES = 5; // TODO: actually enforce this |
| 86 | |
| 87 | private static final String TAG = "BubbleController"; |
| 88 | |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 89 | // Enables some subset of notifs to automatically become bubbles |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 90 | private static final boolean DEBUG_ENABLE_AUTO_BUBBLE = false; |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 91 | |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 92 | // Secure settings flags |
| 93 | // Feature level flag |
| 94 | private static final String ENABLE_BUBBLES = "experiment_enable_bubbles"; |
| 95 | // Auto bubble flags set whether different notification types should be presented as a bubble |
Mady Mellor | ceced17 | 2018-11-27 11:18:39 -0800 | [diff] [blame] | 96 | private static final String ENABLE_AUTO_BUBBLE_MESSAGES = "experiment_autobubble_messaging"; |
| 97 | private static final String ENABLE_AUTO_BUBBLE_ONGOING = "experiment_autobubble_ongoing"; |
| 98 | private static final String ENABLE_AUTO_BUBBLE_ALL = "experiment_autobubble_all"; |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 99 | // Use an activity view for an auto-bubbled notification if it has an appropriate content intent |
Mark Renouf | 89b1a4a | 2018-12-04 14:59:45 -0500 | [diff] [blame] | 100 | private static final String ENABLE_BUBBLE_CONTENT_INTENT = "experiment_bubble_content_intent"; |
Mady Mellor | ceced17 | 2018-11-27 11:18:39 -0800 | [diff] [blame] | 101 | |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 102 | private final Context mContext; |
| 103 | private final NotificationEntryManager mNotificationEntryManager; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 104 | private final IActivityTaskManager mActivityTaskManager; |
| 105 | private final BubbleTaskStackListener mTaskStackListener; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 106 | private BubbleStateChangeListener mStateChangeListener; |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 107 | private BubbleExpandListener mExpandListener; |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 108 | private LayoutInflater mInflater; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 109 | |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 110 | private final Map<String, BubbleView> mBubbles = new HashMap<>(); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 111 | private BubbleStackView mStackView; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 112 | private final Point mDisplaySize; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 113 | |
| 114 | // Bubbles get added to the status bar view |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 115 | private final StatusBarWindowController mStatusBarWindowController; |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 116 | private StatusBarStateListener mStatusBarStateListener; |
| 117 | |
| 118 | private final NotificationInterruptionStateProvider mNotificationInterruptionStateProvider = |
| 119 | Dependency.get(NotificationInterruptionStateProvider.class); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 120 | |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 121 | private INotificationManager mNotificationManagerService; |
| 122 | |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 123 | // Used for determining view rect for touch interaction |
| 124 | private Rect mTempRect = new Rect(); |
| 125 | |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 126 | /** |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 127 | * Listener to be notified when some states of the bubbles change. |
| 128 | */ |
| 129 | public interface BubbleStateChangeListener { |
| 130 | /** |
| 131 | * Called when the stack has bubbles or no longer has bubbles. |
| 132 | */ |
| 133 | void onHasBubblesChanged(boolean hasBubbles); |
| 134 | } |
| 135 | |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 136 | /** |
| 137 | * Listener to find out about stack expansion / collapse events. |
| 138 | */ |
| 139 | public interface BubbleExpandListener { |
| 140 | /** |
| 141 | * Called when the expansion state of the bubble stack changes. |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 142 | * @param isExpanding whether it's expanding or collapsing |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 143 | * @param key the notification key associated with bubble being expanded |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 144 | */ |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 145 | void onBubbleExpandChanged(boolean isExpanding, String key); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Listens for the current state of the status bar and updates the visibility state |
| 150 | * of bubbles as needed. |
| 151 | */ |
| 152 | private class StatusBarStateListener implements StatusBarStateController.StateListener { |
| 153 | private int mState; |
| 154 | /** |
| 155 | * Returns the current status bar state. |
| 156 | */ |
| 157 | public int getCurrentState() { |
| 158 | return mState; |
| 159 | } |
| 160 | |
| 161 | @Override |
| 162 | public void onStateChanged(int newState) { |
| 163 | mState = newState; |
| 164 | updateVisibility(); |
| 165 | } |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 166 | } |
| 167 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 168 | @Inject |
Jason Monk | 92d5c24 | 2018-12-21 14:37:34 -0500 | [diff] [blame] | 169 | public BubbleController(Context context, StatusBarWindowController statusBarWindowController) { |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 170 | mContext = context; |
| 171 | WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); |
| 172 | mDisplaySize = new Point(); |
| 173 | wm.getDefaultDisplay().getSize(mDisplaySize); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 174 | mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 175 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 176 | mNotificationEntryManager = Dependency.get(NotificationEntryManager.class); |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 177 | mNotificationEntryManager.addNotificationEntryListener(mEntryListener); |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 178 | |
| 179 | try { |
| 180 | mNotificationManagerService = INotificationManager.Stub.asInterface( |
| 181 | ServiceManager.getServiceOrThrow(Context.NOTIFICATION_SERVICE)); |
| 182 | } catch (ServiceManager.ServiceNotFoundException e) { |
| 183 | e.printStackTrace(); |
| 184 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 185 | |
| 186 | mStatusBarWindowController = statusBarWindowController; |
| 187 | mStatusBarStateListener = new StatusBarStateListener(); |
| 188 | Dependency.get(StatusBarStateController.class).addCallback(mStatusBarStateListener); |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 189 | |
| 190 | mActivityTaskManager = ActivityTaskManager.getService(); |
| 191 | mTaskStackListener = new BubbleTaskStackListener(); |
| 192 | ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener); |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | /** |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 196 | * Set a listener to be notified when some states of the bubbles change. |
| 197 | */ |
| 198 | public void setBubbleStateChangeListener(BubbleStateChangeListener listener) { |
| 199 | mStateChangeListener = listener; |
| 200 | } |
| 201 | |
| 202 | /** |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 203 | * Set a listener to be notified of bubble expand events. |
| 204 | */ |
| 205 | public void setExpandListener(BubbleExpandListener listener) { |
Issei Suzuki | ac9fcb7 | 2019-02-04 17:45:57 +0100 | [diff] [blame] | 206 | mExpandListener = ((isExpanding, key) -> { |
| 207 | if (listener != null) { |
| 208 | listener.onBubbleExpandChanged(isExpanding, key); |
| 209 | } |
| 210 | mStatusBarWindowController.setBubbleExpanded(isExpanding); |
| 211 | }); |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 212 | if (mStackView != null) { |
| 213 | mStackView.setExpandListener(mExpandListener); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | /** |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 218 | * Whether or not there are bubbles present, regardless of them being visible on the |
| 219 | * screen (e.g. if on AOD). |
| 220 | */ |
| 221 | public boolean hasBubbles() { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 222 | for (BubbleView bv : mBubbles.values()) { |
| 223 | if (!bv.getEntry().isBubbleDismissed()) { |
| 224 | return true; |
| 225 | } |
| 226 | } |
| 227 | return false; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | /** |
| 231 | * Whether the stack of bubbles is expanded or not. |
| 232 | */ |
| 233 | public boolean isStackExpanded() { |
| 234 | return mStackView != null && mStackView.isExpanded(); |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Tell the stack of bubbles to collapse. |
| 239 | */ |
| 240 | public void collapseStack() { |
| 241 | if (mStackView != null) { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 242 | mStackView.collapseStack(); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Tell the stack of bubbles to be dismissed, this will remove all of the bubbles in the stack. |
| 248 | */ |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 249 | void dismissStack() { |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 250 | if (mStackView == null) { |
| 251 | return; |
| 252 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 253 | Set<String> keys = mBubbles.keySet(); |
| 254 | for (String key: keys) { |
| 255 | mBubbles.get(key).getEntry().setBubbleDismissed(true); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 256 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 257 | mStackView.stackDismissed(); |
| 258 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 259 | updateVisibility(); |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 260 | mNotificationEntryManager.updateNotifications(); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | /** |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 264 | * Adds or updates a bubble associated with the provided notification entry. |
| 265 | * |
| 266 | * @param notif the notification associated with this bubble. |
| 267 | * @param updatePosition whether this update should promote the bubble to the top of the stack. |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 268 | */ |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 269 | public void updateBubble(NotificationEntry notif, boolean updatePosition) { |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 270 | if (mBubbles.containsKey(notif.key)) { |
| 271 | // It's an update |
| 272 | BubbleView bubble = mBubbles.get(notif.key); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 273 | mStackView.updateBubble(bubble, notif, updatePosition); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 274 | } else { |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 275 | if (mStackView == null) { |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 276 | mStackView = new BubbleStackView(mContext); |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 277 | ViewGroup sbv = mStatusBarWindowController.getStatusBarView(); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 278 | // XXX: Bug when you expand the shade on top of expanded bubble, there is no scrim |
| 279 | // between bubble and the shade |
| 280 | int bubblePosition = sbv.indexOfChild(sbv.findViewById(R.id.scrim_behind)) + 1; |
| 281 | sbv.addView(mStackView, bubblePosition, |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 282 | new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)); |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 283 | if (mExpandListener != null) { |
| 284 | mStackView.setExpandListener(mExpandListener); |
| 285 | } |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 286 | mStackView.setOnBlockedListener(this); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 287 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 288 | // It's new |
| 289 | BubbleView bubble = (BubbleView) mInflater.inflate( |
| 290 | R.layout.bubble_view, mStackView, false /* attachToRoot */); |
| 291 | bubble.setNotif(notif); |
Mady Mellor | edd4ee1 | 2019-01-18 10:45:11 -0800 | [diff] [blame] | 292 | PendingIntent bubbleIntent = getValidBubbleIntent(notif); |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 293 | if (bubbleIntent != null) { |
| 294 | bubble.setBubbleIntent(bubbleIntent); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 295 | } |
| 296 | mBubbles.put(bubble.getKey(), bubble); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 297 | mStackView.addBubble(bubble); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 298 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 299 | updateVisibility(); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | /** |
| 303 | * Removes the bubble associated with the {@param uri}. |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 304 | * <p> |
| 305 | * Must be called from the main thread. |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 306 | */ |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 307 | @MainThread |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 308 | void removeBubble(String key) { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 309 | BubbleView bv = mBubbles.remove(key); |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 310 | if (mStackView != null && bv != null) { |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 311 | mStackView.removeBubble(bv); |
Mark Renouf | 89b1a4a | 2018-12-04 14:59:45 -0500 | [diff] [blame] | 312 | bv.destroyActivityView(mStackView); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 313 | } |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 314 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 315 | NotificationEntry entry = bv != null ? bv.getEntry() : null; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 316 | if (entry != null) { |
| 317 | entry.setBubbleDismissed(true); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 318 | mNotificationEntryManager.updateNotifications(); |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 319 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 320 | updateVisibility(); |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 321 | } |
| 322 | |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 323 | @Override |
| 324 | public void onBubbleBlocked(NotificationEntry entry) { |
| 325 | Object[] bubbles = mBubbles.values().toArray(); |
| 326 | for (int i = 0; i < bubbles.length; i++) { |
| 327 | NotificationEntry e = ((BubbleView) bubbles[i]).getEntry(); |
| 328 | boolean samePackage = entry.notification.getPackageName().equals( |
| 329 | e.notification.getPackageName()); |
| 330 | if (samePackage) { |
| 331 | removeBubble(entry.key); |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 336 | @SuppressWarnings("FieldCanBeLocal") |
| 337 | private final NotificationEntryListener mEntryListener = new NotificationEntryListener() { |
| 338 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 339 | public void onPendingEntryAdded(NotificationEntry entry) { |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 340 | if (!areBubblesEnabled(mContext)) { |
| 341 | return; |
| 342 | } |
| 343 | if (shouldAutoBubbleForFlags(mContext, entry) || shouldBubble(entry)) { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 344 | // TODO: handle group summaries |
| 345 | // It's a new notif, it shows in the shade and as a bubble |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 346 | entry.setIsBubble(true); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 347 | entry.setShowInShadeWhenBubble(true); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | @Override |
| 352 | public void onEntryInflated(NotificationEntry entry, |
| 353 | @NotificationInflater.InflationFlag int inflatedFlags) { |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 354 | if (!areBubblesEnabled(mContext)) { |
| 355 | return; |
| 356 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 357 | if (entry.isBubble() && mNotificationInterruptionStateProvider.shouldBubbleUp(entry)) { |
| 358 | updateBubble(entry, true /* updatePosition */); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | @Override |
| 363 | public void onPreEntryUpdated(NotificationEntry entry) { |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 364 | if (!areBubblesEnabled(mContext)) { |
| 365 | return; |
| 366 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 367 | if (mNotificationInterruptionStateProvider.shouldBubbleUp(entry) |
| 368 | && alertAgain(entry, entry.notification.getNotification())) { |
| 369 | entry.setShowInShadeWhenBubble(true); |
| 370 | entry.setBubbleDismissed(false); // updates come back as bubbles even if dismissed |
| 371 | if (mBubbles.containsKey(entry.key)) { |
| 372 | mBubbles.get(entry.key).updateDotVisibility(); |
| 373 | } |
| 374 | updateBubble(entry, true /* updatePosition */); |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | @Override |
| 379 | public void onEntryRemoved(NotificationEntry entry, |
| 380 | @Nullable NotificationVisibility visibility, |
| 381 | boolean removedByUser) { |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 382 | if (!areBubblesEnabled(mContext)) { |
| 383 | return; |
| 384 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 385 | entry.setShowInShadeWhenBubble(false); |
| 386 | if (mBubbles.containsKey(entry.key)) { |
| 387 | mBubbles.get(entry.key).updateDotVisibility(); |
| 388 | } |
| 389 | if (!removedByUser) { |
| 390 | // This was a cancel so we should remove the bubble |
| 391 | removeBubble(entry.key); |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 392 | } |
| 393 | } |
| 394 | }; |
| 395 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 396 | /** |
| 397 | * Lets any listeners know if bubble state has changed. |
| 398 | */ |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 399 | private void updateBubblesShowing() { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 400 | if (mStackView == null) { |
| 401 | return; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 402 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 403 | |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 404 | boolean hadBubbles = mStatusBarWindowController.getBubblesShowing(); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 405 | boolean hasBubblesShowing = hasBubbles() && mStackView.getVisibility() == VISIBLE; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 406 | mStatusBarWindowController.setBubblesShowing(hasBubblesShowing); |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 407 | if (mStateChangeListener != null && hadBubbles != hasBubblesShowing) { |
| 408 | mStateChangeListener.onHasBubblesChanged(hasBubblesShowing); |
| 409 | } |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | /** |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 413 | * Updates the visibility of the bubbles based on current state. |
| 414 | * Does not un-bubble, just hides or un-hides. Will notify any |
| 415 | * {@link BubbleStateChangeListener}s if visibility changes. |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 416 | */ |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 417 | public void updateVisibility() { |
| 418 | if (mStatusBarStateListener.getCurrentState() == SHADE && hasBubbles()) { |
| 419 | // Bubbles only appear in unlocked shade |
| 420 | mStackView.setVisibility(hasBubbles() ? VISIBLE : INVISIBLE); |
| 421 | } else if (mStackView != null) { |
| 422 | mStackView.setVisibility(INVISIBLE); |
| 423 | collapseStack(); |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 424 | } |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 425 | updateBubblesShowing(); |
| 426 | } |
| 427 | |
| 428 | /** |
| 429 | * Rect indicating the touchable region for the bubble stack / expanded stack. |
| 430 | */ |
| 431 | public Rect getTouchableRegion() { |
| 432 | if (mStackView == null || mStackView.getVisibility() != VISIBLE) { |
| 433 | return null; |
| 434 | } |
| 435 | mStackView.getBoundsOnScreen(mTempRect); |
| 436 | return mTempRect; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 437 | } |
| 438 | |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 439 | @VisibleForTesting |
| 440 | BubbleStackView getStackView() { |
| 441 | return mStackView; |
| 442 | } |
| 443 | |
| 444 | @Nullable |
| 445 | private PendingIntent getValidBubbleIntent(NotificationEntry notif) { |
| 446 | Notification notification = notif.notification.getNotification(); |
Steven Wu | 552f63f | 2019-02-05 13:41:36 -0500 | [diff] [blame] | 447 | String packageName = notif.notification.getPackageName(); |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 448 | Notification.BubbleMetadata data = notif.getBubbleMetadata(); |
Steven Wu | 552f63f | 2019-02-05 13:41:36 -0500 | [diff] [blame] | 449 | if (data != null && canLaunchInActivityView(data.getIntent(), |
| 450 | true /* enable logging for bubbles */, packageName)) { |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 451 | return data.getIntent(); |
Steven Wu | 552f63f | 2019-02-05 13:41:36 -0500 | [diff] [blame] | 452 | } |
| 453 | if (shouldUseContentIntent(mContext) |
| 454 | && canLaunchInActivityView(notification.contentIntent, |
| 455 | false /* disable logging for notifications */, packageName)) { |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 456 | Log.d(TAG, "[addBubble " + notif.key |
| 457 | + "]: No appOverlayIntent, using contentIntent."); |
| 458 | return notification.contentIntent; |
| 459 | } |
| 460 | Log.d(TAG, "[addBubble " + notif.key + "]: No supported intent for ActivityView."); |
| 461 | return null; |
| 462 | } |
| 463 | |
| 464 | /** |
| 465 | * Whether an intent is properly configured to display in an {@link android.app.ActivityView}. |
Steven Wu | 552f63f | 2019-02-05 13:41:36 -0500 | [diff] [blame] | 466 | * |
| 467 | * @param intent the pending intent of the bubble. |
| 468 | * @param enableLogging whether bubble developer error should be logged. |
| 469 | * @param packageName the notification package name for this bubble. |
| 470 | * @return |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 471 | */ |
Steven Wu | 552f63f | 2019-02-05 13:41:36 -0500 | [diff] [blame] | 472 | private boolean canLaunchInActivityView(PendingIntent intent, boolean enableLogging, |
| 473 | String packageName) { |
Mark Renouf | 89b1a4a | 2018-12-04 14:59:45 -0500 | [diff] [blame] | 474 | if (intent == null) { |
| 475 | return false; |
| 476 | } |
| 477 | ActivityInfo info = |
| 478 | intent.getIntent().resolveActivityInfo(mContext.getPackageManager(), 0); |
Steven Wu | 552f63f | 2019-02-05 13:41:36 -0500 | [diff] [blame] | 479 | if (info == null) { |
| 480 | if (enableLogging) { |
| 481 | StatsLog.write(StatsLog.BUBBLE_DEVELOPER_ERROR_REPORTED, packageName, |
| 482 | BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__ACTIVITY_INFO_MISSING); |
| 483 | } |
| 484 | return false; |
| 485 | } |
| 486 | if (!ActivityInfo.isResizeableMode(info.resizeMode)) { |
| 487 | if (enableLogging) { |
| 488 | StatsLog.write(StatsLog.BUBBLE_DEVELOPER_ERROR_REPORTED, packageName, |
| 489 | BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__ACTIVITY_INFO_NOT_RESIZABLE); |
| 490 | } |
| 491 | return false; |
| 492 | } |
| 493 | if (info.documentLaunchMode != DOCUMENT_LAUNCH_ALWAYS) { |
| 494 | if (enableLogging) { |
| 495 | StatsLog.write(StatsLog.BUBBLE_DEVELOPER_ERROR_REPORTED, packageName, |
| 496 | BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__DOCUMENT_LAUNCH_NOT_ALWAYS); |
| 497 | } |
| 498 | return false; |
| 499 | } |
| 500 | return (info.flags & ActivityInfo.FLAG_ALLOW_EMBEDDED) != 0; |
Mark Renouf | 89b1a4a | 2018-12-04 14:59:45 -0500 | [diff] [blame] | 501 | } |
| 502 | |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 503 | /** |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 504 | * Whether the notification has been developer configured to bubble and is allowed by the user. |
| 505 | */ |
Mady Mellor | c18ba96 | 2019-01-29 11:11:56 -0800 | [diff] [blame] | 506 | @VisibleForTesting |
| 507 | protected boolean shouldBubble(NotificationEntry entry) { |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 508 | StatusBarNotification n = entry.notification; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 509 | boolean hasOverlayIntent = n.getNotification().getBubbleMetadata() != null |
| 510 | && n.getNotification().getBubbleMetadata().getIntent() != null; |
Julia Reynolds | 4509ce7 | 2019-01-31 13:12:43 -0500 | [diff] [blame] | 511 | return hasOverlayIntent && entry.canBubble; |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | /** |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 515 | * Whether the notification should automatically bubble or not. Gated by secure settings flags. |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 516 | */ |
Mady Mellor | 9bad224 | 2019-01-28 11:21:51 -0800 | [diff] [blame] | 517 | @VisibleForTesting |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 518 | protected boolean shouldAutoBubbleForFlags(Context context, NotificationEntry entry) { |
Mady Mellor | ceced17 | 2018-11-27 11:18:39 -0800 | [diff] [blame] | 519 | if (entry.isBubbleDismissed()) { |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 520 | return false; |
| 521 | } |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 522 | StatusBarNotification n = entry.notification; |
Mady Mellor | ceced17 | 2018-11-27 11:18:39 -0800 | [diff] [blame] | 523 | |
| 524 | boolean autoBubbleMessages = shouldAutoBubbleMessages(context) || DEBUG_ENABLE_AUTO_BUBBLE; |
| 525 | boolean autoBubbleOngoing = shouldAutoBubbleOngoing(context) || DEBUG_ENABLE_AUTO_BUBBLE; |
| 526 | boolean autoBubbleAll = shouldAutoBubbleAll(context) || DEBUG_ENABLE_AUTO_BUBBLE; |
| 527 | |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 528 | boolean hasRemoteInput = false; |
| 529 | if (n.getNotification().actions != null) { |
| 530 | for (Notification.Action action : n.getNotification().actions) { |
| 531 | if (action.getRemoteInputs() != null) { |
| 532 | hasRemoteInput = true; |
| 533 | break; |
| 534 | } |
| 535 | } |
| 536 | } |
Mady Mellor | 711f956 | 2018-12-05 14:53:46 -0800 | [diff] [blame] | 537 | boolean isCall = Notification.CATEGORY_CALL.equals(n.getNotification().category) |
| 538 | && n.isOngoing(); |
| 539 | boolean isMusic = n.getNotification().hasMediaSession(); |
| 540 | boolean isImportantOngoing = isMusic || isCall; |
Mady Mellor | ceced17 | 2018-11-27 11:18:39 -0800 | [diff] [blame] | 541 | |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 542 | Class<? extends Notification.Style> style = n.getNotification().getNotificationStyle(); |
Mady Mellor | e317537 | 2018-12-04 17:05:11 -0800 | [diff] [blame] | 543 | boolean isMessageType = Notification.CATEGORY_MESSAGE.equals(n.getNotification().category); |
| 544 | boolean isMessageStyle = Notification.MessagingStyle.class.equals(style); |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 545 | return (((isMessageType && hasRemoteInput) || isMessageStyle) && autoBubbleMessages) |
Mady Mellor | 711f956 | 2018-12-05 14:53:46 -0800 | [diff] [blame] | 546 | || (isImportantOngoing && autoBubbleOngoing) |
Mady Mellor | ceced17 | 2018-11-27 11:18:39 -0800 | [diff] [blame] | 547 | || autoBubbleAll; |
| 548 | } |
| 549 | |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 550 | /** |
| 551 | * This task stack listener is responsible for responding to tasks moved to the front |
| 552 | * which are on the default (main) display. When this happens, expanded bubbles must be |
| 553 | * collapsed so the user may interact with the app which was just moved to the front. |
| 554 | * <p> |
| 555 | * This listener is registered with SystemUI's ActivityManagerWrapper which dispatches |
| 556 | * these calls via a main thread Handler. |
| 557 | */ |
| 558 | @MainThread |
| 559 | private class BubbleTaskStackListener extends TaskStackChangeListener { |
| 560 | |
| 561 | @Nullable |
| 562 | private ActivityManager.StackInfo findStackInfo(int taskId) throws RemoteException { |
| 563 | final List<ActivityManager.StackInfo> stackInfoList = |
| 564 | mActivityTaskManager.getAllStackInfos(); |
| 565 | // Iterate through stacks from top to bottom. |
| 566 | final int stackCount = stackInfoList.size(); |
| 567 | for (int stackIndex = 0; stackIndex < stackCount; stackIndex++) { |
| 568 | final ActivityManager.StackInfo stackInfo = stackInfoList.get(stackIndex); |
| 569 | // Iterate through tasks from top to bottom. |
| 570 | for (int taskIndex = stackInfo.taskIds.length - 1; taskIndex >= 0; taskIndex--) { |
| 571 | if (stackInfo.taskIds[taskIndex] == taskId) { |
| 572 | return stackInfo; |
| 573 | } |
| 574 | } |
| 575 | } |
| 576 | return null; |
| 577 | } |
| 578 | |
| 579 | @Override |
| 580 | public void onTaskMovedToFront(int taskId) { |
| 581 | ActivityManager.StackInfo stackInfo = null; |
| 582 | try { |
| 583 | stackInfo = findStackInfo(taskId); |
| 584 | } catch (RemoteException e) { |
| 585 | e.rethrowAsRuntimeException(); |
| 586 | } |
| 587 | if (stackInfo != null && stackInfo.displayId == Display.DEFAULT_DISPLAY |
| 588 | && mStackView != null) { |
| 589 | mStackView.collapseStack(); |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | /** |
| 594 | * This is a workaround for the case when the activity had to be created in a new task. |
| 595 | * Existing code in ActivityStackSupervisor checks the display where the activity |
| 596 | * ultimately ended up, displays an error message toast, and calls this method instead of |
| 597 | * onTaskMovedToFront. |
| 598 | */ |
| 599 | // TODO(b/124058588): add requestedDisplayId to this callback, ignore unless matches |
| 600 | @Override |
| 601 | public void onActivityLaunchOnSecondaryDisplayFailed() { |
| 602 | if (mStackView != null) { |
| 603 | mStackView.collapseStack(); |
| 604 | } |
| 605 | } |
| 606 | } |
| 607 | |
Mady Mellor | ceced17 | 2018-11-27 11:18:39 -0800 | [diff] [blame] | 608 | private static boolean shouldAutoBubbleMessages(Context context) { |
| 609 | return Settings.Secure.getInt(context.getContentResolver(), |
| 610 | ENABLE_AUTO_BUBBLE_MESSAGES, 0) != 0; |
| 611 | } |
| 612 | |
| 613 | private static boolean shouldAutoBubbleOngoing(Context context) { |
| 614 | return Settings.Secure.getInt(context.getContentResolver(), |
| 615 | ENABLE_AUTO_BUBBLE_ONGOING, 0) != 0; |
| 616 | } |
| 617 | |
| 618 | private static boolean shouldAutoBubbleAll(Context context) { |
| 619 | return Settings.Secure.getInt(context.getContentResolver(), |
| 620 | ENABLE_AUTO_BUBBLE_ALL, 0) != 0; |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 621 | } |
Mark Renouf | 89b1a4a | 2018-12-04 14:59:45 -0500 | [diff] [blame] | 622 | |
Mark Renouf | 89b1a4a | 2018-12-04 14:59:45 -0500 | [diff] [blame] | 623 | private static boolean shouldUseContentIntent(Context context) { |
| 624 | return Settings.Secure.getInt(context.getContentResolver(), |
| 625 | ENABLE_BUBBLE_CONTENT_INTENT, 0) != 0; |
| 626 | } |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 627 | |
| 628 | private static boolean areBubblesEnabled(Context context) { |
| 629 | return Settings.Secure.getInt(context.getContentResolver(), |
| 630 | ENABLE_BUBBLES, 1) != 0; |
| 631 | } |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 632 | } |