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