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 | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 19 | import static android.app.Notification.FLAG_AUTOGROUP_SUMMARY; |
Mady Mellor | 3a0a1b4 | 2019-05-23 06:40:21 -0700 | [diff] [blame] | 20 | import static android.app.Notification.FLAG_BUBBLE; |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 21 | import static android.content.pm.ActivityInfo.DOCUMENT_LAUNCH_ALWAYS; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 22 | import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL; |
| 23 | import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL_ALL; |
| 24 | import static android.service.notification.NotificationListenerService.REASON_CANCEL; |
| 25 | import static android.service.notification.NotificationListenerService.REASON_CANCEL_ALL; |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 26 | import static android.service.notification.NotificationListenerService.REASON_CLICK; |
| 27 | import static android.service.notification.NotificationListenerService.REASON_GROUP_SUMMARY_CANCELED; |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 28 | import static android.view.Display.DEFAULT_DISPLAY; |
| 29 | import static android.view.Display.INVALID_DISPLAY; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 30 | import static android.view.View.INVISIBLE; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 31 | import static android.view.View.VISIBLE; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 32 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 33 | |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 34 | import static com.android.systemui.bubbles.BubbleDebugConfig.DEBUG_BUBBLE_CONTROLLER; |
| 35 | import static com.android.systemui.bubbles.BubbleDebugConfig.TAG_BUBBLES; |
| 36 | import static com.android.systemui.bubbles.BubbleDebugConfig.TAG_WITH_CLASS_NAME; |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 37 | import static com.android.systemui.statusbar.StatusBarState.SHADE; |
Mady Mellor | 1a4e86f | 2019-05-03 16:07:23 -0700 | [diff] [blame] | 38 | import static com.android.systemui.statusbar.notification.NotificationEntryManager.UNDEFINED_DISMISS_REASON; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 39 | |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 40 | import static java.lang.annotation.ElementType.FIELD; |
| 41 | import static java.lang.annotation.ElementType.LOCAL_VARIABLE; |
| 42 | import static java.lang.annotation.ElementType.PARAMETER; |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 43 | import static java.lang.annotation.RetentionPolicy.SOURCE; |
| 44 | |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 45 | import android.annotation.UserIdInt; |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 46 | import android.app.ActivityManager.RunningTaskInfo; |
Mady Mellor | 66efd5e | 2019-05-15 13:38:11 -0700 | [diff] [blame] | 47 | import android.app.NotificationManager; |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 48 | import android.app.PendingIntent; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 49 | import android.content.Context; |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 50 | import android.content.pm.ActivityInfo; |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 51 | import android.content.pm.ParceledListSlice; |
Joshua Tsuji | f418f9e | 2019-04-04 17:09:53 -0400 | [diff] [blame] | 52 | import android.content.res.Configuration; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 53 | import android.graphics.Rect; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 54 | import android.os.RemoteException; |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 55 | import android.os.ServiceManager; |
Mady Mellor | ceced17 | 2018-11-27 11:18:39 -0800 | [diff] [blame] | 56 | import android.provider.Settings; |
Mark Renouf | bbcf07f | 2019-05-09 10:42:43 -0400 | [diff] [blame] | 57 | import android.service.notification.NotificationListenerService.RankingMap; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 58 | import android.service.notification.ZenModeConfig; |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 59 | import android.util.ArraySet; |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 60 | import android.util.Log; |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 61 | import android.util.Pair; |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 62 | import android.util.SparseSetArray; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 63 | import android.view.Display; |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 64 | import android.view.IPinnedStackController; |
| 65 | import android.view.IPinnedStackListener; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 66 | import android.view.ViewGroup; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 67 | import android.widget.FrameLayout; |
| 68 | |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 69 | import androidx.annotation.IntDef; |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 70 | import androidx.annotation.MainThread; |
Joshua Tsuji | c650a14 | 2019-05-22 11:31:19 -0400 | [diff] [blame] | 71 | import androidx.annotation.Nullable; |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 72 | |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 73 | import com.android.internal.annotations.VisibleForTesting; |
Mady Mellor | a54e9fa | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 74 | import com.android.internal.statusbar.IStatusBarService; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 75 | import com.android.systemui.Dependency; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 76 | import com.android.systemui.R; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 77 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 78 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
| 79 | import com.android.systemui.shared.system.TaskStackChangeListener; |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 80 | import com.android.systemui.shared.system.WindowManagerWrapper; |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 81 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 82 | import com.android.systemui.statusbar.NotificationRemoveInterceptor; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 83 | import com.android.systemui.statusbar.notification.NotificationEntryListener; |
| 84 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 85 | import com.android.systemui.statusbar.notification.NotificationInterruptionStateProvider; |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 86 | import com.android.systemui.statusbar.notification.collection.NotificationData; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 87 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 88 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 89 | import com.android.systemui.statusbar.phone.StatusBarWindowController; |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 90 | import com.android.systemui.statusbar.policy.ConfigurationController; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 91 | import com.android.systemui.statusbar.policy.ZenModeController; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 92 | |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 93 | import java.io.FileDescriptor; |
| 94 | import java.io.PrintWriter; |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 95 | import java.lang.annotation.Retention; |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 96 | import java.lang.annotation.Target; |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 97 | import java.util.ArrayList; |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 98 | import java.util.List; |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 99 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 100 | import javax.inject.Inject; |
| 101 | import javax.inject.Singleton; |
| 102 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 103 | /** |
| 104 | * Bubbles are a special type of content that can "float" on top of other apps or System UI. |
| 105 | * Bubbles can be expanded to show more content. |
| 106 | * |
| 107 | * The controller manages addition, removal, and visible state of bubbles on screen. |
| 108 | */ |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 109 | @Singleton |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 110 | public class BubbleController implements ConfigurationController.ConfigurationListener { |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 111 | |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 112 | private static final String TAG = TAG_WITH_CLASS_NAME ? "BubbleController" : TAG_BUBBLES; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 113 | |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 114 | @Retention(SOURCE) |
| 115 | @IntDef({DISMISS_USER_GESTURE, DISMISS_AGED, DISMISS_TASK_FINISHED, DISMISS_BLOCKED, |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 116 | DISMISS_NOTIF_CANCEL, DISMISS_ACCESSIBILITY_ACTION, DISMISS_NO_LONGER_BUBBLE, |
Mady Mellor | 8454ddf | 2019-08-15 11:16:23 -0700 | [diff] [blame] | 117 | DISMISS_USER_CHANGED, DISMISS_GROUP_CANCELLED, DISMISS_INVALID_INTENT}) |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 118 | @Target({FIELD, LOCAL_VARIABLE, PARAMETER}) |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 119 | @interface DismissReason {} |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 120 | |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 121 | static final int DISMISS_USER_GESTURE = 1; |
| 122 | static final int DISMISS_AGED = 2; |
| 123 | static final int DISMISS_TASK_FINISHED = 3; |
| 124 | static final int DISMISS_BLOCKED = 4; |
| 125 | static final int DISMISS_NOTIF_CANCEL = 5; |
| 126 | static final int DISMISS_ACCESSIBILITY_ACTION = 6; |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 127 | static final int DISMISS_NO_LONGER_BUBBLE = 7; |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 128 | static final int DISMISS_USER_CHANGED = 8; |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 129 | static final int DISMISS_GROUP_CANCELLED = 9; |
Mady Mellor | 8454ddf | 2019-08-15 11:16:23 -0700 | [diff] [blame] | 130 | static final int DISMISS_INVALID_INTENT = 10; |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 131 | |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 132 | public static final int MAX_BUBBLES = 5; // TODO: actually enforce this |
Joshua Tsuji | 25a4b7b | 2019-03-22 14:11:06 -0400 | [diff] [blame] | 133 | |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 134 | /** Flag to enable or disable the entire feature */ |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 135 | private static final String ENABLE_BUBBLES = "experiment_enable_bubbles"; |
Joshua Tsuji | 010c2b1 | 2019-02-25 18:11:25 -0500 | [diff] [blame] | 136 | |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 137 | private final Context mContext; |
| 138 | private final NotificationEntryManager mNotificationEntryManager; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 139 | private final BubbleTaskStackListener mTaskStackListener; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 140 | private BubbleStateChangeListener mStateChangeListener; |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 141 | private BubbleExpandListener mExpandListener; |
Issei Suzuki | c038754 | 2019-03-08 17:31:14 +0100 | [diff] [blame] | 142 | @Nullable private BubbleStackView.SurfaceSynchronizer mSurfaceSynchronizer; |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 143 | private final NotificationGroupManager mNotificationGroupManager; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 144 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 145 | private BubbleData mBubbleData; |
Joshua Tsuji | c650a14 | 2019-05-22 11:31:19 -0400 | [diff] [blame] | 146 | @Nullable private BubbleStackView mStackView; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 147 | |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 148 | // Tracks the id of the current (foreground) user. |
| 149 | private int mCurrentUserId; |
| 150 | // Saves notification keys of active bubbles when users are switched. |
| 151 | private final SparseSetArray<String> mSavedBubbleKeysPerUser; |
| 152 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 153 | // Bubbles get added to the status bar view |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 154 | private final StatusBarWindowController mStatusBarWindowController; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 155 | private final ZenModeController mZenModeController; |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 156 | private StatusBarStateListener mStatusBarStateListener; |
| 157 | |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 158 | private final NotificationInterruptionStateProvider mNotificationInterruptionStateProvider; |
Mady Mellor | a54e9fa | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 159 | private IStatusBarService mBarService; |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 160 | |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 161 | // Used for determining view rect for touch interaction |
| 162 | private Rect mTempRect = new Rect(); |
| 163 | |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 164 | // Listens to user switch so bubbles can be saved and restored. |
| 165 | private final NotificationLockscreenUserManager mNotifUserManager; |
| 166 | |
Joshua Tsuji | f418f9e | 2019-04-04 17:09:53 -0400 | [diff] [blame] | 167 | /** Last known orientation, used to detect orientation changes in {@link #onConfigChanged}. */ |
| 168 | private int mOrientation = Configuration.ORIENTATION_UNDEFINED; |
| 169 | |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 170 | /** |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 171 | * Listener to be notified when some states of the bubbles change. |
| 172 | */ |
| 173 | public interface BubbleStateChangeListener { |
| 174 | /** |
| 175 | * Called when the stack has bubbles or no longer has bubbles. |
| 176 | */ |
| 177 | void onHasBubblesChanged(boolean hasBubbles); |
| 178 | } |
| 179 | |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 180 | /** |
| 181 | * Listener to find out about stack expansion / collapse events. |
| 182 | */ |
| 183 | public interface BubbleExpandListener { |
| 184 | /** |
| 185 | * Called when the expansion state of the bubble stack changes. |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 186 | * |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 187 | * @param isExpanding whether it's expanding or collapsing |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 188 | * @param key the notification key associated with bubble being expanded |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 189 | */ |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 190 | void onBubbleExpandChanged(boolean isExpanding, String key); |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Listens for the current state of the status bar and updates the visibility state |
| 195 | * of bubbles as needed. |
| 196 | */ |
| 197 | private class StatusBarStateListener implements StatusBarStateController.StateListener { |
| 198 | private int mState; |
| 199 | /** |
| 200 | * Returns the current status bar state. |
| 201 | */ |
| 202 | public int getCurrentState() { |
| 203 | return mState; |
| 204 | } |
| 205 | |
| 206 | @Override |
| 207 | public void onStateChanged(int newState) { |
| 208 | mState = newState; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 209 | boolean shouldCollapse = (mState != SHADE); |
| 210 | if (shouldCollapse) { |
| 211 | collapseStack(); |
| 212 | } |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 213 | updateStack(); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 214 | } |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 215 | } |
| 216 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 217 | @Inject |
Mady Mellor | cfd06c1 | 2019-02-13 14:32:12 -0800 | [diff] [blame] | 218 | public BubbleController(Context context, StatusBarWindowController statusBarWindowController, |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 219 | BubbleData data, ConfigurationController configurationController, |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 220 | NotificationInterruptionStateProvider interruptionStateProvider, |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 221 | ZenModeController zenModeController, |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 222 | NotificationLockscreenUserManager notifUserManager, |
| 223 | NotificationGroupManager groupManager) { |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 224 | this(context, statusBarWindowController, data, null /* synchronizer */, |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 225 | configurationController, interruptionStateProvider, zenModeController, |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 226 | notifUserManager, groupManager); |
Issei Suzuki | c038754 | 2019-03-08 17:31:14 +0100 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | public BubbleController(Context context, StatusBarWindowController statusBarWindowController, |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 230 | BubbleData data, @Nullable BubbleStackView.SurfaceSynchronizer synchronizer, |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 231 | ConfigurationController configurationController, |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 232 | NotificationInterruptionStateProvider interruptionStateProvider, |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 233 | ZenModeController zenModeController, |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 234 | NotificationLockscreenUserManager notifUserManager, |
| 235 | NotificationGroupManager groupManager) { |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 236 | mContext = context; |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 237 | mNotificationInterruptionStateProvider = interruptionStateProvider; |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 238 | mNotifUserManager = notifUserManager; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 239 | mZenModeController = zenModeController; |
| 240 | mZenModeController.addCallback(new ZenModeController.Callback() { |
| 241 | @Override |
| 242 | public void onZenChanged(int zen) { |
Mady Mellor | df48d0a | 2019-06-25 18:26:46 -0700 | [diff] [blame] | 243 | if (mStackView != null) { |
| 244 | mStackView.updateDots(); |
| 245 | } |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | @Override |
| 249 | public void onConfigChanged(ZenModeConfig config) { |
Mady Mellor | df48d0a | 2019-06-25 18:26:46 -0700 | [diff] [blame] | 250 | if (mStackView != null) { |
| 251 | mStackView.updateDots(); |
| 252 | } |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 253 | } |
| 254 | }); |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 255 | |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 256 | configurationController.addCallback(this /* configurationListener */); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 257 | |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 258 | mBubbleData = data; |
| 259 | mBubbleData.setListener(mBubbleDataListener); |
| 260 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 261 | mNotificationEntryManager = Dependency.get(NotificationEntryManager.class); |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 262 | mNotificationEntryManager.addNotificationEntryListener(mEntryListener); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 263 | mNotificationEntryManager.setNotificationRemoveInterceptor(mRemoveInterceptor); |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 264 | mNotificationGroupManager = groupManager; |
Mady Mellor | 740d85d | 2019-07-09 15:26:47 -0700 | [diff] [blame] | 265 | mNotificationGroupManager.addOnGroupChangeListener( |
| 266 | new NotificationGroupManager.OnGroupChangeListener() { |
| 267 | @Override |
| 268 | public void onGroupSuppressionChanged( |
| 269 | NotificationGroupManager.NotificationGroup group, |
| 270 | boolean suppressed) { |
| 271 | // More notifications could be added causing summary to no longer |
| 272 | // be suppressed -- in this case need to remove the key. |
| 273 | final String groupKey = group.summary != null |
| 274 | ? group.summary.notification.getGroupKey() |
| 275 | : null; |
| 276 | if (!suppressed && groupKey != null |
| 277 | && mBubbleData.isSummarySuppressed(groupKey)) { |
| 278 | mBubbleData.removeSuppressedSummary(groupKey); |
| 279 | } |
| 280 | } |
| 281 | }); |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 282 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 283 | mStatusBarWindowController = statusBarWindowController; |
| 284 | mStatusBarStateListener = new StatusBarStateListener(); |
| 285 | Dependency.get(StatusBarStateController.class).addCallback(mStatusBarStateListener); |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 286 | |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 287 | mTaskStackListener = new BubbleTaskStackListener(); |
| 288 | ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 289 | |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 290 | try { |
| 291 | WindowManagerWrapper.getInstance().addPinnedStackListener(new BubblesImeListener()); |
| 292 | } catch (RemoteException e) { |
| 293 | e.printStackTrace(); |
| 294 | } |
Issei Suzuki | c038754 | 2019-03-08 17:31:14 +0100 | [diff] [blame] | 295 | mSurfaceSynchronizer = synchronizer; |
Mady Mellor | a54e9fa | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 296 | |
| 297 | mBarService = IStatusBarService.Stub.asInterface( |
| 298 | ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 299 | |
| 300 | mSavedBubbleKeysPerUser = new SparseSetArray<>(); |
| 301 | mCurrentUserId = mNotifUserManager.getCurrentUserId(); |
| 302 | mNotifUserManager.addUserChangedListener( |
| 303 | newUserId -> { |
| 304 | saveBubbles(mCurrentUserId); |
| 305 | mBubbleData.dismissAll(DISMISS_USER_CHANGED); |
| 306 | restoreBubbles(newUserId); |
| 307 | mCurrentUserId = newUserId; |
| 308 | }); |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 309 | } |
| 310 | |
Mark Renouf | 8b6a3c6 | 2019-04-09 10:17:40 -0400 | [diff] [blame] | 311 | /** |
| 312 | * BubbleStackView is lazily created by this method the first time a Bubble is added. This |
| 313 | * method initializes the stack view and adds it to the StatusBar just above the scrim. |
| 314 | */ |
| 315 | private void ensureStackViewCreated() { |
| 316 | if (mStackView == null) { |
| 317 | mStackView = new BubbleStackView(mContext, mBubbleData, mSurfaceSynchronizer); |
| 318 | ViewGroup sbv = mStatusBarWindowController.getStatusBarView(); |
Selim Cinek | b4ba5c9 | 2019-10-25 17:37:00 -0700 | [diff] [blame] | 319 | // TODO(b/130237686): When you expand the shade on top of expanded bubble, there is no |
| 320 | // scrim between bubble and the shade |
| 321 | int bubblePosition = sbv.indexOfChild(sbv.findViewById(R.id.scrim_behind)) + 1; |
| 322 | sbv.addView(mStackView, bubblePosition, |
Mark Renouf | 8b6a3c6 | 2019-04-09 10:17:40 -0400 | [diff] [blame] | 323 | new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)); |
| 324 | if (mExpandListener != null) { |
| 325 | mStackView.setExpandListener(mExpandListener); |
| 326 | } |
Mark Renouf | 8b6a3c6 | 2019-04-09 10:17:40 -0400 | [diff] [blame] | 327 | } |
| 328 | } |
| 329 | |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 330 | /** |
| 331 | * Records the notification key for any active bubbles. These are used to restore active |
| 332 | * bubbles when the user returns to the foreground. |
| 333 | * |
| 334 | * @param userId the id of the user |
| 335 | */ |
| 336 | private void saveBubbles(@UserIdInt int userId) { |
| 337 | // First clear any existing keys that might be stored. |
| 338 | mSavedBubbleKeysPerUser.remove(userId); |
| 339 | // Add in all active bubbles for the current user. |
| 340 | for (Bubble bubble: mBubbleData.getBubbles()) { |
| 341 | mSavedBubbleKeysPerUser.add(userId, bubble.getKey()); |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | /** |
| 346 | * Promotes existing notifications to Bubbles if they were previously bubbles. |
| 347 | * |
| 348 | * @param userId the id of the user |
| 349 | */ |
| 350 | private void restoreBubbles(@UserIdInt int userId) { |
| 351 | NotificationData notificationData = |
| 352 | mNotificationEntryManager.getNotificationData(); |
| 353 | ArraySet<String> savedBubbleKeys = mSavedBubbleKeysPerUser.get(userId); |
| 354 | if (savedBubbleKeys == null) { |
| 355 | // There were no bubbles saved for this used. |
| 356 | return; |
| 357 | } |
| 358 | for (NotificationEntry e : notificationData.getNotificationsForCurrentUser()) { |
| 359 | if (savedBubbleKeys.contains(e.key) |
| 360 | && mNotificationInterruptionStateProvider.shouldBubbleUp(e) |
| 361 | && canLaunchInActivityView(mContext, e)) { |
| 362 | updateBubble(e, /* suppressFlyout= */ true); |
| 363 | } |
| 364 | } |
| 365 | // Finally, remove the entries for this user now that bubbles are restored. |
| 366 | mSavedBubbleKeysPerUser.remove(mCurrentUserId); |
| 367 | } |
| 368 | |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 369 | @Override |
| 370 | public void onUiModeChanged() { |
| 371 | if (mStackView != null) { |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 372 | mStackView.onThemeChanged(); |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 373 | } |
| 374 | } |
| 375 | |
| 376 | @Override |
| 377 | public void onOverlayChanged() { |
| 378 | if (mStackView != null) { |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 379 | mStackView.onThemeChanged(); |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | |
Joshua Tsuji | f418f9e | 2019-04-04 17:09:53 -0400 | [diff] [blame] | 383 | @Override |
| 384 | public void onConfigChanged(Configuration newConfig) { |
| 385 | if (mStackView != null && newConfig != null && newConfig.orientation != mOrientation) { |
Joshua Tsuji | f418f9e | 2019-04-04 17:09:53 -0400 | [diff] [blame] | 386 | mOrientation = newConfig.orientation; |
Lyn Han | f473031 | 2019-06-18 11:18:58 -0700 | [diff] [blame] | 387 | mStackView.onOrientationChanged(newConfig.orientation); |
Joshua Tsuji | f418f9e | 2019-04-04 17:09:53 -0400 | [diff] [blame] | 388 | } |
| 389 | } |
| 390 | |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 391 | /** |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 392 | * Set a listener to be notified when some states of the bubbles change. |
| 393 | */ |
| 394 | public void setBubbleStateChangeListener(BubbleStateChangeListener listener) { |
| 395 | mStateChangeListener = listener; |
| 396 | } |
| 397 | |
| 398 | /** |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 399 | * Set a listener to be notified of bubble expand events. |
| 400 | */ |
| 401 | public void setExpandListener(BubbleExpandListener listener) { |
Issei Suzuki | ac9fcb7 | 2019-02-04 17:45:57 +0100 | [diff] [blame] | 402 | mExpandListener = ((isExpanding, key) -> { |
| 403 | if (listener != null) { |
| 404 | listener.onBubbleExpandChanged(isExpanding, key); |
| 405 | } |
| 406 | mStatusBarWindowController.setBubbleExpanded(isExpanding); |
| 407 | }); |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 408 | if (mStackView != null) { |
| 409 | mStackView.setExpandListener(mExpandListener); |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | /** |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 414 | * Whether or not there are bubbles present, regardless of them being visible on the |
| 415 | * screen (e.g. if on AOD). |
| 416 | */ |
| 417 | public boolean hasBubbles() { |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 418 | if (mStackView == null) { |
| 419 | return false; |
| 420 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 421 | return mBubbleData.hasBubbles(); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | /** |
| 425 | * Whether the stack of bubbles is expanded or not. |
| 426 | */ |
| 427 | public boolean isStackExpanded() { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 428 | return mBubbleData.isExpanded(); |
| 429 | } |
| 430 | |
| 431 | /** |
| 432 | * Tell the stack of bubbles to expand. |
| 433 | */ |
| 434 | public void expandStack() { |
| 435 | mBubbleData.setExpanded(true); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | /** |
| 439 | * Tell the stack of bubbles to collapse. |
| 440 | */ |
| 441 | public void collapseStack() { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 442 | mBubbleData.setExpanded(false /* expanded */); |
| 443 | } |
| 444 | |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 445 | /** |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 446 | * True if either: |
| 447 | * (1) There is a bubble associated with the provided key and if its notification is hidden |
| 448 | * from the shade. |
| 449 | * (2) There is a group summary associated with the provided key that is hidden from the shade |
| 450 | * because it has been dismissed but still has child bubbles active. |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 451 | * |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 452 | * False otherwise. |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 453 | */ |
| 454 | public boolean isBubbleNotificationSuppressedFromShade(String key) { |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 455 | boolean isBubbleAndSuppressed = mBubbleData.hasBubbleWithKey(key) |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 456 | && !mBubbleData.getBubbleWithKey(key).showInShadeWhenBubble(); |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 457 | NotificationEntry entry = mNotificationEntryManager.getNotificationData().get(key); |
| 458 | String groupKey = entry != null ? entry.notification.getGroupKey() : null; |
| 459 | boolean isSuppressedSummary = mBubbleData.isSummarySuppressed(groupKey); |
Mady Mellor | e434827 | 2019-07-29 17:43:36 -0700 | [diff] [blame] | 460 | boolean isSummary = key.equals(mBubbleData.getSummaryKey(groupKey)); |
| 461 | return (isSummary && isSuppressedSummary) || isBubbleAndSuppressed; |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 462 | } |
| 463 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 464 | void selectBubble(Bubble bubble) { |
| 465 | mBubbleData.setSelectedBubble(bubble); |
| 466 | } |
| 467 | |
| 468 | @VisibleForTesting |
| 469 | void selectBubble(String key) { |
| 470 | Bubble bubble = mBubbleData.getBubbleWithKey(key); |
| 471 | selectBubble(bubble); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | /** |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 475 | * Request the stack expand if needed, then select the specified Bubble as current. |
| 476 | * |
| 477 | * @param notificationKey the notification key for the bubble to be selected |
| 478 | */ |
| 479 | public void expandStackAndSelectBubble(String notificationKey) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 480 | Bubble bubble = mBubbleData.getBubbleWithKey(notificationKey); |
| 481 | if (bubble != null) { |
| 482 | mBubbleData.setSelectedBubble(bubble); |
| 483 | mBubbleData.setExpanded(true); |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 484 | } |
| 485 | } |
| 486 | |
| 487 | /** |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 488 | * Tell the stack of bubbles to be dismissed, this will remove all of the bubbles in the stack. |
| 489 | */ |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 490 | void dismissStack(@DismissReason int reason) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 491 | mBubbleData.dismissAll(reason); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | /** |
Mark Renouf | 041d726 | 2019-02-06 12:09:41 -0500 | [diff] [blame] | 495 | * Directs a back gesture at the bubble stack. When opened, the current expanded bubble |
| 496 | * is forwarded a back key down/up pair. |
| 497 | */ |
| 498 | public void performBackPressIfNeeded() { |
| 499 | if (mStackView != null) { |
| 500 | mStackView.performBackPressIfNeeded(); |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | /** |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 505 | * Adds or updates a bubble associated with the provided notification entry. |
| 506 | * |
Mark Renouf | 8b6a3c6 | 2019-04-09 10:17:40 -0400 | [diff] [blame] | 507 | * @param notif the notification associated with this bubble. |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 508 | */ |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 509 | void updateBubble(NotificationEntry notif) { |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 510 | updateBubble(notif, /* supressFlyout */ false); |
| 511 | } |
| 512 | |
| 513 | void updateBubble(NotificationEntry notif, boolean suppressFlyout) { |
Mady Mellor | 66efd5e | 2019-05-15 13:38:11 -0700 | [diff] [blame] | 514 | // If this is an interruptive notif, mark that it's interrupted |
| 515 | if (notif.importance >= NotificationManager.IMPORTANCE_HIGH) { |
| 516 | notif.setInterruption(); |
| 517 | } |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 518 | mBubbleData.notificationEntryUpdated(notif, suppressFlyout); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | /** |
| 522 | * Removes the bubble associated with the {@param uri}. |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 523 | * <p> |
| 524 | * Must be called from the main thread. |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 525 | */ |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 526 | @MainThread |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 527 | void removeBubble(String key, int reason) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 528 | // TEMP: refactor to change this to pass entry |
| 529 | Bubble bubble = mBubbleData.getBubbleWithKey(key); |
| 530 | if (bubble != null) { |
Mady Mellor | ed99c27 | 2019-06-13 15:58:30 -0700 | [diff] [blame] | 531 | mBubbleData.notificationEntryRemoved(bubble.getEntry(), reason); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 532 | } |
| 533 | } |
| 534 | |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 535 | @SuppressWarnings("FieldCanBeLocal") |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 536 | private final NotificationRemoveInterceptor mRemoveInterceptor = |
| 537 | new NotificationRemoveInterceptor() { |
| 538 | @Override |
| 539 | public boolean onNotificationRemoveRequested(String key, int reason) { |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 540 | NotificationEntry entry = mNotificationEntryManager.getNotificationData().get(key); |
| 541 | String groupKey = entry != null ? entry.notification.getGroupKey() : null; |
| 542 | ArrayList<Bubble> bubbleChildren = mBubbleData.getBubblesInGroup(groupKey); |
| 543 | |
| 544 | boolean inBubbleData = mBubbleData.hasBubbleWithKey(key); |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 545 | boolean isSuppressedSummary = (mBubbleData.isSummarySuppressed(groupKey) |
| 546 | && mBubbleData.getSummaryKey(groupKey).equals(key)); |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 547 | boolean isSummary = entry != null |
| 548 | && entry.notification.getNotification().isGroupSummary(); |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 549 | boolean isSummaryOfBubbles = (isSuppressedSummary || isSummary) |
| 550 | && bubbleChildren != null && !bubbleChildren.isEmpty(); |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 551 | |
| 552 | if (!inBubbleData && !isSummaryOfBubbles) { |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 553 | return false; |
| 554 | } |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 555 | |
| 556 | final boolean isClearAll = reason == REASON_CANCEL_ALL; |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 557 | final boolean isUserDimiss = reason == REASON_CANCEL || reason == REASON_CLICK; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 558 | final boolean isAppCancel = reason == REASON_APP_CANCEL |
| 559 | || reason == REASON_APP_CANCEL_ALL; |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 560 | final boolean isSummaryCancel = reason == REASON_GROUP_SUMMARY_CANCELED; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 561 | |
| 562 | // Need to check for !appCancel here because the notification may have |
| 563 | // previously been dismissed & entry.isRowDismissed would still be true |
Mady Mellor | ca184aae | 2019-09-17 16:07:12 -0700 | [diff] [blame] | 564 | boolean userRemovedNotif = (entry != null && entry.isRowDismissed() && !isAppCancel) |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 565 | || isClearAll || isUserDimiss || isSummaryCancel; |
| 566 | |
| 567 | if (isSummaryOfBubbles) { |
| 568 | return handleSummaryRemovalInterception(entry, userRemovedNotif); |
| 569 | } |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 570 | |
| 571 | // The bubble notification sticks around in the data as long as the bubble is |
| 572 | // not dismissed and the app hasn't cancelled the notification. |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 573 | Bubble bubble = mBubbleData.getBubbleWithKey(key); |
Mady Mellor | ca184aae | 2019-09-17 16:07:12 -0700 | [diff] [blame] | 574 | boolean bubbleExtended = entry != null && entry.isBubble() && userRemovedNotif; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 575 | if (bubbleExtended) { |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 576 | bubble.setShowInShadeWhenBubble(false); |
Mady Mellor | df48d0a | 2019-06-25 18:26:46 -0700 | [diff] [blame] | 577 | bubble.setShowBubbleDot(false); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 578 | if (mStackView != null) { |
| 579 | mStackView.updateDotVisibility(entry.key); |
| 580 | } |
| 581 | mNotificationEntryManager.updateNotifications(); |
| 582 | return true; |
Mady Mellor | ca184aae | 2019-09-17 16:07:12 -0700 | [diff] [blame] | 583 | } else if (!userRemovedNotif && entry != null) { |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 584 | // This wasn't a user removal so we should remove the bubble as well |
| 585 | mBubbleData.notificationEntryRemoved(entry, DISMISS_NOTIF_CANCEL); |
| 586 | return false; |
| 587 | } |
| 588 | return false; |
| 589 | } |
| 590 | }; |
| 591 | |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 592 | private boolean handleSummaryRemovalInterception(NotificationEntry summary, |
| 593 | boolean userRemovedNotif) { |
| 594 | String groupKey = summary.notification.getGroupKey(); |
| 595 | ArrayList<Bubble> bubbleChildren = mBubbleData.getBubblesInGroup(groupKey); |
| 596 | |
| 597 | if (userRemovedNotif) { |
| 598 | // If it's a user dismiss we mark the children to be hidden from the shade. |
| 599 | for (int i = 0; i < bubbleChildren.size(); i++) { |
| 600 | Bubble bubbleChild = bubbleChildren.get(i); |
| 601 | // As far as group manager is concerned, once a child is no longer shown |
| 602 | // in the shade, it is essentially removed. |
| 603 | mNotificationGroupManager.onEntryRemoved(bubbleChild.getEntry()); |
| 604 | bubbleChild.setShowInShadeWhenBubble(false); |
| 605 | bubbleChild.setShowBubbleDot(false); |
| 606 | if (mStackView != null) { |
| 607 | mStackView.updateDotVisibility(bubbleChild.getKey()); |
| 608 | } |
| 609 | } |
| 610 | // And since all children are removed, remove the summary. |
| 611 | mNotificationGroupManager.onEntryRemoved(summary); |
| 612 | |
| 613 | // If the summary was auto-generated we don't need to keep that notification around |
| 614 | // because apps can't cancel it; so we only intercept & suppress real summaries. |
| 615 | boolean isAutogroupSummary = (summary.notification.getNotification().flags |
| 616 | & FLAG_AUTOGROUP_SUMMARY) != 0; |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 617 | if (!isAutogroupSummary) { |
| 618 | mBubbleData.addSummaryToSuppress(summary.notification.getGroupKey(), |
| 619 | summary.key); |
| 620 | // Tell shade to update for the suppression |
| 621 | mNotificationEntryManager.updateNotifications(); |
| 622 | } |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 623 | return !isAutogroupSummary; |
| 624 | } else { |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 625 | // If it's not a user dismiss it's a cancel. |
| 626 | mBubbleData.removeSuppressedSummary(groupKey); |
| 627 | |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 628 | // Remove any associated bubble children. |
| 629 | for (int i = 0; i < bubbleChildren.size(); i++) { |
| 630 | Bubble bubbleChild = bubbleChildren.get(i); |
| 631 | mBubbleData.notificationEntryRemoved(bubbleChild.getEntry(), |
| 632 | DISMISS_GROUP_CANCELLED); |
| 633 | } |
| 634 | return false; |
| 635 | } |
| 636 | } |
| 637 | |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 638 | @SuppressWarnings("FieldCanBeLocal") |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 639 | private final NotificationEntryListener mEntryListener = new NotificationEntryListener() { |
| 640 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 641 | public void onPendingEntryAdded(NotificationEntry entry) { |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 642 | if (!areBubblesEnabled(mContext)) { |
| 643 | return; |
| 644 | } |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 645 | if (mNotificationInterruptionStateProvider.shouldBubbleUp(entry) |
| 646 | && canLaunchInActivityView(mContext, entry)) { |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 647 | updateBubble(entry); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 648 | } |
| 649 | } |
| 650 | |
| 651 | @Override |
| 652 | public void onPreEntryUpdated(NotificationEntry entry) { |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 653 | if (!areBubblesEnabled(mContext)) { |
| 654 | return; |
| 655 | } |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 656 | boolean shouldBubble = mNotificationInterruptionStateProvider.shouldBubbleUp(entry) |
| 657 | && canLaunchInActivityView(mContext, entry); |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 658 | if (!shouldBubble && mBubbleData.hasBubbleWithKey(entry.key)) { |
| 659 | // It was previously a bubble but no longer a bubble -- lets remove it |
| 660 | removeBubble(entry.key, DISMISS_NO_LONGER_BUBBLE); |
Mady Mellor | ff40e01 | 2019-05-03 15:34:41 -0700 | [diff] [blame] | 661 | } else if (shouldBubble) { |
Mady Mellor | ed99c27 | 2019-06-13 15:58:30 -0700 | [diff] [blame] | 662 | Bubble b = mBubbleData.getBubbleWithKey(entry.key); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 663 | updateBubble(entry); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 664 | } |
| 665 | } |
Mark Renouf | bbcf07f | 2019-05-09 10:42:43 -0400 | [diff] [blame] | 666 | |
| 667 | @Override |
| 668 | public void onNotificationRankingUpdated(RankingMap rankingMap) { |
| 669 | // Forward to BubbleData to block any bubbles which should no longer be shown |
| 670 | mBubbleData.notificationRankingUpdated(rankingMap); |
| 671 | } |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 672 | }; |
| 673 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 674 | @SuppressWarnings("FieldCanBeLocal") |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 675 | private final BubbleData.Listener mBubbleDataListener = new BubbleData.Listener() { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 676 | |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 677 | @Override |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 678 | public void applyUpdate(BubbleData.Update update) { |
| 679 | if (mStackView == null && update.addedBubble != null) { |
| 680 | // Lazy init stack view when the first bubble is added. |
| 681 | ensureStackViewCreated(); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 682 | } |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 683 | |
| 684 | // If not yet initialized, ignore all other changes. |
| 685 | if (mStackView == null) { |
| 686 | return; |
| 687 | } |
| 688 | |
| 689 | if (update.addedBubble != null) { |
| 690 | mStackView.addBubble(update.addedBubble); |
| 691 | } |
| 692 | |
| 693 | // Collapsing? Do this first before remaining steps. |
| 694 | if (update.expandedChanged && !update.expanded) { |
| 695 | mStackView.setExpanded(false); |
| 696 | } |
| 697 | |
| 698 | // Do removals, if any. |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 699 | ArrayList<Pair<Bubble, Integer>> removedBubbles = |
| 700 | new ArrayList<>(update.removedBubbles); |
| 701 | for (Pair<Bubble, Integer> removed : removedBubbles) { |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 702 | final Bubble bubble = removed.first; |
| 703 | @DismissReason final int reason = removed.second; |
| 704 | mStackView.removeBubble(bubble); |
| 705 | |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 706 | // If the bubble is removed for user switching, leave the notification in place. |
| 707 | if (reason != DISMISS_USER_CHANGED) { |
| 708 | if (!mBubbleData.hasBubbleWithKey(bubble.getKey()) |
| 709 | && !bubble.showInShadeWhenBubble()) { |
| 710 | // The bubble is gone & the notification is gone, time to actually remove it |
| 711 | mNotificationEntryManager.performRemoveNotification( |
| 712 | bubble.getEntry().notification, UNDEFINED_DISMISS_REASON); |
| 713 | } else { |
| 714 | // Update the flag for SysUI |
| 715 | bubble.getEntry().notification.getNotification().flags &= ~FLAG_BUBBLE; |
Mady Mellor | 3a0a1b4 | 2019-05-23 06:40:21 -0700 | [diff] [blame] | 716 | |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 717 | // Make sure NoMan knows it's not a bubble anymore so anyone querying it |
| 718 | // will get right result back |
| 719 | try { |
| 720 | mBarService.onNotificationBubbleChanged(bubble.getKey(), |
| 721 | false /* isBubble */); |
| 722 | } catch (RemoteException e) { |
| 723 | // Bad things have happened |
| 724 | } |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 725 | } |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 726 | |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 727 | // Check if removed bubble has an associated suppressed group summary that needs |
| 728 | // to be removed now. |
| 729 | final String groupKey = bubble.getEntry().notification.getGroupKey(); |
| 730 | if (mBubbleData.isSummarySuppressed(groupKey) |
| 731 | && mBubbleData.getBubblesInGroup(groupKey).isEmpty()) { |
| 732 | // Time to actually remove the summary. |
| 733 | String notifKey = mBubbleData.getSummaryKey(groupKey); |
| 734 | mBubbleData.removeSuppressedSummary(groupKey); |
| 735 | NotificationEntry entry = |
| 736 | mNotificationEntryManager.getNotificationData().get(notifKey); |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 737 | mNotificationEntryManager.performRemoveNotification( |
| 738 | entry.notification, UNDEFINED_DISMISS_REASON); |
| 739 | } |
| 740 | |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 741 | // Check if summary should be removed from NoManGroup |
| 742 | NotificationEntry summary = mNotificationGroupManager.getLogicalGroupSummary( |
| 743 | bubble.getEntry().notification); |
| 744 | if (summary != null) { |
| 745 | ArrayList<NotificationEntry> summaryChildren = |
| 746 | mNotificationGroupManager.getLogicalChildren(summary.notification); |
Mady Mellor | e434827 | 2019-07-29 17:43:36 -0700 | [diff] [blame] | 747 | boolean isSummaryThisNotif = summary.key.equals(bubble.getEntry().key); |
| 748 | if (!isSummaryThisNotif |
| 749 | && (summaryChildren == null || summaryChildren.isEmpty())) { |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 750 | mNotificationEntryManager.performRemoveNotification( |
| 751 | summary.notification, UNDEFINED_DISMISS_REASON); |
| 752 | } |
| 753 | } |
Mady Mellor | a54e9fa | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 754 | } |
| 755 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 756 | |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 757 | if (update.updatedBubble != null) { |
| 758 | mStackView.updateBubble(update.updatedBubble); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 759 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 760 | |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 761 | if (update.orderChanged) { |
| 762 | mStackView.updateBubbleOrder(update.bubbles); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 763 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 764 | |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 765 | if (update.selectionChanged) { |
| 766 | mStackView.setSelectedBubble(update.selectedBubble); |
Mady Mellor | 740d85d | 2019-07-09 15:26:47 -0700 | [diff] [blame] | 767 | if (update.selectedBubble != null) { |
| 768 | mNotificationGroupManager.updateSuppression( |
| 769 | update.selectedBubble.getEntry()); |
| 770 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 771 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 772 | |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 773 | // Expanding? Apply this last. |
| 774 | if (update.expandedChanged && update.expanded) { |
| 775 | mStackView.setExpanded(true); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 776 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 777 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 778 | mNotificationEntryManager.updateNotifications(); |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 779 | updateStack(); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 780 | |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 781 | if (DEBUG_BUBBLE_CONTROLLER) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 782 | Log.d(TAG, "[BubbleData]"); |
| 783 | Log.d(TAG, formatBubblesString(mBubbleData.getBubbles(), |
| 784 | mBubbleData.getSelectedBubble())); |
| 785 | |
| 786 | if (mStackView != null) { |
| 787 | Log.d(TAG, "[BubbleStackView]"); |
| 788 | Log.d(TAG, formatBubblesString(mStackView.getBubblesOnScreen(), |
| 789 | mStackView.getExpandedBubble())); |
| 790 | } |
| 791 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 792 | } |
| 793 | }; |
| 794 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 795 | /** |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 796 | * Lets any listeners know if bubble state has changed. |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 797 | * Updates the visibility of the bubbles based on current state. |
| 798 | * Does not un-bubble, just hides or un-hides. Notifies any |
| 799 | * {@link BubbleStateChangeListener}s of visibility changes. |
| 800 | * Updates stack description for TalkBack focus. |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 801 | */ |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 802 | public void updateStack() { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 803 | if (mStackView == null) { |
| 804 | return; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 805 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 806 | if (mStatusBarStateListener.getCurrentState() == SHADE && hasBubbles()) { |
| 807 | // Bubbles only appear in unlocked shade |
| 808 | mStackView.setVisibility(hasBubbles() ? VISIBLE : INVISIBLE); |
Mady Mellor | 698d9e8 | 2019-08-01 23:11:53 +0000 | [diff] [blame] | 809 | } else if (mStackView != null) { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 810 | mStackView.setVisibility(INVISIBLE); |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 811 | } |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 812 | |
Mady Mellor | 698d9e8 | 2019-08-01 23:11:53 +0000 | [diff] [blame] | 813 | // Let listeners know if bubble state changed. |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 814 | boolean hadBubbles = mStatusBarWindowController.getBubblesShowing(); |
Mady Mellor | 698d9e8 | 2019-08-01 23:11:53 +0000 | [diff] [blame] | 815 | boolean hasBubblesShowing = hasBubbles() && mStackView.getVisibility() == VISIBLE; |
Mady Mellor | 88552b8 | 2019-08-05 22:38:59 +0000 | [diff] [blame] | 816 | mStatusBarWindowController.setBubblesShowing(hasBubblesShowing); |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 817 | if (mStateChangeListener != null && hadBubbles != hasBubblesShowing) { |
| 818 | mStateChangeListener.onHasBubblesChanged(hasBubblesShowing); |
| 819 | } |
| 820 | |
| 821 | mStackView.updateContentDescription(); |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | /** |
| 825 | * Rect indicating the touchable region for the bubble stack / expanded stack. |
| 826 | */ |
| 827 | public Rect getTouchableRegion() { |
| 828 | if (mStackView == null || mStackView.getVisibility() != VISIBLE) { |
| 829 | return null; |
| 830 | } |
| 831 | mStackView.getBoundsOnScreen(mTempRect); |
| 832 | return mTempRect; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 833 | } |
| 834 | |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 835 | /** |
| 836 | * The display id of the expanded view, if the stack is expanded and not occluded by the |
| 837 | * status bar, otherwise returns {@link Display#INVALID_DISPLAY}. |
| 838 | */ |
| 839 | public int getExpandedDisplayId(Context context) { |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 840 | final Bubble bubble = getExpandedBubble(context); |
| 841 | return bubble != null ? bubble.getDisplayId() : INVALID_DISPLAY; |
| 842 | } |
| 843 | |
| 844 | @Nullable |
| 845 | private Bubble getExpandedBubble(Context context) { |
Joel Galenson | 4071ddb | 2019-04-18 13:30:45 -0700 | [diff] [blame] | 846 | if (mStackView == null) { |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 847 | return null; |
Joel Galenson | 4071ddb | 2019-04-18 13:30:45 -0700 | [diff] [blame] | 848 | } |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 849 | final boolean defaultDisplay = context.getDisplay() != null |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 850 | && context.getDisplay().getDisplayId() == DEFAULT_DISPLAY; |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 851 | final Bubble expandedBubble = mStackView.getExpandedBubble(); |
| 852 | if (defaultDisplay && expandedBubble != null && isStackExpanded() |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 853 | && !mStatusBarWindowController.getPanelExpanded()) { |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 854 | return expandedBubble; |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 855 | } |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 856 | return null; |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 857 | } |
| 858 | |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 859 | @VisibleForTesting |
| 860 | BubbleStackView getStackView() { |
| 861 | return mStackView; |
| 862 | } |
| 863 | |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 864 | /** |
| 865 | * Description of current bubble state. |
| 866 | */ |
| 867 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 868 | pw.println("BubbleController state:"); |
| 869 | mBubbleData.dump(fd, pw, args); |
| 870 | pw.println(); |
Joshua Tsuji | 395bcfe | 2019-07-02 19:23:23 -0400 | [diff] [blame] | 871 | if (mStackView != null) { |
| 872 | mStackView.dump(fd, pw, args); |
| 873 | } |
| 874 | pw.println(); |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 875 | } |
| 876 | |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 877 | static String formatBubblesString(List<Bubble> bubbles, Bubble selected) { |
| 878 | StringBuilder sb = new StringBuilder(); |
| 879 | for (Bubble bubble : bubbles) { |
| 880 | if (bubble == null) { |
| 881 | sb.append(" <null> !!!!!\n"); |
| 882 | } else { |
| 883 | boolean isSelected = (bubble == selected); |
| 884 | sb.append(String.format("%s Bubble{act=%12d, ongoing=%d, key=%s}\n", |
| 885 | ((isSelected) ? "->" : " "), |
| 886 | bubble.getLastActivity(), |
| 887 | (bubble.isOngoing() ? 1 : 0), |
| 888 | bubble.getKey())); |
| 889 | } |
| 890 | } |
| 891 | return sb.toString(); |
| 892 | } |
| 893 | |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 894 | /** |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 895 | * This task stack listener is responsible for responding to tasks moved to the front |
| 896 | * which are on the default (main) display. When this happens, expanded bubbles must be |
| 897 | * collapsed so the user may interact with the app which was just moved to the front. |
| 898 | * <p> |
| 899 | * This listener is registered with SystemUI's ActivityManagerWrapper which dispatches |
| 900 | * these calls via a main thread Handler. |
| 901 | */ |
| 902 | @MainThread |
| 903 | private class BubbleTaskStackListener extends TaskStackChangeListener { |
| 904 | |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 905 | @Override |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 906 | public void onTaskMovedToFront(RunningTaskInfo taskInfo) { |
| 907 | if (mStackView != null && taskInfo.displayId == Display.DEFAULT_DISPLAY) { |
Mady Mellor | 047e24e | 2019-08-05 11:35:40 -0700 | [diff] [blame] | 908 | if (!mStackView.isExpansionAnimating()) { |
| 909 | mBubbleData.setExpanded(false); |
| 910 | } |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 911 | } |
| 912 | } |
| 913 | |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 914 | @Override |
Mark Renouf | a12e876 | 2019-03-07 15:43:01 -0500 | [diff] [blame] | 915 | public void onActivityLaunchOnSecondaryDisplayRerouted() { |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 916 | if (mStackView != null) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 917 | mBubbleData.setExpanded(false); |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 918 | } |
| 919 | } |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 920 | |
| 921 | @Override |
| 922 | public void onBackPressedOnTaskRoot(RunningTaskInfo taskInfo) { |
| 923 | if (mStackView != null && taskInfo.displayId == getExpandedDisplayId(mContext)) { |
| 924 | mBubbleData.setExpanded(false); |
| 925 | } |
| 926 | } |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 927 | |
| 928 | @Override |
| 929 | public void onSingleTaskDisplayDrawn(int displayId) { |
Mady Mellor | 5186b13 | 2019-09-16 17:55:48 -0700 | [diff] [blame] | 930 | final Bubble expandedBubble = mStackView != null |
| 931 | ? mStackView.getExpandedBubble() |
| 932 | : null; |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 933 | if (expandedBubble != null && expandedBubble.getDisplayId() == displayId) { |
| 934 | expandedBubble.setContentVisibility(true); |
| 935 | } |
| 936 | } |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 937 | |
| 938 | @Override |
| 939 | public void onSingleTaskDisplayEmpty(int displayId) { |
Mady Mellor | 5186b13 | 2019-09-16 17:55:48 -0700 | [diff] [blame] | 940 | final Bubble expandedBubble = mStackView != null |
| 941 | ? mStackView.getExpandedBubble() |
| 942 | : null; |
Mady Mellor | ca184aae | 2019-09-17 16:07:12 -0700 | [diff] [blame] | 943 | int expandedId = expandedBubble != null ? expandedBubble.getDisplayId() : -1; |
| 944 | if (mStackView != null && mStackView.isExpanded() && expandedId == displayId) { |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 945 | mBubbleData.setExpanded(false); |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 946 | } |
Mady Mellor | ca184aae | 2019-09-17 16:07:12 -0700 | [diff] [blame] | 947 | mBubbleData.notifyDisplayEmpty(displayId); |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 948 | } |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 949 | } |
| 950 | |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 951 | private static boolean areBubblesEnabled(Context context) { |
| 952 | return Settings.Secure.getInt(context.getContentResolver(), |
| 953 | ENABLE_BUBBLES, 1) != 0; |
| 954 | } |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 955 | |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 956 | /** |
| 957 | * Whether an intent is properly configured to display in an {@link android.app.ActivityView}. |
| 958 | * |
| 959 | * Keep checks in sync with NotificationManagerService#canLaunchInActivityView. Typically |
| 960 | * that should filter out any invalid bubbles, but should protect SysUI side just in case. |
| 961 | * |
| 962 | * @param context the context to use. |
| 963 | * @param entry the entry to bubble. |
| 964 | */ |
| 965 | static boolean canLaunchInActivityView(Context context, NotificationEntry entry) { |
| 966 | PendingIntent intent = entry.getBubbleMetadata() != null |
| 967 | ? entry.getBubbleMetadata().getIntent() |
| 968 | : null; |
| 969 | if (intent == null) { |
| 970 | Log.w(TAG, "Unable to create bubble -- no intent"); |
| 971 | return false; |
| 972 | } |
| 973 | ActivityInfo info = |
| 974 | intent.getIntent().resolveActivityInfo(context.getPackageManager(), 0); |
| 975 | if (info == null) { |
| 976 | Log.w(TAG, "Unable to send as bubble -- couldn't find activity info for intent: " |
| 977 | + intent); |
| 978 | return false; |
| 979 | } |
| 980 | if (!ActivityInfo.isResizeableMode(info.resizeMode)) { |
| 981 | Log.w(TAG, "Unable to send as bubble -- activity is not resizable for intent: " |
| 982 | + intent); |
| 983 | return false; |
| 984 | } |
| 985 | if (info.documentLaunchMode != DOCUMENT_LAUNCH_ALWAYS) { |
| 986 | Log.w(TAG, "Unable to send as bubble -- activity is not documentLaunchMode=always " |
| 987 | + "for intent: " + intent); |
| 988 | return false; |
| 989 | } |
| 990 | if ((info.flags & ActivityInfo.FLAG_ALLOW_EMBEDDED) == 0) { |
| 991 | Log.w(TAG, "Unable to send as bubble -- activity is not embeddable for intent: " |
| 992 | + intent); |
| 993 | return false; |
| 994 | } |
| 995 | return true; |
| 996 | } |
| 997 | |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 998 | /** PinnedStackListener that dispatches IME visibility updates to the stack. */ |
| 999 | private class BubblesImeListener extends IPinnedStackListener.Stub { |
| 1000 | |
| 1001 | @Override |
| 1002 | public void onListenerRegistered(IPinnedStackController controller) throws RemoteException { |
| 1003 | } |
| 1004 | |
| 1005 | @Override |
| 1006 | public void onMovementBoundsChanged(Rect insetBounds, Rect normalBounds, |
| 1007 | Rect animatingBounds, boolean fromImeAdjustment, boolean fromShelfAdjustment, |
| 1008 | int displayRotation) throws RemoteException {} |
| 1009 | |
| 1010 | @Override |
Joshua Tsuji | d942283 | 2019-03-05 13:32:37 -0500 | [diff] [blame] | 1011 | public void onImeVisibilityChanged(boolean imeVisible, int imeHeight) { |
| 1012 | if (mStackView != null && mStackView.getBubbleCount() > 0) { |
| 1013 | mStackView.post(() -> mStackView.onImeVisibilityChanged(imeVisible, imeHeight)); |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | @Override |
| 1018 | public void onShelfVisibilityChanged(boolean shelfVisible, int shelfHeight) |
| 1019 | throws RemoteException {} |
| 1020 | |
| 1021 | @Override |
| 1022 | public void onMinimizedStateChanged(boolean isMinimized) throws RemoteException {} |
| 1023 | |
| 1024 | @Override |
| 1025 | public void onActionsChanged(ParceledListSlice actions) throws RemoteException {} |
| 1026 | } |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1027 | } |