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