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