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