Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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.collection; |
| 18 | |
| 19 | import static android.app.Notification.CATEGORY_ALARM; |
| 20 | import static android.app.Notification.CATEGORY_CALL; |
| 21 | import static android.app.Notification.CATEGORY_EVENT; |
| 22 | import static android.app.Notification.CATEGORY_MESSAGE; |
| 23 | import static android.app.Notification.CATEGORY_REMINDER; |
Mady Mellor | fc02cc3 | 2019-04-01 14:47:55 -0700 | [diff] [blame] | 24 | import static android.app.Notification.FLAG_BUBBLE; |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 25 | import static android.app.Notification.FLAG_FOREGROUND_SERVICE; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 26 | import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT; |
Mady Mellor | df48d0a | 2019-06-25 18:26:46 -0700 | [diff] [blame] | 27 | import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_BADGE; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 28 | import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT; |
| 29 | import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST; |
| 30 | import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK; |
| 31 | import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_STATUS_BAR; |
| 32 | |
Ned Burns | 4258d70 | 2020-01-08 19:58:57 -0500 | [diff] [blame] | 33 | import static com.android.systemui.statusbar.notification.collection.NotifCollection.REASON_NOT_CANCELED; |
Steve Elliott | 981cca1 | 2020-05-14 11:59:49 -0400 | [diff] [blame] | 34 | import static com.android.systemui.statusbar.notification.stack.NotificationSectionsManagerKt.BUCKET_ALERTING; |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 35 | |
Ned Burns | 4258d70 | 2020-01-08 19:58:57 -0500 | [diff] [blame] | 36 | import static java.util.Objects.requireNonNull; |
| 37 | |
Evan Laird | ccf5c5e | 2020-02-06 14:01:28 -0500 | [diff] [blame] | 38 | import android.annotation.CurrentTimeMillisLong; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 39 | import android.app.Notification; |
Julia Reynolds | 5cb8d5a | 2019-09-03 11:46:31 -0400 | [diff] [blame] | 40 | import android.app.Notification.MessagingStyle.Message; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 41 | import android.app.NotificationChannel; |
| 42 | import android.app.NotificationManager.Policy; |
| 43 | import android.app.Person; |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 44 | import android.app.RemoteInput; |
Aran Ink | 2e3cc41 | 2019-12-13 16:30:17 -0500 | [diff] [blame] | 45 | import android.app.RemoteInputHistoryItem; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 46 | import android.content.Context; |
Alex Mang | ac2e48e | 2020-02-10 16:11:13 -0800 | [diff] [blame] | 47 | import android.content.pm.ShortcutInfo; |
Aran Ink | 2e3cc41 | 2019-12-13 16:30:17 -0500 | [diff] [blame] | 48 | import android.net.Uri; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 49 | import android.os.Bundle; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 50 | import android.os.SystemClock; |
Ned Burns | ae90a9e | 2019-08-26 17:11:26 -0400 | [diff] [blame] | 51 | import android.service.notification.NotificationListenerService.Ranking; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 52 | import android.service.notification.SnoozeCriterion; |
| 53 | import android.service.notification.StatusBarNotification; |
| 54 | import android.util.ArraySet; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 55 | |
Ned Burns | 4258d70 | 2020-01-08 19:58:57 -0500 | [diff] [blame] | 56 | import androidx.annotation.NonNull; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 57 | import androidx.annotation.Nullable; |
| 58 | |
| 59 | import com.android.internal.annotations.VisibleForTesting; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 60 | import com.android.internal.util.ArrayUtils; |
| 61 | import com.android.internal.util.ContrastColorUtil; |
| 62 | import com.android.systemui.statusbar.InflationTask; |
Ned Burns | 4258d70 | 2020-01-08 19:58:57 -0500 | [diff] [blame] | 63 | import com.android.systemui.statusbar.notification.collection.NotifCollection.CancellationReason; |
Ned Burns | 77050aa | 2019-10-17 21:55:24 -0400 | [diff] [blame] | 64 | import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifFilter; |
| 65 | import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifPromoter; |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 66 | import com.android.systemui.statusbar.notification.collection.notifcollection.NotifDismissInterceptor; |
Ned Burns | 012048d | 2020-01-08 19:57:30 -0500 | [diff] [blame] | 67 | import com.android.systemui.statusbar.notification.collection.notifcollection.NotifLifetimeExtender; |
Ned Burns | d8b5154 | 2020-03-13 20:52:43 -0400 | [diff] [blame] | 68 | import com.android.systemui.statusbar.notification.icon.IconPack; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 69 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
Dave Mankoff | c0211ff | 2020-02-07 15:36:12 -0500 | [diff] [blame] | 70 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRowController; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 71 | import com.android.systemui.statusbar.notification.row.NotificationGuts; |
Steve Elliott | 981cca1 | 2020-05-14 11:59:49 -0400 | [diff] [blame] | 72 | import com.android.systemui.statusbar.notification.stack.PriorityBucket; |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 73 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 74 | |
| 75 | import java.util.ArrayList; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 76 | import java.util.List; |
| 77 | import java.util.Objects; |
| 78 | |
| 79 | /** |
| 80 | * Represents a notification that the system UI knows about |
| 81 | * |
| 82 | * Whenever the NotificationManager tells us about the existence of a new notification, we wrap it |
| 83 | * in a NotificationEntry. Thus, every notification has an associated NotificationEntry, even if |
| 84 | * that notification is never displayed to the user (for example, if it's filtered out for some |
| 85 | * reason). |
| 86 | * |
| 87 | * Entries store information about the current state of the notification. Essentially: |
| 88 | * anything that needs to persist or be modifiable even when the notification's views don't |
| 89 | * exist. Any other state should be stored on the views/view controllers themselves. |
| 90 | * |
| 91 | * At the moment, there are many things here that shouldn't be and vice-versa. Hopefully we can |
| 92 | * clean this up in the future. |
| 93 | */ |
Ned Burns | 77050aa | 2019-10-17 21:55:24 -0400 | [diff] [blame] | 94 | public final class NotificationEntry extends ListEntry { |
Ned Burns | 47c98f1 | 2019-09-06 17:12:07 -0400 | [diff] [blame] | 95 | |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 96 | private final String mKey; |
| 97 | private StatusBarNotification mSbn; |
Ned Burns | ae90a9e | 2019-08-26 17:11:26 -0400 | [diff] [blame] | 98 | private Ranking mRanking; |
Evan Laird | ccf5c5e | 2020-02-06 14:01:28 -0500 | [diff] [blame] | 99 | private long mCreationTime; |
Ned Burns | ae90a9e | 2019-08-26 17:11:26 -0400 | [diff] [blame] | 100 | |
Ned Burns | f098dbf | 2019-09-13 19:17:53 -0400 | [diff] [blame] | 101 | /* |
| 102 | * Bookkeeping members |
| 103 | */ |
| 104 | |
| 105 | /** List of lifetime extenders that are extending the lifetime of this notification. */ |
| 106 | final List<NotifLifetimeExtender> mLifetimeExtenders = new ArrayList<>(); |
| 107 | |
Beverly | a53fb0d | 2020-01-29 15:26:13 -0500 | [diff] [blame] | 108 | /** List of dismiss interceptors that are intercepting the dismissal of this notification. */ |
| 109 | final List<NotifDismissInterceptor> mDismissInterceptors = new ArrayList<>(); |
| 110 | |
Ned Burns | 4258d70 | 2020-01-08 19:58:57 -0500 | [diff] [blame] | 111 | /** |
| 112 | * If this notification was cancelled by system server, then the reason that was supplied. |
| 113 | * Uncancelled notifications always have REASON_NOT_CANCELED. Note that lifetime-extended |
| 114 | * notifications will have this set even though they are still in the active notification set. |
| 115 | */ |
| 116 | @CancellationReason int mCancellationReason = REASON_NOT_CANCELED; |
| 117 | |
Ned Burns | 4258d70 | 2020-01-08 19:58:57 -0500 | [diff] [blame] | 118 | /** @see #getDismissState() */ |
| 119 | @NonNull private DismissState mDismissState = DismissState.NOT_DISMISSED; |
Ned Burns | f098dbf | 2019-09-13 19:17:53 -0400 | [diff] [blame] | 120 | |
| 121 | /* |
| 122 | * Old members |
| 123 | * TODO: Remove every member beneath this line if possible |
| 124 | */ |
| 125 | |
Ned Burns | d8b5154 | 2020-03-13 20:52:43 -0400 | [diff] [blame] | 126 | private IconPack mIcons = IconPack.buildEmptyPack(null); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 127 | private boolean interruption; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 128 | public int targetSdk; |
| 129 | private long lastFullScreenIntentLaunchTime = NOT_LAUNCHED_YET; |
| 130 | public CharSequence remoteInputText; |
Aran Ink | 2e3cc41 | 2019-12-13 16:30:17 -0500 | [diff] [blame] | 131 | public String remoteInputMimeType; |
| 132 | public Uri remoteInputUri; |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 133 | private Notification.BubbleMetadata mBubbleMetadata; |
Julia Reynolds | 138111f | 2020-02-26 11:17:39 -0500 | [diff] [blame] | 134 | private ShortcutInfo mShortcutInfo; |
Milo Sredkov | 13d8811 | 2019-02-01 12:23:24 +0000 | [diff] [blame] | 135 | |
| 136 | /** |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 137 | * If {@link RemoteInput#getEditChoicesBeforeSending} is enabled, and the user is |
Milo Sredkov | 13d8811 | 2019-02-01 12:23:24 +0000 | [diff] [blame] | 138 | * currently editing a choice (smart reply), then this field contains the information about the |
| 139 | * suggestion being edited. Otherwise <code>null</code>. |
| 140 | */ |
| 141 | public EditedSuggestionInfo editedSuggestionInfo; |
| 142 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 143 | private ExpandableNotificationRow row; // the outer expanded view |
Dave Mankoff | c0211ff | 2020-02-07 15:36:12 -0500 | [diff] [blame] | 144 | private ExpandableNotificationRowController mRowController; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 145 | |
| 146 | private int mCachedContrastColor = COLOR_INVALID; |
| 147 | private int mCachedContrastColorIsFor = COLOR_INVALID; |
| 148 | private InflationTask mRunningTask = null; |
| 149 | private Throwable mDebugThrowable; |
| 150 | public CharSequence remoteInputTextWhenReset; |
| 151 | public long lastRemoteInputSent = NOT_LAUNCHED_YET; |
Beverly | 201cdd5 | 2019-10-18 14:30:46 -0400 | [diff] [blame] | 152 | public final ArraySet<Integer> mActiveAppOps = new ArraySet<>(3); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 153 | public CharSequence headsUpStatusBarText; |
| 154 | public CharSequence headsUpStatusBarTextPublic; |
| 155 | |
Beverly | 95fdfad | 2020-05-15 10:15:42 -0400 | [diff] [blame] | 156 | // indicates when this entry's view was first attached to a window |
| 157 | // this value will reset when the view is completely removed from the shade (ie: filtered out) |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 158 | private long initializationTime = -1; |
| 159 | |
| 160 | /** |
| 161 | * Whether or not this row represents a system notification. Note that if this is |
| 162 | * {@code null}, that means we were either unable to retrieve the info or have yet to |
| 163 | * retrieve the info. |
| 164 | */ |
| 165 | public Boolean mIsSystemNotification; |
| 166 | |
| 167 | /** |
| 168 | * Has the user sent a reply through this Notification. |
| 169 | */ |
| 170 | private boolean hasSentReply; |
| 171 | |
Selim Cinek | b2c5dc5 | 2019-06-24 15:46:52 -0700 | [diff] [blame] | 172 | private boolean mSensitive = true; |
Ned Burns | d8b5154 | 2020-03-13 20:52:43 -0400 | [diff] [blame] | 173 | private List<OnSensitivityChangedListener> mOnSensitivityChangedListeners = new ArrayList<>(); |
| 174 | |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 175 | private boolean mAutoHeadsUp; |
Selim Cinek | 65c96f2 | 2019-07-25 20:09:04 -0700 | [diff] [blame] | 176 | private boolean mPulseSupressed; |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 177 | private boolean mAllowFgsDismissal; |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 178 | private int mBucket = BUCKET_ALERTING; |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 179 | @Nullable private Long mPendingAnimationDuration; |
| 180 | private boolean mIsMarkedForUserTriggeredMovement; |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 181 | |
Evan Laird | ccf5c5e | 2020-02-06 14:01:28 -0500 | [diff] [blame] | 182 | /** |
| 183 | * @param sbn the StatusBarNotification from system server |
| 184 | * @param ranking also from system server |
| 185 | * @param creationTime SystemClock.uptimeMillis of when we were created |
| 186 | */ |
Ned Burns | ae90a9e | 2019-08-26 17:11:26 -0400 | [diff] [blame] | 187 | public NotificationEntry( |
Ned Burns | 636c379 | 2019-09-11 16:59:07 -0400 | [diff] [blame] | 188 | @NonNull StatusBarNotification sbn, |
Evan Laird | ccf5c5e | 2020-02-06 14:01:28 -0500 | [diff] [blame] | 189 | @NonNull Ranking ranking, |
| 190 | long creationTime) { |
| 191 | this(sbn, ranking, false, creationTime); |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | public NotificationEntry( |
| 195 | @NonNull StatusBarNotification sbn, |
| 196 | @NonNull Ranking ranking, |
Evan Laird | ccf5c5e | 2020-02-06 14:01:28 -0500 | [diff] [blame] | 197 | boolean allowFgsDismissal, |
| 198 | long creationTime |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 199 | ) { |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 200 | super(requireNonNull(requireNonNull(sbn).getKey())); |
Ned Burns | 77050aa | 2019-10-17 21:55:24 -0400 | [diff] [blame] | 201 | |
Ned Burns | 4258d70 | 2020-01-08 19:58:57 -0500 | [diff] [blame] | 202 | requireNonNull(ranking); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 203 | |
Evan Laird | ccf5c5e | 2020-02-06 14:01:28 -0500 | [diff] [blame] | 204 | mCreationTime = creationTime; |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 205 | mKey = sbn.getKey(); |
| 206 | setSbn(sbn); |
Ned Burns | 636c379 | 2019-09-11 16:59:07 -0400 | [diff] [blame] | 207 | setRanking(ranking); |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 208 | |
| 209 | mAllowFgsDismissal = allowFgsDismissal; |
Ned Burns | ae90a9e | 2019-08-26 17:11:26 -0400 | [diff] [blame] | 210 | } |
| 211 | |
Ned Burns | 77050aa | 2019-10-17 21:55:24 -0400 | [diff] [blame] | 212 | @Override |
| 213 | public NotificationEntry getRepresentativeEntry() { |
| 214 | return this; |
| 215 | } |
| 216 | |
Ned Burns | ae90a9e | 2019-08-26 17:11:26 -0400 | [diff] [blame] | 217 | /** The key for this notification. Guaranteed to be immutable and unique */ |
Selim Cinek | 5dbef2d | 2020-05-07 17:44:38 -0700 | [diff] [blame] | 218 | @NonNull public String getKey() { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 219 | return mKey; |
Ned Burns | ae90a9e | 2019-08-26 17:11:26 -0400 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | /** |
| 223 | * The StatusBarNotification that represents one half of a NotificationEntry (the other half |
| 224 | * being the Ranking). This object is swapped out whenever a notification is updated. |
| 225 | */ |
Selim Cinek | 5dbef2d | 2020-05-07 17:44:38 -0700 | [diff] [blame] | 226 | @NonNull public StatusBarNotification getSbn() { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 227 | return mSbn; |
Ned Burns | ae90a9e | 2019-08-26 17:11:26 -0400 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | /** |
| 231 | * Should only be called by NotificationEntryManager and friends. |
| 232 | * TODO: Make this package-private |
| 233 | */ |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 234 | public void setSbn(@NonNull StatusBarNotification sbn) { |
Ned Burns | 4258d70 | 2020-01-08 19:58:57 -0500 | [diff] [blame] | 235 | requireNonNull(sbn); |
| 236 | requireNonNull(sbn.getKey()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 237 | |
| 238 | if (!sbn.getKey().equals(mKey)) { |
Ned Burns | ae90a9e | 2019-08-26 17:11:26 -0400 | [diff] [blame] | 239 | throw new IllegalArgumentException("New key " + sbn.getKey() |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 240 | + " doesn't match existing key " + mKey); |
Ned Burns | ae90a9e | 2019-08-26 17:11:26 -0400 | [diff] [blame] | 241 | } |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 242 | |
Beverly | e558f1d | 2020-01-07 16:28:58 -0500 | [diff] [blame] | 243 | mSbn = sbn; |
| 244 | mBubbleMetadata = mSbn.getNotification().getBubbleMetadata(); |
Ned Burns | ae90a9e | 2019-08-26 17:11:26 -0400 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | /** |
| 248 | * The Ranking that represents one half of a NotificationEntry (the other half being the |
| 249 | * StatusBarNotification). This object is swapped out whenever a the ranking is updated (which |
| 250 | * generally occurs whenever anything changes in the notification list). |
| 251 | */ |
Evan Laird | 9afe766 | 2019-10-16 17:16:39 -0400 | [diff] [blame] | 252 | public Ranking getRanking() { |
Ned Burns | ae90a9e | 2019-08-26 17:11:26 -0400 | [diff] [blame] | 253 | return mRanking; |
| 254 | } |
| 255 | |
| 256 | /** |
Evan Laird | ccf5c5e | 2020-02-06 14:01:28 -0500 | [diff] [blame] | 257 | * A timestamp of SystemClock.uptimeMillis() of when this entry was first created, regardless |
| 258 | * of any changes to the data presented. It is set once on creation and will never change, and |
| 259 | * allows us to know exactly how long this notification has been alive for in our listener |
| 260 | * service. It is entirely unrelated to the information inside of the notification. |
| 261 | * |
| 262 | * This is different to Notification#when because it persists throughout updates, whereas |
| 263 | * system server treats every single call to notify() as a new notification and we handle |
| 264 | * updates to NotificationEntry locally. |
| 265 | */ |
| 266 | @CurrentTimeMillisLong |
| 267 | public long getCreationTime() { |
| 268 | return mCreationTime; |
| 269 | } |
| 270 | |
| 271 | /** |
Ned Burns | ae90a9e | 2019-08-26 17:11:26 -0400 | [diff] [blame] | 272 | * Should only be called by NotificationEntryManager and friends. |
| 273 | * TODO: Make this package-private |
| 274 | */ |
| 275 | public void setRanking(@NonNull Ranking ranking) { |
Ned Burns | 4258d70 | 2020-01-08 19:58:57 -0500 | [diff] [blame] | 276 | requireNonNull(ranking); |
| 277 | requireNonNull(ranking.getKey()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 278 | |
| 279 | if (!ranking.getKey().equals(mKey)) { |
Ned Burns | 636c379 | 2019-09-11 16:59:07 -0400 | [diff] [blame] | 280 | throw new IllegalArgumentException("New key " + ranking.getKey() |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 281 | + " doesn't match existing key " + mKey); |
Ned Burns | 636c379 | 2019-09-11 16:59:07 -0400 | [diff] [blame] | 282 | } |
Ned Burns | 6264472 | 2019-10-18 13:13:00 -0400 | [diff] [blame] | 283 | |
Beverly | e558f1d | 2020-01-07 16:28:58 -0500 | [diff] [blame] | 284 | mRanking = ranking; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 285 | } |
| 286 | |
Ned Burns | 6264472 | 2019-10-18 13:13:00 -0400 | [diff] [blame] | 287 | /* |
Ned Burns | 4258d70 | 2020-01-08 19:58:57 -0500 | [diff] [blame] | 288 | * Bookkeeping getters and setters |
| 289 | */ |
| 290 | |
| 291 | /** |
Ned Burns | 4258d70 | 2020-01-08 19:58:57 -0500 | [diff] [blame] | 292 | * Set if the user has dismissed this notif but we haven't yet heard back from system server to |
| 293 | * confirm the dismissal. |
| 294 | */ |
| 295 | @NonNull public DismissState getDismissState() { |
| 296 | return mDismissState; |
| 297 | } |
| 298 | |
| 299 | void setDismissState(@NonNull DismissState dismissState) { |
| 300 | mDismissState = requireNonNull(dismissState); |
| 301 | } |
| 302 | |
Ned Burns | d97aab0 | 2020-03-30 23:08:39 -0400 | [diff] [blame] | 303 | @Nullable public NotifFilter getExcludingFilter() { |
| 304 | return getAttachState().getExcludingFilter(); |
| 305 | } |
| 306 | |
| 307 | @Nullable public NotifPromoter getNotifPromoter() { |
| 308 | return getAttachState().getPromoter(); |
| 309 | } |
| 310 | |
Ned Burns | 4258d70 | 2020-01-08 19:58:57 -0500 | [diff] [blame] | 311 | /* |
Ned Burns | 6264472 | 2019-10-18 13:13:00 -0400 | [diff] [blame] | 312 | * Convenience getters for SBN and Ranking members |
| 313 | */ |
| 314 | |
Ned Burns | 296aec16 | 2019-09-04 17:30:59 -0400 | [diff] [blame] | 315 | public NotificationChannel getChannel() { |
| 316 | return mRanking.getChannel(); |
| 317 | } |
| 318 | |
Ned Burns | 60e9459 | 2019-09-06 14:47:25 -0400 | [diff] [blame] | 319 | public long getLastAudiblyAlertedMs() { |
| 320 | return mRanking.getLastAudiblyAlertedMillis(); |
| 321 | } |
| 322 | |
| 323 | public boolean isAmbient() { |
| 324 | return mRanking.isAmbient(); |
| 325 | } |
| 326 | |
| 327 | public int getImportance() { |
| 328 | return mRanking.getImportance(); |
| 329 | } |
| 330 | |
Ned Burns | 47c98f1 | 2019-09-06 17:12:07 -0400 | [diff] [blame] | 331 | public List<SnoozeCriterion> getSnoozeCriteria() { |
| 332 | return mRanking.getSnoozeCriteria(); |
| 333 | } |
| 334 | |
| 335 | public int getUserSentiment() { |
| 336 | return mRanking.getUserSentiment(); |
| 337 | } |
| 338 | |
| 339 | public int getSuppressedVisualEffects() { |
| 340 | return mRanking.getSuppressedVisualEffects(); |
| 341 | } |
| 342 | |
Ned Burns | 47c98f1 | 2019-09-06 17:12:07 -0400 | [diff] [blame] | 343 | /** @see Ranking#canBubble() */ |
| 344 | public boolean canBubble() { |
| 345 | return mRanking.canBubble(); |
| 346 | } |
| 347 | |
Ned Burns | 5a9e3520 | 2019-09-06 22:26:33 -0400 | [diff] [blame] | 348 | public @NonNull List<Notification.Action> getSmartActions() { |
| 349 | return mRanking.getSmartActions(); |
| 350 | } |
| 351 | |
| 352 | public @NonNull List<CharSequence> getSmartReplies() { |
| 353 | return mRanking.getSmartReplies(); |
| 354 | } |
| 355 | |
Ned Burns | 47c98f1 | 2019-09-06 17:12:07 -0400 | [diff] [blame] | 356 | |
Ned Burns | 6264472 | 2019-10-18 13:13:00 -0400 | [diff] [blame] | 357 | /* |
| 358 | * Old methods |
| 359 | * |
| 360 | * TODO: Remove as many of these as possible |
| 361 | */ |
| 362 | |
Ned Burns | d8b5154 | 2020-03-13 20:52:43 -0400 | [diff] [blame] | 363 | @NonNull |
| 364 | public IconPack getIcons() { |
| 365 | return mIcons; |
| 366 | } |
| 367 | |
| 368 | public void setIcons(@NonNull IconPack icons) { |
| 369 | mIcons = icons; |
| 370 | } |
| 371 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 372 | public void setInterruption() { |
| 373 | interruption = true; |
| 374 | } |
| 375 | |
| 376 | public boolean hasInterrupted() { |
| 377 | return interruption; |
| 378 | } |
| 379 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 380 | public boolean isBubble() { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 381 | return (mSbn.getNotification().flags & FLAG_BUBBLE) != 0; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 382 | } |
| 383 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 384 | /** |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 385 | * Returns the data needed for a bubble for this notification, if it exists. |
| 386 | */ |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 387 | @Nullable |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 388 | public Notification.BubbleMetadata getBubbleMetadata() { |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 389 | return mBubbleMetadata; |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * Sets bubble metadata for this notification. |
| 394 | */ |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 395 | public void setBubbleMetadata(@Nullable Notification.BubbleMetadata metadata) { |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 396 | mBubbleMetadata = metadata; |
| 397 | } |
| 398 | |
| 399 | /** |
| 400 | * Updates the {@link Notification#FLAG_BUBBLE} flag on this notification to indicate |
| 401 | * whether it is a bubble or not. If this entry is set to not bubble, or does not have |
| 402 | * the required info to bubble, the flag cannot be set to true. |
| 403 | * |
| 404 | * @param shouldBubble whether this notification should be flagged as a bubble. |
| 405 | * @return true if the value changed. |
| 406 | */ |
| 407 | public boolean setFlagBubble(boolean shouldBubble) { |
| 408 | boolean wasBubble = isBubble(); |
| 409 | if (!shouldBubble) { |
| 410 | mSbn.getNotification().flags &= ~FLAG_BUBBLE; |
| 411 | } else if (mBubbleMetadata != null && canBubble()) { |
| 412 | // wants to be bubble & can bubble, set flag |
| 413 | mSbn.getNotification().flags |= FLAG_BUBBLE; |
| 414 | } |
| 415 | return wasBubble != isBubble(); |
Mady Mellor | 9801e85 | 2019-01-22 14:50:28 -0800 | [diff] [blame] | 416 | } |
| 417 | |
Steve Elliott | 981cca1 | 2020-05-14 11:59:49 -0400 | [diff] [blame] | 418 | @PriorityBucket |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 419 | public int getBucket() { |
| 420 | return mBucket; |
| 421 | } |
| 422 | |
Steve Elliott | 981cca1 | 2020-05-14 11:59:49 -0400 | [diff] [blame] | 423 | public void setBucket(@PriorityBucket int bucket) { |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 424 | mBucket = bucket; |
| 425 | } |
| 426 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 427 | public ExpandableNotificationRow getRow() { |
| 428 | return row; |
| 429 | } |
| 430 | |
| 431 | //TODO: This will go away when we have a way to bind an entry to a row |
| 432 | public void setRow(ExpandableNotificationRow row) { |
| 433 | this.row = row; |
| 434 | } |
| 435 | |
Dave Mankoff | c0211ff | 2020-02-07 15:36:12 -0500 | [diff] [blame] | 436 | public ExpandableNotificationRowController getRowController() { |
| 437 | return mRowController; |
| 438 | } |
| 439 | |
| 440 | public void setRowController(ExpandableNotificationRowController controller) { |
| 441 | mRowController = controller; |
| 442 | } |
| 443 | |
Kevin Han | 43077f9 | 2020-02-28 12:51:53 -0800 | [diff] [blame] | 444 | /** |
| 445 | * Get the children that are actually attached to this notification's row. |
| 446 | * |
| 447 | * TODO: Seems like most callers here should probably be using |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 448 | * {@link NotificationGroupManager#getChildren} |
Kevin Han | 43077f9 | 2020-02-28 12:51:53 -0800 | [diff] [blame] | 449 | */ |
| 450 | public @Nullable List<NotificationEntry> getAttachedNotifChildren() { |
Evan Laird | ce2d1af | 2019-05-30 16:00:22 -0400 | [diff] [blame] | 451 | if (row == null) { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 452 | return null; |
| 453 | } |
| 454 | |
Kevin Han | 43077f9 | 2020-02-28 12:51:53 -0800 | [diff] [blame] | 455 | List<ExpandableNotificationRow> rowChildren = row.getAttachedChildren(); |
Evan Laird | ce2d1af | 2019-05-30 16:00:22 -0400 | [diff] [blame] | 456 | if (rowChildren == null) { |
| 457 | return null; |
| 458 | } |
| 459 | |
| 460 | ArrayList<NotificationEntry> children = new ArrayList<>(); |
| 461 | for (ExpandableNotificationRow child : rowChildren) { |
| 462 | children.add(child.getEntry()); |
| 463 | } |
| 464 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 465 | return children; |
| 466 | } |
| 467 | |
| 468 | public void notifyFullScreenIntentLaunched() { |
| 469 | setInterruption(); |
| 470 | lastFullScreenIntentLaunchTime = SystemClock.elapsedRealtime(); |
| 471 | } |
| 472 | |
| 473 | public boolean hasJustLaunchedFullScreenIntent() { |
| 474 | return SystemClock.elapsedRealtime() < lastFullScreenIntentLaunchTime + LAUNCH_COOLDOWN; |
| 475 | } |
| 476 | |
| 477 | public boolean hasJustSentRemoteInput() { |
| 478 | return SystemClock.elapsedRealtime() < lastRemoteInputSent + REMOTE_INPUT_COOLDOWN; |
| 479 | } |
| 480 | |
| 481 | public boolean hasFinishedInitialization() { |
Beverly | 95fdfad | 2020-05-15 10:15:42 -0400 | [diff] [blame] | 482 | return initializationTime != -1 |
| 483 | && SystemClock.elapsedRealtime() > initializationTime + INITIALIZATION_DELAY; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 484 | } |
| 485 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 486 | public int getContrastedColor(Context context, boolean isLowPriority, |
| 487 | int backgroundColor) { |
| 488 | int rawColor = isLowPriority ? Notification.COLOR_DEFAULT : |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 489 | mSbn.getNotification().color; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 490 | if (mCachedContrastColorIsFor == rawColor && mCachedContrastColor != COLOR_INVALID) { |
| 491 | return mCachedContrastColor; |
| 492 | } |
| 493 | final int contrasted = ContrastColorUtil.resolveContrastColor(context, rawColor, |
| 494 | backgroundColor); |
| 495 | mCachedContrastColorIsFor = rawColor; |
| 496 | mCachedContrastColor = contrasted; |
| 497 | return mCachedContrastColor; |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * Abort all existing inflation tasks |
| 502 | */ |
| 503 | public void abortTask() { |
| 504 | if (mRunningTask != null) { |
| 505 | mRunningTask.abort(); |
| 506 | mRunningTask = null; |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | public void setInflationTask(InflationTask abortableTask) { |
| 511 | // abort any existing inflation |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 512 | abortTask(); |
| 513 | mRunningTask = abortableTask; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | public void onInflationTaskFinished() { |
| 517 | mRunningTask = null; |
| 518 | } |
| 519 | |
| 520 | @VisibleForTesting |
| 521 | public InflationTask getRunningTask() { |
| 522 | return mRunningTask; |
| 523 | } |
| 524 | |
| 525 | /** |
| 526 | * Set a throwable that is used for debugging |
| 527 | * |
| 528 | * @param debugThrowable the throwable to save |
| 529 | */ |
| 530 | public void setDebugThrowable(Throwable debugThrowable) { |
| 531 | mDebugThrowable = debugThrowable; |
| 532 | } |
| 533 | |
| 534 | public Throwable getDebugThrowable() { |
| 535 | return mDebugThrowable; |
| 536 | } |
| 537 | |
| 538 | public void onRemoteInputInserted() { |
| 539 | lastRemoteInputSent = NOT_LAUNCHED_YET; |
| 540 | remoteInputTextWhenReset = null; |
| 541 | } |
| 542 | |
| 543 | public void setHasSentReply() { |
| 544 | hasSentReply = true; |
| 545 | } |
| 546 | |
| 547 | public boolean isLastMessageFromReply() { |
| 548 | if (!hasSentReply) { |
| 549 | return false; |
| 550 | } |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 551 | Bundle extras = mSbn.getNotification().extras; |
Aran Ink | 2e3cc41 | 2019-12-13 16:30:17 -0500 | [diff] [blame] | 552 | RemoteInputHistoryItem[] replyTexts = (RemoteInputHistoryItem[]) extras.getParcelableArray( |
| 553 | Notification.EXTRA_REMOTE_INPUT_HISTORY_ITEMS); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 554 | if (!ArrayUtils.isEmpty(replyTexts)) { |
| 555 | return true; |
| 556 | } |
Julia Reynolds | 5cb8d5a | 2019-09-03 11:46:31 -0400 | [diff] [blame] | 557 | List<Message> messages = Message.getMessagesFromBundleArray( |
| 558 | extras.getParcelableArray(Notification.EXTRA_MESSAGES)); |
| 559 | if (messages != null && !messages.isEmpty()) { |
| 560 | Message lastMessage = messages.get(messages.size() -1); |
| 561 | |
| 562 | if (lastMessage != null) { |
| 563 | Person senderPerson = lastMessage.getSenderPerson(); |
| 564 | if (senderPerson == null) { |
| 565 | return true; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 566 | } |
Julia Reynolds | 5cb8d5a | 2019-09-03 11:46:31 -0400 | [diff] [blame] | 567 | Person user = extras.getParcelable(Notification.EXTRA_MESSAGING_PERSON); |
| 568 | return Objects.equals(user, senderPerson); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 569 | } |
| 570 | } |
| 571 | return false; |
| 572 | } |
| 573 | |
Beverly | 95fdfad | 2020-05-15 10:15:42 -0400 | [diff] [blame] | 574 | public void resetInitializationTime() { |
| 575 | initializationTime = -1; |
| 576 | } |
| 577 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 578 | public void setInitializationTime(long time) { |
| 579 | if (initializationTime == -1) { |
| 580 | initializationTime = time; |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | public void sendAccessibilityEvent(int eventType) { |
| 585 | if (row != null) { |
| 586 | row.sendAccessibilityEvent(eventType); |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | /** |
| 591 | * Used by NotificationMediaManager to determine... things |
| 592 | * @return {@code true} if we are a media notification |
| 593 | */ |
| 594 | public boolean isMediaNotification() { |
| 595 | if (row == null) return false; |
| 596 | |
| 597 | return row.isMediaRow(); |
| 598 | } |
| 599 | |
| 600 | /** |
| 601 | * We are a top level child if our parent is the list of notifications duh |
| 602 | * @return {@code true} if we're a top level notification |
| 603 | */ |
| 604 | public boolean isTopLevelChild() { |
| 605 | return row != null && row.isTopLevelChild(); |
| 606 | } |
| 607 | |
| 608 | public void resetUserExpansion() { |
| 609 | if (row != null) row.resetUserExpansion(); |
| 610 | } |
| 611 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 612 | public boolean rowExists() { |
| 613 | return row != null; |
| 614 | } |
| 615 | |
| 616 | public boolean isRowDismissed() { |
| 617 | return row != null && row.isDismissed(); |
| 618 | } |
| 619 | |
| 620 | public boolean isRowRemoved() { |
| 621 | return row != null && row.isRemoved(); |
| 622 | } |
| 623 | |
| 624 | /** |
| 625 | * @return {@code true} if the row is null or removed |
| 626 | */ |
| 627 | public boolean isRemoved() { |
| 628 | //TODO: recycling invalidates this |
| 629 | return row == null || row.isRemoved(); |
| 630 | } |
| 631 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 632 | public boolean isRowPinned() { |
| 633 | return row != null && row.isPinned(); |
| 634 | } |
| 635 | |
Selim Cinek | 94d0be8 | 2020-04-06 19:20:47 -0700 | [diff] [blame] | 636 | /** |
| 637 | * Is this entry pinned and was expanded while doing so |
| 638 | */ |
| 639 | public boolean isPinnedAndExpanded() { |
| 640 | return row != null && row.isPinnedAndExpanded(); |
| 641 | } |
| 642 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 643 | public void setRowPinned(boolean pinned) { |
| 644 | if (row != null) row.setPinned(pinned); |
| 645 | } |
| 646 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 647 | public boolean isRowHeadsUp() { |
| 648 | return row != null && row.isHeadsUp(); |
| 649 | } |
| 650 | |
Selim Cinek | b57dd8a | 2019-06-14 12:27:58 -0700 | [diff] [blame] | 651 | public boolean showingPulsing() { |
| 652 | return row != null && row.showingPulsing(); |
| 653 | } |
| 654 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 655 | public void setHeadsUp(boolean shouldHeadsUp) { |
| 656 | if (row != null) row.setHeadsUp(shouldHeadsUp); |
| 657 | } |
| 658 | |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 659 | public void setHeadsUpAnimatingAway(boolean animatingAway) { |
| 660 | if (row != null) row.setHeadsUpAnimatingAway(animatingAway); |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 661 | } |
| 662 | |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 663 | /** |
| 664 | * Set that this notification was automatically heads upped. This happens for example when |
| 665 | * the user bypasses the lockscreen and media is playing. |
| 666 | */ |
| 667 | public void setAutoHeadsUp(boolean autoHeadsUp) { |
| 668 | mAutoHeadsUp = autoHeadsUp; |
| 669 | } |
| 670 | |
| 671 | /** |
| 672 | * @return if this notification was automatically heads upped. This happens for example when |
| 673 | * * the user bypasses the lockscreen and media is playing. |
| 674 | */ |
| 675 | public boolean isAutoHeadsUp() { |
| 676 | return mAutoHeadsUp; |
| 677 | } |
Selim Cinek | 459aee3 | 2019-02-20 11:18:56 -0800 | [diff] [blame] | 678 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 679 | public boolean mustStayOnScreen() { |
| 680 | return row != null && row.mustStayOnScreen(); |
| 681 | } |
| 682 | |
| 683 | public void setHeadsUpIsVisible() { |
| 684 | if (row != null) row.setHeadsUpIsVisible(); |
| 685 | } |
| 686 | |
| 687 | //TODO: i'm imagining a world where this isn't just the row, but I could be rwong |
| 688 | public ExpandableNotificationRow getHeadsUpAnimationView() { |
| 689 | return row; |
| 690 | } |
| 691 | |
| 692 | public void setUserLocked(boolean userLocked) { |
| 693 | if (row != null) row.setUserLocked(userLocked); |
| 694 | } |
| 695 | |
| 696 | public void setUserExpanded(boolean userExpanded, boolean allowChildExpansion) { |
| 697 | if (row != null) row.setUserExpanded(userExpanded, allowChildExpansion); |
| 698 | } |
| 699 | |
| 700 | public void setGroupExpansionChanging(boolean changing) { |
| 701 | if (row != null) row.setGroupExpansionChanging(changing); |
| 702 | } |
| 703 | |
| 704 | public void notifyHeightChanged(boolean needsAnimation) { |
| 705 | if (row != null) row.notifyHeightChanged(needsAnimation); |
| 706 | } |
| 707 | |
| 708 | public void closeRemoteInput() { |
| 709 | if (row != null) row.closeRemoteInput(); |
| 710 | } |
| 711 | |
| 712 | public boolean areChildrenExpanded() { |
| 713 | return row != null && row.areChildrenExpanded(); |
| 714 | } |
| 715 | |
| 716 | public boolean keepInParent() { |
| 717 | return row != null && row.keepInParent(); |
| 718 | } |
| 719 | |
| 720 | //TODO: probably less confusing to say "is group fully visible" |
| 721 | public boolean isGroupNotFullyVisible() { |
| 722 | return row == null || row.isGroupNotFullyVisible(); |
| 723 | } |
| 724 | |
| 725 | public NotificationGuts getGuts() { |
| 726 | if (row != null) return row.getGuts(); |
| 727 | return null; |
| 728 | } |
| 729 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 730 | public void removeRow() { |
| 731 | if (row != null) row.setRemoved(); |
| 732 | } |
| 733 | |
| 734 | public boolean isSummaryWithChildren() { |
| 735 | return row != null && row.isSummaryWithChildren(); |
| 736 | } |
| 737 | |
| 738 | public void setKeepInParent(boolean keep) { |
| 739 | if (row != null) row.setKeepInParent(keep); |
| 740 | } |
| 741 | |
| 742 | public void onDensityOrFontScaleChanged() { |
| 743 | if (row != null) row.onDensityOrFontScaleChanged(); |
| 744 | } |
| 745 | |
| 746 | public boolean areGutsExposed() { |
| 747 | return row != null && row.getGuts() != null && row.getGuts().isExposed(); |
| 748 | } |
| 749 | |
| 750 | public boolean isChildInGroup() { |
Selim Cinek | ba069ae | 2020-04-01 19:45:16 -0700 | [diff] [blame] | 751 | return row != null && row.isChildInGroup(); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 752 | } |
| 753 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 754 | /** |
| 755 | * @return Can the underlying notification be cleared? This can be different from whether the |
| 756 | * notification can be dismissed in case notifications are sensitive on the lockscreen. |
| 757 | * @see #canViewBeDismissed() |
| 758 | */ |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 759 | // TOOD: This logic doesn't belong on NotificationEntry. It should be moved to the |
| 760 | // ForegroundsServiceDismissalFeatureController or some other controller that can be added |
| 761 | // as a dependency to any class that needs to answer this question. |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 762 | public boolean isClearable() { |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 763 | if (!isDismissable()) { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 764 | return false; |
| 765 | } |
Evan Laird | ce2d1af | 2019-05-30 16:00:22 -0400 | [diff] [blame] | 766 | |
Kevin Han | 43077f9 | 2020-02-28 12:51:53 -0800 | [diff] [blame] | 767 | List<NotificationEntry> children = getAttachedNotifChildren(); |
Evan Laird | ce2d1af | 2019-05-30 16:00:22 -0400 | [diff] [blame] | 768 | if (children != null && children.size() > 0) { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 769 | for (int i = 0; i < children.size(); i++) { |
| 770 | NotificationEntry child = children.get(i); |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 771 | if (!child.isDismissable()) { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 772 | return false; |
| 773 | } |
| 774 | } |
| 775 | } |
| 776 | return true; |
| 777 | } |
| 778 | |
Evan Laird | 0437366 | 2020-01-24 17:37:39 -0500 | [diff] [blame] | 779 | /** |
| 780 | * Notifications might have any combination of flags: |
| 781 | * - FLAG_ONGOING_EVENT |
| 782 | * - FLAG_NO_CLEAR |
| 783 | * - FLAG_FOREGROUND_SERVICE |
| 784 | * |
| 785 | * We want to allow dismissal of notifications that represent foreground services, which may |
| 786 | * have all 3 flags set. If we only find NO_CLEAR though, we don't want to allow dismissal |
| 787 | */ |
| 788 | private boolean isDismissable() { |
| 789 | boolean ongoing = ((mSbn.getNotification().flags & Notification.FLAG_ONGOING_EVENT) != 0); |
| 790 | boolean noclear = ((mSbn.getNotification().flags & Notification.FLAG_NO_CLEAR) != 0); |
| 791 | boolean fgs = ((mSbn.getNotification().flags & FLAG_FOREGROUND_SERVICE) != 0); |
| 792 | |
| 793 | if (mAllowFgsDismissal) { |
| 794 | if (noclear && !ongoing && !fgs) { |
| 795 | return false; |
| 796 | } |
| 797 | return true; |
| 798 | } else { |
| 799 | return mSbn.isClearable(); |
| 800 | } |
| 801 | |
| 802 | } |
| 803 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 804 | public boolean canViewBeDismissed() { |
| 805 | if (row == null) return true; |
| 806 | return row.canViewBeDismissed(); |
| 807 | } |
| 808 | |
| 809 | @VisibleForTesting |
| 810 | boolean isExemptFromDndVisualSuppression() { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 811 | if (isNotificationBlockedByPolicy(mSbn.getNotification())) { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 812 | return false; |
| 813 | } |
| 814 | |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 815 | if ((mSbn.getNotification().flags |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 816 | & FLAG_FOREGROUND_SERVICE) != 0) { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 817 | return true; |
| 818 | } |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 819 | if (mSbn.getNotification().isMediaNotification()) { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 820 | return true; |
| 821 | } |
| 822 | if (mIsSystemNotification != null && mIsSystemNotification) { |
| 823 | return true; |
| 824 | } |
| 825 | return false; |
| 826 | } |
| 827 | |
| 828 | private boolean shouldSuppressVisualEffect(int effect) { |
| 829 | if (isExemptFromDndVisualSuppression()) { |
| 830 | return false; |
| 831 | } |
Ned Burns | 47c98f1 | 2019-09-06 17:12:07 -0400 | [diff] [blame] | 832 | return (getSuppressedVisualEffects() & effect) != 0; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | /** |
| 836 | * Returns whether {@link Policy#SUPPRESSED_EFFECT_FULL_SCREEN_INTENT} |
| 837 | * is set for this entry. |
| 838 | */ |
| 839 | public boolean shouldSuppressFullScreenIntent() { |
| 840 | return shouldSuppressVisualEffect(SUPPRESSED_EFFECT_FULL_SCREEN_INTENT); |
| 841 | } |
| 842 | |
| 843 | /** |
| 844 | * Returns whether {@link Policy#SUPPRESSED_EFFECT_PEEK} |
| 845 | * is set for this entry. |
| 846 | */ |
| 847 | public boolean shouldSuppressPeek() { |
| 848 | return shouldSuppressVisualEffect(SUPPRESSED_EFFECT_PEEK); |
| 849 | } |
| 850 | |
| 851 | /** |
| 852 | * Returns whether {@link Policy#SUPPRESSED_EFFECT_STATUS_BAR} |
| 853 | * is set for this entry. |
| 854 | */ |
| 855 | public boolean shouldSuppressStatusBar() { |
| 856 | return shouldSuppressVisualEffect(SUPPRESSED_EFFECT_STATUS_BAR); |
| 857 | } |
| 858 | |
| 859 | /** |
| 860 | * Returns whether {@link Policy#SUPPRESSED_EFFECT_AMBIENT} |
| 861 | * is set for this entry. |
| 862 | */ |
| 863 | public boolean shouldSuppressAmbient() { |
| 864 | return shouldSuppressVisualEffect(SUPPRESSED_EFFECT_AMBIENT); |
| 865 | } |
| 866 | |
| 867 | /** |
| 868 | * Returns whether {@link Policy#SUPPRESSED_EFFECT_NOTIFICATION_LIST} |
| 869 | * is set for this entry. |
| 870 | */ |
| 871 | public boolean shouldSuppressNotificationList() { |
| 872 | return shouldSuppressVisualEffect(SUPPRESSED_EFFECT_NOTIFICATION_LIST); |
| 873 | } |
| 874 | |
Mady Mellor | df48d0a | 2019-06-25 18:26:46 -0700 | [diff] [blame] | 875 | |
| 876 | /** |
| 877 | * Returns whether {@link Policy#SUPPRESSED_EFFECT_BADGE} |
| 878 | * is set for this entry. This badge is not an app badge, but rather an indicator of "unseen" |
| 879 | * content. Typically this is referred to as a "dot" internally in Launcher & SysUI code. |
| 880 | */ |
| 881 | public boolean shouldSuppressNotificationDot() { |
| 882 | return shouldSuppressVisualEffect(SUPPRESSED_EFFECT_BADGE); |
| 883 | } |
| 884 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 885 | /** |
| 886 | * Categories that are explicitly called out on DND settings screens are always blocked, if |
| 887 | * DND has flagged them, even if they are foreground or system notifications that might |
| 888 | * otherwise visually bypass DND. |
| 889 | */ |
| 890 | private static boolean isNotificationBlockedByPolicy(Notification n) { |
| 891 | return isCategory(CATEGORY_CALL, n) |
| 892 | || isCategory(CATEGORY_MESSAGE, n) |
| 893 | || isCategory(CATEGORY_ALARM, n) |
| 894 | || isCategory(CATEGORY_EVENT, n) |
| 895 | || isCategory(CATEGORY_REMINDER, n); |
| 896 | } |
| 897 | |
| 898 | private static boolean isCategory(String category, Notification n) { |
| 899 | return Objects.equals(n.category, category); |
| 900 | } |
Milo Sredkov | 13d8811 | 2019-02-01 12:23:24 +0000 | [diff] [blame] | 901 | |
Selim Cinek | b2c5dc5 | 2019-06-24 15:46:52 -0700 | [diff] [blame] | 902 | /** |
Beverly | 8c80e0c | 2019-12-03 11:25:39 -0500 | [diff] [blame] | 903 | * Whether or not this row represents a system notification. Note that if this is |
| 904 | * {@code null}, that means we were either unable to retrieve the info or have yet to |
| 905 | * retrieve the info. |
| 906 | */ |
| 907 | public Boolean isSystemNotification() { |
| 908 | return mIsSystemNotification; |
| 909 | } |
| 910 | |
| 911 | /** |
Selim Cinek | b2c5dc5 | 2019-06-24 15:46:52 -0700 | [diff] [blame] | 912 | * Set this notification to be sensitive. |
| 913 | * |
| 914 | * @param sensitive true if the content of this notification is sensitive right now |
| 915 | * @param deviceSensitive true if the device in general is sensitive right now |
| 916 | */ |
| 917 | public void setSensitive(boolean sensitive, boolean deviceSensitive) { |
| 918 | getRow().setSensitive(sensitive, deviceSensitive); |
| 919 | if (sensitive != mSensitive) { |
| 920 | mSensitive = sensitive; |
Ned Burns | d8b5154 | 2020-03-13 20:52:43 -0400 | [diff] [blame] | 921 | for (int i = 0; i < mOnSensitivityChangedListeners.size(); i++) { |
| 922 | mOnSensitivityChangedListeners.get(i).onSensitivityChanged(this); |
Selim Cinek | b2c5dc5 | 2019-06-24 15:46:52 -0700 | [diff] [blame] | 923 | } |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | public boolean isSensitive() { |
| 928 | return mSensitive; |
| 929 | } |
| 930 | |
Ned Burns | d8b5154 | 2020-03-13 20:52:43 -0400 | [diff] [blame] | 931 | /** Add a listener to be notified when the entry's sensitivity changes. */ |
| 932 | public void addOnSensitivityChangedListener(OnSensitivityChangedListener listener) { |
| 933 | mOnSensitivityChangedListeners.add(listener); |
| 934 | } |
| 935 | |
| 936 | /** Remove a listener that was registered above. */ |
| 937 | public void removeOnSensitivityChangedListener(OnSensitivityChangedListener listener) { |
| 938 | mOnSensitivityChangedListeners.remove(listener); |
Selim Cinek | b2c5dc5 | 2019-06-24 15:46:52 -0700 | [diff] [blame] | 939 | } |
| 940 | |
Selim Cinek | 65c96f2 | 2019-07-25 20:09:04 -0700 | [diff] [blame] | 941 | public boolean isPulseSuppressed() { |
| 942 | return mPulseSupressed; |
| 943 | } |
| 944 | |
| 945 | public void setPulseSuppressed(boolean suppressed) { |
| 946 | mPulseSupressed = suppressed; |
| 947 | } |
| 948 | |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 949 | /** Whether or not this entry has been marked for a user-triggered movement. */ |
| 950 | public boolean isMarkedForUserTriggeredMovement() { |
| 951 | return mIsMarkedForUserTriggeredMovement; |
| 952 | } |
| 953 | |
| 954 | /** |
| 955 | * Mark this entry for movement triggered by a user action (ex: changing the priorirty of a |
| 956 | * conversation). This can then be used for custom animations. |
| 957 | */ |
| 958 | public void markForUserTriggeredMovement(boolean marked) { |
| 959 | mIsMarkedForUserTriggeredMovement = marked; |
| 960 | } |
| 961 | |
Milo Sredkov | 13d8811 | 2019-02-01 12:23:24 +0000 | [diff] [blame] | 962 | /** Information about a suggestion that is being edited. */ |
| 963 | public static class EditedSuggestionInfo { |
| 964 | |
| 965 | /** |
| 966 | * The value of the suggestion (before any user edits). |
| 967 | */ |
| 968 | public final CharSequence originalText; |
| 969 | |
| 970 | /** |
| 971 | * The index of the suggestion that is being edited. |
| 972 | */ |
| 973 | public final int index; |
| 974 | |
| 975 | public EditedSuggestionInfo(CharSequence originalText, int index) { |
| 976 | this.originalText = originalText; |
| 977 | this.index = index; |
| 978 | } |
| 979 | } |
Ned Burns | 9ebf382 | 2019-10-18 13:31:20 -0400 | [diff] [blame] | 980 | |
Ned Burns | d8b5154 | 2020-03-13 20:52:43 -0400 | [diff] [blame] | 981 | /** Listener interface for {@link #addOnSensitivityChangedListener} */ |
| 982 | public interface OnSensitivityChangedListener { |
| 983 | /** Called when the sensitivity changes */ |
| 984 | void onSensitivityChanged(@NonNull NotificationEntry entry); |
| 985 | } |
| 986 | |
Ned Burns | 4258d70 | 2020-01-08 19:58:57 -0500 | [diff] [blame] | 987 | /** @see #getDismissState() */ |
| 988 | public enum DismissState { |
| 989 | /** User has not dismissed this notif or its parent */ |
| 990 | NOT_DISMISSED, |
| 991 | /** User has dismissed this notif specifically */ |
| 992 | DISMISSED, |
| 993 | /** User has dismissed this notif's parent (which implicitly dismisses this one as well) */ |
| 994 | PARENT_DISMISSED, |
| 995 | } |
| 996 | |
Ned Burns | 9ebf382 | 2019-10-18 13:31:20 -0400 | [diff] [blame] | 997 | private static final long LAUNCH_COOLDOWN = 2000; |
| 998 | private static final long REMOTE_INPUT_COOLDOWN = 500; |
| 999 | private static final long INITIALIZATION_DELAY = 400; |
| 1000 | private static final long NOT_LAUNCHED_YET = -LAUNCH_COOLDOWN; |
| 1001 | private static final int COLOR_INVALID = 1; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1002 | } |