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; |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [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 | |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [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, |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [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, |
| 307 | NotificationInterruptionStateProvider interruptionStateProvider, |
| 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; |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 319 | mNotificationInterruptionStateProvider = interruptionStateProvider; |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 320 | mNotifUserManager = notifUserManager; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 321 | mZenModeController = zenModeController; |
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, |
| 428 | boolean removedByUser) { |
| 429 | BubbleController.this.onEntryRemoved(entry); |
| 430 | } |
| 431 | |
| 432 | @Override |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 433 | public void onNotificationRankingUpdated(RankingMap rankingMap) { |
| 434 | onRankingUpdated(rankingMap); |
| 435 | } |
| 436 | }); |
| 437 | |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 438 | mNotificationEntryManager.addNotificationRemoveInterceptor( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 439 | new NotificationRemoveInterceptor() { |
| 440 | @Override |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 441 | public boolean onNotificationRemoveRequested( |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 442 | String key, |
| 443 | NotificationEntry entry, |
| 444 | int dismissReason) { |
| 445 | final boolean isClearAll = dismissReason == REASON_CANCEL_ALL; |
| 446 | final boolean isUserDimiss = dismissReason == REASON_CANCEL |
| 447 | || dismissReason == REASON_CLICK; |
| 448 | final boolean isAppCancel = dismissReason == REASON_APP_CANCEL |
| 449 | || dismissReason == REASON_APP_CANCEL_ALL; |
| 450 | final boolean isSummaryCancel = |
| 451 | dismissReason == REASON_GROUP_SUMMARY_CANCELED; |
| 452 | |
| 453 | // Need to check for !appCancel here because the notification may have |
| 454 | // previously been dismissed & entry.isRowDismissed would still be true |
| 455 | boolean userRemovedNotif = |
| 456 | (entry != null && entry.isRowDismissed() && !isAppCancel) |
| 457 | || isClearAll || isUserDimiss || isSummaryCancel; |
| 458 | |
| 459 | if (userRemovedNotif || isUserCreatedBubble(key) |
| 460 | || isSummaryOfUserCreatedBubble(entry)) { |
| 461 | return handleDismissalInterception(entry); |
| 462 | } |
| 463 | |
| 464 | return false; |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 465 | } |
| 466 | }); |
| 467 | |
| 468 | mNotificationGroupManager.addOnGroupChangeListener( |
| 469 | new NotificationGroupManager.OnGroupChangeListener() { |
| 470 | @Override |
| 471 | public void onGroupSuppressionChanged( |
| 472 | NotificationGroupManager.NotificationGroup group, |
| 473 | boolean suppressed) { |
| 474 | // More notifications could be added causing summary to no longer |
| 475 | // be suppressed -- in this case need to remove the key. |
| 476 | final String groupKey = group.summary != null |
| 477 | ? group.summary.getSbn().getGroupKey() |
| 478 | : null; |
| 479 | if (!suppressed && groupKey != null |
| 480 | && mBubbleData.isSummarySuppressed(groupKey)) { |
| 481 | mBubbleData.removeSuppressedSummary(groupKey); |
| 482 | } |
| 483 | } |
| 484 | }); |
| 485 | |
| 486 | addNotifCallback(new NotifCallback() { |
| 487 | @Override |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 488 | public void removeNotification(NotificationEntry entry, int reason) { |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 489 | mNotificationEntryManager.performRemoveNotification(entry.getSbn(), |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 490 | reason); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | @Override |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 494 | public void invalidateNotifications(String reason) { |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 495 | mNotificationEntryManager.updateNotifications(reason); |
| 496 | } |
| 497 | |
| 498 | @Override |
| 499 | public void maybeCancelSummary(NotificationEntry entry) { |
| 500 | // Check if removed bubble has an associated suppressed group summary that needs |
| 501 | // to be removed now. |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 502 | final String groupKey = entry.getSbn().getGroupKey(); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 503 | if (mBubbleData.isSummarySuppressed(groupKey)) { |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 504 | mBubbleData.removeSuppressedSummary(groupKey); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 505 | |
| 506 | final NotificationEntry summary = |
| 507 | mNotificationEntryManager.getActiveNotificationUnfiltered( |
| 508 | mBubbleData.getSummaryKey(groupKey)); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 509 | if (summary != null) { |
| 510 | mNotificationEntryManager.performRemoveNotification(summary.getSbn(), |
| 511 | UNDEFINED_DISMISS_REASON); |
| 512 | } |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 513 | } |
| 514 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 515 | // Check if we still need to remove the summary from NoManGroup because the summary |
| 516 | // may not be in the mBubbleData.mSuppressedGroupKeys list and removed above. |
| 517 | // For example: |
| 518 | // 1. Bubbled notifications (group) is posted to shade and are visible bubbles |
| 519 | // 2. User expands bubbles so now their respective notifications in the shade are |
| 520 | // hidden, including the group summary |
| 521 | // 3. User removes all bubbles |
| 522 | // 4. We expect all the removed bubbles AND the summary (note: the summary was |
| 523 | // never added to the suppressedSummary list in BubbleData, so we add this check) |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 524 | NotificationEntry summary = |
| 525 | mNotificationGroupManager.getLogicalGroupSummary(entry.getSbn()); |
| 526 | if (summary != null) { |
| 527 | ArrayList<NotificationEntry> summaryChildren = |
| 528 | mNotificationGroupManager.getLogicalChildren(summary.getSbn()); |
| 529 | boolean isSummaryThisNotif = summary.getKey().equals(entry.getKey()); |
| 530 | if (!isSummaryThisNotif && (summaryChildren == null |
| 531 | || summaryChildren.isEmpty())) { |
| 532 | mNotificationEntryManager.performRemoveNotification(summary.getSbn(), |
| 533 | UNDEFINED_DISMISS_REASON); |
| 534 | } |
| 535 | } |
| 536 | } |
| 537 | }); |
| 538 | } |
| 539 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 540 | private void setupNotifPipeline() { |
| 541 | mNotifPipeline.addCollectionListener(new NotifCollectionListener() { |
| 542 | @Override |
| 543 | public void onEntryAdded(NotificationEntry entry) { |
| 544 | BubbleController.this.onEntryAdded(entry); |
| 545 | } |
| 546 | |
| 547 | @Override |
| 548 | public void onEntryUpdated(NotificationEntry entry) { |
| 549 | BubbleController.this.onEntryUpdated(entry); |
| 550 | } |
| 551 | |
| 552 | @Override |
| 553 | public void onRankingUpdate(RankingMap rankingMap) { |
| 554 | onRankingUpdated(rankingMap); |
| 555 | } |
| 556 | |
| 557 | @Override |
| 558 | public void onEntryRemoved(NotificationEntry entry, |
| 559 | @NotifCollection.CancellationReason int reason) { |
| 560 | BubbleController.this.onEntryRemoved(entry); |
| 561 | } |
| 562 | }); |
| 563 | } |
| 564 | |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 565 | /** |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 566 | * Sets whether to perform inflation on the same thread as the caller. This method should only |
| 567 | * be used in tests, not in production. |
| 568 | */ |
| 569 | @VisibleForTesting |
| 570 | void setInflateSynchronously(boolean inflateSynchronously) { |
| 571 | mInflateSynchronously = inflateSynchronously; |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 572 | } |
| 573 | |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 574 | void setOverflowCallback(Runnable updateOverflow) { |
| 575 | mOverflowCallback = updateOverflow; |
| 576 | } |
| 577 | |
| 578 | /** |
| 579 | * @return Bubbles for updating overflow. |
| 580 | */ |
| 581 | List<Bubble> getOverflowBubbles() { |
| 582 | return mBubbleData.getOverflowBubbles(); |
| 583 | } |
| 584 | |
| 585 | |
Mark Renouf | 8b6a3c6 | 2019-04-09 10:17:40 -0400 | [diff] [blame] | 586 | /** |
| 587 | * BubbleStackView is lazily created by this method the first time a Bubble is added. This |
| 588 | * method initializes the stack view and adds it to the StatusBar just above the scrim. |
| 589 | */ |
| 590 | private void ensureStackViewCreated() { |
| 591 | if (mStackView == null) { |
Joshua Tsuji | 7155bf1 | 2020-02-13 16:14:29 -0500 | [diff] [blame] | 592 | mStackView = new BubbleStackView( |
| 593 | mContext, mBubbleData, mSurfaceSynchronizer, mFloatingContentCoordinator); |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 594 | ViewGroup nsv = mNotificationShadeWindowController.getNotificationShadeView(); |
| 595 | int bubbleScrimIndex = nsv.indexOfChild(nsv.findViewById(R.id.scrim_for_bubble)); |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 596 | int stackIndex = bubbleScrimIndex + 1; // Show stack above bubble scrim. |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 597 | nsv.addView(mStackView, stackIndex, |
Mark Renouf | 8b6a3c6 | 2019-04-09 10:17:40 -0400 | [diff] [blame] | 598 | new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)); |
| 599 | if (mExpandListener != null) { |
| 600 | mStackView.setExpandListener(mExpandListener); |
| 601 | } |
Mark Renouf | 8b6a3c6 | 2019-04-09 10:17:40 -0400 | [diff] [blame] | 602 | } |
| 603 | } |
| 604 | |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 605 | /** |
| 606 | * Records the notification key for any active bubbles. These are used to restore active |
| 607 | * bubbles when the user returns to the foreground. |
| 608 | * |
| 609 | * @param userId the id of the user |
| 610 | */ |
| 611 | private void saveBubbles(@UserIdInt int userId) { |
| 612 | // First clear any existing keys that might be stored. |
| 613 | mSavedBubbleKeysPerUser.remove(userId); |
| 614 | // Add in all active bubbles for the current user. |
| 615 | for (Bubble bubble: mBubbleData.getBubbles()) { |
| 616 | mSavedBubbleKeysPerUser.add(userId, bubble.getKey()); |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | /** |
| 621 | * Promotes existing notifications to Bubbles if they were previously bubbles. |
| 622 | * |
| 623 | * @param userId the id of the user |
| 624 | */ |
| 625 | private void restoreBubbles(@UserIdInt int userId) { |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 626 | ArraySet<String> savedBubbleKeys = mSavedBubbleKeysPerUser.get(userId); |
| 627 | if (savedBubbleKeys == null) { |
| 628 | // There were no bubbles saved for this used. |
| 629 | return; |
| 630 | } |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 631 | for (NotificationEntry e : |
| 632 | mNotificationEntryManager.getActiveNotificationsForCurrentUser()) { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 633 | if (savedBubbleKeys.contains(e.getKey()) |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 634 | && mNotificationInterruptionStateProvider.shouldBubbleUp(e) |
| 635 | && canLaunchInActivityView(mContext, e)) { |
| 636 | updateBubble(e, /* suppressFlyout= */ true); |
| 637 | } |
| 638 | } |
| 639 | // Finally, remove the entries for this user now that bubbles are restored. |
| 640 | mSavedBubbleKeysPerUser.remove(mCurrentUserId); |
| 641 | } |
| 642 | |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 643 | @Override |
| 644 | public void onUiModeChanged() { |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 645 | updateForThemeChanges(); |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | @Override |
| 649 | public void onOverlayChanged() { |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 650 | updateForThemeChanges(); |
| 651 | } |
| 652 | |
| 653 | private void updateForThemeChanges() { |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 654 | if (mStackView != null) { |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 655 | mStackView.onThemeChanged(); |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 656 | } |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 657 | mBubbleIconFactory = new BubbleIconFactory(mContext); |
| 658 | for (Bubble b: mBubbleData.getBubbles()) { |
| 659 | // Reload each bubble |
| 660 | b.inflate(null /* callback */, mContext, mStackView, mBubbleIconFactory); |
| 661 | } |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 662 | } |
| 663 | |
Joshua Tsuji | f418f9e | 2019-04-04 17:09:53 -0400 | [diff] [blame] | 664 | @Override |
| 665 | public void onConfigChanged(Configuration newConfig) { |
| 666 | if (mStackView != null && newConfig != null && newConfig.orientation != mOrientation) { |
Joshua Tsuji | f418f9e | 2019-04-04 17:09:53 -0400 | [diff] [blame] | 667 | mOrientation = newConfig.orientation; |
Lyn Han | f473031 | 2019-06-18 11:18:58 -0700 | [diff] [blame] | 668 | mStackView.onOrientationChanged(newConfig.orientation); |
Joshua Tsuji | f418f9e | 2019-04-04 17:09:53 -0400 | [diff] [blame] | 669 | } |
| 670 | } |
| 671 | |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 672 | /** |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 673 | * Set a listener to be notified when some states of the bubbles change. |
| 674 | */ |
| 675 | public void setBubbleStateChangeListener(BubbleStateChangeListener listener) { |
| 676 | mStateChangeListener = listener; |
| 677 | } |
| 678 | |
| 679 | /** |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 680 | * Set a listener to be notified of bubble expand events. |
| 681 | */ |
| 682 | public void setExpandListener(BubbleExpandListener listener) { |
Issei Suzuki | ac9fcb7 | 2019-02-04 17:45:57 +0100 | [diff] [blame] | 683 | mExpandListener = ((isExpanding, key) -> { |
| 684 | if (listener != null) { |
| 685 | listener.onBubbleExpandChanged(isExpanding, key); |
| 686 | } |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 687 | mNotificationShadeWindowController.setBubbleExpanded(isExpanding); |
Issei Suzuki | ac9fcb7 | 2019-02-04 17:45:57 +0100 | [diff] [blame] | 688 | }); |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 689 | if (mStackView != null) { |
| 690 | mStackView.setExpandListener(mExpandListener); |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | /** |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 695 | * Whether or not there are bubbles present, regardless of them being visible on the |
| 696 | * screen (e.g. if on AOD). |
| 697 | */ |
| 698 | public boolean hasBubbles() { |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 699 | if (mStackView == null) { |
| 700 | return false; |
| 701 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 702 | return mBubbleData.hasBubbles(); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | /** |
| 706 | * Whether the stack of bubbles is expanded or not. |
| 707 | */ |
| 708 | public boolean isStackExpanded() { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 709 | return mBubbleData.isExpanded(); |
| 710 | } |
| 711 | |
| 712 | /** |
| 713 | * Tell the stack of bubbles to expand. |
| 714 | */ |
| 715 | public void expandStack() { |
| 716 | mBubbleData.setExpanded(true); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | /** |
| 720 | * Tell the stack of bubbles to collapse. |
| 721 | */ |
| 722 | public void collapseStack() { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 723 | mBubbleData.setExpanded(false /* expanded */); |
| 724 | } |
| 725 | |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 726 | /** |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 727 | * True if either: |
| 728 | * (1) There is a bubble associated with the provided key and if its notification is hidden |
| 729 | * from the shade. |
| 730 | * (2) There is a group summary associated with the provided key that is hidden from the shade |
| 731 | * because it has been dismissed but still has child bubbles active. |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 732 | * |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 733 | * False otherwise. |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 734 | */ |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 735 | public boolean isBubbleNotificationSuppressedFromShade(NotificationEntry entry) { |
| 736 | String key = entry.getKey(); |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 737 | boolean isBubbleAndSuppressed = mBubbleData.hasBubbleWithKey(key) |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 738 | && !mBubbleData.getBubbleWithKey(key).showInShade(); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 739 | |
| 740 | String groupKey = entry.getSbn().getGroupKey(); |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 741 | boolean isSuppressedSummary = mBubbleData.isSummarySuppressed(groupKey); |
Mady Mellor | e434827 | 2019-07-29 17:43:36 -0700 | [diff] [blame] | 742 | boolean isSummary = key.equals(mBubbleData.getSummaryKey(groupKey)); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 743 | |
Mady Mellor | e434827 | 2019-07-29 17:43:36 -0700 | [diff] [blame] | 744 | return (isSummary && isSuppressedSummary) || isBubbleAndSuppressed; |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 745 | } |
| 746 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 747 | @VisibleForTesting |
| 748 | void selectBubble(String key) { |
| 749 | Bubble bubble = mBubbleData.getBubbleWithKey(key); |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 750 | mBubbleData.setSelectedBubble(bubble); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 751 | } |
| 752 | |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 753 | void promoteBubbleFromOverflow(Bubble bubble) { |
Lyn Han | 1e19d7f | 2020-02-05 19:10:58 -0800 | [diff] [blame] | 754 | bubble.setInflateSynchronously(mInflateSynchronously); |
| 755 | mBubbleData.promoteBubbleFromOverflow(bubble, mStackView, mBubbleIconFactory); |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 756 | } |
| 757 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 758 | /** |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 759 | * Request the stack expand if needed, then select the specified Bubble as current. |
| 760 | * |
| 761 | * @param notificationKey the notification key for the bubble to be selected |
| 762 | */ |
| 763 | public void expandStackAndSelectBubble(String notificationKey) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 764 | Bubble bubble = mBubbleData.getBubbleWithKey(notificationKey); |
| 765 | if (bubble != null) { |
| 766 | mBubbleData.setSelectedBubble(bubble); |
| 767 | mBubbleData.setExpanded(true); |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 768 | } |
| 769 | } |
| 770 | |
| 771 | /** |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 772 | * Tell the stack of bubbles to be dismissed, this will remove all of the bubbles in the stack. |
| 773 | */ |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 774 | void dismissStack(@DismissReason int reason) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 775 | mBubbleData.dismissAll(reason); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | /** |
Mark Renouf | 041d726 | 2019-02-06 12:09:41 -0500 | [diff] [blame] | 779 | * Directs a back gesture at the bubble stack. When opened, the current expanded bubble |
| 780 | * is forwarded a back key down/up pair. |
| 781 | */ |
| 782 | public void performBackPressIfNeeded() { |
| 783 | if (mStackView != null) { |
| 784 | mStackView.performBackPressIfNeeded(); |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | /** |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 789 | * Adds or updates a bubble associated with the provided notification entry. |
| 790 | * |
Mark Renouf | 8b6a3c6 | 2019-04-09 10:17:40 -0400 | [diff] [blame] | 791 | * @param notif the notification associated with this bubble. |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 792 | */ |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 793 | void updateBubble(NotificationEntry notif) { |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 794 | updateBubble(notif, false /* suppressFlyout */); |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | void updateBubble(NotificationEntry notif, boolean suppressFlyout) { |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 798 | updateBubble(notif, suppressFlyout, true /* showInShade */); |
| 799 | } |
| 800 | |
| 801 | void updateBubble(NotificationEntry notif, boolean suppressFlyout, boolean showInShade) { |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 802 | if (mStackView == null) { |
| 803 | // Lazy init stack view when a bubble is created |
| 804 | ensureStackViewCreated(); |
| 805 | } |
Mady Mellor | 66efd5e | 2019-05-15 13:38:11 -0700 | [diff] [blame] | 806 | // If this is an interruptive notif, mark that it's interrupted |
Ned Burns | 60e9459 | 2019-09-06 14:47:25 -0400 | [diff] [blame] | 807 | if (notif.getImportance() >= NotificationManager.IMPORTANCE_HIGH) { |
Mady Mellor | 66efd5e | 2019-05-15 13:38:11 -0700 | [diff] [blame] | 808 | notif.setInterruption(); |
| 809 | } |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 810 | Bubble bubble = mBubbleData.getOrCreateBubble(notif); |
| 811 | bubble.setInflateSynchronously(mInflateSynchronously); |
| 812 | bubble.inflate( |
| 813 | b -> mBubbleData.notificationEntryUpdated(b, suppressFlyout, showInShade), |
| 814 | mContext, mStackView, mBubbleIconFactory); |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | /** |
| 818 | * Called when a user has indicated that an active notification should be shown as a bubble. |
| 819 | * <p> |
| 820 | * This method will collapse the shade, create the bubble without a flyout or dot, and suppress |
| 821 | * the notification from appearing in the shade. |
| 822 | * |
| 823 | * @param entry the notification to show as a bubble. |
| 824 | */ |
| 825 | public void onUserCreatedBubbleFromNotification(NotificationEntry entry) { |
Mady Mellor | ff076eb | 2019-11-13 10:12:06 -0800 | [diff] [blame] | 826 | if (DEBUG_EXPERIMENTS || DEBUG_BUBBLE_CONTROLLER) { |
| 827 | Log.d(TAG, "onUserCreatedBubble: " + entry.getKey()); |
| 828 | } |
Heemin Seog | ba6337f | 2019-12-10 15:34:37 -0800 | [diff] [blame] | 829 | mShadeController.collapsePanel(true); |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 830 | entry.setFlagBubble(true); |
| 831 | updateBubble(entry, true /* suppressFlyout */, false /* showInShade */); |
Mady Mellor | ff076eb | 2019-11-13 10:12:06 -0800 | [diff] [blame] | 832 | mUserCreatedBubbles.add(entry.getKey()); |
Mady Mellor | 3b86a4f | 2019-12-11 13:15:41 -0800 | [diff] [blame] | 833 | mUserBlockedBubbles.remove(entry.getKey()); |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | /** |
| 837 | * Called when a user has indicated that an active notification appearing as a bubble should |
| 838 | * no longer be shown as a bubble. |
| 839 | * |
| 840 | * @param entry the notification to no longer show as a bubble. |
| 841 | */ |
| 842 | public void onUserDemotedBubbleFromNotification(NotificationEntry entry) { |
Mady Mellor | ff076eb | 2019-11-13 10:12:06 -0800 | [diff] [blame] | 843 | if (DEBUG_EXPERIMENTS || DEBUG_BUBBLE_CONTROLLER) { |
| 844 | Log.d(TAG, "onUserDemotedBubble: " + entry.getKey()); |
| 845 | } |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 846 | entry.setFlagBubble(false); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 847 | removeBubble(entry, DISMISS_BLOCKED); |
Mady Mellor | ff076eb | 2019-11-13 10:12:06 -0800 | [diff] [blame] | 848 | mUserCreatedBubbles.remove(entry.getKey()); |
Mady Mellor | 3b86a4f | 2019-12-11 13:15:41 -0800 | [diff] [blame] | 849 | if (BubbleExperimentConfig.isPackageWhitelistedToAutoBubble( |
| 850 | mContext, entry.getSbn().getPackageName())) { |
| 851 | // This package is whitelist but user demoted the bubble, let's save it so we don't |
| 852 | // auto-bubble for the whitelist again. |
| 853 | mUserBlockedBubbles.add(entry.getKey()); |
| 854 | } |
Mady Mellor | ff076eb | 2019-11-13 10:12:06 -0800 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | /** |
| 858 | * Whether this bubble was explicitly created by the user via a SysUI affordance. |
| 859 | */ |
| 860 | boolean isUserCreatedBubble(String key) { |
| 861 | return mUserCreatedBubbles.contains(key); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 862 | } |
| 863 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 864 | boolean isSummaryOfUserCreatedBubble(NotificationEntry entry) { |
| 865 | if (isSummaryOfBubbles(entry)) { |
| 866 | List<Bubble> bubbleChildren = |
| 867 | mBubbleData.getBubblesInGroup(entry.getSbn().getGroupKey()); |
| 868 | for (int i = 0; i < bubbleChildren.size(); i++) { |
| 869 | // Check if any are user-created (i.e. experimental bubbles) |
| 870 | if (isUserCreatedBubble(bubbleChildren.get(i).getKey())) { |
| 871 | return true; |
| 872 | } |
| 873 | } |
| 874 | } |
| 875 | return false; |
| 876 | } |
| 877 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 878 | /** |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 879 | * Removes the bubble with the given NotificationEntry. |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 880 | * <p> |
| 881 | * Must be called from the main thread. |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 882 | */ |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 883 | @MainThread |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 884 | void removeBubble(NotificationEntry entry, int reason) { |
| 885 | if (mBubbleData.hasBubbleWithKey(entry.getKey())) { |
| 886 | mBubbleData.notificationEntryRemoved(entry, reason); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 887 | } |
| 888 | } |
| 889 | |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 890 | private void onEntryAdded(NotificationEntry entry) { |
| 891 | boolean previouslyUserCreated = mUserCreatedBubbles.contains(entry.getKey()); |
| 892 | boolean userBlocked = mUserBlockedBubbles.contains(entry.getKey()); |
| 893 | boolean wasAdjusted = BubbleExperimentConfig.adjustForExperiments( |
| 894 | mContext, entry, previouslyUserCreated, userBlocked); |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 895 | |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 896 | if (mNotificationInterruptionStateProvider.shouldBubbleUp(entry) |
| 897 | && (canLaunchInActivityView(mContext, entry) || wasAdjusted)) { |
| 898 | if (wasAdjusted && !previouslyUserCreated) { |
| 899 | // Gotta treat the auto-bubbled / whitelisted packaged bubbles as usercreated |
| 900 | mUserCreatedBubbles.add(entry.getKey()); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 901 | } |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 902 | updateBubble(entry); |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 903 | } |
| 904 | } |
| 905 | |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 906 | private void onEntryUpdated(NotificationEntry entry) { |
| 907 | boolean previouslyUserCreated = mUserCreatedBubbles.contains(entry.getKey()); |
| 908 | boolean userBlocked = mUserBlockedBubbles.contains(entry.getKey()); |
| 909 | boolean wasAdjusted = BubbleExperimentConfig.adjustForExperiments( |
| 910 | mContext, entry, previouslyUserCreated, userBlocked); |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 911 | |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 912 | boolean shouldBubble = mNotificationInterruptionStateProvider.shouldBubbleUp(entry) |
| 913 | && (canLaunchInActivityView(mContext, entry) || wasAdjusted); |
| 914 | if (!shouldBubble && mBubbleData.hasBubbleWithKey(entry.getKey())) { |
| 915 | // It was previously a bubble but no longer a bubble -- lets remove it |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 916 | removeBubble(entry, DISMISS_NO_LONGER_BUBBLE); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 917 | } else if (shouldBubble) { |
| 918 | if (wasAdjusted && !previouslyUserCreated) { |
| 919 | // Gotta treat the auto-bubbled / whitelisted packaged bubbles as usercreated |
| 920 | mUserCreatedBubbles.add(entry.getKey()); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 921 | } |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 922 | updateBubble(entry); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 923 | } |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 924 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 925 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 926 | private void onEntryRemoved(NotificationEntry entry) { |
| 927 | if (isSummaryOfBubbles(entry)) { |
| 928 | final String groupKey = entry.getSbn().getGroupKey(); |
| 929 | mBubbleData.removeSuppressedSummary(groupKey); |
| 930 | |
| 931 | // Remove any associated bubble children with the summary |
| 932 | final List<Bubble> bubbleChildren = mBubbleData.getBubblesInGroup(groupKey); |
| 933 | for (int i = 0; i < bubbleChildren.size(); i++) { |
| 934 | removeBubble(bubbleChildren.get(i).getEntry(), DISMISS_GROUP_CANCELLED); |
| 935 | } |
| 936 | } else { |
| 937 | removeBubble(entry, DISMISS_NOTIF_CANCEL); |
| 938 | } |
| 939 | } |
| 940 | |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 941 | private void onRankingUpdated(RankingMap rankingMap) { |
| 942 | // Forward to BubbleData to block any bubbles which should no longer be shown |
| 943 | mBubbleData.notificationRankingUpdated(rankingMap); |
| 944 | } |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 945 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 946 | @SuppressWarnings("FieldCanBeLocal") |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 947 | private final BubbleData.Listener mBubbleDataListener = new BubbleData.Listener() { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 948 | |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 949 | @Override |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 950 | public void applyUpdate(BubbleData.Update update) { |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 951 | // Update bubbles in overflow. |
| 952 | if (mOverflowCallback != null) { |
| 953 | mOverflowCallback.run(); |
| 954 | } |
| 955 | |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 956 | // Collapsing? Do this first before remaining steps. |
| 957 | if (update.expandedChanged && !update.expanded) { |
| 958 | mStackView.setExpanded(false); |
| 959 | } |
| 960 | |
| 961 | // Do removals, if any. |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 962 | ArrayList<Pair<Bubble, Integer>> removedBubbles = |
| 963 | new ArrayList<>(update.removedBubbles); |
| 964 | for (Pair<Bubble, Integer> removed : removedBubbles) { |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 965 | final Bubble bubble = removed.first; |
| 966 | @DismissReason final int reason = removed.second; |
| 967 | mStackView.removeBubble(bubble); |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 968 | // If the bubble is removed for user switching, leave the notification in place. |
| 969 | if (reason != DISMISS_USER_CHANGED) { |
| 970 | if (!mBubbleData.hasBubbleWithKey(bubble.getKey()) |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 971 | && !bubble.showInShade()) { |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 972 | // The bubble is now gone & the notification is hidden from the shade, so |
| 973 | // time to actually remove it |
| 974 | for (NotifCallback cb : mCallbacks) { |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 975 | cb.removeNotification(bubble.getEntry(), REASON_CANCEL); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 976 | } |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 977 | } else { |
| 978 | // Update the flag for SysUI |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 979 | bubble.getEntry().getSbn().getNotification().flags &= ~FLAG_BUBBLE; |
Mady Mellor | 3a0a1b4 | 2019-05-23 06:40:21 -0700 | [diff] [blame] | 980 | |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 981 | // Make sure NoMan knows it's not a bubble anymore so anyone querying it |
| 982 | // will get right result back |
| 983 | try { |
| 984 | mBarService.onNotificationBubbleChanged(bubble.getKey(), |
| 985 | false /* isBubble */); |
| 986 | } catch (RemoteException e) { |
| 987 | // Bad things have happened |
| 988 | } |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 989 | } |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 990 | |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 991 | final String groupKey = bubble.getEntry().getSbn().getGroupKey(); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 992 | if (mBubbleData.getBubblesInGroup(groupKey).isEmpty()) { |
| 993 | // Time to potentially remove the summary |
| 994 | for (NotifCallback cb : mCallbacks) { |
| 995 | cb.maybeCancelSummary(bubble.getEntry()); |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 996 | } |
| 997 | } |
Mady Mellor | a54e9fa | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 998 | } |
| 999 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 1000 | |
Lyn Han | c47e171 | 2020-01-28 21:43:34 -0800 | [diff] [blame] | 1001 | if (update.addedBubble != null) { |
| 1002 | mStackView.addBubble(update.addedBubble); |
| 1003 | } |
| 1004 | |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 1005 | if (update.updatedBubble != null) { |
| 1006 | mStackView.updateBubble(update.updatedBubble); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 1007 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 1008 | |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 1009 | // At this point, the correct bubbles are inflated in the stack. |
| 1010 | // Make sure the order in bubble data is reflected in bubble row. |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 1011 | if (update.orderChanged) { |
| 1012 | mStackView.updateBubbleOrder(update.bubbles); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 1013 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 1014 | |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 1015 | if (update.selectionChanged) { |
| 1016 | mStackView.setSelectedBubble(update.selectedBubble); |
Mady Mellor | 740d85d | 2019-07-09 15:26:47 -0700 | [diff] [blame] | 1017 | if (update.selectedBubble != null) { |
| 1018 | mNotificationGroupManager.updateSuppression( |
| 1019 | update.selectedBubble.getEntry()); |
| 1020 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 1021 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 1022 | |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 1023 | // Expanding? Apply this last. |
| 1024 | if (update.expandedChanged && update.expanded) { |
| 1025 | mStackView.setExpanded(true); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 1026 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 1027 | |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1028 | for (NotifCallback cb : mCallbacks) { |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1029 | cb.invalidateNotifications("BubbleData.Listener.applyUpdate"); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1030 | } |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 1031 | updateStack(); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1032 | |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 1033 | if (DEBUG_BUBBLE_CONTROLLER) { |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 1034 | Log.d(TAG, "\n[BubbleData] bubbles:"); |
Lyn Han | 767d70e | 2019-12-10 18:02:23 -0800 | [diff] [blame] | 1035 | Log.d(TAG, BubbleDebugConfig.formatBubblesString(mBubbleData.getBubbles(), |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1036 | mBubbleData.getSelectedBubble())); |
| 1037 | |
| 1038 | if (mStackView != null) { |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 1039 | Log.d(TAG, "\n[BubbleStackView]"); |
Lyn Han | 767d70e | 2019-12-10 18:02:23 -0800 | [diff] [blame] | 1040 | Log.d(TAG, BubbleDebugConfig.formatBubblesString(mStackView.getBubblesOnScreen(), |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1041 | mStackView.getExpandedBubble())); |
| 1042 | } |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 1043 | Log.d(TAG, "\n[BubbleData] overflow:"); |
| 1044 | Log.d(TAG, BubbleDebugConfig.formatBubblesString(mBubbleData.getOverflowBubbles(), |
| 1045 | null)); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1046 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 1047 | } |
| 1048 | }; |
| 1049 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 1050 | /** |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1051 | * We intercept notification entries (including group summaries) dismissed by the user when |
| 1052 | * there is an active bubble associated with it. We do this so that developers can still |
| 1053 | * cancel it (and hence the bubbles associated with it). However, these intercepted |
| 1054 | * notifications should then be hidden from the shade since the user has cancelled them, so we |
| 1055 | * {@link Bubble#setSuppressNotification}. For the case of suppressed summaries, we also add |
| 1056 | * {@link BubbleData#addSummaryToSuppress}. |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1057 | * |
Mady Mellor | 91b31e6 | 2020-01-30 17:40:48 -0800 | [diff] [blame] | 1058 | * @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] | 1059 | */ |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1060 | public boolean handleDismissalInterception(NotificationEntry entry) { |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1061 | if (entry == null) { |
| 1062 | return false; |
| 1063 | } |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1064 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1065 | final boolean interceptBubbleDismissal = mBubbleData.hasBubbleWithKey(entry.getKey()) |
| 1066 | && entry.isBubble(); |
| 1067 | final boolean interceptSummaryDismissal = isSummaryOfBubbles(entry); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1068 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1069 | if (interceptSummaryDismissal) { |
| 1070 | handleSummaryDismissalInterception(entry); |
| 1071 | } else if (interceptBubbleDismissal) { |
| 1072 | Bubble bubble = mBubbleData.getBubbleWithKey(entry.getKey()); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1073 | bubble.setSuppressNotification(true); |
| 1074 | bubble.setShowDot(false /* show */, true /* animate */); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1075 | } else { |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1076 | return false; |
| 1077 | } |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1078 | |
| 1079 | // Update the shade |
| 1080 | for (NotifCallback cb : mCallbacks) { |
| 1081 | cb.invalidateNotifications("BubbleController.handleDismissalInterception"); |
| 1082 | } |
| 1083 | return true; |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1084 | } |
| 1085 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1086 | private boolean isSummaryOfBubbles(NotificationEntry entry) { |
| 1087 | if (entry == null) { |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1088 | return false; |
| 1089 | } |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1090 | |
| 1091 | String groupKey = entry.getSbn().getGroupKey(); |
| 1092 | ArrayList<Bubble> bubbleChildren = mBubbleData.getBubblesInGroup(groupKey); |
| 1093 | boolean isSuppressedSummary = (mBubbleData.isSummarySuppressed(groupKey) |
| 1094 | && mBubbleData.getSummaryKey(groupKey).equals(entry.getKey())); |
| 1095 | boolean isSummary = entry.getSbn().getNotification().isGroupSummary(); |
| 1096 | return (isSuppressedSummary || isSummary) |
| 1097 | && bubbleChildren != null |
| 1098 | && !bubbleChildren.isEmpty(); |
| 1099 | } |
| 1100 | |
| 1101 | private void handleSummaryDismissalInterception(NotificationEntry summary) { |
| 1102 | // current children in the row: |
| 1103 | final List<NotificationEntry> children = summary.getChildren(); |
| 1104 | if (children != null) { |
| 1105 | for (int i = 0; i < children.size(); i++) { |
| 1106 | NotificationEntry child = children.get(i); |
| 1107 | if (mBubbleData.hasBubbleWithKey(child.getKey())) { |
| 1108 | // Suppress the bubbled child |
| 1109 | // As far as group manager is concerned, once a child is no longer shown |
| 1110 | // in the shade, it is essentially removed. |
| 1111 | Bubble bubbleChild = mBubbleData.getBubbleWithKey(child.getKey()); |
| 1112 | mNotificationGroupManager.onEntryRemoved(bubbleChild.getEntry()); |
| 1113 | bubbleChild.setSuppressNotification(true); |
| 1114 | bubbleChild.setShowDot(false /* show */, true /* animate */); |
| 1115 | } else { |
| 1116 | // non-bubbled children can be removed |
| 1117 | for (NotifCallback cb : mCallbacks) { |
| 1118 | cb.removeNotification(child, REASON_GROUP_SUMMARY_CANCELED); |
| 1119 | } |
| 1120 | } |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | // And since all children are removed, remove the summary. |
| 1125 | mNotificationGroupManager.onEntryRemoved(summary); |
| 1126 | |
| 1127 | // TODO: (b/145659174) remove references to mSuppressedGroupKeys once fully migrated |
| 1128 | mBubbleData.addSummaryToSuppress(summary.getSbn().getGroupKey(), |
| 1129 | summary.getKey()); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | /** |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 1133 | * Lets any listeners know if bubble state has changed. |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 1134 | * Updates the visibility of the bubbles based on current state. |
| 1135 | * Does not un-bubble, just hides or un-hides. Notifies any |
| 1136 | * {@link BubbleStateChangeListener}s of visibility changes. |
| 1137 | * Updates stack description for TalkBack focus. |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 1138 | */ |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 1139 | public void updateStack() { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 1140 | if (mStackView == null) { |
| 1141 | return; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 1142 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 1143 | if (mStatusBarStateListener.getCurrentState() == SHADE && hasBubbles()) { |
| 1144 | // Bubbles only appear in unlocked shade |
| 1145 | mStackView.setVisibility(hasBubbles() ? VISIBLE : INVISIBLE); |
Mady Mellor | 698d9e8 | 2019-08-01 23:11:53 +0000 | [diff] [blame] | 1146 | } else if (mStackView != null) { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 1147 | mStackView.setVisibility(INVISIBLE); |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 1148 | } |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 1149 | |
Mady Mellor | 698d9e8 | 2019-08-01 23:11:53 +0000 | [diff] [blame] | 1150 | // Let listeners know if bubble state changed. |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 1151 | boolean hadBubbles = mNotificationShadeWindowController.getBubblesShowing(); |
Mady Mellor | 698d9e8 | 2019-08-01 23:11:53 +0000 | [diff] [blame] | 1152 | boolean hasBubblesShowing = hasBubbles() && mStackView.getVisibility() == VISIBLE; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 1153 | mNotificationShadeWindowController.setBubblesShowing(hasBubblesShowing); |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 1154 | if (mStateChangeListener != null && hadBubbles != hasBubblesShowing) { |
| 1155 | mStateChangeListener.onHasBubblesChanged(hasBubblesShowing); |
| 1156 | } |
| 1157 | |
| 1158 | mStackView.updateContentDescription(); |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | /** |
| 1162 | * Rect indicating the touchable region for the bubble stack / expanded stack. |
| 1163 | */ |
| 1164 | public Rect getTouchableRegion() { |
| 1165 | if (mStackView == null || mStackView.getVisibility() != VISIBLE) { |
| 1166 | return null; |
| 1167 | } |
| 1168 | mStackView.getBoundsOnScreen(mTempRect); |
| 1169 | return mTempRect; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1170 | } |
| 1171 | |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 1172 | /** |
| 1173 | * The display id of the expanded view, if the stack is expanded and not occluded by the |
| 1174 | * status bar, otherwise returns {@link Display#INVALID_DISPLAY}. |
| 1175 | */ |
| 1176 | public int getExpandedDisplayId(Context context) { |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 1177 | final Bubble bubble = getExpandedBubble(context); |
| 1178 | return bubble != null ? bubble.getDisplayId() : INVALID_DISPLAY; |
| 1179 | } |
| 1180 | |
| 1181 | @Nullable |
| 1182 | private Bubble getExpandedBubble(Context context) { |
Joel Galenson | 4071ddb | 2019-04-18 13:30:45 -0700 | [diff] [blame] | 1183 | if (mStackView == null) { |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 1184 | return null; |
Joel Galenson | 4071ddb | 2019-04-18 13:30:45 -0700 | [diff] [blame] | 1185 | } |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 1186 | final boolean defaultDisplay = context.getDisplay() != null |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 1187 | && context.getDisplay().getDisplayId() == DEFAULT_DISPLAY; |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 1188 | final Bubble expandedBubble = mStackView.getExpandedBubble(); |
| 1189 | if (defaultDisplay && expandedBubble != null && isStackExpanded() |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 1190 | && !mNotificationShadeWindowController.getPanelExpanded()) { |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 1191 | return expandedBubble; |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 1192 | } |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 1193 | return null; |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 1194 | } |
| 1195 | |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 1196 | @VisibleForTesting |
| 1197 | BubbleStackView getStackView() { |
| 1198 | return mStackView; |
| 1199 | } |
| 1200 | |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 1201 | /** |
| 1202 | * Description of current bubble state. |
| 1203 | */ |
| 1204 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1205 | pw.println("BubbleController state:"); |
| 1206 | mBubbleData.dump(fd, pw, args); |
| 1207 | pw.println(); |
Joshua Tsuji | 395bcfe | 2019-07-02 19:23:23 -0400 | [diff] [blame] | 1208 | if (mStackView != null) { |
| 1209 | mStackView.dump(fd, pw, args); |
| 1210 | } |
| 1211 | pw.println(); |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 1212 | } |
| 1213 | |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 1214 | /** |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 1215 | * This task stack listener is responsible for responding to tasks moved to the front |
| 1216 | * which are on the default (main) display. When this happens, expanded bubbles must be |
| 1217 | * collapsed so the user may interact with the app which was just moved to the front. |
| 1218 | * <p> |
| 1219 | * This listener is registered with SystemUI's ActivityManagerWrapper which dispatches |
| 1220 | * these calls via a main thread Handler. |
| 1221 | */ |
| 1222 | @MainThread |
| 1223 | private class BubbleTaskStackListener extends TaskStackChangeListener { |
| 1224 | |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 1225 | @Override |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 1226 | public void onTaskMovedToFront(RunningTaskInfo taskInfo) { |
| 1227 | if (mStackView != null && taskInfo.displayId == Display.DEFAULT_DISPLAY) { |
Mady Mellor | 047e24e | 2019-08-05 11:35:40 -0700 | [diff] [blame] | 1228 | if (!mStackView.isExpansionAnimating()) { |
| 1229 | mBubbleData.setExpanded(false); |
| 1230 | } |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 1231 | } |
| 1232 | } |
| 1233 | |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 1234 | @Override |
Mark Renouf | a12e876 | 2019-03-07 15:43:01 -0500 | [diff] [blame] | 1235 | public void onActivityLaunchOnSecondaryDisplayRerouted() { |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 1236 | if (mStackView != null) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 1237 | mBubbleData.setExpanded(false); |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 1238 | } |
| 1239 | } |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 1240 | |
| 1241 | @Override |
| 1242 | public void onBackPressedOnTaskRoot(RunningTaskInfo taskInfo) { |
| 1243 | if (mStackView != null && taskInfo.displayId == getExpandedDisplayId(mContext)) { |
| 1244 | mBubbleData.setExpanded(false); |
| 1245 | } |
| 1246 | } |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 1247 | |
| 1248 | @Override |
| 1249 | public void onSingleTaskDisplayDrawn(int displayId) { |
Lyn Han | a0bb02e | 2020-01-28 17:57:27 -0800 | [diff] [blame] | 1250 | if (mStackView == null) { |
| 1251 | return; |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 1252 | } |
Lyn Han | a0bb02e | 2020-01-28 17:57:27 -0800 | [diff] [blame] | 1253 | mStackView.showExpandedViewContents(displayId); |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 1254 | } |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 1255 | |
| 1256 | @Override |
| 1257 | public void onSingleTaskDisplayEmpty(int displayId) { |
Mady Mellor | 5186b13 | 2019-09-16 17:55:48 -0700 | [diff] [blame] | 1258 | final Bubble expandedBubble = mStackView != null |
| 1259 | ? mStackView.getExpandedBubble() |
| 1260 | : null; |
Mady Mellor | ca184aae | 2019-09-17 16:07:12 -0700 | [diff] [blame] | 1261 | int expandedId = expandedBubble != null ? expandedBubble.getDisplayId() : -1; |
| 1262 | if (mStackView != null && mStackView.isExpanded() && expandedId == displayId) { |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 1263 | mBubbleData.setExpanded(false); |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 1264 | } |
Mady Mellor | ca184aae | 2019-09-17 16:07:12 -0700 | [diff] [blame] | 1265 | mBubbleData.notifyDisplayEmpty(displayId); |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 1266 | } |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 1267 | } |
| 1268 | |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1269 | /** |
| 1270 | * Whether an intent is properly configured to display in an {@link android.app.ActivityView}. |
| 1271 | * |
| 1272 | * Keep checks in sync with NotificationManagerService#canLaunchInActivityView. Typically |
| 1273 | * that should filter out any invalid bubbles, but should protect SysUI side just in case. |
| 1274 | * |
| 1275 | * @param context the context to use. |
| 1276 | * @param entry the entry to bubble. |
| 1277 | */ |
| 1278 | static boolean canLaunchInActivityView(Context context, NotificationEntry entry) { |
| 1279 | PendingIntent intent = entry.getBubbleMetadata() != null |
Mady Mellor | 2ac2d3a | 2020-01-08 17:18:54 -0800 | [diff] [blame] | 1280 | ? entry.getBubbleMetadata().getBubbleIntent() |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1281 | : null; |
Mady Mellor | 2ac2d3a | 2020-01-08 17:18:54 -0800 | [diff] [blame] | 1282 | if (entry.getBubbleMetadata() != null |
| 1283 | && entry.getBubbleMetadata().getShortcutId() != null) { |
| 1284 | return true; |
| 1285 | } |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1286 | if (intent == null) { |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 1287 | Log.w(TAG, "Unable to create bubble -- no intent: " + entry.getKey()); |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1288 | return false; |
| 1289 | } |
Mady Mellor | f3b9fab | 2019-11-13 17:27:32 -0800 | [diff] [blame] | 1290 | PackageManager packageManager = StatusBar.getPackageManagerForUser( |
| 1291 | context, entry.getSbn().getUser().getIdentifier()); |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1292 | ActivityInfo info = |
Mady Mellor | f3b9fab | 2019-11-13 17:27:32 -0800 | [diff] [blame] | 1293 | intent.getIntent().resolveActivityInfo(packageManager, 0); |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1294 | if (info == null) { |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 1295 | Log.w(TAG, "Unable to send as bubble, " |
| 1296 | + entry.getKey() + " couldn't find activity info for intent: " |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1297 | + intent); |
| 1298 | return false; |
| 1299 | } |
| 1300 | if (!ActivityInfo.isResizeableMode(info.resizeMode)) { |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 1301 | Log.w(TAG, "Unable to send as bubble, " |
| 1302 | + entry.getKey() + " activity is not resizable for intent: " |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1303 | + intent); |
| 1304 | return false; |
| 1305 | } |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1306 | return true; |
| 1307 | } |
| 1308 | |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 1309 | /** PinnedStackListener that dispatches IME visibility updates to the stack. */ |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 1310 | private class BubblesImeListener extends PinnedStackListenerForwarder.PinnedStackListener { |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 1311 | @Override |
Joshua Tsuji | d942283 | 2019-03-05 13:32:37 -0500 | [diff] [blame] | 1312 | public void onImeVisibilityChanged(boolean imeVisible, int imeHeight) { |
| 1313 | if (mStackView != null && mStackView.getBubbleCount() > 0) { |
| 1314 | mStackView.post(() -> mStackView.onImeVisibilityChanged(imeVisible, imeHeight)); |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 1315 | } |
| 1316 | } |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 1317 | } |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1318 | } |