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