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