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