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