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