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