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