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