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