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