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