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