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