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