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