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