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