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