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 | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 117 | DISMISS_USER_CHANGED, DISMISS_GROUP_CANCELLED}) |
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; |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 130 | |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 131 | public static final int MAX_BUBBLES = 5; // TODO: actually enforce this |
Joshua Tsuji | 25a4b7b | 2019-03-22 14:11:06 -0400 | [diff] [blame] | 132 | |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 133 | /** Flag to enable or disable the entire feature */ |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 134 | private static final String ENABLE_BUBBLES = "experiment_enable_bubbles"; |
Joshua Tsuji | 010c2b1 | 2019-02-25 18:11:25 -0500 | [diff] [blame] | 135 | |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 136 | private final Context mContext; |
| 137 | private final NotificationEntryManager mNotificationEntryManager; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 138 | private final BubbleTaskStackListener mTaskStackListener; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 139 | private BubbleStateChangeListener mStateChangeListener; |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 140 | private BubbleExpandListener mExpandListener; |
Issei Suzuki | c038754 | 2019-03-08 17:31:14 +0100 | [diff] [blame] | 141 | @Nullable private BubbleStackView.SurfaceSynchronizer mSurfaceSynchronizer; |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 142 | private final NotificationGroupManager mNotificationGroupManager; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 143 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 144 | private BubbleData mBubbleData; |
Joshua Tsuji | c650a14 | 2019-05-22 11:31:19 -0400 | [diff] [blame] | 145 | @Nullable private BubbleStackView mStackView; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 146 | |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 147 | // Tracks the id of the current (foreground) user. |
| 148 | private int mCurrentUserId; |
| 149 | // Saves notification keys of active bubbles when users are switched. |
| 150 | private final SparseSetArray<String> mSavedBubbleKeysPerUser; |
| 151 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 152 | // Bubbles get added to the status bar view |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 153 | private final StatusBarWindowController mStatusBarWindowController; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 154 | private final ZenModeController mZenModeController; |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 155 | private StatusBarStateListener mStatusBarStateListener; |
| 156 | |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 157 | private final NotificationInterruptionStateProvider mNotificationInterruptionStateProvider; |
Mady Mellor | a54e9fa | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 158 | private IStatusBarService mBarService; |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 159 | |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 160 | // Used for determining view rect for touch interaction |
| 161 | private Rect mTempRect = new Rect(); |
| 162 | |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 163 | // Listens to user switch so bubbles can be saved and restored. |
| 164 | private final NotificationLockscreenUserManager mNotifUserManager; |
| 165 | |
Joshua Tsuji | f418f9e | 2019-04-04 17:09:53 -0400 | [diff] [blame] | 166 | /** Last known orientation, used to detect orientation changes in {@link #onConfigChanged}. */ |
| 167 | private int mOrientation = Configuration.ORIENTATION_UNDEFINED; |
| 168 | |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 169 | /** |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 170 | * Listener to be notified when some states of the bubbles change. |
| 171 | */ |
| 172 | public interface BubbleStateChangeListener { |
| 173 | /** |
| 174 | * Called when the stack has bubbles or no longer has bubbles. |
| 175 | */ |
| 176 | void onHasBubblesChanged(boolean hasBubbles); |
| 177 | } |
| 178 | |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 179 | /** |
| 180 | * Listener to find out about stack expansion / collapse events. |
| 181 | */ |
| 182 | public interface BubbleExpandListener { |
| 183 | /** |
| 184 | * Called when the expansion state of the bubble stack changes. |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 185 | * |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 186 | * @param isExpanding whether it's expanding or collapsing |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 187 | * @param key the notification key associated with bubble being expanded |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 188 | */ |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 189 | void onBubbleExpandChanged(boolean isExpanding, String key); |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Listens for the current state of the status bar and updates the visibility state |
| 194 | * of bubbles as needed. |
| 195 | */ |
| 196 | private class StatusBarStateListener implements StatusBarStateController.StateListener { |
| 197 | private int mState; |
| 198 | /** |
| 199 | * Returns the current status bar state. |
| 200 | */ |
| 201 | public int getCurrentState() { |
| 202 | return mState; |
| 203 | } |
| 204 | |
| 205 | @Override |
| 206 | public void onStateChanged(int newState) { |
| 207 | mState = newState; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 208 | boolean shouldCollapse = (mState != SHADE); |
| 209 | if (shouldCollapse) { |
| 210 | collapseStack(); |
| 211 | } |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 212 | updateStack(); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 213 | } |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 214 | } |
| 215 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 216 | @Inject |
Mady Mellor | cfd06c1 | 2019-02-13 14:32:12 -0800 | [diff] [blame] | 217 | public BubbleController(Context context, StatusBarWindowController statusBarWindowController, |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 218 | BubbleData data, ConfigurationController configurationController, |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 219 | NotificationInterruptionStateProvider interruptionStateProvider, |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 220 | ZenModeController zenModeController, |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 221 | NotificationLockscreenUserManager notifUserManager, |
| 222 | NotificationGroupManager groupManager) { |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 223 | this(context, statusBarWindowController, data, null /* synchronizer */, |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 224 | configurationController, interruptionStateProvider, zenModeController, |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 225 | notifUserManager, groupManager); |
Issei Suzuki | c038754 | 2019-03-08 17:31:14 +0100 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | public BubbleController(Context context, StatusBarWindowController statusBarWindowController, |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 229 | BubbleData data, @Nullable BubbleStackView.SurfaceSynchronizer synchronizer, |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 230 | ConfigurationController configurationController, |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 231 | NotificationInterruptionStateProvider interruptionStateProvider, |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 232 | ZenModeController zenModeController, |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 233 | NotificationLockscreenUserManager notifUserManager, |
| 234 | NotificationGroupManager groupManager) { |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 235 | mContext = context; |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 236 | mNotificationInterruptionStateProvider = interruptionStateProvider; |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 237 | mNotifUserManager = notifUserManager; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 238 | mZenModeController = zenModeController; |
| 239 | mZenModeController.addCallback(new ZenModeController.Callback() { |
| 240 | @Override |
| 241 | public void onZenChanged(int zen) { |
Mady Mellor | df48d0a | 2019-06-25 18:26:46 -0700 | [diff] [blame] | 242 | if (mStackView != null) { |
| 243 | mStackView.updateDots(); |
| 244 | } |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | @Override |
| 248 | public void onConfigChanged(ZenModeConfig config) { |
Mady Mellor | df48d0a | 2019-06-25 18:26:46 -0700 | [diff] [blame] | 249 | if (mStackView != null) { |
| 250 | mStackView.updateDots(); |
| 251 | } |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 252 | } |
| 253 | }); |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 254 | |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 255 | configurationController.addCallback(this /* configurationListener */); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 256 | |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 257 | mBubbleData = data; |
| 258 | mBubbleData.setListener(mBubbleDataListener); |
| 259 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 260 | mNotificationEntryManager = Dependency.get(NotificationEntryManager.class); |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 261 | mNotificationEntryManager.addNotificationEntryListener(mEntryListener); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 262 | mNotificationEntryManager.setNotificationRemoveInterceptor(mRemoveInterceptor); |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 263 | mNotificationGroupManager = groupManager; |
Mady Mellor | 740d85d | 2019-07-09 15:26:47 -0700 | [diff] [blame^] | 264 | mNotificationGroupManager.addOnGroupChangeListener( |
| 265 | new NotificationGroupManager.OnGroupChangeListener() { |
| 266 | @Override |
| 267 | public void onGroupSuppressionChanged( |
| 268 | NotificationGroupManager.NotificationGroup group, |
| 269 | boolean suppressed) { |
| 270 | // More notifications could be added causing summary to no longer |
| 271 | // be suppressed -- in this case need to remove the key. |
| 272 | final String groupKey = group.summary != null |
| 273 | ? group.summary.notification.getGroupKey() |
| 274 | : null; |
| 275 | if (!suppressed && groupKey != null |
| 276 | && mBubbleData.isSummarySuppressed(groupKey)) { |
| 277 | mBubbleData.removeSuppressedSummary(groupKey); |
| 278 | } |
| 279 | } |
| 280 | }); |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 281 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 282 | mStatusBarWindowController = statusBarWindowController; |
| 283 | mStatusBarStateListener = new StatusBarStateListener(); |
| 284 | Dependency.get(StatusBarStateController.class).addCallback(mStatusBarStateListener); |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 285 | |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 286 | mTaskStackListener = new BubbleTaskStackListener(); |
| 287 | ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 288 | |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 289 | try { |
| 290 | WindowManagerWrapper.getInstance().addPinnedStackListener(new BubblesImeListener()); |
| 291 | } catch (RemoteException e) { |
| 292 | e.printStackTrace(); |
| 293 | } |
Issei Suzuki | c038754 | 2019-03-08 17:31:14 +0100 | [diff] [blame] | 294 | mSurfaceSynchronizer = synchronizer; |
Mady Mellor | a54e9fa | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 295 | |
| 296 | mBarService = IStatusBarService.Stub.asInterface( |
| 297 | ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 298 | |
| 299 | mSavedBubbleKeysPerUser = new SparseSetArray<>(); |
| 300 | mCurrentUserId = mNotifUserManager.getCurrentUserId(); |
| 301 | mNotifUserManager.addUserChangedListener( |
| 302 | newUserId -> { |
| 303 | saveBubbles(mCurrentUserId); |
| 304 | mBubbleData.dismissAll(DISMISS_USER_CHANGED); |
| 305 | restoreBubbles(newUserId); |
| 306 | mCurrentUserId = newUserId; |
| 307 | }); |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 308 | } |
| 309 | |
Mark Renouf | 8b6a3c6 | 2019-04-09 10:17:40 -0400 | [diff] [blame] | 310 | /** |
| 311 | * BubbleStackView is lazily created by this method the first time a Bubble is added. This |
| 312 | * method initializes the stack view and adds it to the StatusBar just above the scrim. |
| 313 | */ |
| 314 | private void ensureStackViewCreated() { |
| 315 | if (mStackView == null) { |
| 316 | mStackView = new BubbleStackView(mContext, mBubbleData, mSurfaceSynchronizer); |
| 317 | ViewGroup sbv = mStatusBarWindowController.getStatusBarView(); |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 318 | int bubbleScrimIndex = sbv.indexOfChild(sbv.findViewById(R.id.scrim_for_bubble)); |
| 319 | int stackIndex = bubbleScrimIndex + 1; // Show stack above bubble scrim. |
| 320 | sbv.addView(mStackView, stackIndex, |
Mark Renouf | 8b6a3c6 | 2019-04-09 10:17:40 -0400 | [diff] [blame] | 321 | new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)); |
| 322 | if (mExpandListener != null) { |
| 323 | mStackView.setExpandListener(mExpandListener); |
| 324 | } |
Mark Renouf | 8b6a3c6 | 2019-04-09 10:17:40 -0400 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 328 | /** |
| 329 | * Records the notification key for any active bubbles. These are used to restore active |
| 330 | * bubbles when the user returns to the foreground. |
| 331 | * |
| 332 | * @param userId the id of the user |
| 333 | */ |
| 334 | private void saveBubbles(@UserIdInt int userId) { |
| 335 | // First clear any existing keys that might be stored. |
| 336 | mSavedBubbleKeysPerUser.remove(userId); |
| 337 | // Add in all active bubbles for the current user. |
| 338 | for (Bubble bubble: mBubbleData.getBubbles()) { |
| 339 | mSavedBubbleKeysPerUser.add(userId, bubble.getKey()); |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | * Promotes existing notifications to Bubbles if they were previously bubbles. |
| 345 | * |
| 346 | * @param userId the id of the user |
| 347 | */ |
| 348 | private void restoreBubbles(@UserIdInt int userId) { |
| 349 | NotificationData notificationData = |
| 350 | mNotificationEntryManager.getNotificationData(); |
| 351 | ArraySet<String> savedBubbleKeys = mSavedBubbleKeysPerUser.get(userId); |
| 352 | if (savedBubbleKeys == null) { |
| 353 | // There were no bubbles saved for this used. |
| 354 | return; |
| 355 | } |
| 356 | for (NotificationEntry e : notificationData.getNotificationsForCurrentUser()) { |
| 357 | if (savedBubbleKeys.contains(e.key) |
| 358 | && mNotificationInterruptionStateProvider.shouldBubbleUp(e) |
| 359 | && canLaunchInActivityView(mContext, e)) { |
| 360 | updateBubble(e, /* suppressFlyout= */ true); |
| 361 | } |
| 362 | } |
| 363 | // Finally, remove the entries for this user now that bubbles are restored. |
| 364 | mSavedBubbleKeysPerUser.remove(mCurrentUserId); |
| 365 | } |
| 366 | |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 367 | @Override |
| 368 | public void onUiModeChanged() { |
| 369 | if (mStackView != null) { |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 370 | mStackView.onThemeChanged(); |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | |
| 374 | @Override |
| 375 | public void onOverlayChanged() { |
| 376 | if (mStackView != null) { |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 377 | mStackView.onThemeChanged(); |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | |
Joshua Tsuji | f418f9e | 2019-04-04 17:09:53 -0400 | [diff] [blame] | 381 | @Override |
| 382 | public void onConfigChanged(Configuration newConfig) { |
| 383 | if (mStackView != null && newConfig != null && newConfig.orientation != mOrientation) { |
Joshua Tsuji | f418f9e | 2019-04-04 17:09:53 -0400 | [diff] [blame] | 384 | mOrientation = newConfig.orientation; |
Lyn Han | f473031 | 2019-06-18 11:18:58 -0700 | [diff] [blame] | 385 | mStackView.onOrientationChanged(newConfig.orientation); |
Joshua Tsuji | f418f9e | 2019-04-04 17:09:53 -0400 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 389 | /** |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 390 | * Set a listener to be notified when some states of the bubbles change. |
| 391 | */ |
| 392 | public void setBubbleStateChangeListener(BubbleStateChangeListener listener) { |
| 393 | mStateChangeListener = listener; |
| 394 | } |
| 395 | |
| 396 | /** |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 397 | * Set a listener to be notified of bubble expand events. |
| 398 | */ |
| 399 | public void setExpandListener(BubbleExpandListener listener) { |
Issei Suzuki | ac9fcb7 | 2019-02-04 17:45:57 +0100 | [diff] [blame] | 400 | mExpandListener = ((isExpanding, key) -> { |
| 401 | if (listener != null) { |
| 402 | listener.onBubbleExpandChanged(isExpanding, key); |
| 403 | } |
| 404 | mStatusBarWindowController.setBubbleExpanded(isExpanding); |
| 405 | }); |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 406 | if (mStackView != null) { |
| 407 | mStackView.setExpandListener(mExpandListener); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | /** |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 412 | * Whether or not there are bubbles present, regardless of them being visible on the |
| 413 | * screen (e.g. if on AOD). |
| 414 | */ |
| 415 | public boolean hasBubbles() { |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 416 | if (mStackView == null) { |
| 417 | return false; |
| 418 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 419 | return mBubbleData.hasBubbles(); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | /** |
| 423 | * Whether the stack of bubbles is expanded or not. |
| 424 | */ |
| 425 | public boolean isStackExpanded() { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 426 | return mBubbleData.isExpanded(); |
| 427 | } |
| 428 | |
| 429 | /** |
| 430 | * Tell the stack of bubbles to expand. |
| 431 | */ |
| 432 | public void expandStack() { |
| 433 | mBubbleData.setExpanded(true); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | /** |
| 437 | * Tell the stack of bubbles to collapse. |
| 438 | */ |
| 439 | public void collapseStack() { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 440 | mBubbleData.setExpanded(false /* expanded */); |
| 441 | } |
| 442 | |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 443 | /** |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 444 | * True if either: |
| 445 | * (1) There is a bubble associated with the provided key and if its notification is hidden |
| 446 | * from the shade. |
| 447 | * (2) There is a group summary associated with the provided key that is hidden from the shade |
| 448 | * because it has been dismissed but still has child bubbles active. |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 449 | * |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 450 | * False otherwise. |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 451 | */ |
| 452 | public boolean isBubbleNotificationSuppressedFromShade(String key) { |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 453 | boolean isBubbleAndSuppressed = mBubbleData.hasBubbleWithKey(key) |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 454 | && !mBubbleData.getBubbleWithKey(key).showInShadeWhenBubble(); |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 455 | NotificationEntry entry = mNotificationEntryManager.getNotificationData().get(key); |
| 456 | String groupKey = entry != null ? entry.notification.getGroupKey() : null; |
| 457 | boolean isSuppressedSummary = mBubbleData.isSummarySuppressed(groupKey); |
| 458 | return isSuppressedSummary || isBubbleAndSuppressed; |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 461 | void selectBubble(Bubble bubble) { |
| 462 | mBubbleData.setSelectedBubble(bubble); |
| 463 | } |
| 464 | |
| 465 | @VisibleForTesting |
| 466 | void selectBubble(String key) { |
| 467 | Bubble bubble = mBubbleData.getBubbleWithKey(key); |
| 468 | selectBubble(bubble); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | /** |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 472 | * Request the stack expand if needed, then select the specified Bubble as current. |
| 473 | * |
| 474 | * @param notificationKey the notification key for the bubble to be selected |
| 475 | */ |
| 476 | public void expandStackAndSelectBubble(String notificationKey) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 477 | Bubble bubble = mBubbleData.getBubbleWithKey(notificationKey); |
| 478 | if (bubble != null) { |
| 479 | mBubbleData.setSelectedBubble(bubble); |
| 480 | mBubbleData.setExpanded(true); |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 481 | } |
| 482 | } |
| 483 | |
| 484 | /** |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 485 | * Tell the stack of bubbles to be dismissed, this will remove all of the bubbles in the stack. |
| 486 | */ |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 487 | void dismissStack(@DismissReason int reason) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 488 | mBubbleData.dismissAll(reason); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | /** |
Mark Renouf | 041d726 | 2019-02-06 12:09:41 -0500 | [diff] [blame] | 492 | * Directs a back gesture at the bubble stack. When opened, the current expanded bubble |
| 493 | * is forwarded a back key down/up pair. |
| 494 | */ |
| 495 | public void performBackPressIfNeeded() { |
| 496 | if (mStackView != null) { |
| 497 | mStackView.performBackPressIfNeeded(); |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | /** |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 502 | * Adds or updates a bubble associated with the provided notification entry. |
| 503 | * |
Mark Renouf | 8b6a3c6 | 2019-04-09 10:17:40 -0400 | [diff] [blame] | 504 | * @param notif the notification associated with this bubble. |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 505 | */ |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 506 | void updateBubble(NotificationEntry notif) { |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 507 | updateBubble(notif, /* supressFlyout */ false); |
| 508 | } |
| 509 | |
| 510 | void updateBubble(NotificationEntry notif, boolean suppressFlyout) { |
Mady Mellor | 66efd5e | 2019-05-15 13:38:11 -0700 | [diff] [blame] | 511 | // If this is an interruptive notif, mark that it's interrupted |
| 512 | if (notif.importance >= NotificationManager.IMPORTANCE_HIGH) { |
| 513 | notif.setInterruption(); |
| 514 | } |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 515 | mBubbleData.notificationEntryUpdated(notif, suppressFlyout); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | /** |
| 519 | * Removes the bubble associated with the {@param uri}. |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 520 | * <p> |
| 521 | * Must be called from the main thread. |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 522 | */ |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 523 | @MainThread |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 524 | void removeBubble(String key, int reason) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 525 | // TEMP: refactor to change this to pass entry |
| 526 | Bubble bubble = mBubbleData.getBubbleWithKey(key); |
| 527 | if (bubble != null) { |
Mady Mellor | ed99c27 | 2019-06-13 15:58:30 -0700 | [diff] [blame] | 528 | mBubbleData.notificationEntryRemoved(bubble.getEntry(), reason); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 529 | } |
| 530 | } |
| 531 | |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 532 | @SuppressWarnings("FieldCanBeLocal") |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 533 | private final NotificationRemoveInterceptor mRemoveInterceptor = |
| 534 | new NotificationRemoveInterceptor() { |
| 535 | @Override |
| 536 | public boolean onNotificationRemoveRequested(String key, int reason) { |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 537 | NotificationEntry entry = mNotificationEntryManager.getNotificationData().get(key); |
| 538 | String groupKey = entry != null ? entry.notification.getGroupKey() : null; |
| 539 | ArrayList<Bubble> bubbleChildren = mBubbleData.getBubblesInGroup(groupKey); |
| 540 | |
| 541 | boolean inBubbleData = mBubbleData.hasBubbleWithKey(key); |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 542 | boolean isSuppressedSummary = (mBubbleData.isSummarySuppressed(groupKey) |
| 543 | && mBubbleData.getSummaryKey(groupKey).equals(key)); |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 544 | boolean isSummary = entry != null |
| 545 | && entry.notification.getNotification().isGroupSummary(); |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 546 | boolean isSummaryOfBubbles = (isSuppressedSummary || isSummary) |
| 547 | && bubbleChildren != null && !bubbleChildren.isEmpty(); |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 548 | |
| 549 | if (!inBubbleData && !isSummaryOfBubbles) { |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 550 | return false; |
| 551 | } |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 552 | |
| 553 | final boolean isClearAll = reason == REASON_CANCEL_ALL; |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 554 | final boolean isUserDimiss = reason == REASON_CANCEL || reason == REASON_CLICK; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 555 | final boolean isAppCancel = reason == REASON_APP_CANCEL |
| 556 | || reason == REASON_APP_CANCEL_ALL; |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 557 | final boolean isSummaryCancel = reason == REASON_GROUP_SUMMARY_CANCELED; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 558 | |
| 559 | // Need to check for !appCancel here because the notification may have |
| 560 | // previously been dismissed & entry.isRowDismissed would still be true |
| 561 | boolean userRemovedNotif = (entry.isRowDismissed() && !isAppCancel) |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 562 | || isClearAll || isUserDimiss || isSummaryCancel; |
| 563 | |
| 564 | if (isSummaryOfBubbles) { |
| 565 | return handleSummaryRemovalInterception(entry, userRemovedNotif); |
| 566 | } |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 567 | |
| 568 | // The bubble notification sticks around in the data as long as the bubble is |
| 569 | // not dismissed and the app hasn't cancelled the notification. |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 570 | Bubble bubble = mBubbleData.getBubbleWithKey(key); |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 571 | boolean bubbleExtended = entry.isBubble() && userRemovedNotif; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 572 | if (bubbleExtended) { |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 573 | bubble.setShowInShadeWhenBubble(false); |
Mady Mellor | df48d0a | 2019-06-25 18:26:46 -0700 | [diff] [blame] | 574 | bubble.setShowBubbleDot(false); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 575 | if (mStackView != null) { |
| 576 | mStackView.updateDotVisibility(entry.key); |
| 577 | } |
| 578 | mNotificationEntryManager.updateNotifications(); |
| 579 | return true; |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 580 | } else if (!userRemovedNotif) { |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 581 | // This wasn't a user removal so we should remove the bubble as well |
| 582 | mBubbleData.notificationEntryRemoved(entry, DISMISS_NOTIF_CANCEL); |
| 583 | return false; |
| 584 | } |
| 585 | return false; |
| 586 | } |
| 587 | }; |
| 588 | |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 589 | private boolean handleSummaryRemovalInterception(NotificationEntry summary, |
| 590 | boolean userRemovedNotif) { |
| 591 | String groupKey = summary.notification.getGroupKey(); |
| 592 | ArrayList<Bubble> bubbleChildren = mBubbleData.getBubblesInGroup(groupKey); |
| 593 | |
| 594 | if (userRemovedNotif) { |
| 595 | // If it's a user dismiss we mark the children to be hidden from the shade. |
| 596 | for (int i = 0; i < bubbleChildren.size(); i++) { |
| 597 | Bubble bubbleChild = bubbleChildren.get(i); |
| 598 | // As far as group manager is concerned, once a child is no longer shown |
| 599 | // in the shade, it is essentially removed. |
| 600 | mNotificationGroupManager.onEntryRemoved(bubbleChild.getEntry()); |
| 601 | bubbleChild.setShowInShadeWhenBubble(false); |
| 602 | bubbleChild.setShowBubbleDot(false); |
| 603 | if (mStackView != null) { |
| 604 | mStackView.updateDotVisibility(bubbleChild.getKey()); |
| 605 | } |
| 606 | } |
| 607 | // And since all children are removed, remove the summary. |
| 608 | mNotificationGroupManager.onEntryRemoved(summary); |
| 609 | |
| 610 | // If the summary was auto-generated we don't need to keep that notification around |
| 611 | // because apps can't cancel it; so we only intercept & suppress real summaries. |
| 612 | boolean isAutogroupSummary = (summary.notification.getNotification().flags |
| 613 | & FLAG_AUTOGROUP_SUMMARY) != 0; |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 614 | if (!isAutogroupSummary) { |
| 615 | mBubbleData.addSummaryToSuppress(summary.notification.getGroupKey(), |
| 616 | summary.key); |
| 617 | // Tell shade to update for the suppression |
| 618 | mNotificationEntryManager.updateNotifications(); |
| 619 | } |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 620 | return !isAutogroupSummary; |
| 621 | } else { |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 622 | // If it's not a user dismiss it's a cancel. |
| 623 | mBubbleData.removeSuppressedSummary(groupKey); |
| 624 | |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 625 | // Remove any associated bubble children. |
| 626 | for (int i = 0; i < bubbleChildren.size(); i++) { |
| 627 | Bubble bubbleChild = bubbleChildren.get(i); |
| 628 | mBubbleData.notificationEntryRemoved(bubbleChild.getEntry(), |
| 629 | DISMISS_GROUP_CANCELLED); |
| 630 | } |
| 631 | return false; |
| 632 | } |
| 633 | } |
| 634 | |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 635 | @SuppressWarnings("FieldCanBeLocal") |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 636 | private final NotificationEntryListener mEntryListener = new NotificationEntryListener() { |
| 637 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 638 | public void onPendingEntryAdded(NotificationEntry entry) { |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 639 | if (!areBubblesEnabled(mContext)) { |
| 640 | return; |
| 641 | } |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 642 | if (mNotificationInterruptionStateProvider.shouldBubbleUp(entry) |
| 643 | && canLaunchInActivityView(mContext, entry)) { |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 644 | updateBubble(entry); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 645 | } |
| 646 | } |
| 647 | |
| 648 | @Override |
| 649 | public void onPreEntryUpdated(NotificationEntry entry) { |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 650 | if (!areBubblesEnabled(mContext)) { |
| 651 | return; |
| 652 | } |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 653 | boolean shouldBubble = mNotificationInterruptionStateProvider.shouldBubbleUp(entry) |
| 654 | && canLaunchInActivityView(mContext, entry); |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 655 | if (!shouldBubble && mBubbleData.hasBubbleWithKey(entry.key)) { |
| 656 | // It was previously a bubble but no longer a bubble -- lets remove it |
| 657 | removeBubble(entry.key, DISMISS_NO_LONGER_BUBBLE); |
Mady Mellor | ff40e01 | 2019-05-03 15:34:41 -0700 | [diff] [blame] | 658 | } else if (shouldBubble) { |
Mady Mellor | ed99c27 | 2019-06-13 15:58:30 -0700 | [diff] [blame] | 659 | Bubble b = mBubbleData.getBubbleWithKey(entry.key); |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 660 | updateBubble(entry); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 661 | } |
| 662 | } |
Mark Renouf | bbcf07f | 2019-05-09 10:42:43 -0400 | [diff] [blame] | 663 | |
| 664 | @Override |
| 665 | public void onNotificationRankingUpdated(RankingMap rankingMap) { |
| 666 | // Forward to BubbleData to block any bubbles which should no longer be shown |
| 667 | mBubbleData.notificationRankingUpdated(rankingMap); |
| 668 | } |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 669 | }; |
| 670 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 671 | @SuppressWarnings("FieldCanBeLocal") |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 672 | private final BubbleData.Listener mBubbleDataListener = new BubbleData.Listener() { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 673 | |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 674 | @Override |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 675 | public void applyUpdate(BubbleData.Update update) { |
| 676 | if (mStackView == null && update.addedBubble != null) { |
| 677 | // Lazy init stack view when the first bubble is added. |
| 678 | ensureStackViewCreated(); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 679 | } |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 680 | |
| 681 | // If not yet initialized, ignore all other changes. |
| 682 | if (mStackView == null) { |
| 683 | return; |
| 684 | } |
| 685 | |
| 686 | if (update.addedBubble != null) { |
| 687 | mStackView.addBubble(update.addedBubble); |
| 688 | } |
| 689 | |
| 690 | // Collapsing? Do this first before remaining steps. |
| 691 | if (update.expandedChanged && !update.expanded) { |
| 692 | mStackView.setExpanded(false); |
| 693 | } |
| 694 | |
| 695 | // Do removals, if any. |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 696 | ArrayList<Pair<Bubble, Integer>> removedBubbles = |
| 697 | new ArrayList<>(update.removedBubbles); |
| 698 | for (Pair<Bubble, Integer> removed : removedBubbles) { |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 699 | final Bubble bubble = removed.first; |
| 700 | @DismissReason final int reason = removed.second; |
| 701 | mStackView.removeBubble(bubble); |
| 702 | |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 703 | // If the bubble is removed for user switching, leave the notification in place. |
| 704 | if (reason != DISMISS_USER_CHANGED) { |
| 705 | if (!mBubbleData.hasBubbleWithKey(bubble.getKey()) |
| 706 | && !bubble.showInShadeWhenBubble()) { |
| 707 | // The bubble is gone & the notification is gone, time to actually remove it |
| 708 | mNotificationEntryManager.performRemoveNotification( |
| 709 | bubble.getEntry().notification, UNDEFINED_DISMISS_REASON); |
| 710 | } else { |
| 711 | // Update the flag for SysUI |
| 712 | bubble.getEntry().notification.getNotification().flags &= ~FLAG_BUBBLE; |
Mady Mellor | 3a0a1b4 | 2019-05-23 06:40:21 -0700 | [diff] [blame] | 713 | |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 714 | // Make sure NoMan knows it's not a bubble anymore so anyone querying it |
| 715 | // will get right result back |
| 716 | try { |
| 717 | mBarService.onNotificationBubbleChanged(bubble.getKey(), |
| 718 | false /* isBubble */); |
| 719 | } catch (RemoteException e) { |
| 720 | // Bad things have happened |
| 721 | } |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 722 | } |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 723 | |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 724 | // Check if removed bubble has an associated suppressed group summary that needs |
| 725 | // to be removed now. |
| 726 | final String groupKey = bubble.getEntry().notification.getGroupKey(); |
| 727 | if (mBubbleData.isSummarySuppressed(groupKey) |
| 728 | && mBubbleData.getBubblesInGroup(groupKey).isEmpty()) { |
| 729 | // Time to actually remove the summary. |
| 730 | String notifKey = mBubbleData.getSummaryKey(groupKey); |
| 731 | mBubbleData.removeSuppressedSummary(groupKey); |
| 732 | NotificationEntry entry = |
| 733 | mNotificationEntryManager.getNotificationData().get(notifKey); |
| 734 | if (entry == null) { |
| 735 | Log.w("mady", "WTF summary isn't in data... " + notifKey); |
| 736 | return; |
| 737 | } |
| 738 | mNotificationEntryManager.performRemoveNotification( |
| 739 | entry.notification, UNDEFINED_DISMISS_REASON); |
| 740 | } |
| 741 | |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 742 | // Check if summary should be removed from NoManGroup |
| 743 | NotificationEntry summary = mNotificationGroupManager.getLogicalGroupSummary( |
| 744 | bubble.getEntry().notification); |
| 745 | if (summary != null) { |
| 746 | ArrayList<NotificationEntry> summaryChildren = |
| 747 | mNotificationGroupManager.getLogicalChildren(summary.notification); |
| 748 | if (summaryChildren == null || summaryChildren.isEmpty()) { |
| 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); |
| 808 | } else if (mStackView != null) { |
| 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 | |
| 812 | // Let listeners know if bubble state changed. |
| 813 | boolean hadBubbles = mStatusBarWindowController.getBubblesShowing(); |
| 814 | boolean hasBubblesShowing = hasBubbles() && mStackView.getVisibility() == VISIBLE; |
| 815 | mStatusBarWindowController.setBubblesShowing(hasBubblesShowing); |
| 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) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 907 | mBubbleData.setExpanded(false); |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 908 | } |
| 909 | } |
| 910 | |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 911 | @Override |
Mark Renouf | a12e876 | 2019-03-07 15:43:01 -0500 | [diff] [blame] | 912 | public void onActivityLaunchOnSecondaryDisplayRerouted() { |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 913 | if (mStackView != null) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 914 | mBubbleData.setExpanded(false); |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 915 | } |
| 916 | } |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 917 | |
| 918 | @Override |
| 919 | public void onBackPressedOnTaskRoot(RunningTaskInfo taskInfo) { |
| 920 | if (mStackView != null && taskInfo.displayId == getExpandedDisplayId(mContext)) { |
| 921 | mBubbleData.setExpanded(false); |
| 922 | } |
| 923 | } |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 924 | |
| 925 | @Override |
| 926 | public void onSingleTaskDisplayDrawn(int displayId) { |
| 927 | final Bubble expandedBubble = getExpandedBubble(mContext); |
| 928 | if (expandedBubble != null && expandedBubble.getDisplayId() == displayId) { |
| 929 | expandedBubble.setContentVisibility(true); |
| 930 | } |
| 931 | } |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 932 | |
| 933 | @Override |
| 934 | public void onSingleTaskDisplayEmpty(int displayId) { |
| 935 | final Bubble expandedBubble = getExpandedBubble(mContext); |
| 936 | if (expandedBubble == null) { |
| 937 | return; |
| 938 | } |
| 939 | if (expandedBubble.getDisplayId() == displayId) { |
| 940 | mBubbleData.setExpanded(false); |
| 941 | } |
Mady Mellor | ed99c27 | 2019-06-13 15:58:30 -0700 | [diff] [blame] | 942 | if (expandedBubble.getExpandedView() != null) { |
| 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 | } |