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