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