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