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