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