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