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; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 20 | import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_BADGE; |
| 21 | import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST; |
| 22 | import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK; |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 23 | import static android.content.pm.ActivityInfo.DOCUMENT_LAUNCH_ALWAYS; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 24 | import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL; |
| 25 | import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL_ALL; |
| 26 | import static android.service.notification.NotificationListenerService.REASON_CANCEL; |
| 27 | import static android.service.notification.NotificationListenerService.REASON_CANCEL_ALL; |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 28 | import static android.view.Display.DEFAULT_DISPLAY; |
| 29 | import static android.view.Display.INVALID_DISPLAY; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 30 | import static android.view.View.INVISIBLE; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 31 | import static android.view.View.VISIBLE; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 32 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 33 | |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 34 | import static com.android.systemui.bubbles.BubbleDebugConfig.DEBUG_BUBBLE_CONTROLLER; |
| 35 | import static com.android.systemui.bubbles.BubbleDebugConfig.TAG_BUBBLES; |
| 36 | import static com.android.systemui.bubbles.BubbleDebugConfig.TAG_WITH_CLASS_NAME; |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 37 | import static com.android.systemui.statusbar.StatusBarState.SHADE; |
Mady Mellor | 1a4e86f | 2019-05-03 16:07:23 -0700 | [diff] [blame] | 38 | import static com.android.systemui.statusbar.notification.NotificationEntryManager.UNDEFINED_DISMISS_REASON; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 39 | |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 40 | import static java.lang.annotation.ElementType.FIELD; |
| 41 | import static java.lang.annotation.ElementType.LOCAL_VARIABLE; |
| 42 | import static java.lang.annotation.ElementType.PARAMETER; |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 43 | import static java.lang.annotation.RetentionPolicy.SOURCE; |
| 44 | |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 45 | import android.app.ActivityManager; |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 46 | import android.app.ActivityManager.RunningTaskInfo; |
Mady Mellor | 66efd5e | 2019-05-15 13:38:11 -0700 | [diff] [blame] | 47 | import android.app.NotificationManager; |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 48 | import android.app.PendingIntent; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 49 | import android.content.Context; |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 50 | import android.content.pm.ActivityInfo; |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 51 | import android.content.pm.ParceledListSlice; |
Joshua Tsuji | f418f9e | 2019-04-04 17:09:53 -0400 | [diff] [blame] | 52 | import android.content.res.Configuration; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 53 | import android.graphics.Rect; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 54 | import android.os.RemoteException; |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 55 | import android.os.ServiceManager; |
Mady Mellor | ceced17 | 2018-11-27 11:18:39 -0800 | [diff] [blame] | 56 | import android.provider.Settings; |
Mark Renouf | bbcf07f | 2019-05-09 10:42:43 -0400 | [diff] [blame] | 57 | import android.service.notification.NotificationListenerService.RankingMap; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 58 | import android.service.notification.ZenModeConfig; |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 59 | import android.util.Log; |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 60 | import android.util.Pair; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 61 | import android.view.Display; |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 62 | import android.view.IPinnedStackController; |
| 63 | import android.view.IPinnedStackListener; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 64 | import android.view.ViewGroup; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 65 | import android.widget.FrameLayout; |
| 66 | |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 67 | import androidx.annotation.IntDef; |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 68 | import androidx.annotation.MainThread; |
Joshua Tsuji | c650a14 | 2019-05-22 11:31:19 -0400 | [diff] [blame] | 69 | import androidx.annotation.Nullable; |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 70 | |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 71 | import com.android.internal.annotations.VisibleForTesting; |
Mady Mellor | a54e9fa | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 72 | import com.android.internal.statusbar.IStatusBarService; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 73 | import com.android.systemui.Dependency; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 74 | import com.android.systemui.R; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 75 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 76 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
| 77 | import com.android.systemui.shared.system.TaskStackChangeListener; |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 78 | import com.android.systemui.shared.system.WindowManagerWrapper; |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 79 | import com.android.systemui.statusbar.NotificationRemoveInterceptor; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 80 | import com.android.systemui.statusbar.notification.NotificationEntryListener; |
| 81 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 82 | import com.android.systemui.statusbar.notification.NotificationInterruptionStateProvider; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 83 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Ned Burns | 1a5e22f | 2019-02-14 15:11:52 -0500 | [diff] [blame] | 84 | import com.android.systemui.statusbar.notification.row.NotificationContentInflater.InflationFlag; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 85 | import com.android.systemui.statusbar.phone.StatusBarWindowController; |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 86 | import com.android.systemui.statusbar.policy.ConfigurationController; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 87 | import com.android.systemui.statusbar.policy.ZenModeController; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 88 | |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 89 | import java.lang.annotation.Retention; |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 90 | import java.lang.annotation.Target; |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 91 | import java.util.List; |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 92 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 93 | import javax.inject.Inject; |
| 94 | import javax.inject.Singleton; |
| 95 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 96 | /** |
| 97 | * Bubbles are a special type of content that can "float" on top of other apps or System UI. |
| 98 | * Bubbles can be expanded to show more content. |
| 99 | * |
| 100 | * The controller manages addition, removal, and visible state of bubbles on screen. |
| 101 | */ |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 102 | @Singleton |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 103 | public class BubbleController implements ConfigurationController.ConfigurationListener { |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 104 | |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 105 | private static final String TAG = TAG_WITH_CLASS_NAME ? "BubbleController" : TAG_BUBBLES; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 106 | |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 107 | @Retention(SOURCE) |
| 108 | @IntDef({DISMISS_USER_GESTURE, DISMISS_AGED, DISMISS_TASK_FINISHED, DISMISS_BLOCKED, |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 109 | DISMISS_NOTIF_CANCEL, DISMISS_ACCESSIBILITY_ACTION, DISMISS_NO_LONGER_BUBBLE}) |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 110 | @Target({FIELD, LOCAL_VARIABLE, PARAMETER}) |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 111 | @interface DismissReason {} |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 112 | |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 113 | static final int DISMISS_USER_GESTURE = 1; |
| 114 | static final int DISMISS_AGED = 2; |
| 115 | static final int DISMISS_TASK_FINISHED = 3; |
| 116 | static final int DISMISS_BLOCKED = 4; |
| 117 | static final int DISMISS_NOTIF_CANCEL = 5; |
| 118 | static final int DISMISS_ACCESSIBILITY_ACTION = 6; |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 119 | static final int DISMISS_NO_LONGER_BUBBLE = 7; |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 120 | |
Joshua Tsuji | 4accf598 | 2019-04-22 17:36:11 -0400 | [diff] [blame] | 121 | public static final int MAX_BUBBLES = 5; // TODO: actually enforce this |
Joshua Tsuji | 25a4b7b | 2019-03-22 14:11:06 -0400 | [diff] [blame] | 122 | |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 123 | /** Flag to enable or disable the entire feature */ |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 124 | private static final String ENABLE_BUBBLES = "experiment_enable_bubbles"; |
Joshua Tsuji | 010c2b1 | 2019-02-25 18:11:25 -0500 | [diff] [blame] | 125 | |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 126 | private final Context mContext; |
| 127 | private final NotificationEntryManager mNotificationEntryManager; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 128 | private final BubbleTaskStackListener mTaskStackListener; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 129 | private BubbleStateChangeListener mStateChangeListener; |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 130 | private BubbleExpandListener mExpandListener; |
Issei Suzuki | c038754 | 2019-03-08 17:31:14 +0100 | [diff] [blame] | 131 | @Nullable private BubbleStackView.SurfaceSynchronizer mSurfaceSynchronizer; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 132 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 133 | private BubbleData mBubbleData; |
Joshua Tsuji | c650a14 | 2019-05-22 11:31:19 -0400 | [diff] [blame] | 134 | @Nullable private BubbleStackView mStackView; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 135 | |
| 136 | // Bubbles get added to the status bar view |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 137 | private final StatusBarWindowController mStatusBarWindowController; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 138 | private final ZenModeController mZenModeController; |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 139 | private StatusBarStateListener mStatusBarStateListener; |
| 140 | |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 141 | private final NotificationInterruptionStateProvider mNotificationInterruptionStateProvider; |
Mady Mellor | a54e9fa | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 142 | private IStatusBarService mBarService; |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 143 | |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 144 | // Used for determining view rect for touch interaction |
| 145 | private Rect mTempRect = new Rect(); |
| 146 | |
Joshua Tsuji | f418f9e | 2019-04-04 17:09:53 -0400 | [diff] [blame] | 147 | /** Last known orientation, used to detect orientation changes in {@link #onConfigChanged}. */ |
| 148 | private int mOrientation = Configuration.ORIENTATION_UNDEFINED; |
| 149 | |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 150 | /** |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 151 | * Listener to be notified when some states of the bubbles change. |
| 152 | */ |
| 153 | public interface BubbleStateChangeListener { |
| 154 | /** |
| 155 | * Called when the stack has bubbles or no longer has bubbles. |
| 156 | */ |
| 157 | void onHasBubblesChanged(boolean hasBubbles); |
| 158 | } |
| 159 | |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 160 | /** |
| 161 | * Listener to find out about stack expansion / collapse events. |
| 162 | */ |
| 163 | public interface BubbleExpandListener { |
| 164 | /** |
| 165 | * Called when the expansion state of the bubble stack changes. |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 166 | * |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 167 | * @param isExpanding whether it's expanding or collapsing |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 168 | * @param key the notification key associated with bubble being expanded |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 169 | */ |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 170 | void onBubbleExpandChanged(boolean isExpanding, String key); |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * Listens for the current state of the status bar and updates the visibility state |
| 175 | * of bubbles as needed. |
| 176 | */ |
| 177 | private class StatusBarStateListener implements StatusBarStateController.StateListener { |
| 178 | private int mState; |
| 179 | /** |
| 180 | * Returns the current status bar state. |
| 181 | */ |
| 182 | public int getCurrentState() { |
| 183 | return mState; |
| 184 | } |
| 185 | |
| 186 | @Override |
| 187 | public void onStateChanged(int newState) { |
| 188 | mState = newState; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 189 | boolean shouldCollapse = (mState != SHADE); |
| 190 | if (shouldCollapse) { |
| 191 | collapseStack(); |
| 192 | } |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 193 | updateStack(); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 194 | } |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 195 | } |
| 196 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 197 | @Inject |
Mady Mellor | cfd06c1 | 2019-02-13 14:32:12 -0800 | [diff] [blame] | 198 | public BubbleController(Context context, StatusBarWindowController statusBarWindowController, |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 199 | BubbleData data, ConfigurationController configurationController, |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 200 | NotificationInterruptionStateProvider interruptionStateProvider, |
| 201 | ZenModeController zenModeController) { |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 202 | this(context, statusBarWindowController, data, null /* synchronizer */, |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 203 | configurationController, interruptionStateProvider, zenModeController); |
Issei Suzuki | c038754 | 2019-03-08 17:31:14 +0100 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | public BubbleController(Context context, StatusBarWindowController statusBarWindowController, |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 207 | BubbleData data, @Nullable BubbleStackView.SurfaceSynchronizer synchronizer, |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 208 | ConfigurationController configurationController, |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 209 | NotificationInterruptionStateProvider interruptionStateProvider, |
| 210 | ZenModeController zenModeController) { |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 211 | mContext = context; |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 212 | mNotificationInterruptionStateProvider = interruptionStateProvider; |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 213 | mZenModeController = zenModeController; |
| 214 | mZenModeController.addCallback(new ZenModeController.Callback() { |
| 215 | @Override |
| 216 | public void onZenChanged(int zen) { |
| 217 | updateStackViewForZenConfig(); |
| 218 | } |
| 219 | |
| 220 | @Override |
| 221 | public void onConfigChanged(ZenModeConfig config) { |
| 222 | updateStackViewForZenConfig(); |
| 223 | } |
| 224 | }); |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 225 | |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 226 | configurationController.addCallback(this /* configurationListener */); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 227 | |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 228 | mBubbleData = data; |
| 229 | mBubbleData.setListener(mBubbleDataListener); |
| 230 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 231 | mNotificationEntryManager = Dependency.get(NotificationEntryManager.class); |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 232 | mNotificationEntryManager.addNotificationEntryListener(mEntryListener); |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 233 | mNotificationEntryManager.setNotificationRemoveInterceptor(mRemoveInterceptor); |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 234 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 235 | mStatusBarWindowController = statusBarWindowController; |
| 236 | mStatusBarStateListener = new StatusBarStateListener(); |
| 237 | Dependency.get(StatusBarStateController.class).addCallback(mStatusBarStateListener); |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 238 | |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 239 | mTaskStackListener = new BubbleTaskStackListener(); |
| 240 | ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 241 | |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 242 | try { |
| 243 | WindowManagerWrapper.getInstance().addPinnedStackListener(new BubblesImeListener()); |
| 244 | } catch (RemoteException e) { |
| 245 | e.printStackTrace(); |
| 246 | } |
Issei Suzuki | c038754 | 2019-03-08 17:31:14 +0100 | [diff] [blame] | 247 | mSurfaceSynchronizer = synchronizer; |
Mady Mellor | a54e9fa | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 248 | |
| 249 | mBarService = IStatusBarService.Stub.asInterface( |
| 250 | ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 251 | } |
| 252 | |
Mark Renouf | 8b6a3c6 | 2019-04-09 10:17:40 -0400 | [diff] [blame] | 253 | /** |
| 254 | * BubbleStackView is lazily created by this method the first time a Bubble is added. This |
| 255 | * method initializes the stack view and adds it to the StatusBar just above the scrim. |
| 256 | */ |
| 257 | private void ensureStackViewCreated() { |
| 258 | if (mStackView == null) { |
| 259 | mStackView = new BubbleStackView(mContext, mBubbleData, mSurfaceSynchronizer); |
| 260 | ViewGroup sbv = mStatusBarWindowController.getStatusBarView(); |
Lyn Han | bde4820 | 2019-05-29 19:18:29 -0700 | [diff] [blame] | 261 | int bubbleScrimIndex = sbv.indexOfChild(sbv.findViewById(R.id.scrim_for_bubble)); |
| 262 | int stackIndex = bubbleScrimIndex + 1; // Show stack above bubble scrim. |
| 263 | sbv.addView(mStackView, stackIndex, |
Mark Renouf | 8b6a3c6 | 2019-04-09 10:17:40 -0400 | [diff] [blame] | 264 | new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)); |
| 265 | if (mExpandListener != null) { |
| 266 | mStackView.setExpandListener(mExpandListener); |
| 267 | } |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 268 | |
| 269 | updateStackViewForZenConfig(); |
Mark Renouf | 8b6a3c6 | 2019-04-09 10:17:40 -0400 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 273 | @Override |
| 274 | public void onUiModeChanged() { |
| 275 | if (mStackView != null) { |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 276 | mStackView.onThemeChanged(); |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | |
| 280 | @Override |
| 281 | public void onOverlayChanged() { |
| 282 | if (mStackView != null) { |
Lyn Han | 02cca81 | 2019-04-02 16:27:32 -0700 | [diff] [blame] | 283 | mStackView.onThemeChanged(); |
Lyn Han | f1c9b8b | 2019-03-14 16:49:48 -0700 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | |
Joshua Tsuji | f418f9e | 2019-04-04 17:09:53 -0400 | [diff] [blame] | 287 | @Override |
| 288 | public void onConfigChanged(Configuration newConfig) { |
| 289 | if (mStackView != null && newConfig != null && newConfig.orientation != mOrientation) { |
| 290 | mStackView.onOrientationChanged(); |
| 291 | mOrientation = newConfig.orientation; |
| 292 | } |
| 293 | } |
| 294 | |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 295 | /** |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 296 | * Set a listener to be notified when some states of the bubbles change. |
| 297 | */ |
| 298 | public void setBubbleStateChangeListener(BubbleStateChangeListener listener) { |
| 299 | mStateChangeListener = listener; |
| 300 | } |
| 301 | |
| 302 | /** |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 303 | * Set a listener to be notified of bubble expand events. |
| 304 | */ |
| 305 | public void setExpandListener(BubbleExpandListener listener) { |
Issei Suzuki | ac9fcb7 | 2019-02-04 17:45:57 +0100 | [diff] [blame] | 306 | mExpandListener = ((isExpanding, key) -> { |
| 307 | if (listener != null) { |
| 308 | listener.onBubbleExpandChanged(isExpanding, key); |
| 309 | } |
| 310 | mStatusBarWindowController.setBubbleExpanded(isExpanding); |
| 311 | }); |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 312 | if (mStackView != null) { |
| 313 | mStackView.setExpandListener(mExpandListener); |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | /** |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 318 | * Whether or not there are bubbles present, regardless of them being visible on the |
| 319 | * screen (e.g. if on AOD). |
| 320 | */ |
| 321 | public boolean hasBubbles() { |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 322 | if (mStackView == null) { |
| 323 | return false; |
| 324 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 325 | return mBubbleData.hasBubbles(); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | /** |
| 329 | * Whether the stack of bubbles is expanded or not. |
| 330 | */ |
| 331 | public boolean isStackExpanded() { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 332 | return mBubbleData.isExpanded(); |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * Tell the stack of bubbles to expand. |
| 337 | */ |
| 338 | public void expandStack() { |
| 339 | mBubbleData.setExpanded(true); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | /** |
| 343 | * Tell the stack of bubbles to collapse. |
| 344 | */ |
| 345 | public void collapseStack() { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 346 | mBubbleData.setExpanded(false /* expanded */); |
| 347 | } |
| 348 | |
| 349 | void selectBubble(Bubble bubble) { |
| 350 | mBubbleData.setSelectedBubble(bubble); |
| 351 | } |
| 352 | |
| 353 | @VisibleForTesting |
| 354 | void selectBubble(String key) { |
| 355 | Bubble bubble = mBubbleData.getBubbleWithKey(key); |
| 356 | selectBubble(bubble); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | /** |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 360 | * Request the stack expand if needed, then select the specified Bubble as current. |
| 361 | * |
| 362 | * @param notificationKey the notification key for the bubble to be selected |
| 363 | */ |
| 364 | public void expandStackAndSelectBubble(String notificationKey) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 365 | Bubble bubble = mBubbleData.getBubbleWithKey(notificationKey); |
| 366 | if (bubble != null) { |
| 367 | mBubbleData.setSelectedBubble(bubble); |
| 368 | mBubbleData.setExpanded(true); |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | |
| 372 | /** |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 373 | * Tell the stack of bubbles to be dismissed, this will remove all of the bubbles in the stack. |
| 374 | */ |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 375 | void dismissStack(@DismissReason int reason) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 376 | mBubbleData.dismissAll(reason); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | /** |
Mark Renouf | 041d726 | 2019-02-06 12:09:41 -0500 | [diff] [blame] | 380 | * Directs a back gesture at the bubble stack. When opened, the current expanded bubble |
| 381 | * is forwarded a back key down/up pair. |
| 382 | */ |
| 383 | public void performBackPressIfNeeded() { |
| 384 | if (mStackView != null) { |
| 385 | mStackView.performBackPressIfNeeded(); |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | /** |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 390 | * Adds or updates a bubble associated with the provided notification entry. |
| 391 | * |
Mark Renouf | 8b6a3c6 | 2019-04-09 10:17:40 -0400 | [diff] [blame] | 392 | * @param notif the notification associated with this bubble. |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 393 | */ |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 394 | void updateBubble(NotificationEntry notif) { |
Mady Mellor | 66efd5e | 2019-05-15 13:38:11 -0700 | [diff] [blame] | 395 | // If this is an interruptive notif, mark that it's interrupted |
| 396 | if (notif.importance >= NotificationManager.IMPORTANCE_HIGH) { |
| 397 | notif.setInterruption(); |
| 398 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 399 | mBubbleData.notificationEntryUpdated(notif); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | /** |
| 403 | * Removes the bubble associated with the {@param uri}. |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 404 | * <p> |
| 405 | * Must be called from the main thread. |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 406 | */ |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 407 | @MainThread |
Mark Renouf | 08bc42a | 2019-03-07 13:01:59 -0500 | [diff] [blame] | 408 | void removeBubble(String key, int reason) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 409 | // TEMP: refactor to change this to pass entry |
| 410 | Bubble bubble = mBubbleData.getBubbleWithKey(key); |
| 411 | if (bubble != null) { |
| 412 | mBubbleData.notificationEntryRemoved(bubble.entry, reason); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 413 | } |
| 414 | } |
| 415 | |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 416 | @SuppressWarnings("FieldCanBeLocal") |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 417 | private final NotificationRemoveInterceptor mRemoveInterceptor = |
| 418 | new NotificationRemoveInterceptor() { |
| 419 | @Override |
| 420 | public boolean onNotificationRemoveRequested(String key, int reason) { |
| 421 | if (!mBubbleData.hasBubbleWithKey(key)) { |
| 422 | return false; |
| 423 | } |
| 424 | NotificationEntry entry = mBubbleData.getBubbleWithKey(key).entry; |
| 425 | |
| 426 | final boolean isClearAll = reason == REASON_CANCEL_ALL; |
| 427 | final boolean isUserDimiss = reason == REASON_CANCEL; |
| 428 | final boolean isAppCancel = reason == REASON_APP_CANCEL |
| 429 | || reason == REASON_APP_CANCEL_ALL; |
| 430 | |
| 431 | // Need to check for !appCancel here because the notification may have |
| 432 | // previously been dismissed & entry.isRowDismissed would still be true |
| 433 | boolean userRemovedNotif = (entry.isRowDismissed() && !isAppCancel) |
| 434 | || isClearAll || isUserDimiss; |
| 435 | |
| 436 | // The bubble notification sticks around in the data as long as the bubble is |
| 437 | // not dismissed and the app hasn't cancelled the notification. |
| 438 | boolean bubbleExtended = entry.isBubble() && !entry.isBubbleDismissed() |
| 439 | && userRemovedNotif; |
| 440 | if (bubbleExtended) { |
| 441 | entry.setShowInShadeWhenBubble(false); |
| 442 | if (mStackView != null) { |
| 443 | mStackView.updateDotVisibility(entry.key); |
| 444 | } |
| 445 | mNotificationEntryManager.updateNotifications(); |
| 446 | return true; |
| 447 | } else if (!userRemovedNotif && !entry.isBubbleDismissed()) { |
| 448 | // This wasn't a user removal so we should remove the bubble as well |
| 449 | mBubbleData.notificationEntryRemoved(entry, DISMISS_NOTIF_CANCEL); |
| 450 | return false; |
| 451 | } |
| 452 | return false; |
| 453 | } |
| 454 | }; |
| 455 | |
| 456 | @SuppressWarnings("FieldCanBeLocal") |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 457 | private final NotificationEntryListener mEntryListener = new NotificationEntryListener() { |
| 458 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 459 | public void onPendingEntryAdded(NotificationEntry entry) { |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 460 | if (!areBubblesEnabled(mContext)) { |
| 461 | return; |
| 462 | } |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 463 | if (mNotificationInterruptionStateProvider.shouldBubbleUp(entry) |
| 464 | && canLaunchInActivityView(mContext, entry)) { |
Mady Mellor | 8a1f025 | 2019-04-01 11:31:34 -0700 | [diff] [blame] | 465 | updateShowInShadeForSuppressNotification(entry); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 466 | } |
| 467 | } |
| 468 | |
| 469 | @Override |
Ned Burns | 1a5e22f | 2019-02-14 15:11:52 -0500 | [diff] [blame] | 470 | public void onEntryInflated(NotificationEntry entry, @InflationFlag int inflatedFlags) { |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 471 | if (!areBubblesEnabled(mContext)) { |
| 472 | return; |
| 473 | } |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 474 | if (mNotificationInterruptionStateProvider.shouldBubbleUp(entry) |
| 475 | && canLaunchInActivityView(mContext, entry)) { |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 476 | updateBubble(entry); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 477 | } |
| 478 | } |
| 479 | |
| 480 | @Override |
| 481 | public void onPreEntryUpdated(NotificationEntry entry) { |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 482 | if (!areBubblesEnabled(mContext)) { |
| 483 | return; |
| 484 | } |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 485 | boolean shouldBubble = mNotificationInterruptionStateProvider.shouldBubbleUp(entry) |
| 486 | && canLaunchInActivityView(mContext, entry); |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 487 | if (!shouldBubble && mBubbleData.hasBubbleWithKey(entry.key)) { |
| 488 | // It was previously a bubble but no longer a bubble -- lets remove it |
| 489 | removeBubble(entry.key, DISMISS_NO_LONGER_BUBBLE); |
Mady Mellor | ff40e01 | 2019-05-03 15:34:41 -0700 | [diff] [blame] | 490 | } else if (shouldBubble) { |
Mady Mellor | 8a1f025 | 2019-04-01 11:31:34 -0700 | [diff] [blame] | 491 | updateShowInShadeForSuppressNotification(entry); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 492 | entry.setBubbleDismissed(false); // updates come back as bubbles even if dismissed |
Mark Renouf | f97ed46 | 2019-04-05 13:46:24 -0400 | [diff] [blame] | 493 | updateBubble(entry); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 494 | } |
| 495 | } |
Mark Renouf | bbcf07f | 2019-05-09 10:42:43 -0400 | [diff] [blame] | 496 | |
| 497 | @Override |
| 498 | public void onNotificationRankingUpdated(RankingMap rankingMap) { |
| 499 | // Forward to BubbleData to block any bubbles which should no longer be shown |
| 500 | mBubbleData.notificationRankingUpdated(rankingMap); |
| 501 | } |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 502 | }; |
| 503 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 504 | @SuppressWarnings("FieldCanBeLocal") |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 505 | private final BubbleData.Listener mBubbleDataListener = new BubbleData.Listener() { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 506 | |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 507 | @Override |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 508 | public void applyUpdate(BubbleData.Update update) { |
| 509 | if (mStackView == null && update.addedBubble != null) { |
| 510 | // Lazy init stack view when the first bubble is added. |
| 511 | ensureStackViewCreated(); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 512 | } |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 513 | |
| 514 | // If not yet initialized, ignore all other changes. |
| 515 | if (mStackView == null) { |
| 516 | return; |
| 517 | } |
| 518 | |
| 519 | if (update.addedBubble != null) { |
| 520 | mStackView.addBubble(update.addedBubble); |
| 521 | } |
| 522 | |
| 523 | // Collapsing? Do this first before remaining steps. |
| 524 | if (update.expandedChanged && !update.expanded) { |
| 525 | mStackView.setExpanded(false); |
| 526 | } |
| 527 | |
| 528 | // Do removals, if any. |
| 529 | for (Pair<Bubble, Integer> removed : update.removedBubbles) { |
| 530 | final Bubble bubble = removed.first; |
| 531 | @DismissReason final int reason = removed.second; |
| 532 | mStackView.removeBubble(bubble); |
| 533 | |
| 534 | if (!mBubbleData.hasBubbleWithKey(bubble.getKey()) |
| 535 | && !bubble.entry.showInShadeWhenBubble()) { |
| 536 | // The bubble is gone & the notification is gone, time to actually remove it |
| 537 | mNotificationEntryManager.performRemoveNotification(bubble.entry.notification, |
| 538 | UNDEFINED_DISMISS_REASON); |
| 539 | } else { |
Mady Mellor | 3a0a1b4 | 2019-05-23 06:40:21 -0700 | [diff] [blame] | 540 | // Update the flag for SysUI |
| 541 | bubble.entry.notification.getNotification().flags &= ~FLAG_BUBBLE; |
| 542 | |
| 543 | // Make sure NoMan knows it's not a bubble anymore so anyone querying it will |
| 544 | // get right result back |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 545 | try { |
| 546 | mBarService.onNotificationBubbleChanged(bubble.getKey(), |
| 547 | false /* isBubble */); |
| 548 | } catch (RemoteException e) { |
| 549 | // Bad things have happened |
| 550 | } |
Mady Mellor | a54e9fa | 2019-04-18 13:26:18 -0700 | [diff] [blame] | 551 | } |
| 552 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 553 | |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 554 | if (update.updatedBubble != null) { |
| 555 | mStackView.updateBubble(update.updatedBubble); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 556 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 557 | |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 558 | if (update.orderChanged) { |
| 559 | mStackView.updateBubbleOrder(update.bubbles); |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 560 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 561 | |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 562 | if (update.selectionChanged) { |
| 563 | mStackView.setSelectedBubble(update.selectedBubble); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 564 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 565 | |
Mark Renouf | 82a40e6 | 2019-05-23 16:16:24 -0400 | [diff] [blame] | 566 | // Expanding? Apply this last. |
| 567 | if (update.expandedChanged && update.expanded) { |
| 568 | mStackView.setExpanded(true); |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 569 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 570 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 571 | mNotificationEntryManager.updateNotifications(); |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 572 | updateStack(); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 573 | |
Issei Suzuki | a8d0731 | 2019-06-07 12:56:19 +0200 | [diff] [blame] | 574 | if (DEBUG_BUBBLE_CONTROLLER) { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 575 | Log.d(TAG, "[BubbleData]"); |
| 576 | Log.d(TAG, formatBubblesString(mBubbleData.getBubbles(), |
| 577 | mBubbleData.getSelectedBubble())); |
| 578 | |
| 579 | if (mStackView != null) { |
| 580 | Log.d(TAG, "[BubbleStackView]"); |
| 581 | Log.d(TAG, formatBubblesString(mStackView.getBubblesOnScreen(), |
| 582 | mStackView.getExpandedBubble())); |
| 583 | } |
| 584 | } |
Mark Renouf | 3bc5b36 | 2019-04-05 14:37:59 -0400 | [diff] [blame] | 585 | } |
| 586 | }; |
| 587 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 588 | /** |
Joshua Tsuji | dd4d9f9 | 2019-05-13 13:57:38 -0400 | [diff] [blame] | 589 | * Updates the stack view's suppression flags from the latest config from the zen (do not |
| 590 | * disturb) controller. |
| 591 | */ |
| 592 | private void updateStackViewForZenConfig() { |
| 593 | final ZenModeConfig zenModeConfig = mZenModeController.getConfig(); |
| 594 | |
| 595 | if (zenModeConfig == null || mStackView == null) { |
| 596 | return; |
| 597 | } |
| 598 | |
| 599 | final int suppressedEffects = zenModeConfig.suppressedVisualEffects; |
| 600 | final boolean hideNotificationDotsSelected = |
| 601 | (suppressedEffects & SUPPRESSED_EFFECT_BADGE) != 0; |
| 602 | final boolean dontPopNotifsOnScreenSelected = |
| 603 | (suppressedEffects & SUPPRESSED_EFFECT_PEEK) != 0; |
| 604 | final boolean hideFromPullDownShadeSelected = |
| 605 | (suppressedEffects & SUPPRESSED_EFFECT_NOTIFICATION_LIST) != 0; |
| 606 | |
| 607 | final boolean dndEnabled = mZenModeController.getZen() != Settings.Global.ZEN_MODE_OFF; |
| 608 | |
| 609 | mStackView.setSuppressNewDot( |
| 610 | dndEnabled && hideNotificationDotsSelected); |
| 611 | mStackView.setSuppressFlyout( |
| 612 | dndEnabled && (dontPopNotifsOnScreenSelected |
| 613 | || hideFromPullDownShadeSelected)); |
| 614 | } |
| 615 | |
| 616 | /** |
| 617 | * Lets any listeners know if bubble state has changed. |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 618 | * Updates the visibility of the bubbles based on current state. |
| 619 | * Does not un-bubble, just hides or un-hides. Notifies any |
| 620 | * {@link BubbleStateChangeListener}s of visibility changes. |
| 621 | * Updates stack description for TalkBack focus. |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 622 | */ |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 623 | public void updateStack() { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 624 | if (mStackView == null) { |
| 625 | return; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 626 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 627 | if (mStatusBarStateListener.getCurrentState() == SHADE && hasBubbles()) { |
| 628 | // Bubbles only appear in unlocked shade |
| 629 | mStackView.setVisibility(hasBubbles() ? VISIBLE : INVISIBLE); |
| 630 | } else if (mStackView != null) { |
| 631 | mStackView.setVisibility(INVISIBLE); |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 632 | } |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 633 | |
| 634 | // Let listeners know if bubble state changed. |
| 635 | boolean hadBubbles = mStatusBarWindowController.getBubblesShowing(); |
| 636 | boolean hasBubblesShowing = hasBubbles() && mStackView.getVisibility() == VISIBLE; |
| 637 | mStatusBarWindowController.setBubblesShowing(hasBubblesShowing); |
| 638 | if (mStateChangeListener != null && hadBubbles != hasBubblesShowing) { |
| 639 | mStateChangeListener.onHasBubblesChanged(hasBubblesShowing); |
| 640 | } |
| 641 | |
| 642 | mStackView.updateContentDescription(); |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | /** |
| 646 | * Rect indicating the touchable region for the bubble stack / expanded stack. |
| 647 | */ |
| 648 | public Rect getTouchableRegion() { |
| 649 | if (mStackView == null || mStackView.getVisibility() != VISIBLE) { |
| 650 | return null; |
| 651 | } |
| 652 | mStackView.getBoundsOnScreen(mTempRect); |
| 653 | return mTempRect; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 654 | } |
| 655 | |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 656 | /** |
| 657 | * The display id of the expanded view, if the stack is expanded and not occluded by the |
| 658 | * status bar, otherwise returns {@link Display#INVALID_DISPLAY}. |
| 659 | */ |
| 660 | public int getExpandedDisplayId(Context context) { |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 661 | final Bubble bubble = getExpandedBubble(context); |
| 662 | return bubble != null ? bubble.getDisplayId() : INVALID_DISPLAY; |
| 663 | } |
| 664 | |
| 665 | @Nullable |
| 666 | private Bubble getExpandedBubble(Context context) { |
Joel Galenson | 4071ddb | 2019-04-18 13:30:45 -0700 | [diff] [blame] | 667 | if (mStackView == null) { |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 668 | return null; |
Joel Galenson | 4071ddb | 2019-04-18 13:30:45 -0700 | [diff] [blame] | 669 | } |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 670 | final boolean defaultDisplay = context.getDisplay() != null |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 671 | && context.getDisplay().getDisplayId() == DEFAULT_DISPLAY; |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 672 | final Bubble expandedBubble = mStackView.getExpandedBubble(); |
| 673 | if (defaultDisplay && expandedBubble != null && isStackExpanded() |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 674 | && !mStatusBarWindowController.getPanelExpanded()) { |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 675 | return expandedBubble; |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 676 | } |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 677 | return null; |
Mady Mellor | 390bff4 | 2019-04-05 15:09:01 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 680 | @VisibleForTesting |
| 681 | BubbleStackView getStackView() { |
| 682 | return mStackView; |
| 683 | } |
| 684 | |
Mady Mellor | 8a1f025 | 2019-04-01 11:31:34 -0700 | [diff] [blame] | 685 | private void updateShowInShadeForSuppressNotification(NotificationEntry entry) { |
| 686 | boolean suppressNotification = entry.getBubbleMetadata() != null |
Mady Mellor | c529d6d | 2019-04-16 14:22:52 -0700 | [diff] [blame] | 687 | && entry.getBubbleMetadata().isNotificationSuppressed() |
Steven Wu | 8ba8ca9 | 2019-04-11 10:47:42 -0400 | [diff] [blame] | 688 | && isForegroundApp(mContext, entry.notification.getPackageName()); |
Mady Mellor | be341bf | 2019-06-07 14:11:07 -0700 | [diff] [blame] | 689 | Bubble b = mBubbleData.getBubbleWithKey(entry.key); |
| 690 | if (b != null && mBubbleData.getSelectedBubble() == b && mBubbleData.isExpanded()) { |
| 691 | // If we're expanded & selected don't show in shade |
| 692 | suppressNotification = true; |
| 693 | } |
Mady Mellor | 8a1f025 | 2019-04-01 11:31:34 -0700 | [diff] [blame] | 694 | entry.setShowInShadeWhenBubble(!suppressNotification); |
| 695 | } |
| 696 | |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 697 | static String formatBubblesString(List<Bubble> bubbles, Bubble selected) { |
| 698 | StringBuilder sb = new StringBuilder(); |
| 699 | for (Bubble bubble : bubbles) { |
| 700 | if (bubble == null) { |
| 701 | sb.append(" <null> !!!!!\n"); |
| 702 | } else { |
| 703 | boolean isSelected = (bubble == selected); |
| 704 | sb.append(String.format("%s Bubble{act=%12d, ongoing=%d, key=%s}\n", |
| 705 | ((isSelected) ? "->" : " "), |
| 706 | bubble.getLastActivity(), |
| 707 | (bubble.isOngoing() ? 1 : 0), |
| 708 | bubble.getKey())); |
| 709 | } |
| 710 | } |
| 711 | return sb.toString(); |
| 712 | } |
| 713 | |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 714 | /** |
| 715 | * Return true if the applications with the package name is running in foreground. |
| 716 | * |
Steven Wu | 8ba8ca9 | 2019-04-11 10:47:42 -0400 | [diff] [blame] | 717 | * @param context application context. |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 718 | * @param pkgName application package name. |
| 719 | */ |
Steven Wu | 8ba8ca9 | 2019-04-11 10:47:42 -0400 | [diff] [blame] | 720 | public static boolean isForegroundApp(Context context, String pkgName) { |
| 721 | ActivityManager am = context.getSystemService(ActivityManager.class); |
Mady Mellor | e80930e | 2019-03-21 16:00:45 -0700 | [diff] [blame] | 722 | List<RunningTaskInfo> tasks = am.getRunningTasks(1 /* maxNum */); |
| 723 | return !tasks.isEmpty() && pkgName.equals(tasks.get(0).topActivity.getPackageName()); |
| 724 | } |
| 725 | |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 726 | /** |
| 727 | * This task stack listener is responsible for responding to tasks moved to the front |
| 728 | * which are on the default (main) display. When this happens, expanded bubbles must be |
| 729 | * collapsed so the user may interact with the app which was just moved to the front. |
| 730 | * <p> |
| 731 | * This listener is registered with SystemUI's ActivityManagerWrapper which dispatches |
| 732 | * these calls via a main thread Handler. |
| 733 | */ |
| 734 | @MainThread |
| 735 | private class BubbleTaskStackListener extends TaskStackChangeListener { |
| 736 | |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 737 | @Override |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 738 | public void onTaskMovedToFront(RunningTaskInfo taskInfo) { |
| 739 | if (mStackView != null && taskInfo.displayId == Display.DEFAULT_DISPLAY) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 740 | mBubbleData.setExpanded(false); |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 741 | } |
| 742 | } |
| 743 | |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 744 | @Override |
Mark Renouf | a12e876 | 2019-03-07 15:43:01 -0500 | [diff] [blame] | 745 | public void onActivityLaunchOnSecondaryDisplayRerouted() { |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 746 | if (mStackView != null) { |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 747 | mBubbleData.setExpanded(false); |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 748 | } |
| 749 | } |
Mark Renouf | 446251d | 2019-04-26 10:22:41 -0400 | [diff] [blame] | 750 | |
| 751 | @Override |
| 752 | public void onBackPressedOnTaskRoot(RunningTaskInfo taskInfo) { |
| 753 | if (mStackView != null && taskInfo.displayId == getExpandedDisplayId(mContext)) { |
| 754 | mBubbleData.setExpanded(false); |
| 755 | } |
| 756 | } |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 757 | |
| 758 | @Override |
| 759 | public void onSingleTaskDisplayDrawn(int displayId) { |
| 760 | final Bubble expandedBubble = getExpandedBubble(mContext); |
| 761 | if (expandedBubble != null && expandedBubble.getDisplayId() == displayId) { |
| 762 | expandedBubble.setContentVisibility(true); |
| 763 | } |
| 764 | } |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 765 | } |
| 766 | |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 767 | private static boolean areBubblesEnabled(Context context) { |
| 768 | return Settings.Secure.getInt(context.getContentResolver(), |
| 769 | ENABLE_BUBBLES, 1) != 0; |
| 770 | } |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 771 | |
Mady Mellor | ca0c24c | 2019-05-16 16:14:32 -0700 | [diff] [blame] | 772 | /** |
| 773 | * Whether an intent is properly configured to display in an {@link android.app.ActivityView}. |
| 774 | * |
| 775 | * Keep checks in sync with NotificationManagerService#canLaunchInActivityView. Typically |
| 776 | * that should filter out any invalid bubbles, but should protect SysUI side just in case. |
| 777 | * |
| 778 | * @param context the context to use. |
| 779 | * @param entry the entry to bubble. |
| 780 | */ |
| 781 | static boolean canLaunchInActivityView(Context context, NotificationEntry entry) { |
| 782 | PendingIntent intent = entry.getBubbleMetadata() != null |
| 783 | ? entry.getBubbleMetadata().getIntent() |
| 784 | : null; |
| 785 | if (intent == null) { |
| 786 | Log.w(TAG, "Unable to create bubble -- no intent"); |
| 787 | return false; |
| 788 | } |
| 789 | ActivityInfo info = |
| 790 | intent.getIntent().resolveActivityInfo(context.getPackageManager(), 0); |
| 791 | if (info == null) { |
| 792 | Log.w(TAG, "Unable to send as bubble -- couldn't find activity info for intent: " |
| 793 | + intent); |
| 794 | return false; |
| 795 | } |
| 796 | if (!ActivityInfo.isResizeableMode(info.resizeMode)) { |
| 797 | Log.w(TAG, "Unable to send as bubble -- activity is not resizable for intent: " |
| 798 | + intent); |
| 799 | return false; |
| 800 | } |
| 801 | if (info.documentLaunchMode != DOCUMENT_LAUNCH_ALWAYS) { |
| 802 | Log.w(TAG, "Unable to send as bubble -- activity is not documentLaunchMode=always " |
| 803 | + "for intent: " + intent); |
| 804 | return false; |
| 805 | } |
| 806 | if ((info.flags & ActivityInfo.FLAG_ALLOW_EMBEDDED) == 0) { |
| 807 | Log.w(TAG, "Unable to send as bubble -- activity is not embeddable for intent: " |
| 808 | + intent); |
| 809 | return false; |
| 810 | } |
| 811 | return true; |
| 812 | } |
| 813 | |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 814 | /** PinnedStackListener that dispatches IME visibility updates to the stack. */ |
| 815 | private class BubblesImeListener extends IPinnedStackListener.Stub { |
| 816 | |
| 817 | @Override |
| 818 | public void onListenerRegistered(IPinnedStackController controller) throws RemoteException { |
| 819 | } |
| 820 | |
| 821 | @Override |
| 822 | public void onMovementBoundsChanged(Rect insetBounds, Rect normalBounds, |
| 823 | Rect animatingBounds, boolean fromImeAdjustment, boolean fromShelfAdjustment, |
| 824 | int displayRotation) throws RemoteException {} |
| 825 | |
| 826 | @Override |
Joshua Tsuji | d942283 | 2019-03-05 13:32:37 -0500 | [diff] [blame] | 827 | public void onImeVisibilityChanged(boolean imeVisible, int imeHeight) { |
| 828 | if (mStackView != null && mStackView.getBubbleCount() > 0) { |
| 829 | mStackView.post(() -> mStackView.onImeVisibilityChanged(imeVisible, imeHeight)); |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 830 | } |
| 831 | } |
| 832 | |
| 833 | @Override |
| 834 | public void onShelfVisibilityChanged(boolean shelfVisible, int shelfHeight) |
| 835 | throws RemoteException {} |
| 836 | |
| 837 | @Override |
| 838 | public void onMinimizedStateChanged(boolean isMinimized) throws RemoteException {} |
| 839 | |
| 840 | @Override |
| 841 | public void onActionsChanged(ParceledListSlice actions) throws RemoteException {} |
| 842 | } |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 843 | } |