Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [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.statusbar.notification; |
| 18 | |
| 19 | import static com.android.systemui.statusbar.StatusBarState.SHADE; |
| 20 | |
| 21 | import android.app.Notification; |
| 22 | import android.app.NotificationManager; |
| 23 | import android.content.Context; |
| 24 | import android.database.ContentObserver; |
Lucas Dupin | 2c3992b | 2019-03-11 16:34:08 -0700 | [diff] [blame] | 25 | import android.hardware.display.AmbientDisplayConfiguration; |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 26 | import android.os.PowerManager; |
| 27 | import android.os.RemoteException; |
| 28 | import android.os.ServiceManager; |
Lucas Dupin | 2c3992b | 2019-03-11 16:34:08 -0700 | [diff] [blame] | 29 | import android.os.UserHandle; |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 30 | import android.provider.Settings; |
| 31 | import android.service.dreams.DreamService; |
| 32 | import android.service.dreams.IDreamManager; |
| 33 | import android.service.notification.StatusBarNotification; |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 34 | import android.util.Log; |
| 35 | |
| 36 | import com.android.internal.annotations.VisibleForTesting; |
| 37 | import com.android.systemui.Dependency; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 38 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 39 | import com.android.systemui.statusbar.NotificationPresenter; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 40 | import com.android.systemui.statusbar.StatusBarState; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 41 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 42 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
| 43 | |
Govinda Wasserman | 3e7ce55 | 2019-08-13 11:35:44 -0400 | [diff] [blame] | 44 | import javax.inject.Inject; |
| 45 | import javax.inject.Singleton; |
| 46 | |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 47 | /** |
| 48 | * Provides heads-up and pulsing state for notification entries. |
| 49 | */ |
Govinda Wasserman | 3e7ce55 | 2019-08-13 11:35:44 -0400 | [diff] [blame] | 50 | @Singleton |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 51 | public class NotificationInterruptionStateProvider { |
| 52 | |
| 53 | private static final String TAG = "InterruptionStateProvider"; |
| 54 | private static final boolean DEBUG = false; |
Lucas Dupin | c0b8111 | 2019-07-25 18:56:12 -0700 | [diff] [blame] | 55 | private static final boolean DEBUG_HEADS_UP = true; |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 56 | private static final boolean ENABLE_HEADS_UP = true; |
| 57 | private static final String SETTING_HEADS_UP_TICKER = "ticker_gets_heads_up"; |
| 58 | |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 59 | private final StatusBarStateController mStatusBarStateController; |
| 60 | private final NotificationFilter mNotificationFilter; |
Lucas Dupin | 2c3992b | 2019-03-11 16:34:08 -0700 | [diff] [blame] | 61 | private final AmbientDisplayConfiguration mAmbientDisplayConfiguration; |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 62 | |
| 63 | private final Context mContext; |
| 64 | private final PowerManager mPowerManager; |
| 65 | private final IDreamManager mDreamManager; |
| 66 | |
| 67 | private NotificationPresenter mPresenter; |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 68 | private HeadsUpManager mHeadsUpManager; |
| 69 | private HeadsUpSuppressor mHeadsUpSuppressor; |
| 70 | |
| 71 | private ContentObserver mHeadsUpObserver; |
| 72 | @VisibleForTesting |
| 73 | protected boolean mUseHeadsUp = false; |
| 74 | private boolean mDisableNotificationAlerts; |
| 75 | |
Govinda Wasserman | 3e7ce55 | 2019-08-13 11:35:44 -0400 | [diff] [blame] | 76 | @Inject |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 77 | public NotificationInterruptionStateProvider(Context context, NotificationFilter filter, |
| 78 | StatusBarStateController stateController) { |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 79 | this(context, |
| 80 | (PowerManager) context.getSystemService(Context.POWER_SERVICE), |
| 81 | IDreamManager.Stub.asInterface( |
Lucas Dupin | 2c3992b | 2019-03-11 16:34:08 -0700 | [diff] [blame] | 82 | ServiceManager.checkService(DreamService.DREAM_SERVICE)), |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 83 | new AmbientDisplayConfiguration(context), |
| 84 | filter, |
| 85 | stateController); |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | @VisibleForTesting |
| 89 | protected NotificationInterruptionStateProvider( |
| 90 | Context context, |
| 91 | PowerManager powerManager, |
Lucas Dupin | 2c3992b | 2019-03-11 16:34:08 -0700 | [diff] [blame] | 92 | IDreamManager dreamManager, |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 93 | AmbientDisplayConfiguration ambientDisplayConfiguration, |
| 94 | NotificationFilter notificationFilter, |
| 95 | StatusBarStateController statusBarStateController) { |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 96 | mContext = context; |
| 97 | mPowerManager = powerManager; |
| 98 | mDreamManager = dreamManager; |
Lucas Dupin | 2c3992b | 2019-03-11 16:34:08 -0700 | [diff] [blame] | 99 | mAmbientDisplayConfiguration = ambientDisplayConfiguration; |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 100 | mNotificationFilter = notificationFilter; |
| 101 | mStatusBarStateController = statusBarStateController; |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | /** Sets up late-binding dependencies for this component. */ |
| 105 | public void setUpWithPresenter( |
| 106 | NotificationPresenter notificationPresenter, |
| 107 | HeadsUpManager headsUpManager, |
| 108 | HeadsUpSuppressor headsUpSuppressor) { |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 109 | setUpWithPresenter(notificationPresenter, headsUpManager, headsUpSuppressor, |
| 110 | new ContentObserver(Dependency.get(Dependency.MAIN_HANDLER)) { |
| 111 | @Override |
| 112 | public void onChange(boolean selfChange) { |
| 113 | boolean wasUsing = mUseHeadsUp; |
| 114 | mUseHeadsUp = ENABLE_HEADS_UP && !mDisableNotificationAlerts |
| 115 | && Settings.Global.HEADS_UP_OFF != Settings.Global.getInt( |
| 116 | mContext.getContentResolver(), |
| 117 | Settings.Global.HEADS_UP_NOTIFICATIONS_ENABLED, |
| 118 | Settings.Global.HEADS_UP_OFF); |
| 119 | Log.d(TAG, "heads up is " + (mUseHeadsUp ? "enabled" : "disabled")); |
| 120 | if (wasUsing != mUseHeadsUp) { |
| 121 | if (!mUseHeadsUp) { |
| 122 | Log.d(TAG, |
| 123 | "dismissing any existing heads up notification on disable" |
| 124 | + " event"); |
| 125 | mHeadsUpManager.releaseAllImmediately(); |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | }); |
| 130 | } |
| 131 | |
| 132 | /** Sets up late-binding dependencies for this component. */ |
| 133 | public void setUpWithPresenter( |
| 134 | NotificationPresenter notificationPresenter, |
| 135 | HeadsUpManager headsUpManager, |
| 136 | HeadsUpSuppressor headsUpSuppressor, |
| 137 | ContentObserver observer) { |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 138 | mPresenter = notificationPresenter; |
| 139 | mHeadsUpManager = headsUpManager; |
| 140 | mHeadsUpSuppressor = headsUpSuppressor; |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 141 | mHeadsUpObserver = observer; |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 142 | |
| 143 | if (ENABLE_HEADS_UP) { |
| 144 | mContext.getContentResolver().registerContentObserver( |
| 145 | Settings.Global.getUriFor(Settings.Global.HEADS_UP_NOTIFICATIONS_ENABLED), |
| 146 | true, |
| 147 | mHeadsUpObserver); |
| 148 | mContext.getContentResolver().registerContentObserver( |
| 149 | Settings.Global.getUriFor(SETTING_HEADS_UP_TICKER), true, |
| 150 | mHeadsUpObserver); |
| 151 | } |
| 152 | mHeadsUpObserver.onChange(true); // set up |
| 153 | } |
| 154 | |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 155 | /** |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 156 | * Whether the notification should appear as a bubble with a fly-out on top of the screen. |
| 157 | * |
| 158 | * @param entry the entry to check |
| 159 | * @return true if the entry should bubble up, false otherwise |
| 160 | */ |
| 161 | public boolean shouldBubbleUp(NotificationEntry entry) { |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 162 | final StatusBarNotification sbn = entry.notification; |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 163 | |
| 164 | if (!canAlertCommon(entry)) { |
| 165 | return false; |
| 166 | } |
| 167 | |
| 168 | if (!canAlertAwakeCommon(entry)) { |
| 169 | return false; |
| 170 | } |
| 171 | |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 172 | if (!entry.canBubble) { |
| 173 | if (DEBUG) { |
| 174 | Log.d(TAG, "No bubble up: not allowed to bubble: " + sbn.getKey()); |
| 175 | } |
| 176 | return false; |
| 177 | } |
| 178 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 179 | if (!entry.isBubble()) { |
| 180 | if (DEBUG) { |
| 181 | Log.d(TAG, "No bubble up: notification " + sbn.getKey() |
| 182 | + " is bubble? " + entry.isBubble()); |
| 183 | } |
| 184 | return false; |
| 185 | } |
| 186 | |
Mady Mellor | aa8fef2 | 2019-04-11 13:36:40 -0700 | [diff] [blame] | 187 | final Notification n = sbn.getNotification(); |
| 188 | if (n.getBubbleMetadata() == null || n.getBubbleMetadata().getIntent() == null) { |
| 189 | if (DEBUG) { |
| 190 | Log.d(TAG, "No bubble up: notification: " + sbn.getKey() |
| 191 | + " doesn't have valid metadata"); |
| 192 | } |
| 193 | return false; |
| 194 | } |
| 195 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 196 | return true; |
| 197 | } |
| 198 | |
| 199 | /** |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 200 | * Whether the notification should peek in from the top and alert the user. |
| 201 | * |
| 202 | * @param entry the entry to check |
| 203 | * @return true if the entry should heads up, false otherwise |
| 204 | */ |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 205 | public boolean shouldHeadsUp(NotificationEntry entry) { |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 206 | if (mStatusBarStateController.isDozing()) { |
| 207 | return shouldHeadsUpWhenDozing(entry); |
| 208 | } else { |
| 209 | return shouldHeadsUpWhenAwake(entry); |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 210 | } |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | private boolean shouldHeadsUpWhenAwake(NotificationEntry entry) { |
| 214 | StatusBarNotification sbn = entry.notification; |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 215 | |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 216 | if (!mUseHeadsUp) { |
Mady Mellor | 9defe41 | 2019-08-02 10:06:47 -0700 | [diff] [blame] | 217 | if (DEBUG_HEADS_UP) { |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 218 | Log.d(TAG, "No heads up: no huns"); |
| 219 | } |
| 220 | return false; |
| 221 | } |
| 222 | |
| 223 | if (!canAlertCommon(entry)) { |
| 224 | return false; |
| 225 | } |
| 226 | |
| 227 | if (!canAlertAwakeCommon(entry)) { |
| 228 | return false; |
| 229 | } |
| 230 | |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 231 | boolean inShade = mStatusBarStateController.getState() == SHADE; |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 232 | if (entry.isBubble() && inShade) { |
Lucas Dupin | c0b8111 | 2019-07-25 18:56:12 -0700 | [diff] [blame] | 233 | if (DEBUG_HEADS_UP) { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 234 | Log.d(TAG, "No heads up: in unlocked shade where notification is shown as a " |
| 235 | + "bubble: " + sbn.getKey()); |
| 236 | } |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 237 | return false; |
| 238 | } |
| 239 | |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 240 | if (entry.shouldSuppressPeek()) { |
Lucas Dupin | c0b8111 | 2019-07-25 18:56:12 -0700 | [diff] [blame] | 241 | if (DEBUG_HEADS_UP) { |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 242 | Log.d(TAG, "No heads up: suppressed by DND: " + sbn.getKey()); |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 243 | } |
| 244 | return false; |
| 245 | } |
| 246 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 247 | if (entry.importance < NotificationManager.IMPORTANCE_HIGH) { |
Lucas Dupin | c0b8111 | 2019-07-25 18:56:12 -0700 | [diff] [blame] | 248 | if (DEBUG_HEADS_UP) { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 249 | Log.d(TAG, "No heads up: unimportant notification: " + sbn.getKey()); |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 250 | } |
| 251 | return false; |
| 252 | } |
| 253 | |
| 254 | boolean isDreaming = false; |
| 255 | try { |
| 256 | isDreaming = mDreamManager.isDreaming(); |
| 257 | } catch (RemoteException e) { |
| 258 | Log.e(TAG, "Failed to query dream manager.", e); |
| 259 | } |
| 260 | boolean inUse = mPowerManager.isScreenOn() && !isDreaming; |
| 261 | |
| 262 | if (!inUse) { |
Lucas Dupin | c0b8111 | 2019-07-25 18:56:12 -0700 | [diff] [blame] | 263 | if (DEBUG_HEADS_UP) { |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 264 | Log.d(TAG, "No heads up: not in use: " + sbn.getKey()); |
| 265 | } |
| 266 | return false; |
| 267 | } |
| 268 | |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 269 | if (!mHeadsUpSuppressor.canHeadsUp(entry, sbn)) { |
Lucas Dupin | c0b8111 | 2019-07-25 18:56:12 -0700 | [diff] [blame] | 270 | if (DEBUG_HEADS_UP) { |
| 271 | Log.d(TAG, "No heads up: aborted by suppressor: " + sbn.getKey()); |
| 272 | } |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 273 | return false; |
| 274 | } |
| 275 | |
| 276 | return true; |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * Whether or not the notification should "pulse" on the user's display when the phone is |
| 281 | * dozing. This displays the ambient view of the notification. |
| 282 | * |
| 283 | * @param entry the entry to check |
| 284 | * @return true if the entry should ambient pulse, false otherwise |
| 285 | */ |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 286 | private boolean shouldHeadsUpWhenDozing(NotificationEntry entry) { |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 287 | StatusBarNotification sbn = entry.notification; |
| 288 | |
Lucas Dupin | 2c3992b | 2019-03-11 16:34:08 -0700 | [diff] [blame] | 289 | if (!mAmbientDisplayConfiguration.pulseOnNotificationEnabled(UserHandle.USER_CURRENT)) { |
Lucas Dupin | c0b8111 | 2019-07-25 18:56:12 -0700 | [diff] [blame] | 290 | if (DEBUG_HEADS_UP) { |
Lucas Dupin | 2c3992b | 2019-03-11 16:34:08 -0700 | [diff] [blame] | 291 | Log.d(TAG, "No pulsing: disabled by setting: " + sbn.getKey()); |
| 292 | } |
| 293 | return false; |
| 294 | } |
| 295 | |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 296 | if (!canAlertCommon(entry)) { |
Lucas Dupin | c0b8111 | 2019-07-25 18:56:12 -0700 | [diff] [blame] | 297 | if (DEBUG_HEADS_UP) { |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 298 | Log.d(TAG, "No pulsing: notification shouldn't alert: " + sbn.getKey()); |
| 299 | } |
| 300 | return false; |
| 301 | } |
| 302 | |
| 303 | if (entry.shouldSuppressAmbient()) { |
Lucas Dupin | c0b8111 | 2019-07-25 18:56:12 -0700 | [diff] [blame] | 304 | if (DEBUG_HEADS_UP) { |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 305 | Log.d(TAG, "No pulsing: ambient effect suppressed: " + sbn.getKey()); |
| 306 | } |
| 307 | return false; |
| 308 | } |
| 309 | |
| 310 | if (entry.importance < NotificationManager.IMPORTANCE_DEFAULT) { |
Lucas Dupin | c0b8111 | 2019-07-25 18:56:12 -0700 | [diff] [blame] | 311 | if (DEBUG_HEADS_UP) { |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 312 | Log.d(TAG, "No pulsing: not important enough: " + sbn.getKey()); |
| 313 | } |
| 314 | return false; |
| 315 | } |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 316 | return true; |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | /** |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 320 | * Common checks between regular & AOD heads up and bubbles. |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 321 | * |
| 322 | * @param entry the entry to check |
| 323 | * @return true if these checks pass, false if the notification should not alert |
| 324 | */ |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 325 | @VisibleForTesting |
| 326 | public boolean canAlertCommon(NotificationEntry entry) { |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 327 | StatusBarNotification sbn = entry.notification; |
| 328 | |
| 329 | if (mNotificationFilter.shouldFilterOut(entry)) { |
Lucas Dupin | c0b8111 | 2019-07-25 18:56:12 -0700 | [diff] [blame] | 330 | if (DEBUG || DEBUG_HEADS_UP) { |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 331 | Log.d(TAG, "No alerting: filtered notification: " + sbn.getKey()); |
| 332 | } |
| 333 | return false; |
| 334 | } |
| 335 | |
| 336 | // Don't alert notifications that are suppressed due to group alert behavior |
| 337 | if (sbn.isGroup() && sbn.getNotification().suppressAlertingDueToGrouping()) { |
Lucas Dupin | c0b8111 | 2019-07-25 18:56:12 -0700 | [diff] [blame] | 338 | if (DEBUG || DEBUG_HEADS_UP) { |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 339 | Log.d(TAG, "No alerting: suppressed due to group alert behavior"); |
| 340 | } |
| 341 | return false; |
| 342 | } |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 343 | return true; |
| 344 | } |
| 345 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 346 | /** |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 347 | * Common checks between alerts that occur while the device is awake (heads up & bubbles). |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 348 | * |
| 349 | * @param entry the entry to check |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 350 | * @return true if these checks pass, false if the notification should not alert |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 351 | */ |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 352 | @VisibleForTesting |
| 353 | public boolean canAlertAwakeCommon(NotificationEntry entry) { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 354 | StatusBarNotification sbn = entry.notification; |
| 355 | |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 356 | if (mPresenter.isDeviceInVrMode()) { |
Lucas Dupin | c0b8111 | 2019-07-25 18:56:12 -0700 | [diff] [blame] | 357 | if (DEBUG_HEADS_UP) { |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 358 | Log.d(TAG, "No alerting: no huns or vr mode"); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 359 | } |
| 360 | return false; |
| 361 | } |
| 362 | |
| 363 | if (isSnoozedPackage(sbn)) { |
Lucas Dupin | c0b8111 | 2019-07-25 18:56:12 -0700 | [diff] [blame] | 364 | if (DEBUG_HEADS_UP) { |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 365 | Log.d(TAG, "No alerting: snoozed package: " + sbn.getKey()); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 366 | } |
| 367 | return false; |
| 368 | } |
| 369 | |
| 370 | if (entry.hasJustLaunchedFullScreenIntent()) { |
Lucas Dupin | c0b8111 | 2019-07-25 18:56:12 -0700 | [diff] [blame] | 371 | if (DEBUG_HEADS_UP) { |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 372 | Log.d(TAG, "No alerting: recent fullscreen: " + sbn.getKey()); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 373 | } |
| 374 | return false; |
| 375 | } |
| 376 | |
| 377 | return true; |
| 378 | } |
| 379 | |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 380 | private boolean isSnoozedPackage(StatusBarNotification sbn) { |
| 381 | return mHeadsUpManager.isSnoozed(sbn.getPackageName()); |
| 382 | } |
| 383 | |
| 384 | /** Sets whether to disable all alerts. */ |
| 385 | public void setDisableNotificationAlerts(boolean disableNotificationAlerts) { |
| 386 | mDisableNotificationAlerts = disableNotificationAlerts; |
| 387 | mHeadsUpObserver.onChange(true); |
| 388 | } |
| 389 | |
Mady Mellor | c55b412 | 2019-06-07 18:14:02 -0700 | [diff] [blame] | 390 | /** Whether all alerts are disabled. */ |
| 391 | @VisibleForTesting |
| 392 | public boolean areNotificationAlertsDisabled() { |
| 393 | return mDisableNotificationAlerts; |
| 394 | } |
| 395 | |
| 396 | /** Whether HUNs should be used. */ |
| 397 | @VisibleForTesting |
| 398 | public boolean getUseHeadsUp() { |
| 399 | return mUseHeadsUp; |
| 400 | } |
| 401 | |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 402 | protected NotificationPresenter getPresenter() { |
| 403 | return mPresenter; |
| 404 | } |
| 405 | |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 406 | /** |
| 407 | * When an entry was added, should we launch its fullscreen intent? Examples are Alarms or |
| 408 | * incoming calls. |
| 409 | * |
| 410 | * @param entry the entry that was added |
| 411 | * @return {@code true} if we should launch the full screen intent |
| 412 | */ |
| 413 | public boolean shouldLaunchFullScreenIntentWhenAdded(NotificationEntry entry) { |
| 414 | return entry.notification.getNotification().fullScreenIntent != null |
| 415 | && (!shouldHeadsUp(entry) |
| 416 | || mStatusBarStateController.getState() == StatusBarState.KEYGUARD); |
| 417 | } |
| 418 | |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 419 | /** A component which can suppress heads-up notifications due to the overall state of the UI. */ |
| 420 | public interface HeadsUpSuppressor { |
| 421 | /** |
| 422 | * Returns false if the provided notification is ineligible for heads-up according to this |
| 423 | * component. |
| 424 | * |
| 425 | * @param entry entry of the notification that might be heads upped |
| 426 | * @param sbn notification that might be heads upped |
| 427 | * @return false if the notification can not be heads upped |
| 428 | */ |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 429 | boolean canHeadsUp(NotificationEntry entry, StatusBarNotification sbn); |
Gus Prevas | ec9e1f0 | 2018-12-18 15:28:12 -0500 | [diff] [blame] | 430 | |
| 431 | } |
| 432 | |
| 433 | } |