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) { |
Lyn Han | 1e19d7f | 2020-02-05 19:10:58 -0800 | [diff] [blame^] | 752 | bubble.setInflateSynchronously(mInflateSynchronously); |
| 753 | mBubbleData.promoteBubbleFromOverflow(bubble, mStackView, mBubbleIconFactory); |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 754 | } |
| 755 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 756 | /** |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 757 | * Request the stack expand if needed, then select the specified Bubble as current. |
| 758 | * |
| 759 | * @param notificationKey the notification key for the bubble to be selected |
| 760 | */ |
| 761 | public void expandStackAndSelectBubble(String notificationKey) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 762 | Bubble bubble = mBubbleData.getBubbleWithKey(notificationKey); |
| 763 | if (bubble != null) { |
| 764 | mBubbleData.setSelectedBubble(bubble); |
| 765 | mBubbleData.setExpanded(true); |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 766 | } |
| 767 | } |
| 768 | |
| 769 | /** |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 770 | * Tell the stack of bubbles to be dismissed, this will remove all of the bubbles in the stack. |
| 771 | */ |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 772 | void dismissStack(@DismissReason int reason) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 773 | mBubbleData.dismissAll(reason); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | /** |
Mark Renouf | 041d726 | 2019-02-06 12:09:41 -0500 | [diff] [blame] | 777 | * Directs a back gesture at the bubble stack. When opened, the current expanded bubble |
| 778 | * is forwarded a back key down/up pair. |
| 779 | */ |
| 780 | public void performBackPressIfNeeded() { |
| 781 | if (mStackView != null) { |
| 782 | mStackView.performBackPressIfNeeded(); |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | /** |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 787 | * Adds or updates a bubble associated with the provided notification entry. |
| 788 | * |
Mark Renouf | 8b6a3c6 | 2019-04-09 10:17:40 -0400 | [diff] [blame] | 789 | * @param notif the notification associated with this bubble. |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 790 | */ |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 791 | void updateBubble(NotificationEntry notif) { |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 792 | updateBubble(notif, false /* suppressFlyout */); |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | void updateBubble(NotificationEntry notif, boolean suppressFlyout) { |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 796 | updateBubble(notif, suppressFlyout, true /* showInShade */); |
| 797 | } |
| 798 | |
| 799 | void updateBubble(NotificationEntry notif, boolean suppressFlyout, boolean showInShade) { |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 800 | if (mStackView == null) { |
| 801 | // Lazy init stack view when a bubble is created |
| 802 | ensureStackViewCreated(); |
| 803 | } |
Mady Mellor | 66efd5e | 2019-05-15 13:38:11 -0700 | [diff] [blame] | 804 | // If this is an interruptive notif, mark that it's interrupted |
Ned Burns | 60e9459 | 2019-09-06 14:47:25 -0400 | [diff] [blame] | 805 | if (notif.getImportance() >= NotificationManager.IMPORTANCE_HIGH) { |
Mady Mellor | 66efd5e | 2019-05-15 13:38:11 -0700 | [diff] [blame] | 806 | notif.setInterruption(); |
| 807 | } |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 808 | Bubble bubble = mBubbleData.getOrCreateBubble(notif); |
| 809 | bubble.setInflateSynchronously(mInflateSynchronously); |
| 810 | bubble.inflate( |
| 811 | b -> mBubbleData.notificationEntryUpdated(b, suppressFlyout, showInShade), |
| 812 | mContext, mStackView, mBubbleIconFactory); |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | /** |
| 816 | * Called when a user has indicated that an active notification should be shown as a bubble. |
| 817 | * <p> |
| 818 | * This method will collapse the shade, create the bubble without a flyout or dot, and suppress |
| 819 | * the notification from appearing in the shade. |
| 820 | * |
| 821 | * @param entry the notification to show as a bubble. |
| 822 | */ |
| 823 | public void onUserCreatedBubbleFromNotification(NotificationEntry entry) { |
Mady Mellor | ff076eb | 2019-11-13 10:12:06 -0800 | [diff] [blame] | 824 | if (DEBUG_EXPERIMENTS || DEBUG_BUBBLE_CONTROLLER) { |
| 825 | Log.d(TAG, "onUserCreatedBubble: " + entry.getKey()); |
| 826 | } |
Heemin Seog | ba6337f | 2019-12-10 15:34:37 -0800 | [diff] [blame] | 827 | mShadeController.collapsePanel(true); |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 828 | entry.setFlagBubble(true); |
| 829 | updateBubble(entry, true /* suppressFlyout */, false /* showInShade */); |
Mady Mellor | ff076eb | 2019-11-13 10:12:06 -0800 | [diff] [blame] | 830 | mUserCreatedBubbles.add(entry.getKey()); |
Mady Mellor | 3b86a4f | 2019-12-11 13:15:41 -0800 | [diff] [blame] | 831 | mUserBlockedBubbles.remove(entry.getKey()); |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | /** |
| 835 | * Called when a user has indicated that an active notification appearing as a bubble should |
| 836 | * no longer be shown as a bubble. |
| 837 | * |
| 838 | * @param entry the notification to no longer show as a bubble. |
| 839 | */ |
| 840 | public void onUserDemotedBubbleFromNotification(NotificationEntry entry) { |
Mady Mellor | ff076eb | 2019-11-13 10:12:06 -0800 | [diff] [blame] | 841 | if (DEBUG_EXPERIMENTS || DEBUG_BUBBLE_CONTROLLER) { |
| 842 | Log.d(TAG, "onUserDemotedBubble: " + entry.getKey()); |
| 843 | } |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 844 | entry.setFlagBubble(false); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 845 | removeBubble(entry, DISMISS_BLOCKED); |
Mady Mellor | ff076eb | 2019-11-13 10:12:06 -0800 | [diff] [blame] | 846 | mUserCreatedBubbles.remove(entry.getKey()); |
Mady Mellor | 3b86a4f | 2019-12-11 13:15:41 -0800 | [diff] [blame] | 847 | if (BubbleExperimentConfig.isPackageWhitelistedToAutoBubble( |
| 848 | mContext, entry.getSbn().getPackageName())) { |
| 849 | // This package is whitelist but user demoted the bubble, let's save it so we don't |
| 850 | // auto-bubble for the whitelist again. |
| 851 | mUserBlockedBubbles.add(entry.getKey()); |
| 852 | } |
Mady Mellor | ff076eb | 2019-11-13 10:12:06 -0800 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | /** |
| 856 | * Whether this bubble was explicitly created by the user via a SysUI affordance. |
| 857 | */ |
| 858 | boolean isUserCreatedBubble(String key) { |
| 859 | return mUserCreatedBubbles.contains(key); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 860 | } |
| 861 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 862 | boolean isSummaryOfUserCreatedBubble(NotificationEntry entry) { |
| 863 | if (isSummaryOfBubbles(entry)) { |
| 864 | List<Bubble> bubbleChildren = |
| 865 | mBubbleData.getBubblesInGroup(entry.getSbn().getGroupKey()); |
| 866 | for (int i = 0; i < bubbleChildren.size(); i++) { |
| 867 | // Check if any are user-created (i.e. experimental bubbles) |
| 868 | if (isUserCreatedBubble(bubbleChildren.get(i).getKey())) { |
| 869 | return true; |
| 870 | } |
| 871 | } |
| 872 | } |
| 873 | return false; |
| 874 | } |
| 875 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 876 | /** |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 877 | * Removes the bubble with the given NotificationEntry. |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 878 | * <p> |
| 879 | * Must be called from the main thread. |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 880 | */ |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 881 | @MainThread |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 882 | void removeBubble(NotificationEntry entry, int reason) { |
| 883 | if (mBubbleData.hasBubbleWithKey(entry.getKey())) { |
| 884 | mBubbleData.notificationEntryRemoved(entry, reason); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 885 | } |
| 886 | } |
| 887 | |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 888 | private void onEntryAdded(NotificationEntry entry) { |
| 889 | boolean previouslyUserCreated = mUserCreatedBubbles.contains(entry.getKey()); |
| 890 | boolean userBlocked = mUserBlockedBubbles.contains(entry.getKey()); |
| 891 | boolean wasAdjusted = BubbleExperimentConfig.adjustForExperiments( |
| 892 | mContext, entry, previouslyUserCreated, userBlocked); |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 893 | |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 894 | if (mNotificationInterruptionStateProvider.shouldBubbleUp(entry) |
| 895 | && (canLaunchInActivityView(mContext, entry) || wasAdjusted)) { |
| 896 | if (wasAdjusted && !previouslyUserCreated) { |
| 897 | // Gotta treat the auto-bubbled / whitelisted packaged bubbles as usercreated |
| 898 | mUserCreatedBubbles.add(entry.getKey()); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 899 | } |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 900 | updateBubble(entry); |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 901 | } |
| 902 | } |
| 903 | |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 904 | private void onEntryUpdated(NotificationEntry entry) { |
| 905 | boolean previouslyUserCreated = mUserCreatedBubbles.contains(entry.getKey()); |
| 906 | boolean userBlocked = mUserBlockedBubbles.contains(entry.getKey()); |
| 907 | boolean wasAdjusted = BubbleExperimentConfig.adjustForExperiments( |
| 908 | mContext, entry, previouslyUserCreated, userBlocked); |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 909 | |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 910 | boolean shouldBubble = mNotificationInterruptionStateProvider.shouldBubbleUp(entry) |
| 911 | && (canLaunchInActivityView(mContext, entry) || wasAdjusted); |
| 912 | if (!shouldBubble && mBubbleData.hasBubbleWithKey(entry.getKey())) { |
| 913 | // It was previously a bubble but no longer a bubble -- lets remove it |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 914 | removeBubble(entry, DISMISS_NO_LONGER_BUBBLE); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 915 | } else if (shouldBubble) { |
| 916 | if (wasAdjusted && !previouslyUserCreated) { |
| 917 | // Gotta treat the auto-bubbled / whitelisted packaged bubbles as usercreated |
| 918 | mUserCreatedBubbles.add(entry.getKey()); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 919 | } |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 920 | updateBubble(entry); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 921 | } |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 922 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 923 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 924 | private void onEntryRemoved(NotificationEntry entry) { |
| 925 | if (isSummaryOfBubbles(entry)) { |
| 926 | final String groupKey = entry.getSbn().getGroupKey(); |
| 927 | mBubbleData.removeSuppressedSummary(groupKey); |
| 928 | |
| 929 | // Remove any associated bubble children with the summary |
| 930 | final List<Bubble> bubbleChildren = mBubbleData.getBubblesInGroup(groupKey); |
| 931 | for (int i = 0; i < bubbleChildren.size(); i++) { |
| 932 | removeBubble(bubbleChildren.get(i).getEntry(), DISMISS_GROUP_CANCELLED); |
| 933 | } |
| 934 | } else { |
| 935 | removeBubble(entry, DISMISS_NOTIF_CANCEL); |
| 936 | } |
| 937 | } |
| 938 | |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 939 | private void onRankingUpdated(RankingMap rankingMap) { |
| 940 | // Forward to BubbleData to block any bubbles which should no longer be shown |
| 941 | mBubbleData.notificationRankingUpdated(rankingMap); |
| 942 | } |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 943 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 944 | @SuppressWarnings("FieldCanBeLocal") |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 945 | private final BubbleData.Listener mBubbleDataListener = new BubbleData.Listener() { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 946 | |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 947 | @Override |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 948 | public void applyUpdate(BubbleData.Update update) { |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 949 | // Update bubbles in overflow. |
| 950 | if (mOverflowCallback != null) { |
| 951 | mOverflowCallback.run(); |
| 952 | } |
| 953 | |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 954 | // Collapsing? Do this first before remaining steps. |
| 955 | if (update.expandedChanged && !update.expanded) { |
| 956 | mStackView.setExpanded(false); |
| 957 | } |
| 958 | |
| 959 | // Do removals, if any. |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 960 | ArrayList<Pair<Bubble, Integer>> removedBubbles = |
| 961 | new ArrayList<>(update.removedBubbles); |
| 962 | for (Pair<Bubble, Integer> removed : removedBubbles) { |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 963 | final Bubble bubble = removed.first; |
| 964 | @DismissReason final int reason = removed.second; |
| 965 | mStackView.removeBubble(bubble); |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 966 | // If the bubble is removed for user switching, leave the notification in place. |
| 967 | if (reason != DISMISS_USER_CHANGED) { |
| 968 | if (!mBubbleData.hasBubbleWithKey(bubble.getKey()) |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 969 | && !bubble.showInShade()) { |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 970 | // The bubble is now gone & the notification is hidden from the shade, so |
| 971 | // time to actually remove it |
| 972 | for (NotifCallback cb : mCallbacks) { |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 973 | cb.removeNotification(bubble.getEntry(), REASON_CANCEL); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 974 | } |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 975 | } else { |
| 976 | // Update the flag for SysUI |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 977 | bubble.getEntry().getSbn().getNotification().flags &= ~FLAG_BUBBLE; |
Mady Mellor | 3a0a1b4 | 2019-05-23 06:40:21 -0700 | [diff] [blame] | 978 | |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 979 | // Make sure NoMan knows it's not a bubble anymore so anyone querying it |
| 980 | // will get right result back |
| 981 | try { |
| 982 | mBarService.onNotificationBubbleChanged(bubble.getKey(), |
| 983 | false /* isBubble */); |
| 984 | } catch (RemoteException e) { |
| 985 | // Bad things have happened |
| 986 | } |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 987 | } |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 988 | |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 989 | final String groupKey = bubble.getEntry().getSbn().getGroupKey(); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 990 | if (mBubbleData.getBubblesInGroup(groupKey).isEmpty()) { |
| 991 | // Time to potentially remove the summary |
| 992 | for (NotifCallback cb : mCallbacks) { |
| 993 | cb.maybeCancelSummary(bubble.getEntry()); |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 994 | } |
| 995 | } |
Mady Mellor | a54e9fa | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 996 | } |
| 997 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 998 | |
Lyn Han | c47e171 | 2020-01-28 21:43:34 -0800 | [diff] [blame] | 999 | if (update.addedBubble != null) { |
| 1000 | mStackView.addBubble(update.addedBubble); |
| 1001 | } |
| 1002 | |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 1003 | if (update.updatedBubble != null) { |
| 1004 | mStackView.updateBubble(update.updatedBubble); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 1005 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 1006 | |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 1007 | // At this point, the correct bubbles are inflated in the stack. |
| 1008 | // Make sure the order in bubble data is reflected in bubble row. |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 1009 | if (update.orderChanged) { |
| 1010 | mStackView.updateBubbleOrder(update.bubbles); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 1011 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 1012 | |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 1013 | if (update.selectionChanged) { |
| 1014 | mStackView.setSelectedBubble(update.selectedBubble); |
Mady Mellor | 740d85d | 2019-07-09 15:26:47 -0700 | [diff] [blame] | 1015 | if (update.selectedBubble != null) { |
| 1016 | mNotificationGroupManager.updateSuppression( |
| 1017 | update.selectedBubble.getEntry()); |
| 1018 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 1019 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 1020 | |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 1021 | // Expanding? Apply this last. |
| 1022 | if (update.expandedChanged && update.expanded) { |
| 1023 | mStackView.setExpanded(true); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 1024 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 1025 | |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1026 | for (NotifCallback cb : mCallbacks) { |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1027 | cb.invalidateNotifications("BubbleData.Listener.applyUpdate"); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1028 | } |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 1029 | updateStack(); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1030 | |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 1031 | if (DEBUG_BUBBLE_CONTROLLER) { |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 1032 | Log.d(TAG, "\n[BubbleData] bubbles:"); |
Lyn Han | 767d70e | 2019-12-10 18:02:23 -0800 | [diff] [blame] | 1033 | Log.d(TAG, BubbleDebugConfig.formatBubblesString(mBubbleData.getBubbles(), |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1034 | mBubbleData.getSelectedBubble())); |
| 1035 | |
| 1036 | if (mStackView != null) { |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 1037 | Log.d(TAG, "\n[BubbleStackView]"); |
Lyn Han | 767d70e | 2019-12-10 18:02:23 -0800 | [diff] [blame] | 1038 | Log.d(TAG, BubbleDebugConfig.formatBubblesString(mStackView.getBubblesOnScreen(), |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1039 | mStackView.getExpandedBubble())); |
| 1040 | } |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 1041 | Log.d(TAG, "\n[BubbleData] overflow:"); |
| 1042 | Log.d(TAG, BubbleDebugConfig.formatBubblesString(mBubbleData.getOverflowBubbles(), |
| 1043 | null)); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1044 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 1045 | } |
| 1046 | }; |
| 1047 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 1048 | /** |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1049 | * We intercept notification entries (including group summaries) dismissed by the user when |
| 1050 | * there is an active bubble associated with it. We do this so that developers can still |
| 1051 | * cancel it (and hence the bubbles associated with it). However, these intercepted |
| 1052 | * notifications should then be hidden from the shade since the user has cancelled them, so we |
| 1053 | * {@link Bubble#setSuppressNotification}. For the case of suppressed summaries, we also add |
| 1054 | * {@link BubbleData#addSummaryToSuppress}. |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1055 | * |
Mady Mellor | 91b31e6 | 2020-01-30 17:40:48 -0800 | [diff] [blame] | 1056 | * @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] | 1057 | */ |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1058 | public boolean handleDismissalInterception(NotificationEntry entry) { |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1059 | if (entry == null) { |
| 1060 | return false; |
| 1061 | } |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1062 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1063 | final boolean interceptBubbleDismissal = mBubbleData.hasBubbleWithKey(entry.getKey()) |
| 1064 | && entry.isBubble(); |
| 1065 | final boolean interceptSummaryDismissal = isSummaryOfBubbles(entry); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1066 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1067 | if (interceptSummaryDismissal) { |
| 1068 | handleSummaryDismissalInterception(entry); |
| 1069 | } else if (interceptBubbleDismissal) { |
| 1070 | Bubble bubble = mBubbleData.getBubbleWithKey(entry.getKey()); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1071 | bubble.setSuppressNotification(true); |
| 1072 | bubble.setShowDot(false /* show */, true /* animate */); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1073 | } else { |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1074 | return false; |
| 1075 | } |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1076 | |
| 1077 | // Update the shade |
| 1078 | for (NotifCallback cb : mCallbacks) { |
| 1079 | cb.invalidateNotifications("BubbleController.handleDismissalInterception"); |
| 1080 | } |
| 1081 | return true; |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1082 | } |
| 1083 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1084 | private boolean isSummaryOfBubbles(NotificationEntry entry) { |
| 1085 | if (entry == null) { |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1086 | return false; |
| 1087 | } |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1088 | |
| 1089 | String groupKey = entry.getSbn().getGroupKey(); |
| 1090 | ArrayList<Bubble> bubbleChildren = mBubbleData.getBubblesInGroup(groupKey); |
| 1091 | boolean isSuppressedSummary = (mBubbleData.isSummarySuppressed(groupKey) |
| 1092 | && mBubbleData.getSummaryKey(groupKey).equals(entry.getKey())); |
| 1093 | boolean isSummary = entry.getSbn().getNotification().isGroupSummary(); |
| 1094 | return (isSuppressedSummary || isSummary) |
| 1095 | && bubbleChildren != null |
| 1096 | && !bubbleChildren.isEmpty(); |
| 1097 | } |
| 1098 | |
| 1099 | private void handleSummaryDismissalInterception(NotificationEntry summary) { |
| 1100 | // current children in the row: |
| 1101 | final List<NotificationEntry> children = summary.getChildren(); |
| 1102 | if (children != null) { |
| 1103 | for (int i = 0; i < children.size(); i++) { |
| 1104 | NotificationEntry child = children.get(i); |
| 1105 | if (mBubbleData.hasBubbleWithKey(child.getKey())) { |
| 1106 | // Suppress the bubbled child |
| 1107 | // As far as group manager is concerned, once a child is no longer shown |
| 1108 | // in the shade, it is essentially removed. |
| 1109 | Bubble bubbleChild = mBubbleData.getBubbleWithKey(child.getKey()); |
| 1110 | mNotificationGroupManager.onEntryRemoved(bubbleChild.getEntry()); |
| 1111 | bubbleChild.setSuppressNotification(true); |
| 1112 | bubbleChild.setShowDot(false /* show */, true /* animate */); |
| 1113 | } else { |
| 1114 | // non-bubbled children can be removed |
| 1115 | for (NotifCallback cb : mCallbacks) { |
| 1116 | cb.removeNotification(child, REASON_GROUP_SUMMARY_CANCELED); |
| 1117 | } |
| 1118 | } |
| 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | // And since all children are removed, remove the summary. |
| 1123 | mNotificationGroupManager.onEntryRemoved(summary); |
| 1124 | |
| 1125 | // TODO: (b/145659174) remove references to mSuppressedGroupKeys once fully migrated |
| 1126 | mBubbleData.addSummaryToSuppress(summary.getSbn().getGroupKey(), |
| 1127 | summary.getKey()); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | /** |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 1131 | * Lets any listeners know if bubble state has changed. |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 1132 | * Updates the visibility of the bubbles based on current state. |
| 1133 | * Does not un-bubble, just hides or un-hides. Notifies any |
| 1134 | * {@link BubbleStateChangeListener}s of visibility changes. |
| 1135 | * Updates stack description for TalkBack focus. |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 1136 | */ |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 1137 | public void updateStack() { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 1138 | if (mStackView == null) { |
| 1139 | return; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 1140 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 1141 | if (mStatusBarStateListener.getCurrentState() == SHADE && hasBubbles()) { |
| 1142 | // Bubbles only appear in unlocked shade |
| 1143 | mStackView.setVisibility(hasBubbles() ? VISIBLE : INVISIBLE); |
Mady Mellor | 698d9e8 | 2019-08-01 23:11:53 +0000 | [diff] [blame] | 1144 | } else if (mStackView != null) { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 1145 | mStackView.setVisibility(INVISIBLE); |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 1146 | } |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 1147 | |
Mady Mellor | 698d9e8 | 2019-08-01 23:11:53 +0000 | [diff] [blame] | 1148 | // Let listeners know if bubble state changed. |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 1149 | boolean hadBubbles = mNotificationShadeWindowController.getBubblesShowing(); |
Mady Mellor | 698d9e8 | 2019-08-01 23:11:53 +0000 | [diff] [blame] | 1150 | boolean hasBubblesShowing = hasBubbles() && mStackView.getVisibility() == VISIBLE; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 1151 | mNotificationShadeWindowController.setBubblesShowing(hasBubblesShowing); |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 1152 | if (mStateChangeListener != null && hadBubbles != hasBubblesShowing) { |
| 1153 | mStateChangeListener.onHasBubblesChanged(hasBubblesShowing); |
| 1154 | } |
| 1155 | |
| 1156 | mStackView.updateContentDescription(); |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | /** |
| 1160 | * Rect indicating the touchable region for the bubble stack / expanded stack. |
| 1161 | */ |
| 1162 | public Rect getTouchableRegion() { |
| 1163 | if (mStackView == null || mStackView.getVisibility() != VISIBLE) { |
| 1164 | return null; |
| 1165 | } |
| 1166 | mStackView.getBoundsOnScreen(mTempRect); |
| 1167 | return mTempRect; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1168 | } |
| 1169 | |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 1170 | /** |
| 1171 | * The display id of the expanded view, if the stack is expanded and not occluded by the |
| 1172 | * status bar, otherwise returns {@link Display#INVALID_DISPLAY}. |
| 1173 | */ |
| 1174 | public int getExpandedDisplayId(Context context) { |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 1175 | final Bubble bubble = getExpandedBubble(context); |
| 1176 | return bubble != null ? bubble.getDisplayId() : INVALID_DISPLAY; |
| 1177 | } |
| 1178 | |
| 1179 | @Nullable |
| 1180 | private Bubble getExpandedBubble(Context context) { |
Joel Galenson | 4071ddb | 2019-04-18 13:30:45 -0700 | [diff] [blame] | 1181 | if (mStackView == null) { |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 1182 | return null; |
Joel Galenson | 4071ddb | 2019-04-18 13:30:45 -0700 | [diff] [blame] | 1183 | } |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 1184 | final boolean defaultDisplay = context.getDisplay() != null |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 1185 | && context.getDisplay().getDisplayId() == DEFAULT_DISPLAY; |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 1186 | final Bubble expandedBubble = mStackView.getExpandedBubble(); |
| 1187 | if (defaultDisplay && expandedBubble != null && isStackExpanded() |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 1188 | && !mNotificationShadeWindowController.getPanelExpanded()) { |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 1189 | return expandedBubble; |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 1190 | } |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 1191 | return null; |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 1192 | } |
| 1193 | |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 1194 | @VisibleForTesting |
| 1195 | BubbleStackView getStackView() { |
| 1196 | return mStackView; |
| 1197 | } |
| 1198 | |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 1199 | /** |
| 1200 | * Description of current bubble state. |
| 1201 | */ |
| 1202 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1203 | pw.println("BubbleController state:"); |
| 1204 | mBubbleData.dump(fd, pw, args); |
| 1205 | pw.println(); |
Joshua Tsuji | 395bcfe | 2019-07-02 19:23:23 -0400 | [diff] [blame] | 1206 | if (mStackView != null) { |
| 1207 | mStackView.dump(fd, pw, args); |
| 1208 | } |
| 1209 | pw.println(); |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 1210 | } |
| 1211 | |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 1212 | /** |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 1213 | * This task stack listener is responsible for responding to tasks moved to the front |
| 1214 | * which are on the default (main) display. When this happens, expanded bubbles must be |
| 1215 | * collapsed so the user may interact with the app which was just moved to the front. |
| 1216 | * <p> |
| 1217 | * This listener is registered with SystemUI's ActivityManagerWrapper which dispatches |
| 1218 | * these calls via a main thread Handler. |
| 1219 | */ |
| 1220 | @MainThread |
| 1221 | private class BubbleTaskStackListener extends TaskStackChangeListener { |
| 1222 | |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 1223 | @Override |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 1224 | public void onTaskMovedToFront(RunningTaskInfo taskInfo) { |
| 1225 | if (mStackView != null && taskInfo.displayId == Display.DEFAULT_DISPLAY) { |
Mady Mellor | 047e24e | 2019-08-05 11:35:40 -0700 | [diff] [blame] | 1226 | if (!mStackView.isExpansionAnimating()) { |
| 1227 | mBubbleData.setExpanded(false); |
| 1228 | } |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 1229 | } |
| 1230 | } |
| 1231 | |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 1232 | @Override |
Mark Renouf | a12e876 | 2019-03-07 15:43:01 -0500 | [diff] [blame] | 1233 | public void onActivityLaunchOnSecondaryDisplayRerouted() { |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 1234 | if (mStackView != null) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 1235 | mBubbleData.setExpanded(false); |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 1236 | } |
| 1237 | } |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 1238 | |
| 1239 | @Override |
| 1240 | public void onBackPressedOnTaskRoot(RunningTaskInfo taskInfo) { |
| 1241 | if (mStackView != null && taskInfo.displayId == getExpandedDisplayId(mContext)) { |
| 1242 | mBubbleData.setExpanded(false); |
| 1243 | } |
| 1244 | } |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 1245 | |
| 1246 | @Override |
| 1247 | public void onSingleTaskDisplayDrawn(int displayId) { |
Lyn Han | a0bb02e | 2020-01-28 17:57:27 -0800 | [diff] [blame] | 1248 | if (mStackView == null) { |
| 1249 | return; |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 1250 | } |
Lyn Han | a0bb02e | 2020-01-28 17:57:27 -0800 | [diff] [blame] | 1251 | mStackView.showExpandedViewContents(displayId); |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 1252 | } |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 1253 | |
| 1254 | @Override |
| 1255 | public void onSingleTaskDisplayEmpty(int displayId) { |
Mady Mellor | 5186b13 | 2019-09-16 17:55:48 -0700 | [diff] [blame] | 1256 | final Bubble expandedBubble = mStackView != null |
| 1257 | ? mStackView.getExpandedBubble() |
| 1258 | : null; |
Mady Mellor | ca184aae | 2019-09-17 16:07:12 -0700 | [diff] [blame] | 1259 | int expandedId = expandedBubble != null ? expandedBubble.getDisplayId() : -1; |
| 1260 | if (mStackView != null && mStackView.isExpanded() && expandedId == displayId) { |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 1261 | mBubbleData.setExpanded(false); |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 1262 | } |
Mady Mellor | ca184aae | 2019-09-17 16:07:12 -0700 | [diff] [blame] | 1263 | mBubbleData.notifyDisplayEmpty(displayId); |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 1264 | } |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 1265 | } |
| 1266 | |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1267 | /** |
| 1268 | * Whether an intent is properly configured to display in an {@link android.app.ActivityView}. |
| 1269 | * |
| 1270 | * Keep checks in sync with NotificationManagerService#canLaunchInActivityView. Typically |
| 1271 | * that should filter out any invalid bubbles, but should protect SysUI side just in case. |
| 1272 | * |
| 1273 | * @param context the context to use. |
| 1274 | * @param entry the entry to bubble. |
| 1275 | */ |
| 1276 | static boolean canLaunchInActivityView(Context context, NotificationEntry entry) { |
| 1277 | PendingIntent intent = entry.getBubbleMetadata() != null |
Mady Mellor | 2ac2d3a | 2020-01-08 17:18:54 -0800 | [diff] [blame] | 1278 | ? entry.getBubbleMetadata().getBubbleIntent() |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1279 | : null; |
Mady Mellor | 2ac2d3a | 2020-01-08 17:18:54 -0800 | [diff] [blame] | 1280 | if (entry.getBubbleMetadata() != null |
| 1281 | && entry.getBubbleMetadata().getShortcutId() != null) { |
| 1282 | return true; |
| 1283 | } |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1284 | if (intent == null) { |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 1285 | Log.w(TAG, "Unable to create bubble -- no intent: " + entry.getKey()); |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1286 | return false; |
| 1287 | } |
Mady Mellor | f3b9fab | 2019-11-13 17:27:32 -0800 | [diff] [blame] | 1288 | PackageManager packageManager = StatusBar.getPackageManagerForUser( |
| 1289 | context, entry.getSbn().getUser().getIdentifier()); |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1290 | ActivityInfo info = |
Mady Mellor | f3b9fab | 2019-11-13 17:27:32 -0800 | [diff] [blame] | 1291 | intent.getIntent().resolveActivityInfo(packageManager, 0); |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1292 | if (info == null) { |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 1293 | Log.w(TAG, "Unable to send as bubble, " |
| 1294 | + entry.getKey() + " couldn't find activity info for intent: " |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1295 | + intent); |
| 1296 | return false; |
| 1297 | } |
| 1298 | if (!ActivityInfo.isResizeableMode(info.resizeMode)) { |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 1299 | Log.w(TAG, "Unable to send as bubble, " |
| 1300 | + entry.getKey() + " activity is not resizable for intent: " |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1301 | + intent); |
| 1302 | return false; |
| 1303 | } |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1304 | return true; |
| 1305 | } |
| 1306 | |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 1307 | /** PinnedStackListener that dispatches IME visibility updates to the stack. */ |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 1308 | private class BubblesImeListener extends PinnedStackListenerForwarder.PinnedStackListener { |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 1309 | @Override |
Joshua Tsuji | d942283 | 2019-03-05 13:32:37 -0500 | [diff] [blame] | 1310 | public void onImeVisibilityChanged(boolean imeVisible, int imeHeight) { |
| 1311 | if (mStackView != null && mStackView.getBubbleCount() > 0) { |
| 1312 | mStackView.post(() -> mStackView.onImeVisibilityChanged(imeVisible, imeHeight)); |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 1313 | } |
| 1314 | } |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 1315 | } |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1316 | } |