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