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