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 | 3a0a1b4 | 2019-05-23 06:40:21 -0700 | [diff] [blame] | 19 | import static android.app.Notification.FLAG_BUBBLE; |
Mady Mellor | 9adfe6a | 2020-03-30 17:23:26 -0700 | [diff] [blame^] | 20 | import static android.app.NotificationManager.BUBBLE_PREFERENCE_NONE; |
| 21 | import static android.app.NotificationManager.BUBBLE_PREFERENCE_SELECTED; |
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 | 9adfe6a | 2020-03-30 17:23:26 -0700 | [diff] [blame^] | 47 | import android.app.INotificationManager; |
| 48 | import android.app.Notification; |
| 49 | import android.app.NotificationChannel; |
Mady Mellor | 66efd5e | 2019-05-15 13:38:11 -0700 | [diff] [blame] | 50 | import android.app.NotificationManager; |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 51 | import android.app.PendingIntent; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 52 | import android.content.Context; |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 53 | import android.content.pm.ActivityInfo; |
Mady Mellor | f3b9fab | 2019-11-13 17:27:32 -0800 | [diff] [blame] | 54 | import android.content.pm.PackageManager; |
Joshua Tsuji | f418f9e | 2019-04-04 17:09:53 -0400 | [diff] [blame] | 55 | import android.content.res.Configuration; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 56 | import android.graphics.Rect; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 57 | import android.os.RemoteException; |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 58 | import android.os.ServiceManager; |
Mady Mellor | 56515c4 | 2020-02-18 17:58:36 -0800 | [diff] [blame] | 59 | import android.service.notification.NotificationListenerService; |
Mark Renouf | bbcf07f | 2019-05-09 10:42:43 -0400 | [diff] [blame] | 60 | import android.service.notification.NotificationListenerService.RankingMap; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 61 | import android.service.notification.ZenModeConfig; |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 62 | import android.util.ArraySet; |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 63 | import android.util.Log; |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 64 | import android.util.Pair; |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 65 | import android.util.SparseSetArray; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 66 | import android.view.Display; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 67 | import android.view.ViewGroup; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 68 | import android.widget.FrameLayout; |
| 69 | |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 70 | import androidx.annotation.IntDef; |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 71 | import androidx.annotation.MainThread; |
Joshua Tsuji | c650a14 | 2019-05-22 11:31:19 -0400 | [diff] [blame] | 72 | import androidx.annotation.Nullable; |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 73 | |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 74 | import com.android.internal.annotations.VisibleForTesting; |
Mady Mellor | a54e9fa | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 75 | import com.android.internal.statusbar.IStatusBarService; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 76 | import com.android.internal.statusbar.NotificationVisibility; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 77 | import com.android.systemui.Dumpable; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 78 | import com.android.systemui.R; |
Sergey Nikolaienkov | 5cb6e52 | 2020-02-10 17:33:00 +0100 | [diff] [blame] | 79 | import com.android.systemui.bubbles.dagger.BubbleModule; |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 80 | import com.android.systemui.dump.DumpManager; |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 81 | import com.android.systemui.model.SysUiState; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 82 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 83 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 84 | import com.android.systemui.shared.system.PinnedStackListenerForwarder; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 85 | import com.android.systemui.shared.system.TaskStackChangeListener; |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 86 | import com.android.systemui.shared.system.WindowManagerWrapper; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 87 | import com.android.systemui.statusbar.FeatureFlags; |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 88 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 89 | import com.android.systemui.statusbar.NotificationRemoveInterceptor; |
Mady Mellor | 9adfe6a | 2020-03-30 17:23:26 -0700 | [diff] [blame^] | 90 | import com.android.systemui.statusbar.notification.NotificationChannelHelper; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 91 | import com.android.systemui.statusbar.notification.NotificationEntryListener; |
| 92 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 93 | import com.android.systemui.statusbar.notification.collection.NotifCollection; |
| 94 | import com.android.systemui.statusbar.notification.collection.NotifPipeline; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 95 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 96 | import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener; |
Beverly Tai | d1e175c | 2020-03-10 16:37:04 +0000 | [diff] [blame] | 97 | import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProvider; |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 98 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 99 | import com.android.systemui.statusbar.phone.NotificationShadeWindowController; |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 100 | import com.android.systemui.statusbar.phone.ShadeController; |
Mady Mellor | f3b9fab | 2019-11-13 17:27:32 -0800 | [diff] [blame] | 101 | import com.android.systemui.statusbar.phone.StatusBar; |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 102 | import com.android.systemui.statusbar.policy.ConfigurationController; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 103 | import com.android.systemui.statusbar.policy.ZenModeController; |
Joshua Tsuji | 7155bf1 | 2020-02-13 16:14:29 -0500 | [diff] [blame] | 104 | import com.android.systemui.util.FloatingContentCoordinator; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 105 | |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 106 | import java.io.FileDescriptor; |
| 107 | import java.io.PrintWriter; |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 108 | import java.lang.annotation.Retention; |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 109 | import java.lang.annotation.Target; |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 110 | import java.util.ArrayList; |
Mady Mellor | ff076eb | 2019-11-13 10:12:06 -0800 | [diff] [blame] | 111 | import java.util.HashSet; |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 112 | import java.util.List; |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 113 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 114 | /** |
| 115 | * Bubbles are a special type of content that can "float" on top of other apps or System UI. |
| 116 | * Bubbles can be expanded to show more content. |
| 117 | * |
| 118 | * The controller manages addition, removal, and visible state of bubbles on screen. |
| 119 | */ |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 120 | public class BubbleController implements ConfigurationController.ConfigurationListener, Dumpable { |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 121 | |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 122 | private static final String TAG = TAG_WITH_CLASS_NAME ? "BubbleController" : TAG_BUBBLES; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 123 | |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 124 | @Retention(SOURCE) |
| 125 | @IntDef({DISMISS_USER_GESTURE, DISMISS_AGED, DISMISS_TASK_FINISHED, DISMISS_BLOCKED, |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 126 | DISMISS_NOTIF_CANCEL, DISMISS_ACCESSIBILITY_ACTION, DISMISS_NO_LONGER_BUBBLE, |
Mady Mellor | 8454ddf | 2019-08-15 11:16:23 -0700 | [diff] [blame] | 127 | DISMISS_USER_CHANGED, DISMISS_GROUP_CANCELLED, DISMISS_INVALID_INTENT}) |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 128 | @Target({FIELD, LOCAL_VARIABLE, PARAMETER}) |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 129 | @interface DismissReason {} |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 130 | |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 131 | static final int DISMISS_USER_GESTURE = 1; |
| 132 | static final int DISMISS_AGED = 2; |
| 133 | static final int DISMISS_TASK_FINISHED = 3; |
| 134 | static final int DISMISS_BLOCKED = 4; |
| 135 | static final int DISMISS_NOTIF_CANCEL = 5; |
| 136 | static final int DISMISS_ACCESSIBILITY_ACTION = 6; |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 137 | static final int DISMISS_NO_LONGER_BUBBLE = 7; |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 138 | static final int DISMISS_USER_CHANGED = 8; |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 139 | static final int DISMISS_GROUP_CANCELLED = 9; |
Mady Mellor | 8454ddf | 2019-08-15 11:16:23 -0700 | [diff] [blame] | 140 | static final int DISMISS_INVALID_INTENT = 10; |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 141 | |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 142 | private final Context mContext; |
| 143 | private final NotificationEntryManager mNotificationEntryManager; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 144 | private final NotifPipeline mNotifPipeline; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 145 | private final BubbleTaskStackListener mTaskStackListener; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 146 | private BubbleStateChangeListener mStateChangeListener; |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 147 | private BubbleExpandListener mExpandListener; |
Issei Suzuki | c038754 | 2019-03-08 17:31:14 +0100 | [diff] [blame] | 148 | @Nullable private BubbleStackView.SurfaceSynchronizer mSurfaceSynchronizer; |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 149 | private final NotificationGroupManager mNotificationGroupManager; |
Heemin Seog | ba6337f | 2019-12-10 15:34:37 -0800 | [diff] [blame] | 150 | private final ShadeController mShadeController; |
Joshua Tsuji | 7155bf1 | 2020-02-13 16:14:29 -0500 | [diff] [blame] | 151 | private final FloatingContentCoordinator mFloatingContentCoordinator; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 152 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 153 | private BubbleData mBubbleData; |
Joshua Tsuji | c650a14 | 2019-05-22 11:31:19 -0400 | [diff] [blame] | 154 | @Nullable private BubbleStackView mStackView; |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 155 | private BubbleIconFactory mBubbleIconFactory; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 156 | |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 157 | // Tracks the id of the current (foreground) user. |
| 158 | private int mCurrentUserId; |
| 159 | // Saves notification keys of active bubbles when users are switched. |
| 160 | private final SparseSetArray<String> mSavedBubbleKeysPerUser; |
| 161 | |
Mady Mellor | 56515c4 | 2020-02-18 17:58:36 -0800 | [diff] [blame] | 162 | // Used when ranking updates occur and we check if things should bubble / unbubble |
| 163 | private NotificationListenerService.Ranking mTmpRanking; |
| 164 | |
Mady Mellor | ff076eb | 2019-11-13 10:12:06 -0800 | [diff] [blame] | 165 | // Saves notification keys of user created "fake" bubbles so that we can allow notifications |
| 166 | // like these to bubble by default. Doesn't persist across reboots, not a long-term solution. |
| 167 | private final HashSet<String> mUserCreatedBubbles; |
Mady Mellor | 3b86a4f | 2019-12-11 13:15:41 -0800 | [diff] [blame] | 168 | // If we're auto-bubbling bubbles via a whitelist, we need to track which notifs from that app |
| 169 | // have been "demoted" back to a notification so that we don't auto-bubbles those again. |
| 170 | // Doesn't persist across reboots, not a long-term solution. |
| 171 | private final HashSet<String> mUserBlockedBubbles; |
Mady Mellor | ff076eb | 2019-11-13 10:12:06 -0800 | [diff] [blame] | 172 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 173 | // Bubbles get added to the status bar view |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 174 | private final NotificationShadeWindowController mNotificationShadeWindowController; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 175 | private final ZenModeController mZenModeController; |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 176 | private StatusBarStateListener mStatusBarStateListener; |
Mady Mellor | 9adfe6a | 2020-03-30 17:23:26 -0700 | [diff] [blame^] | 177 | private INotificationManager mINotificationManager; |
Aran Ink | aa4dfa7 | 2019-11-18 16:49:07 -0500 | [diff] [blame] | 178 | |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 179 | // Callback that updates BubbleOverflowActivity on data change. |
| 180 | @Nullable private Runnable mOverflowCallback = null; |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 181 | |
Beverly Tai | d1e175c | 2020-03-10 16:37:04 +0000 | [diff] [blame] | 182 | private final NotificationInterruptStateProvider mNotificationInterruptStateProvider; |
Mady Mellor | a54e9fa | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 183 | private IStatusBarService mBarService; |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 184 | private SysUiState mSysUiState; |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 185 | |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 186 | // Used for determining view rect for touch interaction |
| 187 | private Rect mTempRect = new Rect(); |
| 188 | |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 189 | // Listens to user switch so bubbles can be saved and restored. |
| 190 | private final NotificationLockscreenUserManager mNotifUserManager; |
| 191 | |
Joshua Tsuji | f418f9e | 2019-04-04 17:09:53 -0400 | [diff] [blame] | 192 | /** Last known orientation, used to detect orientation changes in {@link #onConfigChanged}. */ |
| 193 | private int mOrientation = Configuration.ORIENTATION_UNDEFINED; |
| 194 | |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 195 | private boolean mInflateSynchronously; |
| 196 | |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 197 | // TODO (b/145659174): allow for multiple callbacks to support the "shadow" new notif pipeline |
| 198 | private final List<NotifCallback> mCallbacks = new ArrayList<>(); |
| 199 | |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 200 | /** |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 201 | * Listener to be notified when some states of the bubbles change. |
| 202 | */ |
| 203 | public interface BubbleStateChangeListener { |
| 204 | /** |
| 205 | * Called when the stack has bubbles or no longer has bubbles. |
| 206 | */ |
| 207 | void onHasBubblesChanged(boolean hasBubbles); |
| 208 | } |
| 209 | |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 210 | /** |
| 211 | * Listener to find out about stack expansion / collapse events. |
| 212 | */ |
| 213 | public interface BubbleExpandListener { |
| 214 | /** |
| 215 | * Called when the expansion state of the bubble stack changes. |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 216 | * |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 217 | * @param isExpanding whether it's expanding or collapsing |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 218 | * @param key the notification key associated with bubble being expanded |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 219 | */ |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 220 | void onBubbleExpandChanged(boolean isExpanding, String key); |
| 221 | } |
| 222 | |
| 223 | /** |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 224 | * Listener to be notified when a bubbles' notification suppression state changes. |
| 225 | */ |
| 226 | public interface NotificationSuppressionChangedListener { |
| 227 | /** |
| 228 | * Called when the notification suppression state of a bubble changes. |
| 229 | */ |
| 230 | void onBubbleNotificationSuppressionChange(Bubble bubble); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 231 | } |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 232 | |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 233 | /** |
| 234 | * Callback for when the BubbleController wants to interact with the notification pipeline to: |
| 235 | * - Remove a previously bubbled notification |
| 236 | * - Update the notification shade since bubbled notification should/shouldn't be showing |
| 237 | */ |
| 238 | public interface NotifCallback { |
| 239 | /** |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 240 | * Called when a bubbled notification that was hidden from the shade is now being removed |
| 241 | * This can happen when an app cancels a bubbled notification or when the user dismisses a |
| 242 | * bubble. |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 243 | */ |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 244 | void removeNotification(NotificationEntry entry, int reason); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 245 | |
| 246 | /** |
| 247 | * Called when a bubbled notification has changed whether it should be |
| 248 | * filtered from the shade. |
| 249 | */ |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 250 | void invalidateNotifications(String reason); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 251 | |
| 252 | /** |
| 253 | * Called on a bubbled entry that has been removed when there are no longer |
| 254 | * bubbled entries in its group. |
| 255 | * |
| 256 | * Checks whether its group has any other (non-bubbled) children. If it doesn't, |
| 257 | * removes all remnants of the group's summary from the notification pipeline. |
| 258 | * TODO: (b/145659174) Only old pipeline needs this - delete post-migration. |
| 259 | */ |
| 260 | void maybeCancelSummary(NotificationEntry entry); |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | /** |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 264 | * Listens for the current state of the status bar and updates the visibility state |
| 265 | * of bubbles as needed. |
| 266 | */ |
| 267 | private class StatusBarStateListener implements StatusBarStateController.StateListener { |
| 268 | private int mState; |
| 269 | /** |
| 270 | * Returns the current status bar state. |
| 271 | */ |
| 272 | public int getCurrentState() { |
| 273 | return mState; |
| 274 | } |
| 275 | |
| 276 | @Override |
| 277 | public void onStateChanged(int newState) { |
| 278 | mState = newState; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 279 | boolean shouldCollapse = (mState != SHADE); |
| 280 | if (shouldCollapse) { |
| 281 | collapseStack(); |
| 282 | } |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 283 | updateStack(); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 284 | } |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 285 | } |
| 286 | |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 287 | public BubbleController(Context context, |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 288 | NotificationShadeWindowController notificationShadeWindowController, |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 289 | StatusBarStateController statusBarStateController, |
Heemin Seog | ba6337f | 2019-12-10 15:34:37 -0800 | [diff] [blame] | 290 | ShadeController shadeController, |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 291 | BubbleData data, |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 292 | ConfigurationController configurationController, |
Beverly Tai | d1e175c | 2020-03-10 16:37:04 +0000 | [diff] [blame] | 293 | NotificationInterruptStateProvider interruptionStateProvider, |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 294 | ZenModeController zenModeController, |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 295 | NotificationLockscreenUserManager notifUserManager, |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 296 | NotificationGroupManager groupManager, |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 297 | NotificationEntryManager entryManager, |
| 298 | NotifPipeline notifPipeline, |
| 299 | FeatureFlags featureFlags, |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 300 | DumpManager dumpManager, |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 301 | FloatingContentCoordinator floatingContentCoordinator, |
Mady Mellor | 9adfe6a | 2020-03-30 17:23:26 -0700 | [diff] [blame^] | 302 | SysUiState sysUiState, |
| 303 | INotificationManager notificationManager) { |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 304 | this(context, notificationShadeWindowController, statusBarStateController, shadeController, |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 305 | data, null /* synchronizer */, configurationController, interruptionStateProvider, |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 306 | zenModeController, notifUserManager, groupManager, entryManager, |
Mady Mellor | 9adfe6a | 2020-03-30 17:23:26 -0700 | [diff] [blame^] | 307 | notifPipeline, featureFlags, dumpManager, floatingContentCoordinator, sysUiState, |
| 308 | notificationManager); |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Sergey Nikolaienkov | 5cb6e52 | 2020-02-10 17:33:00 +0100 | [diff] [blame] | 311 | /** |
| 312 | * Injected constructor. See {@link BubbleModule}. |
| 313 | */ |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 314 | public BubbleController(Context context, |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 315 | NotificationShadeWindowController notificationShadeWindowController, |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 316 | StatusBarStateController statusBarStateController, |
Heemin Seog | ba6337f | 2019-12-10 15:34:37 -0800 | [diff] [blame] | 317 | ShadeController shadeController, |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 318 | BubbleData data, |
| 319 | @Nullable BubbleStackView.SurfaceSynchronizer synchronizer, |
| 320 | ConfigurationController configurationController, |
Beverly Tai | d1e175c | 2020-03-10 16:37:04 +0000 | [diff] [blame] | 321 | NotificationInterruptStateProvider interruptionStateProvider, |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 322 | ZenModeController zenModeController, |
| 323 | NotificationLockscreenUserManager notifUserManager, |
| 324 | NotificationGroupManager groupManager, |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 325 | NotificationEntryManager entryManager, |
| 326 | NotifPipeline notifPipeline, |
| 327 | FeatureFlags featureFlags, |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 328 | DumpManager dumpManager, |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 329 | FloatingContentCoordinator floatingContentCoordinator, |
Mady Mellor | 9adfe6a | 2020-03-30 17:23:26 -0700 | [diff] [blame^] | 330 | SysUiState sysUiState, |
| 331 | INotificationManager notificationManager) { |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 332 | dumpManager.registerDumpable(TAG, this); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 333 | mContext = context; |
Heemin Seog | ba6337f | 2019-12-10 15:34:37 -0800 | [diff] [blame] | 334 | mShadeController = shadeController; |
Beverly Tai | d1e175c | 2020-03-10 16:37:04 +0000 | [diff] [blame] | 335 | mNotificationInterruptStateProvider = interruptionStateProvider; |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 336 | mNotifUserManager = notifUserManager; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 337 | mZenModeController = zenModeController; |
Joshua Tsuji | 7155bf1 | 2020-02-13 16:14:29 -0500 | [diff] [blame] | 338 | mFloatingContentCoordinator = floatingContentCoordinator; |
Mady Mellor | 9adfe6a | 2020-03-30 17:23:26 -0700 | [diff] [blame^] | 339 | mINotificationManager = notificationManager; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 340 | mZenModeController.addCallback(new ZenModeController.Callback() { |
| 341 | @Override |
| 342 | public void onZenChanged(int zen) { |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 343 | for (Bubble b : mBubbleData.getBubbles()) { |
Joshua Tsuji | 2ed260e | 2020-03-26 14:26:01 -0400 | [diff] [blame] | 344 | b.setShowDot(b.showInShade()); |
Mady Mellor | df48d0a | 2019-06-25 18:26:46 -0700 | [diff] [blame] | 345 | } |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | @Override |
| 349 | public void onConfigChanged(ZenModeConfig config) { |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 350 | for (Bubble b : mBubbleData.getBubbles()) { |
Joshua Tsuji | 2ed260e | 2020-03-26 14:26:01 -0400 | [diff] [blame] | 351 | b.setShowDot(b.showInShade()); |
Mady Mellor | df48d0a | 2019-06-25 18:26:46 -0700 | [diff] [blame] | 352 | } |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 353 | } |
| 354 | }); |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 355 | |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 356 | configurationController.addCallback(this /* configurationListener */); |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 357 | mSysUiState = sysUiState; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 358 | |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 359 | mBubbleData = data; |
| 360 | mBubbleData.setListener(mBubbleDataListener); |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 361 | mBubbleData.setSuppressionChangedListener(new NotificationSuppressionChangedListener() { |
| 362 | @Override |
| 363 | public void onBubbleNotificationSuppressionChange(Bubble bubble) { |
| 364 | // Make sure NoMan knows it's not showing in the shade anymore so anyone querying it |
| 365 | // can tell. |
| 366 | try { |
| 367 | mBarService.onBubbleNotificationSuppressionChanged(bubble.getKey(), |
| 368 | !bubble.showInShade()); |
| 369 | } catch (RemoteException e) { |
| 370 | // Bad things have happened |
| 371 | } |
| 372 | } |
| 373 | }); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 374 | |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 375 | mNotificationEntryManager = entryManager; |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 376 | mNotificationGroupManager = groupManager; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 377 | mNotifPipeline = notifPipeline; |
| 378 | |
| 379 | if (!featureFlags.isNewNotifPipelineRenderingEnabled()) { |
| 380 | setupNEM(); |
| 381 | } else { |
| 382 | setupNotifPipeline(); |
| 383 | } |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 384 | |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 385 | mNotificationShadeWindowController = notificationShadeWindowController; |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 386 | mStatusBarStateListener = new StatusBarStateListener(); |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 387 | statusBarStateController.addCallback(mStatusBarStateListener); |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 388 | |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 389 | mTaskStackListener = new BubbleTaskStackListener(); |
| 390 | ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 391 | |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 392 | try { |
| 393 | WindowManagerWrapper.getInstance().addPinnedStackListener(new BubblesImeListener()); |
| 394 | } catch (RemoteException e) { |
| 395 | e.printStackTrace(); |
| 396 | } |
Issei Suzuki | c038754 | 2019-03-08 17:31:14 +0100 | [diff] [blame] | 397 | mSurfaceSynchronizer = synchronizer; |
Mady Mellor | a54e9fa | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 398 | |
| 399 | mBarService = IStatusBarService.Stub.asInterface( |
| 400 | ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 401 | |
| 402 | mSavedBubbleKeysPerUser = new SparseSetArray<>(); |
| 403 | mCurrentUserId = mNotifUserManager.getCurrentUserId(); |
| 404 | mNotifUserManager.addUserChangedListener( |
Steve Elliott | b47f1c7 | 2019-12-19 12:39:26 -0500 | [diff] [blame] | 405 | new NotificationLockscreenUserManager.UserChangedListener() { |
| 406 | @Override |
| 407 | public void onUserChanged(int newUserId) { |
| 408 | BubbleController.this.saveBubbles(mCurrentUserId); |
| 409 | mBubbleData.dismissAll(DISMISS_USER_CHANGED); |
| 410 | BubbleController.this.restoreBubbles(newUserId); |
| 411 | mCurrentUserId = newUserId; |
| 412 | } |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 413 | }); |
Mady Mellor | ff076eb | 2019-11-13 10:12:06 -0800 | [diff] [blame] | 414 | |
| 415 | mUserCreatedBubbles = new HashSet<>(); |
Mady Mellor | 3b86a4f | 2019-12-11 13:15:41 -0800 | [diff] [blame] | 416 | mUserBlockedBubbles = new HashSet<>(); |
Aran Ink | aa4dfa7 | 2019-11-18 16:49:07 -0500 | [diff] [blame] | 417 | |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 418 | mBubbleIconFactory = new BubbleIconFactory(context); |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 419 | } |
| 420 | |
Mark Renouf | 8b6a3c6 | 2019-04-09 10:17:40 -0400 | [diff] [blame] | 421 | /** |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 422 | * See {@link NotifCallback}. |
| 423 | */ |
| 424 | public void addNotifCallback(NotifCallback callback) { |
| 425 | mCallbacks.add(callback); |
| 426 | } |
| 427 | |
| 428 | private void setupNEM() { |
| 429 | mNotificationEntryManager.addNotificationEntryListener( |
| 430 | new NotificationEntryListener() { |
| 431 | @Override |
Mady Mellor | f9439ab | 2020-01-30 16:06:53 -0800 | [diff] [blame] | 432 | public void onPendingEntryAdded(NotificationEntry entry) { |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 433 | onEntryAdded(entry); |
| 434 | } |
| 435 | |
| 436 | @Override |
| 437 | public void onPreEntryUpdated(NotificationEntry entry) { |
| 438 | onEntryUpdated(entry); |
| 439 | } |
| 440 | |
| 441 | @Override |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 442 | public void onEntryRemoved( |
| 443 | NotificationEntry entry, |
| 444 | @android.annotation.Nullable NotificationVisibility visibility, |
Julia Reynolds | 138111f | 2020-02-26 11:17:39 -0500 | [diff] [blame] | 445 | boolean removedByUser, |
| 446 | int reason) { |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 447 | BubbleController.this.onEntryRemoved(entry); |
| 448 | } |
| 449 | |
| 450 | @Override |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 451 | public void onNotificationRankingUpdated(RankingMap rankingMap) { |
| 452 | onRankingUpdated(rankingMap); |
| 453 | } |
| 454 | }); |
| 455 | |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 456 | mNotificationEntryManager.addNotificationRemoveInterceptor( |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 457 | new NotificationRemoveInterceptor() { |
| 458 | @Override |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 459 | public boolean onNotificationRemoveRequested( |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 460 | String key, |
| 461 | NotificationEntry entry, |
| 462 | int dismissReason) { |
| 463 | final boolean isClearAll = dismissReason == REASON_CANCEL_ALL; |
| 464 | final boolean isUserDimiss = dismissReason == REASON_CANCEL |
| 465 | || dismissReason == REASON_CLICK; |
| 466 | final boolean isAppCancel = dismissReason == REASON_APP_CANCEL |
| 467 | || dismissReason == REASON_APP_CANCEL_ALL; |
| 468 | final boolean isSummaryCancel = |
| 469 | dismissReason == REASON_GROUP_SUMMARY_CANCELED; |
| 470 | |
| 471 | // Need to check for !appCancel here because the notification may have |
| 472 | // previously been dismissed & entry.isRowDismissed would still be true |
| 473 | boolean userRemovedNotif = |
| 474 | (entry != null && entry.isRowDismissed() && !isAppCancel) |
| 475 | || isClearAll || isUserDimiss || isSummaryCancel; |
| 476 | |
| 477 | if (userRemovedNotif || isUserCreatedBubble(key) |
| 478 | || isSummaryOfUserCreatedBubble(entry)) { |
| 479 | return handleDismissalInterception(entry); |
| 480 | } |
| 481 | |
| 482 | return false; |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 483 | } |
| 484 | }); |
| 485 | |
| 486 | mNotificationGroupManager.addOnGroupChangeListener( |
| 487 | new NotificationGroupManager.OnGroupChangeListener() { |
| 488 | @Override |
| 489 | public void onGroupSuppressionChanged( |
| 490 | NotificationGroupManager.NotificationGroup group, |
| 491 | boolean suppressed) { |
| 492 | // More notifications could be added causing summary to no longer |
| 493 | // be suppressed -- in this case need to remove the key. |
| 494 | final String groupKey = group.summary != null |
| 495 | ? group.summary.getSbn().getGroupKey() |
| 496 | : null; |
| 497 | if (!suppressed && groupKey != null |
| 498 | && mBubbleData.isSummarySuppressed(groupKey)) { |
| 499 | mBubbleData.removeSuppressedSummary(groupKey); |
| 500 | } |
| 501 | } |
| 502 | }); |
| 503 | |
| 504 | addNotifCallback(new NotifCallback() { |
| 505 | @Override |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 506 | public void removeNotification(NotificationEntry entry, int reason) { |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 507 | mNotificationEntryManager.performRemoveNotification(entry.getSbn(), |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 508 | reason); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | @Override |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 512 | public void invalidateNotifications(String reason) { |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 513 | mNotificationEntryManager.updateNotifications(reason); |
| 514 | } |
| 515 | |
| 516 | @Override |
| 517 | public void maybeCancelSummary(NotificationEntry entry) { |
| 518 | // Check if removed bubble has an associated suppressed group summary that needs |
| 519 | // to be removed now. |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 520 | final String groupKey = entry.getSbn().getGroupKey(); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 521 | if (mBubbleData.isSummarySuppressed(groupKey)) { |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 522 | mBubbleData.removeSuppressedSummary(groupKey); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 523 | |
| 524 | final NotificationEntry summary = |
| 525 | mNotificationEntryManager.getActiveNotificationUnfiltered( |
| 526 | mBubbleData.getSummaryKey(groupKey)); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 527 | if (summary != null) { |
| 528 | mNotificationEntryManager.performRemoveNotification(summary.getSbn(), |
| 529 | UNDEFINED_DISMISS_REASON); |
| 530 | } |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 531 | } |
| 532 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 533 | // Check if we still need to remove the summary from NoManGroup because the summary |
| 534 | // may not be in the mBubbleData.mSuppressedGroupKeys list and removed above. |
| 535 | // For example: |
| 536 | // 1. Bubbled notifications (group) is posted to shade and are visible bubbles |
| 537 | // 2. User expands bubbles so now their respective notifications in the shade are |
| 538 | // hidden, including the group summary |
| 539 | // 3. User removes all bubbles |
| 540 | // 4. We expect all the removed bubbles AND the summary (note: the summary was |
| 541 | // never added to the suppressedSummary list in BubbleData, so we add this check) |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 542 | NotificationEntry summary = |
| 543 | mNotificationGroupManager.getLogicalGroupSummary(entry.getSbn()); |
| 544 | if (summary != null) { |
| 545 | ArrayList<NotificationEntry> summaryChildren = |
| 546 | mNotificationGroupManager.getLogicalChildren(summary.getSbn()); |
| 547 | boolean isSummaryThisNotif = summary.getKey().equals(entry.getKey()); |
| 548 | if (!isSummaryThisNotif && (summaryChildren == null |
| 549 | || summaryChildren.isEmpty())) { |
| 550 | mNotificationEntryManager.performRemoveNotification(summary.getSbn(), |
| 551 | UNDEFINED_DISMISS_REASON); |
| 552 | } |
| 553 | } |
| 554 | } |
| 555 | }); |
| 556 | } |
| 557 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 558 | private void setupNotifPipeline() { |
| 559 | mNotifPipeline.addCollectionListener(new NotifCollectionListener() { |
| 560 | @Override |
| 561 | public void onEntryAdded(NotificationEntry entry) { |
| 562 | BubbleController.this.onEntryAdded(entry); |
| 563 | } |
| 564 | |
| 565 | @Override |
| 566 | public void onEntryUpdated(NotificationEntry entry) { |
| 567 | BubbleController.this.onEntryUpdated(entry); |
| 568 | } |
| 569 | |
| 570 | @Override |
| 571 | public void onRankingUpdate(RankingMap rankingMap) { |
| 572 | onRankingUpdated(rankingMap); |
| 573 | } |
| 574 | |
| 575 | @Override |
| 576 | public void onEntryRemoved(NotificationEntry entry, |
| 577 | @NotifCollection.CancellationReason int reason) { |
| 578 | BubbleController.this.onEntryRemoved(entry); |
| 579 | } |
| 580 | }); |
| 581 | } |
| 582 | |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 583 | /** |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 584 | * Sets whether to perform inflation on the same thread as the caller. This method should only |
| 585 | * be used in tests, not in production. |
| 586 | */ |
| 587 | @VisibleForTesting |
| 588 | void setInflateSynchronously(boolean inflateSynchronously) { |
| 589 | mInflateSynchronously = inflateSynchronously; |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 590 | } |
| 591 | |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 592 | void setOverflowCallback(Runnable updateOverflow) { |
| 593 | mOverflowCallback = updateOverflow; |
| 594 | } |
| 595 | |
| 596 | /** |
| 597 | * @return Bubbles for updating overflow. |
| 598 | */ |
| 599 | List<Bubble> getOverflowBubbles() { |
| 600 | return mBubbleData.getOverflowBubbles(); |
| 601 | } |
| 602 | |
| 603 | |
Mark Renouf | 8b6a3c6 | 2019-04-09 10:17:40 -0400 | [diff] [blame] | 604 | /** |
| 605 | * BubbleStackView is lazily created by this method the first time a Bubble is added. This |
| 606 | * method initializes the stack view and adds it to the StatusBar just above the scrim. |
| 607 | */ |
| 608 | private void ensureStackViewCreated() { |
| 609 | if (mStackView == null) { |
Joshua Tsuji | 7155bf1 | 2020-02-13 16:14:29 -0500 | [diff] [blame] | 610 | mStackView = new BubbleStackView( |
Joshua Tsuji | be60a58 | 2020-03-23 17:17:26 -0400 | [diff] [blame] | 611 | mContext, mBubbleData, mSurfaceSynchronizer, mFloatingContentCoordinator, |
| 612 | mSysUiState); |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 613 | ViewGroup nsv = mNotificationShadeWindowController.getNotificationShadeView(); |
| 614 | int bubbleScrimIndex = nsv.indexOfChild(nsv.findViewById(R.id.scrim_for_bubble)); |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 615 | int stackIndex = bubbleScrimIndex + 1; // Show stack above bubble scrim. |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 616 | nsv.addView(mStackView, stackIndex, |
Mark Renouf | 8b6a3c6 | 2019-04-09 10:17:40 -0400 | [diff] [blame] | 617 | new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)); |
| 618 | if (mExpandListener != null) { |
| 619 | mStackView.setExpandListener(mExpandListener); |
| 620 | } |
Mark Renouf | 8b6a3c6 | 2019-04-09 10:17:40 -0400 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 624 | /** |
| 625 | * Records the notification key for any active bubbles. These are used to restore active |
| 626 | * bubbles when the user returns to the foreground. |
| 627 | * |
| 628 | * @param userId the id of the user |
| 629 | */ |
| 630 | private void saveBubbles(@UserIdInt int userId) { |
| 631 | // First clear any existing keys that might be stored. |
| 632 | mSavedBubbleKeysPerUser.remove(userId); |
| 633 | // Add in all active bubbles for the current user. |
| 634 | for (Bubble bubble: mBubbleData.getBubbles()) { |
| 635 | mSavedBubbleKeysPerUser.add(userId, bubble.getKey()); |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | /** |
| 640 | * Promotes existing notifications to Bubbles if they were previously bubbles. |
| 641 | * |
| 642 | * @param userId the id of the user |
| 643 | */ |
| 644 | private void restoreBubbles(@UserIdInt int userId) { |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 645 | ArraySet<String> savedBubbleKeys = mSavedBubbleKeysPerUser.get(userId); |
| 646 | if (savedBubbleKeys == null) { |
| 647 | // There were no bubbles saved for this used. |
| 648 | return; |
| 649 | } |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 650 | for (NotificationEntry e : |
| 651 | mNotificationEntryManager.getActiveNotificationsForCurrentUser()) { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 652 | if (savedBubbleKeys.contains(e.getKey()) |
Beverly Tai | d1e175c | 2020-03-10 16:37:04 +0000 | [diff] [blame] | 653 | && mNotificationInterruptStateProvider.shouldBubbleUp(e) |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 654 | && canLaunchInActivityView(mContext, e)) { |
| 655 | updateBubble(e, /* suppressFlyout= */ true); |
| 656 | } |
| 657 | } |
| 658 | // Finally, remove the entries for this user now that bubbles are restored. |
| 659 | mSavedBubbleKeysPerUser.remove(mCurrentUserId); |
| 660 | } |
| 661 | |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 662 | @Override |
| 663 | public void onUiModeChanged() { |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 664 | updateForThemeChanges(); |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | @Override |
| 668 | public void onOverlayChanged() { |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 669 | updateForThemeChanges(); |
| 670 | } |
| 671 | |
| 672 | private void updateForThemeChanges() { |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 673 | if (mStackView != null) { |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 674 | mStackView.onThemeChanged(); |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 675 | } |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 676 | mBubbleIconFactory = new BubbleIconFactory(mContext); |
| 677 | for (Bubble b: mBubbleData.getBubbles()) { |
| 678 | // Reload each bubble |
| 679 | b.inflate(null /* callback */, mContext, mStackView, mBubbleIconFactory); |
| 680 | } |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Joshua Tsuji | f418f9e | 2019-04-04 17:09:53 -0400 | [diff] [blame] | 683 | @Override |
| 684 | public void onConfigChanged(Configuration newConfig) { |
| 685 | if (mStackView != null && newConfig != null && newConfig.orientation != mOrientation) { |
Joshua Tsuji | f418f9e | 2019-04-04 17:09:53 -0400 | [diff] [blame] | 686 | mOrientation = newConfig.orientation; |
Lyn Han | f473031 | 2019-06-18 11:18:58 -0700 | [diff] [blame] | 687 | mStackView.onOrientationChanged(newConfig.orientation); |
Joshua Tsuji | f418f9e | 2019-04-04 17:09:53 -0400 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 691 | /** |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 692 | * Set a listener to be notified when some states of the bubbles change. |
| 693 | */ |
| 694 | public void setBubbleStateChangeListener(BubbleStateChangeListener listener) { |
| 695 | mStateChangeListener = listener; |
| 696 | } |
| 697 | |
| 698 | /** |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 699 | * Set a listener to be notified of bubble expand events. |
| 700 | */ |
| 701 | public void setExpandListener(BubbleExpandListener listener) { |
Issei Suzuki | ac9fcb7 | 2019-02-04 17:45:57 +0100 | [diff] [blame] | 702 | mExpandListener = ((isExpanding, key) -> { |
| 703 | if (listener != null) { |
| 704 | listener.onBubbleExpandChanged(isExpanding, key); |
| 705 | } |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 706 | mNotificationShadeWindowController.setBubbleExpanded(isExpanding); |
Issei Suzuki | ac9fcb7 | 2019-02-04 17:45:57 +0100 | [diff] [blame] | 707 | }); |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 708 | if (mStackView != null) { |
| 709 | mStackView.setExpandListener(mExpandListener); |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | /** |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 714 | * Whether or not there are bubbles present, regardless of them being visible on the |
| 715 | * screen (e.g. if on AOD). |
| 716 | */ |
| 717 | public boolean hasBubbles() { |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 718 | if (mStackView == null) { |
| 719 | return false; |
| 720 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 721 | return mBubbleData.hasBubbles(); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | /** |
| 725 | * Whether the stack of bubbles is expanded or not. |
| 726 | */ |
| 727 | public boolean isStackExpanded() { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 728 | return mBubbleData.isExpanded(); |
| 729 | } |
| 730 | |
| 731 | /** |
| 732 | * Tell the stack of bubbles to expand. |
| 733 | */ |
| 734 | public void expandStack() { |
| 735 | mBubbleData.setExpanded(true); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | /** |
| 739 | * Tell the stack of bubbles to collapse. |
| 740 | */ |
| 741 | public void collapseStack() { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 742 | mBubbleData.setExpanded(false /* expanded */); |
| 743 | } |
| 744 | |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 745 | /** |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 746 | * True if either: |
| 747 | * (1) There is a bubble associated with the provided key and if its notification is hidden |
| 748 | * from the shade. |
| 749 | * (2) There is a group summary associated with the provided key that is hidden from the shade |
| 750 | * because it has been dismissed but still has child bubbles active. |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 751 | * |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 752 | * False otherwise. |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 753 | */ |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 754 | public boolean isBubbleNotificationSuppressedFromShade(NotificationEntry entry) { |
| 755 | String key = entry.getKey(); |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 756 | boolean isBubbleAndSuppressed = mBubbleData.hasBubbleWithKey(key) |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 757 | && !mBubbleData.getBubbleWithKey(key).showInShade(); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 758 | |
| 759 | String groupKey = entry.getSbn().getGroupKey(); |
Mady Mellor | e28fe10 | 2019-07-09 15:33:32 -0700 | [diff] [blame] | 760 | boolean isSuppressedSummary = mBubbleData.isSummarySuppressed(groupKey); |
Mady Mellor | e434827 | 2019-07-29 17:43:36 -0700 | [diff] [blame] | 761 | boolean isSummary = key.equals(mBubbleData.getSummaryKey(groupKey)); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 762 | |
Mady Mellor | e434827 | 2019-07-29 17:43:36 -0700 | [diff] [blame] | 763 | return (isSummary && isSuppressedSummary) || isBubbleAndSuppressed; |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 766 | @VisibleForTesting |
| 767 | void selectBubble(String key) { |
| 768 | Bubble bubble = mBubbleData.getBubbleWithKey(key); |
Mady Mellor | 247ca2c | 2019-12-02 16:18:59 -0800 | [diff] [blame] | 769 | mBubbleData.setSelectedBubble(bubble); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 770 | } |
| 771 | |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 772 | void promoteBubbleFromOverflow(Bubble bubble) { |
Lyn Han | 1e19d7f | 2020-02-05 19:10:58 -0800 | [diff] [blame] | 773 | bubble.setInflateSynchronously(mInflateSynchronously); |
| 774 | mBubbleData.promoteBubbleFromOverflow(bubble, mStackView, mBubbleIconFactory); |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 775 | } |
| 776 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 777 | /** |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 778 | * Request the stack expand if needed, then select the specified Bubble as current. |
| 779 | * |
| 780 | * @param notificationKey the notification key for the bubble to be selected |
| 781 | */ |
| 782 | public void expandStackAndSelectBubble(String notificationKey) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 783 | Bubble bubble = mBubbleData.getBubbleWithKey(notificationKey); |
| 784 | if (bubble != null) { |
| 785 | mBubbleData.setSelectedBubble(bubble); |
| 786 | mBubbleData.setExpanded(true); |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 787 | } |
| 788 | } |
| 789 | |
| 790 | /** |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 791 | * Tell the stack of bubbles to be dismissed, this will remove all of the bubbles in the stack. |
| 792 | */ |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 793 | void dismissStack(@DismissReason int reason) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 794 | mBubbleData.dismissAll(reason); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | /** |
Mark Renouf | 041d726 | 2019-02-06 12:09:41 -0500 | [diff] [blame] | 798 | * Directs a back gesture at the bubble stack. When opened, the current expanded bubble |
| 799 | * is forwarded a back key down/up pair. |
| 800 | */ |
| 801 | public void performBackPressIfNeeded() { |
| 802 | if (mStackView != null) { |
| 803 | mStackView.performBackPressIfNeeded(); |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | /** |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 808 | * Adds or updates a bubble associated with the provided notification entry. |
| 809 | * |
Mark Renouf | 8b6a3c6 | 2019-04-09 10:17:40 -0400 | [diff] [blame] | 810 | * @param notif the notification associated with this bubble. |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 811 | */ |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 812 | void updateBubble(NotificationEntry notif) { |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 813 | updateBubble(notif, false /* suppressFlyout */); |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | void updateBubble(NotificationEntry notif, boolean suppressFlyout) { |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 817 | updateBubble(notif, suppressFlyout, true /* showInShade */); |
| 818 | } |
| 819 | |
| 820 | void updateBubble(NotificationEntry notif, boolean suppressFlyout, boolean showInShade) { |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 821 | if (mStackView == null) { |
| 822 | // Lazy init stack view when a bubble is created |
| 823 | ensureStackViewCreated(); |
| 824 | } |
Mady Mellor | 66efd5e | 2019-05-15 13:38:11 -0700 | [diff] [blame] | 825 | // If this is an interruptive notif, mark that it's interrupted |
Ned Burns | 60e9459 | 2019-09-06 14:47:25 -0400 | [diff] [blame] | 826 | if (notif.getImportance() >= NotificationManager.IMPORTANCE_HIGH) { |
Mady Mellor | 66efd5e | 2019-05-15 13:38:11 -0700 | [diff] [blame] | 827 | notif.setInterruption(); |
| 828 | } |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 829 | Bubble bubble = mBubbleData.getOrCreateBubble(notif); |
| 830 | bubble.setInflateSynchronously(mInflateSynchronously); |
| 831 | bubble.inflate( |
| 832 | b -> mBubbleData.notificationEntryUpdated(b, suppressFlyout, showInShade), |
| 833 | mContext, mStackView, mBubbleIconFactory); |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | /** |
| 837 | * Called when a user has indicated that an active notification should be shown as a bubble. |
| 838 | * <p> |
| 839 | * This method will collapse the shade, create the bubble without a flyout or dot, and suppress |
| 840 | * the notification from appearing in the shade. |
| 841 | * |
Mady Mellor | 9adfe6a | 2020-03-30 17:23:26 -0700 | [diff] [blame^] | 842 | * @param entry the notification to change bubble state for. |
| 843 | * @param shouldBubble whether the notification should show as a bubble or not. |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 844 | */ |
Mady Mellor | 9adfe6a | 2020-03-30 17:23:26 -0700 | [diff] [blame^] | 845 | public void onUserChangedBubble(NotificationEntry entry, boolean shouldBubble) { |
| 846 | NotificationChannel channel = entry.getChannel(); |
| 847 | final String appPkg = entry.getSbn().getPackageName(); |
| 848 | final int appUid = entry.getSbn().getUid(); |
| 849 | if (channel == null || appPkg == null) { |
| 850 | return; |
Mady Mellor | ff076eb | 2019-11-13 10:12:06 -0800 | [diff] [blame] | 851 | } |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 852 | |
Mady Mellor | 9adfe6a | 2020-03-30 17:23:26 -0700 | [diff] [blame^] | 853 | // Update the state in NotificationManagerService |
| 854 | try { |
| 855 | int flags = Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION; |
| 856 | mBarService.onNotificationBubbleChanged(entry.getKey(), shouldBubble, flags); |
| 857 | } catch (RemoteException e) { |
Mady Mellor | ff076eb | 2019-11-13 10:12:06 -0800 | [diff] [blame] | 858 | } |
Mady Mellor | 9adfe6a | 2020-03-30 17:23:26 -0700 | [diff] [blame^] | 859 | |
| 860 | // Change the settings |
| 861 | channel = NotificationChannelHelper.createConversationChannelIfNeeded(mContext, |
| 862 | mINotificationManager, entry, channel); |
| 863 | channel.setAllowBubbles(shouldBubble); |
| 864 | try { |
| 865 | int currentPref = mINotificationManager.getBubblePreferenceForPackage(appPkg, appUid); |
| 866 | if (shouldBubble && currentPref == BUBBLE_PREFERENCE_NONE) { |
| 867 | mINotificationManager.setBubblesAllowed(appPkg, appUid, BUBBLE_PREFERENCE_SELECTED); |
| 868 | } |
| 869 | mINotificationManager.updateNotificationChannelForPackage(appPkg, appUid, channel); |
| 870 | } catch (RemoteException e) { |
| 871 | Log.e(TAG, e.getMessage()); |
| 872 | } |
| 873 | |
| 874 | if (shouldBubble) { |
| 875 | mShadeController.collapsePanel(true); |
| 876 | if (entry.getRow() != null) { |
| 877 | entry.getRow().updateBubbleButton(); |
| 878 | } |
Mady Mellor | 3b86a4f | 2019-12-11 13:15:41 -0800 | [diff] [blame] | 879 | } |
Mady Mellor | ff076eb | 2019-11-13 10:12:06 -0800 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | /** |
| 883 | * Whether this bubble was explicitly created by the user via a SysUI affordance. |
| 884 | */ |
| 885 | boolean isUserCreatedBubble(String key) { |
| 886 | return mUserCreatedBubbles.contains(key); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 887 | } |
| 888 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 889 | boolean isSummaryOfUserCreatedBubble(NotificationEntry entry) { |
| 890 | if (isSummaryOfBubbles(entry)) { |
| 891 | List<Bubble> bubbleChildren = |
| 892 | mBubbleData.getBubblesInGroup(entry.getSbn().getGroupKey()); |
| 893 | for (int i = 0; i < bubbleChildren.size(); i++) { |
| 894 | // Check if any are user-created (i.e. experimental bubbles) |
| 895 | if (isUserCreatedBubble(bubbleChildren.get(i).getKey())) { |
| 896 | return true; |
| 897 | } |
| 898 | } |
| 899 | } |
| 900 | return false; |
| 901 | } |
| 902 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 903 | /** |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 904 | * Removes the bubble with the given NotificationEntry. |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 905 | * <p> |
| 906 | * Must be called from the main thread. |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 907 | */ |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 908 | @MainThread |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 909 | void removeBubble(NotificationEntry entry, int reason) { |
| 910 | if (mBubbleData.hasBubbleWithKey(entry.getKey())) { |
| 911 | mBubbleData.notificationEntryRemoved(entry, reason); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 912 | } |
| 913 | } |
| 914 | |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 915 | private void onEntryAdded(NotificationEntry entry) { |
| 916 | boolean previouslyUserCreated = mUserCreatedBubbles.contains(entry.getKey()); |
| 917 | boolean userBlocked = mUserBlockedBubbles.contains(entry.getKey()); |
| 918 | boolean wasAdjusted = BubbleExperimentConfig.adjustForExperiments( |
| 919 | mContext, entry, previouslyUserCreated, userBlocked); |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 920 | |
Beverly Tai | d1e175c | 2020-03-10 16:37:04 +0000 | [diff] [blame] | 921 | if (mNotificationInterruptStateProvider.shouldBubbleUp(entry) |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 922 | && (canLaunchInActivityView(mContext, entry) || wasAdjusted)) { |
| 923 | if (wasAdjusted && !previouslyUserCreated) { |
| 924 | // Gotta treat the auto-bubbled / whitelisted packaged bubbles as usercreated |
| 925 | mUserCreatedBubbles.add(entry.getKey()); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 926 | } |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 927 | updateBubble(entry); |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 928 | } |
| 929 | } |
| 930 | |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 931 | private void onEntryUpdated(NotificationEntry entry) { |
| 932 | boolean previouslyUserCreated = mUserCreatedBubbles.contains(entry.getKey()); |
| 933 | boolean userBlocked = mUserBlockedBubbles.contains(entry.getKey()); |
| 934 | boolean wasAdjusted = BubbleExperimentConfig.adjustForExperiments( |
| 935 | mContext, entry, previouslyUserCreated, userBlocked); |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 936 | |
Beverly Tai | d1e175c | 2020-03-10 16:37:04 +0000 | [diff] [blame] | 937 | boolean shouldBubble = mNotificationInterruptStateProvider.shouldBubbleUp(entry) |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 938 | && (canLaunchInActivityView(mContext, entry) || wasAdjusted); |
| 939 | if (!shouldBubble && mBubbleData.hasBubbleWithKey(entry.getKey())) { |
| 940 | // It was previously a bubble but no longer a bubble -- lets remove it |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 941 | removeBubble(entry, DISMISS_NO_LONGER_BUBBLE); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 942 | } else if (shouldBubble) { |
| 943 | if (wasAdjusted && !previouslyUserCreated) { |
| 944 | // Gotta treat the auto-bubbled / whitelisted packaged bubbles as usercreated |
| 945 | mUserCreatedBubbles.add(entry.getKey()); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 946 | } |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 947 | updateBubble(entry); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 948 | } |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 949 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 950 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 951 | private void onEntryRemoved(NotificationEntry entry) { |
| 952 | if (isSummaryOfBubbles(entry)) { |
| 953 | final String groupKey = entry.getSbn().getGroupKey(); |
| 954 | mBubbleData.removeSuppressedSummary(groupKey); |
| 955 | |
| 956 | // Remove any associated bubble children with the summary |
| 957 | final List<Bubble> bubbleChildren = mBubbleData.getBubblesInGroup(groupKey); |
| 958 | for (int i = 0; i < bubbleChildren.size(); i++) { |
| 959 | removeBubble(bubbleChildren.get(i).getEntry(), DISMISS_GROUP_CANCELLED); |
| 960 | } |
| 961 | } else { |
| 962 | removeBubble(entry, DISMISS_NOTIF_CANCEL); |
| 963 | } |
| 964 | } |
| 965 | |
Mady Mellor | 56515c4 | 2020-02-18 17:58:36 -0800 | [diff] [blame] | 966 | /** |
| 967 | * Called when NotificationListener has received adjusted notification rank and reapplied |
| 968 | * filtering and sorting. This is used to dismiss or create bubbles based on changes in |
| 969 | * permissions on the notification channel or the global setting. |
| 970 | * |
| 971 | * @param rankingMap the updated ranking map from NotificationListenerService |
| 972 | */ |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 973 | private void onRankingUpdated(RankingMap rankingMap) { |
Mady Mellor | 56515c4 | 2020-02-18 17:58:36 -0800 | [diff] [blame] | 974 | if (mTmpRanking == null) { |
| 975 | mTmpRanking = new NotificationListenerService.Ranking(); |
| 976 | } |
| 977 | String[] orderedKeys = rankingMap.getOrderedKeys(); |
| 978 | for (int i = 0; i < orderedKeys.length; i++) { |
| 979 | String key = orderedKeys[i]; |
| 980 | NotificationEntry entry = mNotificationEntryManager.getPendingOrActiveNotif(key); |
| 981 | rankingMap.getRanking(key, mTmpRanking); |
Mady Mellor | e45ff86 | 2020-03-24 15:54:50 -0700 | [diff] [blame] | 982 | boolean isActiveBubble = mBubbleData.hasBubbleWithKey(key); |
| 983 | if (isActiveBubble && !mTmpRanking.canBubble()) { |
Mady Mellor | 56515c4 | 2020-02-18 17:58:36 -0800 | [diff] [blame] | 984 | mBubbleData.notificationEntryRemoved(entry, BubbleController.DISMISS_BLOCKED); |
Mady Mellor | e45ff86 | 2020-03-24 15:54:50 -0700 | [diff] [blame] | 985 | } else if (entry != null && mTmpRanking.isBubble() && !isActiveBubble) { |
Mady Mellor | 56515c4 | 2020-02-18 17:58:36 -0800 | [diff] [blame] | 986 | entry.setFlagBubble(true); |
| 987 | onEntryUpdated(entry); |
| 988 | } |
| 989 | } |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 990 | } |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 991 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 992 | @SuppressWarnings("FieldCanBeLocal") |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 993 | private final BubbleData.Listener mBubbleDataListener = new BubbleData.Listener() { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 994 | |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 995 | @Override |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 996 | public void applyUpdate(BubbleData.Update update) { |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 997 | // Update bubbles in overflow. |
| 998 | if (mOverflowCallback != null) { |
| 999 | mOverflowCallback.run(); |
| 1000 | } |
| 1001 | |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 1002 | // Collapsing? Do this first before remaining steps. |
| 1003 | if (update.expandedChanged && !update.expanded) { |
| 1004 | mStackView.setExpanded(false); |
| 1005 | } |
| 1006 | |
| 1007 | // Do removals, if any. |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 1008 | ArrayList<Pair<Bubble, Integer>> removedBubbles = |
| 1009 | new ArrayList<>(update.removedBubbles); |
| 1010 | for (Pair<Bubble, Integer> removed : removedBubbles) { |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 1011 | final Bubble bubble = removed.first; |
| 1012 | @DismissReason final int reason = removed.second; |
| 1013 | mStackView.removeBubble(bubble); |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 1014 | // If the bubble is removed for user switching, leave the notification in place. |
| 1015 | if (reason != DISMISS_USER_CHANGED) { |
| 1016 | if (!mBubbleData.hasBubbleWithKey(bubble.getKey()) |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 1017 | && !bubble.showInShade()) { |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1018 | // The bubble is now gone & the notification is hidden from the shade, so |
| 1019 | // time to actually remove it |
| 1020 | for (NotifCallback cb : mCallbacks) { |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1021 | cb.removeNotification(bubble.getEntry(), REASON_CANCEL); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1022 | } |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 1023 | } else { |
| 1024 | // Update the flag for SysUI |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 1025 | bubble.getEntry().getSbn().getNotification().flags &= ~FLAG_BUBBLE; |
Mady Mellor | 9adfe6a | 2020-03-30 17:23:26 -0700 | [diff] [blame^] | 1026 | if (bubble.getEntry().getRow() != null) { |
| 1027 | bubble.getEntry().getRow().updateBubbleButton(); |
| 1028 | } |
Mady Mellor | 3a0a1b4 | 2019-05-23 06:40:21 -0700 | [diff] [blame] | 1029 | |
Mady Mellor | 9adfe6a | 2020-03-30 17:23:26 -0700 | [diff] [blame^] | 1030 | // Update the state in NotificationManagerService |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 1031 | try { |
| 1032 | mBarService.onNotificationBubbleChanged(bubble.getKey(), |
Mady Mellor | 9adfe6a | 2020-03-30 17:23:26 -0700 | [diff] [blame^] | 1033 | false /* isBubble */, 0 /* flags */); |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 1034 | } catch (RemoteException e) { |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 1035 | } |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 1036 | } |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 1037 | |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 1038 | final String groupKey = bubble.getEntry().getSbn().getGroupKey(); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1039 | if (mBubbleData.getBubblesInGroup(groupKey).isEmpty()) { |
| 1040 | // Time to potentially remove the summary |
| 1041 | for (NotifCallback cb : mCallbacks) { |
| 1042 | cb.maybeCancelSummary(bubble.getEntry()); |
Mady Mellor | 22f2f07 | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 1043 | } |
| 1044 | } |
Mady Mellor | a54e9fa | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 1045 | } |
| 1046 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 1047 | |
Lyn Han | c47e171 | 2020-01-28 21:43:34 -0800 | [diff] [blame] | 1048 | if (update.addedBubble != null) { |
| 1049 | mStackView.addBubble(update.addedBubble); |
| 1050 | } |
| 1051 | |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 1052 | if (update.updatedBubble != null) { |
| 1053 | mStackView.updateBubble(update.updatedBubble); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 1054 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 1055 | |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 1056 | // At this point, the correct bubbles are inflated in the stack. |
| 1057 | // Make sure the order in bubble data is reflected in bubble row. |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 1058 | if (update.orderChanged) { |
| 1059 | mStackView.updateBubbleOrder(update.bubbles); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 1060 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 1061 | |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 1062 | if (update.selectionChanged) { |
| 1063 | mStackView.setSelectedBubble(update.selectedBubble); |
Mady Mellor | 740d85d | 2019-07-09 15:26:47 -0700 | [diff] [blame] | 1064 | if (update.selectedBubble != null) { |
| 1065 | mNotificationGroupManager.updateSuppression( |
| 1066 | update.selectedBubble.getEntry()); |
| 1067 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 1068 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 1069 | |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 1070 | // Expanding? Apply this last. |
| 1071 | if (update.expandedChanged && update.expanded) { |
| 1072 | mStackView.setExpanded(true); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 1073 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 1074 | |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1075 | for (NotifCallback cb : mCallbacks) { |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1076 | cb.invalidateNotifications("BubbleData.Listener.applyUpdate"); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1077 | } |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 1078 | updateStack(); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1079 | |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 1080 | if (DEBUG_BUBBLE_CONTROLLER) { |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 1081 | Log.d(TAG, "\n[BubbleData] bubbles:"); |
Lyn Han | 767d70e | 2019-12-10 18:02:23 -0800 | [diff] [blame] | 1082 | Log.d(TAG, BubbleDebugConfig.formatBubblesString(mBubbleData.getBubbles(), |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1083 | mBubbleData.getSelectedBubble())); |
| 1084 | |
| 1085 | if (mStackView != null) { |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 1086 | Log.d(TAG, "\n[BubbleStackView]"); |
Lyn Han | 767d70e | 2019-12-10 18:02:23 -0800 | [diff] [blame] | 1087 | Log.d(TAG, BubbleDebugConfig.formatBubblesString(mStackView.getBubblesOnScreen(), |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1088 | mStackView.getExpandedBubble())); |
| 1089 | } |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 1090 | Log.d(TAG, "\n[BubbleData] overflow:"); |
| 1091 | Log.d(TAG, BubbleDebugConfig.formatBubblesString(mBubbleData.getOverflowBubbles(), |
| 1092 | null)); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 1093 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 1094 | } |
| 1095 | }; |
| 1096 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 1097 | /** |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1098 | * We intercept notification entries (including group summaries) dismissed by the user when |
| 1099 | * there is an active bubble associated with it. We do this so that developers can still |
| 1100 | * cancel it (and hence the bubbles associated with it). However, these intercepted |
| 1101 | * notifications should then be hidden from the shade since the user has cancelled them, so we |
| 1102 | * {@link Bubble#setSuppressNotification}. For the case of suppressed summaries, we also add |
| 1103 | * {@link BubbleData#addSummaryToSuppress}. |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1104 | * |
Mady Mellor | 91b31e6 | 2020-01-30 17:40:48 -0800 | [diff] [blame] | 1105 | * @return true if we want to intercept the dismissal of the entry, else false. |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1106 | */ |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1107 | public boolean handleDismissalInterception(NotificationEntry entry) { |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1108 | if (entry == null) { |
| 1109 | return false; |
| 1110 | } |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1111 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1112 | final boolean interceptBubbleDismissal = mBubbleData.hasBubbleWithKey(entry.getKey()) |
| 1113 | && entry.isBubble(); |
| 1114 | final boolean interceptSummaryDismissal = isSummaryOfBubbles(entry); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1115 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1116 | if (interceptSummaryDismissal) { |
| 1117 | handleSummaryDismissalInterception(entry); |
| 1118 | } else if (interceptBubbleDismissal) { |
| 1119 | Bubble bubble = mBubbleData.getBubbleWithKey(entry.getKey()); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1120 | bubble.setSuppressNotification(true); |
Joshua Tsuji | 2ed260e | 2020-03-26 14:26:01 -0400 | [diff] [blame] | 1121 | bubble.setShowDot(false /* show */); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1122 | } else { |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1123 | return false; |
| 1124 | } |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1125 | |
| 1126 | // Update the shade |
| 1127 | for (NotifCallback cb : mCallbacks) { |
| 1128 | cb.invalidateNotifications("BubbleController.handleDismissalInterception"); |
| 1129 | } |
| 1130 | return true; |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1131 | } |
| 1132 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1133 | private boolean isSummaryOfBubbles(NotificationEntry entry) { |
| 1134 | if (entry == null) { |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1135 | return false; |
| 1136 | } |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1137 | |
| 1138 | String groupKey = entry.getSbn().getGroupKey(); |
| 1139 | ArrayList<Bubble> bubbleChildren = mBubbleData.getBubblesInGroup(groupKey); |
| 1140 | boolean isSuppressedSummary = (mBubbleData.isSummarySuppressed(groupKey) |
| 1141 | && mBubbleData.getSummaryKey(groupKey).equals(entry.getKey())); |
| 1142 | boolean isSummary = entry.getSbn().getNotification().isGroupSummary(); |
| 1143 | return (isSuppressedSummary || isSummary) |
| 1144 | && bubbleChildren != null |
| 1145 | && !bubbleChildren.isEmpty(); |
| 1146 | } |
| 1147 | |
| 1148 | private void handleSummaryDismissalInterception(NotificationEntry summary) { |
| 1149 | // current children in the row: |
| 1150 | final List<NotificationEntry> children = summary.getChildren(); |
| 1151 | if (children != null) { |
| 1152 | for (int i = 0; i < children.size(); i++) { |
| 1153 | NotificationEntry child = children.get(i); |
| 1154 | if (mBubbleData.hasBubbleWithKey(child.getKey())) { |
| 1155 | // Suppress the bubbled child |
| 1156 | // As far as group manager is concerned, once a child is no longer shown |
| 1157 | // in the shade, it is essentially removed. |
| 1158 | Bubble bubbleChild = mBubbleData.getBubbleWithKey(child.getKey()); |
| 1159 | mNotificationGroupManager.onEntryRemoved(bubbleChild.getEntry()); |
| 1160 | bubbleChild.setSuppressNotification(true); |
Joshua Tsuji | 2ed260e | 2020-03-26 14:26:01 -0400 | [diff] [blame] | 1161 | bubbleChild.setShowDot(false /* show */); |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 1162 | } else { |
| 1163 | // non-bubbled children can be removed |
| 1164 | for (NotifCallback cb : mCallbacks) { |
| 1165 | cb.removeNotification(child, REASON_GROUP_SUMMARY_CANCELED); |
| 1166 | } |
| 1167 | } |
| 1168 | } |
| 1169 | } |
| 1170 | |
| 1171 | // And since all children are removed, remove the summary. |
| 1172 | mNotificationGroupManager.onEntryRemoved(summary); |
| 1173 | |
| 1174 | // TODO: (b/145659174) remove references to mSuppressedGroupKeys once fully migrated |
| 1175 | mBubbleData.addSummaryToSuppress(summary.getSbn().getGroupKey(), |
| 1176 | summary.getKey()); |
Beverly | ed8aea2 | 2020-01-22 16:52:47 -0500 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | /** |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 1180 | * Lets any listeners know if bubble state has changed. |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 1181 | * Updates the visibility of the bubbles based on current state. |
| 1182 | * Does not un-bubble, just hides or un-hides. Notifies any |
| 1183 | * {@link BubbleStateChangeListener}s of visibility changes. |
| 1184 | * Updates stack description for TalkBack focus. |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 1185 | */ |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 1186 | public void updateStack() { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 1187 | if (mStackView == null) { |
| 1188 | return; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 1189 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 1190 | if (mStatusBarStateListener.getCurrentState() == SHADE && hasBubbles()) { |
| 1191 | // Bubbles only appear in unlocked shade |
| 1192 | mStackView.setVisibility(hasBubbles() ? VISIBLE : INVISIBLE); |
Mady Mellor | 698d9e8 | 2019-08-01 23:11:53 +0000 | [diff] [blame] | 1193 | } else if (mStackView != null) { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 1194 | mStackView.setVisibility(INVISIBLE); |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 1195 | } |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 1196 | |
Mady Mellor | 698d9e8 | 2019-08-01 23:11:53 +0000 | [diff] [blame] | 1197 | // Let listeners know if bubble state changed. |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 1198 | boolean hadBubbles = mNotificationShadeWindowController.getBubblesShowing(); |
Mady Mellor | 698d9e8 | 2019-08-01 23:11:53 +0000 | [diff] [blame] | 1199 | boolean hasBubblesShowing = hasBubbles() && mStackView.getVisibility() == VISIBLE; |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 1200 | mNotificationShadeWindowController.setBubblesShowing(hasBubblesShowing); |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 1201 | if (mStateChangeListener != null && hadBubbles != hasBubblesShowing) { |
| 1202 | mStateChangeListener.onHasBubblesChanged(hasBubblesShowing); |
| 1203 | } |
| 1204 | |
| 1205 | mStackView.updateContentDescription(); |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | /** |
| 1209 | * Rect indicating the touchable region for the bubble stack / expanded stack. |
| 1210 | */ |
| 1211 | public Rect getTouchableRegion() { |
| 1212 | if (mStackView == null || mStackView.getVisibility() != VISIBLE) { |
| 1213 | return null; |
| 1214 | } |
| 1215 | mStackView.getBoundsOnScreen(mTempRect); |
| 1216 | return mTempRect; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1217 | } |
| 1218 | |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 1219 | /** |
| 1220 | * The display id of the expanded view, if the stack is expanded and not occluded by the |
| 1221 | * status bar, otherwise returns {@link Display#INVALID_DISPLAY}. |
| 1222 | */ |
| 1223 | public int getExpandedDisplayId(Context context) { |
Joel Galenson | 4071ddb | 2019-04-18 13:30:45 -0700 | [diff] [blame] | 1224 | if (mStackView == null) { |
Lyn Han | 9f66c3b | 2020-03-05 23:59:29 -0800 | [diff] [blame] | 1225 | return INVALID_DISPLAY; |
Joel Galenson | 4071ddb | 2019-04-18 13:30:45 -0700 | [diff] [blame] | 1226 | } |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 1227 | final boolean defaultDisplay = context.getDisplay() != null |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 1228 | && context.getDisplay().getDisplayId() == DEFAULT_DISPLAY; |
Lyn Han | 9f66c3b | 2020-03-05 23:59:29 -0800 | [diff] [blame] | 1229 | final BubbleViewProvider expandedViewProvider = mStackView.getExpandedBubble(); |
| 1230 | if (defaultDisplay && expandedViewProvider != null && isStackExpanded() |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 1231 | && !mNotificationShadeWindowController.getPanelExpanded()) { |
Lyn Han | 9f66c3b | 2020-03-05 23:59:29 -0800 | [diff] [blame] | 1232 | return expandedViewProvider.getDisplayId(); |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 1233 | } |
Lyn Han | 9f66c3b | 2020-03-05 23:59:29 -0800 | [diff] [blame] | 1234 | return INVALID_DISPLAY; |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 1235 | } |
| 1236 | |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 1237 | @VisibleForTesting |
| 1238 | BubbleStackView getStackView() { |
| 1239 | return mStackView; |
| 1240 | } |
| 1241 | |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 1242 | /** |
| 1243 | * Description of current bubble state. |
| 1244 | */ |
| 1245 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1246 | pw.println("BubbleController state:"); |
| 1247 | mBubbleData.dump(fd, pw, args); |
| 1248 | pw.println(); |
Joshua Tsuji | 395bcfe | 2019-07-02 19:23:23 -0400 | [diff] [blame] | 1249 | if (mStackView != null) { |
| 1250 | mStackView.dump(fd, pw, args); |
| 1251 | } |
| 1252 | pw.println(); |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 1253 | } |
| 1254 | |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 1255 | /** |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 1256 | * This task stack listener is responsible for responding to tasks moved to the front |
| 1257 | * which are on the default (main) display. When this happens, expanded bubbles must be |
| 1258 | * collapsed so the user may interact with the app which was just moved to the front. |
| 1259 | * <p> |
| 1260 | * This listener is registered with SystemUI's ActivityManagerWrapper which dispatches |
| 1261 | * these calls via a main thread Handler. |
| 1262 | */ |
| 1263 | @MainThread |
| 1264 | private class BubbleTaskStackListener extends TaskStackChangeListener { |
| 1265 | |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 1266 | @Override |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 1267 | public void onTaskMovedToFront(RunningTaskInfo taskInfo) { |
| 1268 | if (mStackView != null && taskInfo.displayId == Display.DEFAULT_DISPLAY) { |
Mady Mellor | 047e24e | 2019-08-05 11:35:40 -0700 | [diff] [blame] | 1269 | if (!mStackView.isExpansionAnimating()) { |
| 1270 | mBubbleData.setExpanded(false); |
| 1271 | } |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 1272 | } |
| 1273 | } |
| 1274 | |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 1275 | @Override |
Winson Chung | e789ff6 | 2020-02-24 14:40:23 -0800 | [diff] [blame] | 1276 | public void onActivityRestartAttempt(RunningTaskInfo task, boolean homeTaskVisible, |
| 1277 | boolean clearedTask) { |
| 1278 | for (Bubble b : mBubbleData.getBubbles()) { |
| 1279 | if (b.getDisplayId() == task.displayId) { |
| 1280 | expandStackAndSelectBubble(b.getKey()); |
| 1281 | return; |
| 1282 | } |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | @Override |
Mark Renouf | a12e876 | 2019-03-07 15:43:01 -0500 | [diff] [blame] | 1287 | public void onActivityLaunchOnSecondaryDisplayRerouted() { |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 1288 | if (mStackView != null) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 1289 | mBubbleData.setExpanded(false); |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 1290 | } |
| 1291 | } |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 1292 | |
| 1293 | @Override |
| 1294 | public void onBackPressedOnTaskRoot(RunningTaskInfo taskInfo) { |
| 1295 | if (mStackView != null && taskInfo.displayId == getExpandedDisplayId(mContext)) { |
| 1296 | mBubbleData.setExpanded(false); |
| 1297 | } |
| 1298 | } |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 1299 | |
| 1300 | @Override |
| 1301 | public void onSingleTaskDisplayDrawn(int displayId) { |
Lyn Han | a0bb02e | 2020-01-28 17:57:27 -0800 | [diff] [blame] | 1302 | if (mStackView == null) { |
| 1303 | return; |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 1304 | } |
Lyn Han | a0bb02e | 2020-01-28 17:57:27 -0800 | [diff] [blame] | 1305 | mStackView.showExpandedViewContents(displayId); |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 1306 | } |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 1307 | |
| 1308 | @Override |
| 1309 | public void onSingleTaskDisplayEmpty(int displayId) { |
Lyn Han | 9f66c3b | 2020-03-05 23:59:29 -0800 | [diff] [blame] | 1310 | final BubbleViewProvider expandedBubble = mStackView != null |
Mady Mellor | 5186b13 | 2019-09-16 17:55:48 -0700 | [diff] [blame] | 1311 | ? mStackView.getExpandedBubble() |
| 1312 | : null; |
Mady Mellor | ca184aae | 2019-09-17 16:07:12 -0700 | [diff] [blame] | 1313 | int expandedId = expandedBubble != null ? expandedBubble.getDisplayId() : -1; |
| 1314 | if (mStackView != null && mStackView.isExpanded() && expandedId == displayId) { |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 1315 | mBubbleData.setExpanded(false); |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 1316 | } |
Mady Mellor | ca184aae | 2019-09-17 16:07:12 -0700 | [diff] [blame] | 1317 | mBubbleData.notifyDisplayEmpty(displayId); |
Issei Suzuki | 734bc94 | 2019-06-05 13:59:52 +0200 | [diff] [blame] | 1318 | } |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 1319 | } |
| 1320 | |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1321 | /** |
| 1322 | * Whether an intent is properly configured to display in an {@link android.app.ActivityView}. |
| 1323 | * |
| 1324 | * Keep checks in sync with NotificationManagerService#canLaunchInActivityView. Typically |
| 1325 | * that should filter out any invalid bubbles, but should protect SysUI side just in case. |
| 1326 | * |
| 1327 | * @param context the context to use. |
| 1328 | * @param entry the entry to bubble. |
| 1329 | */ |
| 1330 | static boolean canLaunchInActivityView(Context context, NotificationEntry entry) { |
| 1331 | PendingIntent intent = entry.getBubbleMetadata() != null |
Mady Mellor | aa9ce17 | 2020-03-17 10:34:20 -0700 | [diff] [blame] | 1332 | ? entry.getBubbleMetadata().getIntent() |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1333 | : null; |
Mady Mellor | 2ac2d3a | 2020-01-08 17:18:54 -0800 | [diff] [blame] | 1334 | if (entry.getBubbleMetadata() != null |
| 1335 | && entry.getBubbleMetadata().getShortcutId() != null) { |
| 1336 | return true; |
| 1337 | } |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1338 | if (intent == null) { |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 1339 | Log.w(TAG, "Unable to create bubble -- no intent: " + entry.getKey()); |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1340 | return false; |
| 1341 | } |
Mady Mellor | f3b9fab | 2019-11-13 17:27:32 -0800 | [diff] [blame] | 1342 | PackageManager packageManager = StatusBar.getPackageManagerForUser( |
| 1343 | context, entry.getSbn().getUser().getIdentifier()); |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1344 | ActivityInfo info = |
Mady Mellor | f3b9fab | 2019-11-13 17:27:32 -0800 | [diff] [blame] | 1345 | intent.getIntent().resolveActivityInfo(packageManager, 0); |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1346 | if (info == null) { |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 1347 | Log.w(TAG, "Unable to send as bubble, " |
| 1348 | + entry.getKey() + " couldn't find activity info for intent: " |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1349 | + intent); |
| 1350 | return false; |
| 1351 | } |
| 1352 | if (!ActivityInfo.isResizeableMode(info.resizeMode)) { |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 1353 | Log.w(TAG, "Unable to send as bubble, " |
| 1354 | + entry.getKey() + " activity is not resizable for intent: " |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1355 | + intent); |
| 1356 | return false; |
| 1357 | } |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 1358 | return true; |
| 1359 | } |
| 1360 | |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 1361 | /** PinnedStackListener that dispatches IME visibility updates to the stack. */ |
Hongwei Wang | 43a752b | 2019-09-17 20:20:30 +0000 | [diff] [blame] | 1362 | private class BubblesImeListener extends PinnedStackListenerForwarder.PinnedStackListener { |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 1363 | @Override |
Joshua Tsuji | d942283 | 2019-03-05 13:32:37 -0500 | [diff] [blame] | 1364 | public void onImeVisibilityChanged(boolean imeVisible, int imeHeight) { |
Joshua Tsuji | ff6b0f2 | 2020-03-09 14:55:19 -0400 | [diff] [blame] | 1365 | if (mStackView != null) { |
Joshua Tsuji | d942283 | 2019-03-05 13:32:37 -0500 | [diff] [blame] | 1366 | mStackView.post(() -> mStackView.onImeVisibilityChanged(imeVisible, imeHeight)); |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 1367 | } |
| 1368 | } |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 1369 | } |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1370 | } |