Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | package com.android.server.notification; |
| 17 | |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 18 | import static android.app.NotificationChannel.USER_LOCKED_IMPORTANCE; |
Julia Reynolds | 8576991 | 2016-10-25 09:08:57 -0400 | [diff] [blame] | 19 | import static android.app.NotificationManager.IMPORTANCE_DEFAULT; |
| 20 | import static android.app.NotificationManager.IMPORTANCE_HIGH; |
| 21 | import static android.app.NotificationManager.IMPORTANCE_LOW; |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 22 | import static android.app.NotificationManager.IMPORTANCE_MIN; |
| 23 | import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED; |
Julia Reynolds | 27c0a96 | 2018-12-10 12:37:28 -0500 | [diff] [blame] | 24 | import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEUTRAL; |
| 25 | import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_POSITIVE; |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 26 | |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 27 | import android.annotation.Nullable; |
| 28 | import android.app.ActivityManager; |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 29 | import android.app.IActivityManager; |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 30 | import android.app.Notification; |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 31 | import android.app.NotificationChannel; |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 32 | import android.content.ContentProvider; |
| 33 | import android.content.ContentResolver; |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 34 | import android.content.Context; |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 35 | import android.content.Intent; |
Tony Mantler | ab55f0f | 2017-06-16 10:50:00 -0700 | [diff] [blame] | 36 | import android.content.pm.PackageManager; |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 37 | import android.content.pm.PackageManagerInternal; |
Julia Reynolds | d61bdf1 | 2020-02-25 12:25:07 -0500 | [diff] [blame] | 38 | import android.content.pm.ShortcutInfo; |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 39 | import android.graphics.Bitmap; |
John Spurlock | bfa5dc4 | 2014-07-28 23:30:45 -0400 | [diff] [blame] | 40 | import android.media.AudioAttributes; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 41 | import android.media.AudioSystem; |
Chris Wren | 9eb5e10 | 2017-01-26 13:15:06 -0500 | [diff] [blame] | 42 | import android.metrics.LogMaker; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 43 | import android.net.Uri; |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 44 | import android.os.Binder; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 45 | import android.os.Build; |
Julia Reynolds | eb3dca7 | 2017-07-11 10:39:58 -0400 | [diff] [blame] | 46 | import android.os.Bundle; |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 47 | import android.os.IBinder; |
Chris Wren | da4bd20 | 2014-09-04 15:53:52 -0400 | [diff] [blame] | 48 | import android.os.UserHandle; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 49 | import android.provider.Settings; |
Julia Reynolds | eb3dca7 | 2017-07-11 10:39:58 -0400 | [diff] [blame] | 50 | import android.service.notification.Adjustment; |
Julia Reynolds | 5d25ee7 | 2015-11-20 15:38:20 -0500 | [diff] [blame] | 51 | import android.service.notification.NotificationListenerService; |
Julia Reynolds | c9842c1 | 2017-02-07 12:46:41 -0500 | [diff] [blame] | 52 | import android.service.notification.NotificationRecordProto; |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 53 | import android.service.notification.NotificationStats; |
Julia Reynolds | 22f02b3 | 2016-12-01 15:05:13 -0500 | [diff] [blame] | 54 | import android.service.notification.SnoozeCriterion; |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 55 | import android.service.notification.StatusBarNotification; |
Julia Reynolds | 4b82f6d | 2017-01-04 10:47:41 -0500 | [diff] [blame] | 56 | import android.text.TextUtils; |
Julia Reynolds | e0d711f | 2017-09-01 08:50:47 -0400 | [diff] [blame] | 57 | import android.util.ArraySet; |
Danning Chen | 10326cf | 2020-01-16 13:29:13 -0800 | [diff] [blame] | 58 | import android.util.FeatureFlagUtils; |
Julia Reynolds | f0f629f | 2016-02-25 09:34:04 -0500 | [diff] [blame] | 59 | import android.util.Log; |
Julia Reynolds | 2a12874 | 2016-11-28 14:29:25 -0500 | [diff] [blame] | 60 | import android.util.TimeUtils; |
Julia Reynolds | c9842c1 | 2017-02-07 12:46:41 -0500 | [diff] [blame] | 61 | import android.util.proto.ProtoOutputStream; |
Dan Sandler | 0a2308e | 2017-05-30 19:50:42 -0400 | [diff] [blame] | 62 | import android.widget.RemoteViews; |
John Spurlock | bfa5dc4 | 2014-07-28 23:30:45 -0400 | [diff] [blame] | 63 | |
Chris Wren | 1031c97 | 2014-07-23 13:11:45 +0000 | [diff] [blame] | 64 | import com.android.internal.annotations.VisibleForTesting; |
Chris Wren | 9eb5e10 | 2017-01-26 13:15:06 -0500 | [diff] [blame] | 65 | import com.android.internal.logging.MetricsLogger; |
| 66 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Chris Wren | 6650e57 | 2015-05-15 17:19:25 -0400 | [diff] [blame] | 67 | import com.android.server.EventLogTags; |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 68 | import com.android.server.LocalServices; |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 69 | import com.android.server.uri.UriGrantsManagerInternal; |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 70 | |
| 71 | import java.io.PrintWriter; |
| 72 | import java.lang.reflect.Array; |
Julia Reynolds | 22f02b3 | 2016-12-01 15:05:13 -0500 | [diff] [blame] | 73 | import java.util.ArrayList; |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 74 | import java.util.Arrays; |
Julia Reynolds | eb3dca7 | 2017-07-11 10:39:58 -0400 | [diff] [blame] | 75 | import java.util.List; |
John Spurlock | 312d1d0 | 2014-07-08 10:24:57 -0400 | [diff] [blame] | 76 | import java.util.Objects; |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 77 | |
| 78 | /** |
| 79 | * Holds data about notifications that should not be shared with the |
| 80 | * {@link android.service.notification.NotificationListenerService}s. |
| 81 | * |
| 82 | * <p>These objects should not be mutated unless the code is synchronized |
Julia Reynolds | 88860ce | 2017-06-01 16:55:49 -0400 | [diff] [blame] | 83 | * on {@link NotificationManagerService#mNotificationLock}, and any |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 84 | * modification should be followed by a sorting of that list.</p> |
| 85 | * |
| 86 | * <p>Is sortable by {@link NotificationComparator}.</p> |
| 87 | * |
| 88 | * {@hide} |
| 89 | */ |
| 90 | public final class NotificationRecord { |
Julia Reynolds | f0f629f | 2016-02-25 09:34:04 -0500 | [diff] [blame] | 91 | static final String TAG = "NotificationRecord"; |
| 92 | static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG); |
Julia Reynolds | d673007 | 2019-01-04 12:52:52 -0500 | [diff] [blame] | 93 | // the period after which a notification is updated where it can make sound |
| 94 | private static final int MAX_SOUND_DELAY_MS = 2000; |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 95 | private final StatusBarNotification sbn; |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 96 | IActivityManager mAm; |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 97 | UriGrantsManagerInternal mUgmInternal; |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 98 | final int mTargetSdkVersion; |
Christoph Studer | 365e4c3 | 2014-09-18 20:35:36 +0200 | [diff] [blame] | 99 | final int mOriginalFlags; |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 100 | private final Context mContext; |
Christoph Studer | 365e4c3 | 2014-09-18 20:35:36 +0200 | [diff] [blame] | 101 | |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 102 | NotificationUsageStats.SingleNotificationStats stats; |
| 103 | boolean isCanceled; |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 104 | IBinder permissionOwner; |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 105 | |
| 106 | // These members are used by NotificationSignalExtractors |
| 107 | // to communicate with the ranking module. |
| 108 | private float mContactAffinity; |
| 109 | private boolean mRecentlyIntrusive; |
Julia Reynolds | 309d1c8 | 2017-05-03 16:00:20 -0400 | [diff] [blame] | 110 | private long mLastIntrusive; |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 111 | |
| 112 | // is this notification currently being intercepted by Zen Mode? |
| 113 | private boolean mIntercept; |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 114 | |
Beverly | 5a20a5e | 2018-03-06 15:02:44 -0500 | [diff] [blame] | 115 | // is this notification hidden since the app pkg is suspended? |
| 116 | private boolean mHidden; |
| 117 | |
Christoph Studer | 52b7a5a | 2014-06-06 16:09:15 +0200 | [diff] [blame] | 118 | // The timestamp used for ranking. |
| 119 | private long mRankingTimeMs; |
| 120 | |
Chris Wren | 640e387 | 2015-04-21 13:23:18 -0400 | [diff] [blame] | 121 | // The first post time, stable across updates. |
| 122 | private long mCreationTimeMs; |
| 123 | |
Chris Wren | 6650e57 | 2015-05-15 17:19:25 -0400 | [diff] [blame] | 124 | // The most recent visibility event. |
| 125 | private long mVisibleSinceMs; |
| 126 | |
| 127 | // The most recent update time, or the creation time if no updates. |
Julia Reynolds | d673007 | 2019-01-04 12:52:52 -0500 | [diff] [blame] | 128 | @VisibleForTesting |
| 129 | final long mUpdateTimeMs; |
Chris Wren | 6650e57 | 2015-05-15 17:19:25 -0400 | [diff] [blame] | 130 | |
Julia Reynolds | d6ba35c | 2018-06-18 09:29:19 -0400 | [diff] [blame] | 131 | // The most recent interruption time, or the creation time if no updates. Differs from the |
| 132 | // above value because updates are filtered based on whether they actually interrupted the |
| 133 | // user |
| 134 | private long mInterruptionTimeMs; |
| 135 | |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 136 | // The most recent time the notification made noise or buzzed the device, or -1 if it did not. |
| 137 | private long mLastAudiblyAlertedMs; |
| 138 | |
Chris Wren | a344656 | 2014-06-03 18:11:47 -0400 | [diff] [blame] | 139 | // Is this record an update of an old record? |
| 140 | public boolean isUpdate; |
Chris Wren | 54bbef4 | 2014-07-09 18:37:56 -0400 | [diff] [blame] | 141 | private int mPackagePriority; |
Chris Wren | a344656 | 2014-06-03 18:11:47 -0400 | [diff] [blame] | 142 | |
Chris Wren | 1031c97 | 2014-07-23 13:11:45 +0000 | [diff] [blame] | 143 | private int mAuthoritativeRank; |
Christoph Studer | cd4adf8 | 2014-08-19 17:50:49 +0200 | [diff] [blame] | 144 | private String mGlobalSortKey; |
Chris Wren | 3ad4e3a | 2014-09-02 17:23:51 -0400 | [diff] [blame] | 145 | private int mPackageVisibility; |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 146 | private int mSystemImportance = IMPORTANCE_UNSPECIFIED; |
| 147 | private int mAssistantImportance = IMPORTANCE_UNSPECIFIED; |
Chris Wren | 4763342 | 2016-01-22 09:56:59 -0500 | [diff] [blame] | 148 | private int mImportance = IMPORTANCE_UNSPECIFIED; |
Alex Mang | 730d949 | 2019-12-03 18:06:09 -0800 | [diff] [blame] | 149 | private float mRankingScore = 0f; |
Brad Stenning | 9a8b2c8 | 2018-08-03 14:14:26 -0700 | [diff] [blame] | 150 | // Field used in global sort key to bypass normal notifications |
| 151 | private int mCriticality = CriticalNotificationExtractor.NORMAL; |
Will Brockman | 934b8e3 | 2019-03-08 11:14:45 -0500 | [diff] [blame] | 152 | // A MetricsEvent.NotificationImportanceExplanation, tracking source of mImportance. |
| 153 | private int mImportanceExplanationCode = MetricsEvent.IMPORTANCE_EXPLANATION_UNKNOWN; |
| 154 | // A MetricsEvent.NotificationImportanceExplanation for initial importance. |
| 155 | private int mInitialImportanceExplanationCode = MetricsEvent.IMPORTANCE_EXPLANATION_UNKNOWN; |
Chris Wren | 1031c97 | 2014-07-23 13:11:45 +0000 | [diff] [blame] | 156 | |
Julia Reynolds | f612869ae | 2015-11-05 16:48:55 -0500 | [diff] [blame] | 157 | private int mSuppressedVisualEffects = 0; |
Julia Reynolds | ef37f28 | 2016-02-12 09:11:27 -0500 | [diff] [blame] | 158 | private String mUserExplanation; |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 159 | private boolean mPreChannelsNotification = true; |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 160 | private Uri mSound; |
| 161 | private long[] mVibration; |
| 162 | private AudioAttributes mAttributes; |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 163 | private NotificationChannel mChannel; |
Julia Reynolds | 22f02b3 | 2016-12-01 15:05:13 -0500 | [diff] [blame] | 164 | private ArrayList<String> mPeopleOverride; |
| 165 | private ArrayList<SnoozeCriterion> mSnoozeCriteria; |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 166 | private boolean mShowBadge; |
Julia Reynolds | 4509ce7 | 2019-01-31 13:12:43 -0500 | [diff] [blame] | 167 | private boolean mAllowBubble; |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 168 | private Light mLight; |
Danning Chen | 10326cf | 2020-01-16 13:29:13 -0800 | [diff] [blame] | 169 | private boolean mIsNotConversationOverride; |
Julia Reynolds | d61bdf1 | 2020-02-25 12:25:07 -0500 | [diff] [blame] | 170 | private ShortcutInfo mShortcutInfo; |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 171 | /** |
| 172 | * This list contains system generated smart actions from NAS, app-generated smart actions are |
Gustav Sennton | 005d7a0 | 2019-01-04 13:41:32 +0000 | [diff] [blame] | 173 | * stored in Notification.actions with isContextual() set to true. |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 174 | */ |
| 175 | private ArrayList<Notification.Action> mSystemGeneratedSmartActions; |
Tony Mak | c9acf67 | 2018-07-20 13:58:24 +0200 | [diff] [blame] | 176 | private ArrayList<CharSequence> mSmartReplies; |
Julia Reynolds | f612869ae | 2015-11-05 16:48:55 -0500 | [diff] [blame] | 177 | |
Julia Reynolds | eb3dca7 | 2017-07-11 10:39:58 -0400 | [diff] [blame] | 178 | private final List<Adjustment> mAdjustments; |
Jan Althaus | 367eb8c | 2019-05-23 11:31:42 +0200 | [diff] [blame] | 179 | private String mAdjustmentIssuer; |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 180 | private final NotificationStats mStats; |
| 181 | private int mUserSentiment; |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 182 | private boolean mIsInterruptive; |
Julia Reynolds | b3c68ff | 2018-05-22 14:58:39 -0400 | [diff] [blame] | 183 | private boolean mTextChanged; |
| 184 | private boolean mRecordedInterruption; |
Kenny Guy | 2399110 | 2018-04-05 21:18:38 +0100 | [diff] [blame] | 185 | private int mNumberOfSmartRepliesAdded; |
Gustav Sennton | d25a64d | 2018-12-07 10:58:39 +0000 | [diff] [blame] | 186 | private int mNumberOfSmartActionsAdded; |
| 187 | private boolean mSuggestionsGeneratedByAssistant; |
Milo Sredkov | 13d8811 | 2019-02-01 12:23:24 +0000 | [diff] [blame] | 188 | private boolean mEditChoicesBeforeSending; |
Kenny Guy | 2399110 | 2018-04-05 21:18:38 +0100 | [diff] [blame] | 189 | private boolean mHasSeenSmartReplies; |
Mady Mellor | 13f9bc8 | 2020-03-24 19:09:28 -0700 | [diff] [blame] | 190 | private boolean mFlagBubbleRemoved; |
Julia Reynolds | 6503162 | 2020-02-27 09:11:25 -0500 | [diff] [blame] | 191 | private boolean mPostSilently; |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 192 | /** |
| 193 | * Whether this notification (and its channels) should be considered user locked. Used in |
| 194 | * conjunction with user sentiment calculation. |
| 195 | */ |
| 196 | private boolean mIsAppImportanceLocked; |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 197 | private ArraySet<Uri> mGrantableUris; |
Julia Reynolds | eb3dca7 | 2017-07-11 10:39:58 -0400 | [diff] [blame] | 198 | |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 199 | public NotificationRecord(Context context, StatusBarNotification sbn, |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 200 | NotificationChannel channel) { |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 201 | this.sbn = sbn; |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 202 | mTargetSdkVersion = LocalServices.getService(PackageManagerInternal.class) |
| 203 | .getPackageTargetSdkVersion(sbn.getPackageName()); |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 204 | mAm = ActivityManager.getService(); |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 205 | mUgmInternal = LocalServices.getService(UriGrantsManagerInternal.class); |
Christoph Studer | 365e4c3 | 2014-09-18 20:35:36 +0200 | [diff] [blame] | 206 | mOriginalFlags = sbn.getNotification().flags; |
Christoph Studer | 52b7a5a | 2014-06-06 16:09:15 +0200 | [diff] [blame] | 207 | mRankingTimeMs = calculateRankingTimeMs(0L); |
Chris Wren | 640e387 | 2015-04-21 13:23:18 -0400 | [diff] [blame] | 208 | mCreationTimeMs = sbn.getPostTime(); |
Chris Wren | 6650e57 | 2015-05-15 17:19:25 -0400 | [diff] [blame] | 209 | mUpdateTimeMs = mCreationTimeMs; |
Julia Reynolds | d6ba35c | 2018-06-18 09:29:19 -0400 | [diff] [blame] | 210 | mInterruptionTimeMs = mCreationTimeMs; |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 211 | mContext = context; |
Chris Wren | cdee8cd | 2016-01-25 17:10:30 -0500 | [diff] [blame] | 212 | stats = new NotificationUsageStats.SingleNotificationStats(); |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 213 | mChannel = channel; |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 214 | mPreChannelsNotification = isPreChannelsNotification(); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 215 | mSound = calculateSound(); |
| 216 | mVibration = calculateVibration(); |
| 217 | mAttributes = calculateAttributes(); |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 218 | mImportance = calculateInitialImportance(); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 219 | mLight = calculateLights(); |
Julia Reynolds | eb3dca7 | 2017-07-11 10:39:58 -0400 | [diff] [blame] | 220 | mAdjustments = new ArrayList<>(); |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 221 | mStats = new NotificationStats(); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 222 | calculateUserSentiment(); |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 223 | calculateGrantableUris(); |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 224 | } |
| 225 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 226 | private boolean isPreChannelsNotification() { |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 227 | if (NotificationChannel.DEFAULT_CHANNEL_ID.equals(getChannel().getId())) { |
| 228 | if (mTargetSdkVersion < Build.VERSION_CODES.O) { |
| 229 | return true; |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 230 | } |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 231 | } |
| 232 | return false; |
| 233 | } |
| 234 | |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 235 | private Uri calculateSound() { |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 236 | final Notification n = getSbn().getNotification(); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 237 | |
Tony Mantler | ab55f0f | 2017-06-16 10:50:00 -0700 | [diff] [blame] | 238 | // No notification sounds on tv |
| 239 | if (mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)) { |
| 240 | return null; |
| 241 | } |
| 242 | |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 243 | Uri sound = mChannel.getSound(); |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 244 | if (mPreChannelsNotification && (getChannel().getUserLockedFields() |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 245 | & NotificationChannel.USER_LOCKED_SOUND) == 0) { |
| 246 | |
| 247 | final boolean useDefaultSound = (n.defaults & Notification.DEFAULT_SOUND) != 0; |
| 248 | if (useDefaultSound) { |
| 249 | sound = Settings.System.DEFAULT_NOTIFICATION_URI; |
Julia Reynolds | b9e712e | 2017-04-17 10:31:03 -0400 | [diff] [blame] | 250 | } else { |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 251 | sound = n.sound; |
| 252 | } |
| 253 | } |
| 254 | return sound; |
| 255 | } |
| 256 | |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 257 | private Light calculateLights() { |
| 258 | int defaultLightColor = mContext.getResources().getColor( |
| 259 | com.android.internal.R.color.config_defaultNotificationColor); |
| 260 | int defaultLightOn = mContext.getResources().getInteger( |
| 261 | com.android.internal.R.integer.config_defaultNotificationLedOn); |
| 262 | int defaultLightOff = mContext.getResources().getInteger( |
| 263 | com.android.internal.R.integer.config_defaultNotificationLedOff); |
| 264 | |
Julia Reynolds | 529e332 | 2017-02-06 08:33:01 -0500 | [diff] [blame] | 265 | int channelLightColor = getChannel().getLightColor() != 0 ? getChannel().getLightColor() |
| 266 | : defaultLightColor; |
| 267 | Light light = getChannel().shouldShowLights() ? new Light(channelLightColor, |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 268 | defaultLightOn, defaultLightOff) : null; |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 269 | if (mPreChannelsNotification |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 270 | && (getChannel().getUserLockedFields() |
| 271 | & NotificationChannel.USER_LOCKED_LIGHTS) == 0) { |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 272 | final Notification notification = getSbn().getNotification(); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 273 | if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0) { |
| 274 | light = new Light(notification.ledARGB, notification.ledOnMS, |
| 275 | notification.ledOffMS); |
| 276 | if ((notification.defaults & Notification.DEFAULT_LIGHTS) != 0) { |
| 277 | light = new Light(defaultLightColor, defaultLightOn, |
| 278 | defaultLightOff); |
| 279 | } |
| 280 | } else { |
| 281 | light = null; |
| 282 | } |
| 283 | } |
| 284 | return light; |
| 285 | } |
| 286 | |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 287 | private long[] calculateVibration() { |
| 288 | long[] vibration; |
| 289 | final long[] defaultVibration = NotificationManagerService.getLongArray( |
| 290 | mContext.getResources(), |
| 291 | com.android.internal.R.array.config_defaultNotificationVibePattern, |
| 292 | NotificationManagerService.VIBRATE_PATTERN_MAXLEN, |
| 293 | NotificationManagerService.DEFAULT_VIBRATE_PATTERN); |
| 294 | if (getChannel().shouldVibrate()) { |
Julia Reynolds | f57de46 | 2016-11-23 11:31:46 -0500 | [diff] [blame] | 295 | vibration = getChannel().getVibrationPattern() == null |
| 296 | ? defaultVibration : getChannel().getVibrationPattern(); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 297 | } else { |
| 298 | vibration = null; |
| 299 | } |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 300 | if (mPreChannelsNotification |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 301 | && (getChannel().getUserLockedFields() |
| 302 | & NotificationChannel.USER_LOCKED_VIBRATION) == 0) { |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 303 | final Notification notification = getSbn().getNotification(); |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 304 | final boolean useDefaultVibrate = |
| 305 | (notification.defaults & Notification.DEFAULT_VIBRATE) != 0; |
| 306 | if (useDefaultVibrate) { |
| 307 | vibration = defaultVibration; |
| 308 | } else { |
| 309 | vibration = notification.vibrate; |
| 310 | } |
| 311 | } |
| 312 | return vibration; |
| 313 | } |
| 314 | |
| 315 | private AudioAttributes calculateAttributes() { |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 316 | final Notification n = getSbn().getNotification(); |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 317 | AudioAttributes attributes = getChannel().getAudioAttributes(); |
| 318 | if (attributes == null) { |
| 319 | attributes = Notification.AUDIO_ATTRIBUTES_DEFAULT; |
| 320 | } |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 321 | |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 322 | if (mPreChannelsNotification |
Julia Reynolds | 619a69f | 2017-01-27 15:11:38 -0500 | [diff] [blame] | 323 | && (getChannel().getUserLockedFields() |
| 324 | & NotificationChannel.USER_LOCKED_SOUND) == 0) { |
| 325 | if (n.audioAttributes != null) { |
| 326 | // prefer audio attributes to stream type |
| 327 | attributes = n.audioAttributes; |
| 328 | } else if (n.audioStreamType >= 0 |
| 329 | && n.audioStreamType < AudioSystem.getNumStreamTypes()) { |
| 330 | // the stream type is valid, use it |
| 331 | attributes = new AudioAttributes.Builder() |
| 332 | .setInternalLegacyStreamType(n.audioStreamType) |
| 333 | .build(); |
| 334 | } else if (n.audioStreamType != AudioSystem.STREAM_DEFAULT) { |
| 335 | Log.w(TAG, String.format("Invalid stream type: %d", n.audioStreamType)); |
| 336 | } |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 337 | } |
| 338 | return attributes; |
| 339 | } |
| 340 | |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 341 | private int calculateInitialImportance() { |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 342 | final Notification n = getSbn().getNotification(); |
Will Brockman | 934b8e3 | 2019-03-08 11:14:45 -0500 | [diff] [blame] | 343 | int importance = getChannel().getImportance(); // Post-channels notifications use this |
| 344 | mInitialImportanceExplanationCode = getChannel().hasUserSetImportance() |
| 345 | ? MetricsEvent.IMPORTANCE_EXPLANATION_USER |
| 346 | : MetricsEvent.IMPORTANCE_EXPLANATION_APP; |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 347 | |
Will Brockman | 934b8e3 | 2019-03-08 11:14:45 -0500 | [diff] [blame] | 348 | // Migrate notification priority flag to a priority value. |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 349 | if (0 != (n.flags & Notification.FLAG_HIGH_PRIORITY)) { |
| 350 | n.priority = Notification.PRIORITY_MAX; |
| 351 | } |
| 352 | |
Will Brockman | 934b8e3 | 2019-03-08 11:14:45 -0500 | [diff] [blame] | 353 | // Convert priority value to an importance value, used only for pre-channels notifications. |
| 354 | int requestedImportance = IMPORTANCE_DEFAULT; |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 355 | n.priority = NotificationManagerService.clamp(n.priority, Notification.PRIORITY_MIN, |
| 356 | Notification.PRIORITY_MAX); |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 357 | switch (n.priority) { |
| 358 | case Notification.PRIORITY_MIN: |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 359 | requestedImportance = IMPORTANCE_MIN; |
Julia Reynolds | f0f629f | 2016-02-25 09:34:04 -0500 | [diff] [blame] | 360 | break; |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 361 | case Notification.PRIORITY_LOW: |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 362 | requestedImportance = IMPORTANCE_LOW; |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 363 | break; |
| 364 | case Notification.PRIORITY_DEFAULT: |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 365 | requestedImportance = IMPORTANCE_DEFAULT; |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 366 | break; |
| 367 | case Notification.PRIORITY_HIGH: |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 368 | case Notification.PRIORITY_MAX: |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 369 | requestedImportance = IMPORTANCE_HIGH; |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 370 | break; |
| 371 | } |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 372 | stats.requestedImportance = requestedImportance; |
| 373 | stats.isNoisy = mSound != null || mVibration != null; |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 374 | |
Will Brockman | 934b8e3 | 2019-03-08 11:14:45 -0500 | [diff] [blame] | 375 | // For pre-channels notifications, apply system overrides and then use requestedImportance |
| 376 | // as importance. |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 377 | if (mPreChannelsNotification |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 378 | && (importance == IMPORTANCE_UNSPECIFIED |
Will Brockman | 934b8e3 | 2019-03-08 11:14:45 -0500 | [diff] [blame] | 379 | || (!getChannel().hasUserSetImportance()))) { |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 380 | if (!stats.isNoisy && requestedImportance > IMPORTANCE_LOW) { |
| 381 | requestedImportance = IMPORTANCE_LOW; |
Julia Reynolds | 83fa107 | 2016-02-17 09:10:19 -0500 | [diff] [blame] | 382 | } |
Julia Reynolds | 83fa107 | 2016-02-17 09:10:19 -0500 | [diff] [blame] | 383 | |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 384 | if (stats.isNoisy) { |
| 385 | if (requestedImportance < IMPORTANCE_DEFAULT) { |
| 386 | requestedImportance = IMPORTANCE_DEFAULT; |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | if (n.fullScreenIntent != null) { |
| 391 | requestedImportance = IMPORTANCE_HIGH; |
| 392 | } |
| 393 | importance = requestedImportance; |
Will Brockman | 934b8e3 | 2019-03-08 11:14:45 -0500 | [diff] [blame] | 394 | mInitialImportanceExplanationCode = |
| 395 | MetricsEvent.IMPORTANCE_EXPLANATION_APP_PRE_CHANNELS; |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 396 | } |
| 397 | |
Chris Wren | cdee8cd | 2016-01-25 17:10:30 -0500 | [diff] [blame] | 398 | stats.naturalImportance = importance; |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 399 | return importance; |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | // copy any notes that the ranking system may have made before the update |
| 403 | public void copyRankingInformation(NotificationRecord previous) { |
| 404 | mContactAffinity = previous.mContactAffinity; |
| 405 | mRecentlyIntrusive = previous.mRecentlyIntrusive; |
Chris Wren | 54bbef4 | 2014-07-09 18:37:56 -0400 | [diff] [blame] | 406 | mPackagePriority = previous.mPackagePriority; |
Chris Wren | 3ad4e3a | 2014-09-02 17:23:51 -0400 | [diff] [blame] | 407 | mPackageVisibility = previous.mPackageVisibility; |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 408 | mIntercept = previous.mIntercept; |
Beverly | 5a20a5e | 2018-03-06 15:02:44 -0500 | [diff] [blame] | 409 | mHidden = previous.mHidden; |
Christoph Studer | 52b7a5a | 2014-06-06 16:09:15 +0200 | [diff] [blame] | 410 | mRankingTimeMs = calculateRankingTimeMs(previous.getRankingTimeMs()); |
Chris Wren | 640e387 | 2015-04-21 13:23:18 -0400 | [diff] [blame] | 411 | mCreationTimeMs = previous.mCreationTimeMs; |
Chris Wren | 6650e57 | 2015-05-15 17:19:25 -0400 | [diff] [blame] | 412 | mVisibleSinceMs = previous.mVisibleSinceMs; |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 413 | if (previous.getSbn().getOverrideGroupKey() != null && !getSbn().isAppGroup()) { |
| 414 | getSbn().setOverrideGroupKey(previous.getSbn().getOverrideGroupKey()); |
Chris Wren | 8a1638f | 2016-05-02 16:19:14 -0400 | [diff] [blame] | 415 | } |
Chris Wren | 1f602dc | 2016-04-11 10:33:46 -0400 | [diff] [blame] | 416 | // Don't copy importance information or mGlobalSortKey, recompute them. |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 417 | } |
| 418 | |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 419 | public Notification getNotification() { return getSbn().getNotification(); } |
| 420 | public int getFlags() { return getSbn().getNotification().flags; } |
| 421 | public UserHandle getUser() { return getSbn().getUser(); } |
| 422 | public String getKey() { return getSbn().getKey(); } |
Chris Wren | da4bd20 | 2014-09-04 15:53:52 -0400 | [diff] [blame] | 423 | /** @deprecated Use {@link #getUser()} instead. */ |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 424 | public int getUserId() { return getSbn().getUserId(); } |
| 425 | public int getUid() { return getSbn().getUid(); } |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 426 | |
Kweku Adams | bc84aec | 2018-01-23 13:33:12 -0800 | [diff] [blame] | 427 | void dump(ProtoOutputStream proto, long fieldId, boolean redact, int state) { |
| 428 | final long token = proto.start(fieldId); |
| 429 | |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 430 | proto.write(NotificationRecordProto.KEY, getSbn().getKey()); |
Kweku Adams | bc84aec | 2018-01-23 13:33:12 -0800 | [diff] [blame] | 431 | proto.write(NotificationRecordProto.STATE, state); |
Julia Reynolds | c9842c1 | 2017-02-07 12:46:41 -0500 | [diff] [blame] | 432 | if (getChannel() != null) { |
| 433 | proto.write(NotificationRecordProto.CHANNEL_ID, getChannel().getId()); |
| 434 | } |
| 435 | proto.write(NotificationRecordProto.CAN_SHOW_LIGHT, getLight() != null); |
| 436 | proto.write(NotificationRecordProto.CAN_VIBRATE, getVibration() != null); |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 437 | proto.write(NotificationRecordProto.FLAGS, getSbn().getNotification().flags); |
Julia Reynolds | c9842c1 | 2017-02-07 12:46:41 -0500 | [diff] [blame] | 438 | proto.write(NotificationRecordProto.GROUP_KEY, getGroupKey()); |
| 439 | proto.write(NotificationRecordProto.IMPORTANCE, getImportance()); |
| 440 | if (getSound() != null) { |
| 441 | proto.write(NotificationRecordProto.SOUND, getSound().toString()); |
| 442 | } |
| 443 | if (getAudioAttributes() != null) { |
Jeffrey Huang | cb78285 | 2019-12-05 11:28:11 -0800 | [diff] [blame] | 444 | getAudioAttributes().dumpDebug(proto, NotificationRecordProto.AUDIO_ATTRIBUTES); |
Julia Reynolds | c9842c1 | 2017-02-07 12:46:41 -0500 | [diff] [blame] | 445 | } |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 446 | proto.write(NotificationRecordProto.PACKAGE, getSbn().getPackageName()); |
| 447 | proto.write(NotificationRecordProto.DELEGATE_PACKAGE, getSbn().getOpPkg()); |
Kweku Adams | bc84aec | 2018-01-23 13:33:12 -0800 | [diff] [blame] | 448 | |
| 449 | proto.end(token); |
Julia Reynolds | c9842c1 | 2017-02-07 12:46:41 -0500 | [diff] [blame] | 450 | } |
| 451 | |
Dan Sandler | 0a2308e | 2017-05-30 19:50:42 -0400 | [diff] [blame] | 452 | String formatRemoteViews(RemoteViews rv) { |
| 453 | if (rv == null) return "null"; |
| 454 | return String.format("%s/0x%08x (%d bytes): %s", |
| 455 | rv.getPackage(), rv.getLayoutId(), rv.estimateMemoryUsage(), rv.toString()); |
| 456 | } |
| 457 | |
Dan Sandler | a177031 | 2015-07-10 13:59:29 -0400 | [diff] [blame] | 458 | void dump(PrintWriter pw, String prefix, Context baseContext, boolean redact) { |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 459 | final Notification notification = getSbn().getNotification(); |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 460 | pw.println(prefix + this); |
Dan Sandler | 0a2308e | 2017-05-30 19:50:42 -0400 | [diff] [blame] | 461 | prefix = prefix + " "; |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 462 | pw.println(prefix + "uid=" + getSbn().getUid() + " userId=" + getSbn().getUserId()); |
| 463 | pw.println(prefix + "opPkg=" + getSbn().getOpPkg()); |
Julia Reynolds | c4ced65 | 2019-07-10 12:41:55 -0400 | [diff] [blame] | 464 | pw.println(prefix + "icon=" + notification.getSmallIcon()); |
Julia Reynolds | 4db5955 | 2017-06-30 13:34:01 -0400 | [diff] [blame] | 465 | pw.println(prefix + "flags=0x" + Integer.toHexString(notification.flags)); |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 466 | pw.println(prefix + "pri=" + notification.priority); |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 467 | pw.println(prefix + "key=" + getSbn().getKey()); |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 468 | pw.println(prefix + "seen=" + mStats.hasSeen()); |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 469 | pw.println(prefix + "groupKey=" + getGroupKey()); |
| 470 | pw.println(prefix + "fullscreenIntent=" + notification.fullScreenIntent); |
| 471 | pw.println(prefix + "contentIntent=" + notification.contentIntent); |
| 472 | pw.println(prefix + "deleteIntent=" + notification.deleteIntent); |
Aaron Heuckroth | b4d6aa7 | 2018-07-02 14:58:33 -0400 | [diff] [blame] | 473 | pw.println(prefix + "number=" + notification.number); |
| 474 | pw.println(prefix + "groupAlertBehavior=" + notification.getGroupAlertBehavior()); |
Julia Reynolds | 434a292 | 2020-01-21 13:33:59 -0500 | [diff] [blame] | 475 | pw.println(prefix + "when=" + notification.when); |
Dan Sandler | 0b4ceb3 | 2017-03-29 14:13:55 -0400 | [diff] [blame] | 476 | |
| 477 | pw.print(prefix + "tickerText="); |
| 478 | if (!TextUtils.isEmpty(notification.tickerText)) { |
| 479 | final String ticker = notification.tickerText.toString(); |
| 480 | if (redact) { |
| 481 | // if the string is long enough, we allow ourselves a few bytes for debugging |
| 482 | pw.print(ticker.length() > 16 ? ticker.substring(0,8) : ""); |
| 483 | pw.println("..."); |
| 484 | } else { |
| 485 | pw.println(ticker); |
| 486 | } |
| 487 | } else { |
| 488 | pw.println("null"); |
| 489 | } |
Dan Sandler | 0a2308e | 2017-05-30 19:50:42 -0400 | [diff] [blame] | 490 | pw.println(prefix + "contentView=" + formatRemoteViews(notification.contentView)); |
| 491 | pw.println(prefix + "bigContentView=" + formatRemoteViews(notification.bigContentView)); |
| 492 | pw.println(prefix + "headsUpContentView=" |
| 493 | + formatRemoteViews(notification.headsUpContentView)); |
| 494 | pw.print(prefix + String.format("color=0x%08x", notification.color)); |
Julia Reynolds | bad4297 | 2017-04-25 13:52:49 -0400 | [diff] [blame] | 495 | pw.println(prefix + "timeout=" |
| 496 | + TimeUtils.formatForLogging(notification.getTimeoutAfter())); |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 497 | if (notification.actions != null && notification.actions.length > 0) { |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 498 | pw.println(prefix + "actions={"); |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 499 | final int N = notification.actions.length; |
Julia Reynolds | 4b82f6d | 2017-01-04 10:47:41 -0500 | [diff] [blame] | 500 | for (int i = 0; i < N; i++) { |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 501 | final Notification.Action action = notification.actions[i]; |
Chris Wren | 1ac52a9 | 2016-02-24 14:54:52 -0500 | [diff] [blame] | 502 | if (action != null) { |
| 503 | pw.println(String.format("%s [%d] \"%s\" -> %s", |
| 504 | prefix, |
| 505 | i, |
| 506 | action.title, |
| 507 | action.actionIntent == null ? "null" : action.actionIntent.toString() |
| 508 | )); |
| 509 | } |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 510 | } |
| 511 | pw.println(prefix + " }"); |
| 512 | } |
| 513 | if (notification.extras != null && notification.extras.size() > 0) { |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 514 | pw.println(prefix + "extras={"); |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 515 | for (String key : notification.extras.keySet()) { |
| 516 | pw.print(prefix + " " + key + "="); |
| 517 | Object val = notification.extras.get(key); |
| 518 | if (val == null) { |
| 519 | pw.println("null"); |
| 520 | } else { |
| 521 | pw.print(val.getClass().getSimpleName()); |
Dan Sandler | a177031 | 2015-07-10 13:59:29 -0400 | [diff] [blame] | 522 | if (redact && (val instanceof CharSequence || val instanceof String)) { |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 523 | // redact contents from bugreports |
| 524 | } else if (val instanceof Bitmap) { |
| 525 | pw.print(String.format(" (%dx%d)", |
| 526 | ((Bitmap) val).getWidth(), |
| 527 | ((Bitmap) val).getHeight())); |
| 528 | } else if (val.getClass().isArray()) { |
| 529 | final int N = Array.getLength(val); |
Dan Sandler | a177031 | 2015-07-10 13:59:29 -0400 | [diff] [blame] | 530 | pw.print(" (" + N + ")"); |
| 531 | if (!redact) { |
Julia Reynolds | 4b82f6d | 2017-01-04 10:47:41 -0500 | [diff] [blame] | 532 | for (int j = 0; j < N; j++) { |
Dan Sandler | a177031 | 2015-07-10 13:59:29 -0400 | [diff] [blame] | 533 | pw.println(); |
| 534 | pw.print(String.format("%s [%d] %s", |
| 535 | prefix, j, String.valueOf(Array.get(val, j)))); |
| 536 | } |
| 537 | } |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 538 | } else { |
| 539 | pw.print(" (" + String.valueOf(val) + ")"); |
| 540 | } |
| 541 | pw.println(); |
| 542 | } |
| 543 | } |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 544 | pw.println(prefix + "}"); |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 545 | } |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 546 | pw.println(prefix + "stats=" + stats.toString()); |
| 547 | pw.println(prefix + "mContactAffinity=" + mContactAffinity); |
| 548 | pw.println(prefix + "mRecentlyIntrusive=" + mRecentlyIntrusive); |
| 549 | pw.println(prefix + "mPackagePriority=" + mPackagePriority); |
| 550 | pw.println(prefix + "mPackageVisibility=" + mPackageVisibility); |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 551 | pw.println(prefix + "mSystemImportance=" |
| 552 | + NotificationListenerService.Ranking.importanceToString(mSystemImportance)); |
| 553 | pw.println(prefix + "mAsstImportance=" |
| 554 | + NotificationListenerService.Ranking.importanceToString(mAssistantImportance)); |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 555 | pw.println(prefix + "mImportance=" |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 556 | + NotificationListenerService.Ranking.importanceToString(mImportance)); |
Will Brockman | 934b8e3 | 2019-03-08 11:14:45 -0500 | [diff] [blame] | 557 | pw.println(prefix + "mImportanceExplanation=" + getImportanceExplanation()); |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 558 | pw.println(prefix + "mIsAppImportanceLocked=" + mIsAppImportanceLocked); |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 559 | pw.println(prefix + "mIntercept=" + mIntercept); |
Beverly | 5a20a5e | 2018-03-06 15:02:44 -0500 | [diff] [blame] | 560 | pw.println(prefix + "mHidden==" + mHidden); |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 561 | pw.println(prefix + "mGlobalSortKey=" + mGlobalSortKey); |
| 562 | pw.println(prefix + "mRankingTimeMs=" + mRankingTimeMs); |
| 563 | pw.println(prefix + "mCreationTimeMs=" + mCreationTimeMs); |
| 564 | pw.println(prefix + "mVisibleSinceMs=" + mVisibleSinceMs); |
| 565 | pw.println(prefix + "mUpdateTimeMs=" + mUpdateTimeMs); |
Julia Reynolds | d6ba35c | 2018-06-18 09:29:19 -0400 | [diff] [blame] | 566 | pw.println(prefix + "mInterruptionTimeMs=" + mInterruptionTimeMs); |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 567 | pw.println(prefix + "mSuppressedVisualEffects= " + mSuppressedVisualEffects); |
Geoffrey Pitsch | a22f644 | 2017-05-05 16:47:38 +0000 | [diff] [blame] | 568 | if (mPreChannelsNotification) { |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 569 | pw.println(prefix + String.format("defaults=0x%08x flags=0x%08x", |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 570 | notification.defaults, notification.flags)); |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 571 | pw.println(prefix + "n.sound=" + notification.sound); |
| 572 | pw.println(prefix + "n.audioStreamType=" + notification.audioStreamType); |
| 573 | pw.println(prefix + "n.audioAttributes=" + notification.audioAttributes); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 574 | pw.println(prefix + String.format(" led=0x%08x onMs=%d offMs=%d", |
| 575 | notification.ledARGB, notification.ledOnMS, notification.ledOffMS)); |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 576 | pw.println(prefix + "vibrate=" + Arrays.toString(notification.vibrate)); |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 577 | } |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 578 | pw.println(prefix + "mSound= " + mSound); |
| 579 | pw.println(prefix + "mVibration= " + mVibration); |
| 580 | pw.println(prefix + "mAttributes= " + mAttributes); |
| 581 | pw.println(prefix + "mLight= " + mLight); |
| 582 | pw.println(prefix + "mShowBadge=" + mShowBadge); |
Julia Reynolds | 4db5955 | 2017-06-30 13:34:01 -0400 | [diff] [blame] | 583 | pw.println(prefix + "mColorized=" + notification.isColorized()); |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 584 | pw.println(prefix + "mIsInterruptive=" + mIsInterruptive); |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 585 | pw.println(prefix + "effectiveNotificationChannel=" + getChannel()); |
Julia Reynolds | 4b82f6d | 2017-01-04 10:47:41 -0500 | [diff] [blame] | 586 | if (getPeopleOverride() != null) { |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 587 | pw.println(prefix + "overridePeople= " + TextUtils.join(",", getPeopleOverride())); |
Julia Reynolds | 4b82f6d | 2017-01-04 10:47:41 -0500 | [diff] [blame] | 588 | } |
| 589 | if (getSnoozeCriteria() != null) { |
Julia Reynolds | a917a11 | 2017-03-21 11:09:14 -0400 | [diff] [blame] | 590 | pw.println(prefix + "snoozeCriteria=" + TextUtils.join(",", getSnoozeCriteria())); |
Julia Reynolds | 4b82f6d | 2017-01-04 10:47:41 -0500 | [diff] [blame] | 591 | } |
Julia Reynolds | eb3dca7 | 2017-07-11 10:39:58 -0400 | [diff] [blame] | 592 | pw.println(prefix + "mAdjustments=" + mAdjustments); |
Julia Reynolds | fa27307 | 2020-04-14 15:31:21 -0400 | [diff] [blame] | 593 | pw.println(prefix + "shortcut=" + notification.getShortcutId() |
| 594 | + " found valid? " + (mShortcutInfo != null)); |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 595 | } |
| 596 | |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 597 | @Override |
| 598 | public final String toString() { |
| 599 | return String.format( |
Julia Reynolds | 8576991 | 2016-10-25 09:08:57 -0400 | [diff] [blame] | 600 | "NotificationRecord(0x%08x: pkg=%s user=%s id=%d tag=%s importance=%d key=%s" + |
Julia Reynolds | 34523cd | 2019-07-02 10:13:29 -0400 | [diff] [blame] | 601 | ": %s)", |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 602 | System.identityHashCode(this), |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 603 | this.getSbn().getPackageName(), this.getSbn().getUser(), this.getSbn().getId(), |
| 604 | this.getSbn().getTag(), this.mImportance, this.getSbn().getKey(), |
| 605 | this.getSbn().getNotification()); |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 606 | } |
| 607 | |
Julia Reynolds | 27c0a96 | 2018-12-10 12:37:28 -0500 | [diff] [blame] | 608 | public boolean hasAdjustment(String key) { |
| 609 | synchronized (mAdjustments) { |
| 610 | for (Adjustment adjustment : mAdjustments) { |
| 611 | if (adjustment.getSignals().containsKey(key)) { |
| 612 | return true; |
| 613 | } |
| 614 | } |
| 615 | } |
| 616 | return false; |
| 617 | } |
| 618 | |
Julia Reynolds | eb3dca7 | 2017-07-11 10:39:58 -0400 | [diff] [blame] | 619 | public void addAdjustment(Adjustment adjustment) { |
| 620 | synchronized (mAdjustments) { |
| 621 | mAdjustments.add(adjustment); |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | public void applyAdjustments() { |
Julia Reynolds | 3dfdde0 | 2018-10-08 09:17:56 -0400 | [diff] [blame] | 626 | long now = System.currentTimeMillis(); |
Julia Reynolds | eb3dca7 | 2017-07-11 10:39:58 -0400 | [diff] [blame] | 627 | synchronized (mAdjustments) { |
| 628 | for (Adjustment adjustment: mAdjustments) { |
| 629 | Bundle signals = adjustment.getSignals(); |
| 630 | if (signals.containsKey(Adjustment.KEY_PEOPLE)) { |
| 631 | final ArrayList<String> people = |
| 632 | adjustment.getSignals().getStringArrayList(Adjustment.KEY_PEOPLE); |
| 633 | setPeopleOverride(people); |
| 634 | } |
| 635 | if (signals.containsKey(Adjustment.KEY_SNOOZE_CRITERIA)) { |
| 636 | final ArrayList<SnoozeCriterion> snoozeCriterionList = |
| 637 | adjustment.getSignals().getParcelableArrayList( |
| 638 | Adjustment.KEY_SNOOZE_CRITERIA); |
| 639 | setSnoozeCriteria(snoozeCriterionList); |
| 640 | } |
| 641 | if (signals.containsKey(Adjustment.KEY_GROUP_KEY)) { |
| 642 | final String groupOverrideKey = |
| 643 | adjustment.getSignals().getString(Adjustment.KEY_GROUP_KEY); |
| 644 | setOverrideGroupKey(groupOverrideKey); |
| 645 | } |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 646 | if (signals.containsKey(Adjustment.KEY_USER_SENTIMENT)) { |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 647 | // Only allow user sentiment update from assistant if user hasn't already |
| 648 | // expressed a preference for this channel |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 649 | if (!mIsAppImportanceLocked |
| 650 | && (getChannel().getUserLockedFields() & USER_LOCKED_IMPORTANCE) == 0) { |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 651 | setUserSentiment(adjustment.getSignals().getInt( |
| 652 | Adjustment.KEY_USER_SENTIMENT, USER_SENTIMENT_NEUTRAL)); |
| 653 | } |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 654 | } |
Tony Mak | a471699 | 2019-01-24 15:41:59 +0000 | [diff] [blame] | 655 | if (signals.containsKey(Adjustment.KEY_CONTEXTUAL_ACTIONS)) { |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 656 | setSystemGeneratedSmartActions( |
Tony Mak | a471699 | 2019-01-24 15:41:59 +0000 | [diff] [blame] | 657 | signals.getParcelableArrayList(Adjustment.KEY_CONTEXTUAL_ACTIONS)); |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 658 | } |
Tony Mak | a471699 | 2019-01-24 15:41:59 +0000 | [diff] [blame] | 659 | if (signals.containsKey(Adjustment.KEY_TEXT_REPLIES)) { |
| 660 | setSmartReplies(signals.getCharSequenceArrayList(Adjustment.KEY_TEXT_REPLIES)); |
Tony Mak | c9acf67 | 2018-07-20 13:58:24 +0200 | [diff] [blame] | 661 | } |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 662 | if (signals.containsKey(Adjustment.KEY_IMPORTANCE)) { |
| 663 | int importance = signals.getInt(Adjustment.KEY_IMPORTANCE); |
| 664 | importance = Math.max(IMPORTANCE_UNSPECIFIED, importance); |
| 665 | importance = Math.min(IMPORTANCE_HIGH, importance); |
| 666 | setAssistantImportance(importance); |
| 667 | } |
Alex Mang | 730d949 | 2019-12-03 18:06:09 -0800 | [diff] [blame] | 668 | if (signals.containsKey(Adjustment.KEY_RANKING_SCORE)) { |
| 669 | mRankingScore = signals.getFloat(Adjustment.KEY_RANKING_SCORE); |
| 670 | } |
Danning Chen | 10326cf | 2020-01-16 13:29:13 -0800 | [diff] [blame] | 671 | if (signals.containsKey(Adjustment.KEY_NOT_CONVERSATION)) { |
| 672 | mIsNotConversationOverride = signals.getBoolean( |
| 673 | Adjustment.KEY_NOT_CONVERSATION); |
| 674 | } |
Jan Althaus | 367eb8c | 2019-05-23 11:31:42 +0200 | [diff] [blame] | 675 | if (!signals.isEmpty() && adjustment.getIssuer() != null) { |
| 676 | mAdjustmentIssuer = adjustment.getIssuer(); |
| 677 | } |
Julia Reynolds | eb3dca7 | 2017-07-11 10:39:58 -0400 | [diff] [blame] | 678 | } |
Will Brockman | b020b5e | 2019-01-25 10:37:30 -0500 | [diff] [blame] | 679 | // We have now gotten all the information out of the adjustments and can forget them. |
| 680 | mAdjustments.clear(); |
Julia Reynolds | eb3dca7 | 2017-07-11 10:39:58 -0400 | [diff] [blame] | 681 | } |
| 682 | } |
| 683 | |
Will Brockman | 2b6959e | 2020-01-22 09:59:50 -0500 | [diff] [blame] | 684 | String getAdjustmentIssuer() { |
| 685 | return mAdjustmentIssuer; |
| 686 | } |
| 687 | |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 688 | public void setIsAppImportanceLocked(boolean isAppImportanceLocked) { |
| 689 | mIsAppImportanceLocked = isAppImportanceLocked; |
| 690 | calculateUserSentiment(); |
| 691 | } |
| 692 | |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 693 | public void setContactAffinity(float contactAffinity) { |
| 694 | mContactAffinity = contactAffinity; |
| 695 | } |
| 696 | |
| 697 | public float getContactAffinity() { |
| 698 | return mContactAffinity; |
| 699 | } |
| 700 | |
John Spurlock | 1d881a1 | 2015-03-18 19:21:54 -0400 | [diff] [blame] | 701 | public void setRecentlyIntrusive(boolean recentlyIntrusive) { |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 702 | mRecentlyIntrusive = recentlyIntrusive; |
Julia Reynolds | 309d1c8 | 2017-05-03 16:00:20 -0400 | [diff] [blame] | 703 | if (recentlyIntrusive) { |
| 704 | mLastIntrusive = System.currentTimeMillis(); |
| 705 | } |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | public boolean isRecentlyIntrusive() { |
| 709 | return mRecentlyIntrusive; |
| 710 | } |
| 711 | |
Julia Reynolds | 309d1c8 | 2017-05-03 16:00:20 -0400 | [diff] [blame] | 712 | public long getLastIntrusive() { |
| 713 | return mLastIntrusive; |
| 714 | } |
| 715 | |
Chris Wren | 54bbef4 | 2014-07-09 18:37:56 -0400 | [diff] [blame] | 716 | public void setPackagePriority(int packagePriority) { |
John Spurlock | 6ac5f8d | 2014-07-18 11:27:54 -0400 | [diff] [blame] | 717 | mPackagePriority = packagePriority; |
Chris Wren | 54bbef4 | 2014-07-09 18:37:56 -0400 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | public int getPackagePriority() { |
| 721 | return mPackagePriority; |
| 722 | } |
| 723 | |
Chris Wren | 3ad4e3a | 2014-09-02 17:23:51 -0400 | [diff] [blame] | 724 | public void setPackageVisibilityOverride(int packageVisibility) { |
| 725 | mPackageVisibility = packageVisibility; |
| 726 | } |
| 727 | |
| 728 | public int getPackageVisibilityOverride() { |
| 729 | return mPackageVisibility; |
| 730 | } |
| 731 | |
Julia Reynolds | ef37f28 | 2016-02-12 09:11:27 -0500 | [diff] [blame] | 732 | private String getUserExplanation() { |
| 733 | if (mUserExplanation == null) { |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 734 | mUserExplanation = mContext.getResources().getString( |
| 735 | com.android.internal.R.string.importance_from_user); |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 736 | } |
Julia Reynolds | ef37f28 | 2016-02-12 09:11:27 -0500 | [diff] [blame] | 737 | return mUserExplanation; |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 738 | } |
| 739 | |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 740 | /** |
| 741 | * Sets the importance value the system thinks the record should have. |
| 742 | * e.g. bumping up foreground service notifications or people to people notifications. |
| 743 | */ |
| 744 | public void setSystemImportance(int importance) { |
| 745 | mSystemImportance = importance; |
Julia Reynolds | 27c0a96 | 2018-12-10 12:37:28 -0500 | [diff] [blame] | 746 | // System importance is only changed in enqueue, so it's ok for us to calculate the |
| 747 | // importance directly instead of waiting for signal extractor. |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 748 | calculateImportance(); |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 749 | } |
| 750 | |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 751 | /** |
| 752 | * Sets the importance value the |
| 753 | * {@link android.service.notification.NotificationAssistantService} thinks the record should |
| 754 | * have. |
| 755 | */ |
| 756 | public void setAssistantImportance(int importance) { |
| 757 | mAssistantImportance = importance; |
Julia Reynolds | 27c0a96 | 2018-12-10 12:37:28 -0500 | [diff] [blame] | 758 | // Unlike the system importance, the assistant importance can change on posted |
| 759 | // notifications, so don't calculateImportance() here, but wait for the signal extractors. |
| 760 | } |
| 761 | |
| 762 | /** |
| 763 | * Returns the importance set by the assistant, or IMPORTANCE_UNSPECIFIED if the assistant |
| 764 | * hasn't set it. |
| 765 | */ |
| 766 | public int getAssistantImportance() { |
| 767 | return mAssistantImportance; |
Julia Reynolds | 5d25ee7 | 2015-11-20 15:38:20 -0500 | [diff] [blame] | 768 | } |
| 769 | |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 770 | /** |
Will Brockman | 934b8e3 | 2019-03-08 11:14:45 -0500 | [diff] [blame] | 771 | * Recalculates the importance of the record after fields affecting importance have changed, |
| 772 | * and records an explanation. |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 773 | */ |
| 774 | protected void calculateImportance() { |
| 775 | mImportance = calculateInitialImportance(); |
Will Brockman | 934b8e3 | 2019-03-08 11:14:45 -0500 | [diff] [blame] | 776 | mImportanceExplanationCode = mInitialImportanceExplanationCode; |
| 777 | |
| 778 | // Consider Notification Assistant and system overrides to importance. If both, system wins. |
Julia Reynolds | 27c0a96 | 2018-12-10 12:37:28 -0500 | [diff] [blame] | 779 | if (!getChannel().hasUserSetImportance() |
Julia Reynolds | 413ba84 | 2019-01-11 10:38:08 -0500 | [diff] [blame] | 780 | && mAssistantImportance != IMPORTANCE_UNSPECIFIED |
Julia Reynolds | 0c24500 | 2019-03-27 16:10:11 -0400 | [diff] [blame] | 781 | && !getChannel().isImportanceLockedByOEM() |
| 782 | && !getChannel().isImportanceLockedByCriticalDeviceFunction()) { |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 783 | mImportance = mAssistantImportance; |
Will Brockman | 934b8e3 | 2019-03-08 11:14:45 -0500 | [diff] [blame] | 784 | mImportanceExplanationCode = MetricsEvent.IMPORTANCE_EXPLANATION_ASST; |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 785 | } |
| 786 | if (mSystemImportance != IMPORTANCE_UNSPECIFIED) { |
| 787 | mImportance = mSystemImportance; |
Will Brockman | 934b8e3 | 2019-03-08 11:14:45 -0500 | [diff] [blame] | 788 | mImportanceExplanationCode = MetricsEvent.IMPORTANCE_EXPLANATION_SYSTEM; |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 789 | } |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | public int getImportance() { |
| 793 | return mImportance; |
| 794 | } |
| 795 | |
Will Brockman | 2b6959e | 2020-01-22 09:59:50 -0500 | [diff] [blame] | 796 | int getInitialImportance() { |
| 797 | return stats.naturalImportance; |
| 798 | } |
| 799 | |
Alex Mang | 730d949 | 2019-12-03 18:06:09 -0800 | [diff] [blame] | 800 | public float getRankingScore() { |
| 801 | return mRankingScore; |
| 802 | } |
| 803 | |
Will Brockman | 2b6959e | 2020-01-22 09:59:50 -0500 | [diff] [blame] | 804 | int getImportanceExplanationCode() { |
| 805 | return mImportanceExplanationCode; |
| 806 | } |
| 807 | |
| 808 | int getInitialImportanceExplanationCode() { |
| 809 | return mInitialImportanceExplanationCode; |
| 810 | } |
| 811 | |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 812 | public CharSequence getImportanceExplanation() { |
Will Brockman | 934b8e3 | 2019-03-08 11:14:45 -0500 | [diff] [blame] | 813 | switch (mImportanceExplanationCode) { |
| 814 | case MetricsEvent.IMPORTANCE_EXPLANATION_UNKNOWN: |
| 815 | return null; |
| 816 | case MetricsEvent.IMPORTANCE_EXPLANATION_APP: |
| 817 | case MetricsEvent.IMPORTANCE_EXPLANATION_APP_PRE_CHANNELS: |
| 818 | return "app"; |
| 819 | case MetricsEvent.IMPORTANCE_EXPLANATION_USER: |
| 820 | return "user"; |
| 821 | case MetricsEvent.IMPORTANCE_EXPLANATION_ASST: |
| 822 | return "asst"; |
| 823 | case MetricsEvent.IMPORTANCE_EXPLANATION_SYSTEM: |
| 824 | return "system"; |
| 825 | } |
| 826 | return null; |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 827 | } |
| 828 | |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 829 | public boolean setIntercepted(boolean intercept) { |
| 830 | mIntercept = intercept; |
| 831 | return mIntercept; |
| 832 | } |
| 833 | |
Brad Stenning | 9a8b2c8 | 2018-08-03 14:14:26 -0700 | [diff] [blame] | 834 | /** |
| 835 | * Set to affect global sort key. |
| 836 | * |
| 837 | * @param criticality used in a string based sort thus 0 is the most critical |
| 838 | */ |
| 839 | public void setCriticality(int criticality) { |
| 840 | mCriticality = criticality; |
| 841 | } |
| 842 | |
| 843 | public int getCriticality() { |
| 844 | return mCriticality; |
| 845 | } |
| 846 | |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 847 | public boolean isIntercepted() { |
| 848 | return mIntercept; |
| 849 | } |
| 850 | |
Julia Reynolds | d673007 | 2019-01-04 12:52:52 -0500 | [diff] [blame] | 851 | public boolean isNewEnoughForAlerting(long now) { |
| 852 | return getFreshnessMs(now) <= MAX_SOUND_DELAY_MS; |
| 853 | } |
| 854 | |
Beverly | 5a20a5e | 2018-03-06 15:02:44 -0500 | [diff] [blame] | 855 | public void setHidden(boolean hidden) { |
| 856 | mHidden = hidden; |
| 857 | } |
| 858 | |
| 859 | public boolean isHidden() { |
| 860 | return mHidden; |
| 861 | } |
| 862 | |
Julia Reynolds | 6503162 | 2020-02-27 09:11:25 -0500 | [diff] [blame] | 863 | /** |
| 864 | * Override of all alerting information on the channel and notification. Used when notifications |
| 865 | * are reposted in response to direct user action and thus don't need to alert. |
| 866 | */ |
| 867 | public void setPostSilently(boolean postSilently) { |
| 868 | mPostSilently = postSilently; |
| 869 | } |
| 870 | |
| 871 | public boolean shouldPostSilently() { |
| 872 | return mPostSilently; |
| 873 | } |
Beverly | 5a20a5e | 2018-03-06 15:02:44 -0500 | [diff] [blame] | 874 | |
Julia Reynolds | f612869ae | 2015-11-05 16:48:55 -0500 | [diff] [blame] | 875 | public void setSuppressedVisualEffects(int effects) { |
| 876 | mSuppressedVisualEffects = effects; |
| 877 | } |
| 878 | |
| 879 | public int getSuppressedVisualEffects() { |
| 880 | return mSuppressedVisualEffects; |
| 881 | } |
| 882 | |
John Spurlock | 312d1d0 | 2014-07-08 10:24:57 -0400 | [diff] [blame] | 883 | public boolean isCategory(String category) { |
John Spurlock | bfa5dc4 | 2014-07-28 23:30:45 -0400 | [diff] [blame] | 884 | return Objects.equals(getNotification().category, category); |
| 885 | } |
| 886 | |
John Spurlock | bfa5dc4 | 2014-07-28 23:30:45 -0400 | [diff] [blame] | 887 | public boolean isAudioAttributesUsage(int usage) { |
Julia Reynolds | 51eb78f8 | 2018-03-07 07:35:21 -0500 | [diff] [blame] | 888 | return mAttributes != null && mAttributes.getUsage() == usage; |
John Spurlock | 312d1d0 | 2014-07-08 10:24:57 -0400 | [diff] [blame] | 889 | } |
| 890 | |
Christoph Studer | 52b7a5a | 2014-06-06 16:09:15 +0200 | [diff] [blame] | 891 | /** |
| 892 | * Returns the timestamp to use for time-based sorting in the ranker. |
| 893 | */ |
| 894 | public long getRankingTimeMs() { |
| 895 | return mRankingTimeMs; |
| 896 | } |
| 897 | |
| 898 | /** |
Chris Wren | e6ddb8a | 2015-05-27 15:21:00 -0400 | [diff] [blame] | 899 | * @param now this current time in milliseconds. |
| 900 | * @returns the number of milliseconds since the most recent update, or the post time if none. |
Chris Wren | 6650e57 | 2015-05-15 17:19:25 -0400 | [diff] [blame] | 901 | */ |
Chris Wren | e6ddb8a | 2015-05-27 15:21:00 -0400 | [diff] [blame] | 902 | public int getFreshnessMs(long now) { |
| 903 | return (int) (now - mUpdateTimeMs); |
Chris Wren | 6650e57 | 2015-05-15 17:19:25 -0400 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | /** |
Chris Wren | e6ddb8a | 2015-05-27 15:21:00 -0400 | [diff] [blame] | 907 | * @param now this current time in milliseconds. |
| 908 | * @returns the number of milliseconds since the the first post, ignoring updates. |
Chris Wren | 640e387 | 2015-04-21 13:23:18 -0400 | [diff] [blame] | 909 | */ |
Chris Wren | e6ddb8a | 2015-05-27 15:21:00 -0400 | [diff] [blame] | 910 | public int getLifespanMs(long now) { |
| 911 | return (int) (now - mCreationTimeMs); |
Chris Wren | 640e387 | 2015-04-21 13:23:18 -0400 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | /** |
Chris Wren | e6ddb8a | 2015-05-27 15:21:00 -0400 | [diff] [blame] | 915 | * @param now this current time in milliseconds. |
| 916 | * @returns the number of milliseconds since the most recent visibility event, or 0 if never. |
Chris Wren | 6650e57 | 2015-05-15 17:19:25 -0400 | [diff] [blame] | 917 | */ |
Chris Wren | e6ddb8a | 2015-05-27 15:21:00 -0400 | [diff] [blame] | 918 | public int getExposureMs(long now) { |
| 919 | return mVisibleSinceMs == 0 ? 0 : (int) (now - mVisibleSinceMs); |
Chris Wren | 6650e57 | 2015-05-15 17:19:25 -0400 | [diff] [blame] | 920 | } |
| 921 | |
Julia Reynolds | d6ba35c | 2018-06-18 09:29:19 -0400 | [diff] [blame] | 922 | public int getInterruptionMs(long now) { |
| 923 | return (int) (now - mInterruptionTimeMs); |
| 924 | } |
| 925 | |
Evan Laird | d04af51 | 2020-01-09 11:18:09 -0500 | [diff] [blame] | 926 | public long getUpdateTimeMs() { |
| 927 | return mUpdateTimeMs; |
| 928 | } |
| 929 | |
Chris Wren | 6650e57 | 2015-05-15 17:19:25 -0400 | [diff] [blame] | 930 | /** |
| 931 | * Set the visibility of the notification. |
| 932 | */ |
Will Brockman | d3d4933 | 2020-02-10 19:43:03 -0500 | [diff] [blame] | 933 | public void setVisibility(boolean visible, int rank, int count, |
| 934 | NotificationRecordLogger notificationRecordLogger) { |
Chris Wren | 6650e57 | 2015-05-15 17:19:25 -0400 | [diff] [blame] | 935 | final long now = System.currentTimeMillis(); |
Chris Wren | e6ddb8a | 2015-05-27 15:21:00 -0400 | [diff] [blame] | 936 | mVisibleSinceMs = visible ? now : mVisibleSinceMs; |
Chris Wren | 6650e57 | 2015-05-15 17:19:25 -0400 | [diff] [blame] | 937 | stats.onVisibilityChanged(visible); |
Chris Wren | 9eb5e10 | 2017-01-26 13:15:06 -0500 | [diff] [blame] | 938 | MetricsLogger.action(getLogMaker(now) |
| 939 | .setCategory(MetricsEvent.NOTIFICATION_ITEM) |
| 940 | .setType(visible ? MetricsEvent.TYPE_OPEN : MetricsEvent.TYPE_CLOSE) |
Dieter Hsu | d39f0d5 | 2018-04-14 02:08:30 +0800 | [diff] [blame] | 941 | .addTaggedData(MetricsEvent.NOTIFICATION_SHADE_INDEX, rank) |
| 942 | .addTaggedData(MetricsEvent.NOTIFICATION_SHADE_COUNT, count)); |
Chris Wren | 9eb5e10 | 2017-01-26 13:15:06 -0500 | [diff] [blame] | 943 | if (visible) { |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 944 | setSeen(); |
Chris Wren | 9eb5e10 | 2017-01-26 13:15:06 -0500 | [diff] [blame] | 945 | MetricsLogger.histogram(mContext, "note_freshness", getFreshnessMs(now)); |
| 946 | } |
Chris Wren | 6650e57 | 2015-05-15 17:19:25 -0400 | [diff] [blame] | 947 | EventLogTags.writeNotificationVisibility(getKey(), visible ? 1 : 0, |
Chris Wren | 9eb5e10 | 2017-01-26 13:15:06 -0500 | [diff] [blame] | 948 | getLifespanMs(now), |
| 949 | getFreshnessMs(now), |
Chris Wren | d1dbc92 | 2015-06-19 17:51:16 -0400 | [diff] [blame] | 950 | 0, // exposure time |
| 951 | rank); |
Will Brockman | d3d4933 | 2020-02-10 19:43:03 -0500 | [diff] [blame] | 952 | notificationRecordLogger.logNotificationVisibility(this, visible); |
Chris Wren | 6650e57 | 2015-05-15 17:19:25 -0400 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | /** |
Christoph Studer | 52b7a5a | 2014-06-06 16:09:15 +0200 | [diff] [blame] | 956 | * @param previousRankingTimeMs for updated notifications, {@link #getRankingTimeMs()} |
| 957 | * of the previous notification record, 0 otherwise |
| 958 | */ |
| 959 | private long calculateRankingTimeMs(long previousRankingTimeMs) { |
| 960 | Notification n = getNotification(); |
| 961 | // Take developer provided 'when', unless it's in the future. |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 962 | if (n.when != 0 && n.when <= getSbn().getPostTime()) { |
Christoph Studer | 52b7a5a | 2014-06-06 16:09:15 +0200 | [diff] [blame] | 963 | return n.when; |
| 964 | } |
| 965 | // If we've ranked a previous instance with a timestamp, inherit it. This case is |
| 966 | // important in order to have ranking stability for updating notifications. |
| 967 | if (previousRankingTimeMs > 0) { |
| 968 | return previousRankingTimeMs; |
| 969 | } |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 970 | return getSbn().getPostTime(); |
Christoph Studer | 52b7a5a | 2014-06-06 16:09:15 +0200 | [diff] [blame] | 971 | } |
Chris Wren | 1031c97 | 2014-07-23 13:11:45 +0000 | [diff] [blame] | 972 | |
Christoph Studer | cd4adf8 | 2014-08-19 17:50:49 +0200 | [diff] [blame] | 973 | public void setGlobalSortKey(String globalSortKey) { |
| 974 | mGlobalSortKey = globalSortKey; |
Chris Wren | 1031c97 | 2014-07-23 13:11:45 +0000 | [diff] [blame] | 975 | } |
| 976 | |
Christoph Studer | cd4adf8 | 2014-08-19 17:50:49 +0200 | [diff] [blame] | 977 | public String getGlobalSortKey() { |
| 978 | return mGlobalSortKey; |
Chris Wren | 1031c97 | 2014-07-23 13:11:45 +0000 | [diff] [blame] | 979 | } |
| 980 | |
Amith Yamasani | f47e51e | 2015-04-17 10:02:15 -0700 | [diff] [blame] | 981 | /** Check if any of the listeners have marked this notification as seen by the user. */ |
| 982 | public boolean isSeen() { |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 983 | return mStats.hasSeen(); |
Amith Yamasani | f47e51e | 2015-04-17 10:02:15 -0700 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | /** Mark the notification as seen by the user. */ |
| 987 | public void setSeen() { |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 988 | mStats.setSeen(); |
Julia Reynolds | b3c68ff | 2018-05-22 14:58:39 -0400 | [diff] [blame] | 989 | if (mTextChanged) { |
Julia Reynolds | d6ba35c | 2018-06-18 09:29:19 -0400 | [diff] [blame] | 990 | setInterruptive(true); |
Julia Reynolds | b3c68ff | 2018-05-22 14:58:39 -0400 | [diff] [blame] | 991 | } |
Amith Yamasani | f47e51e | 2015-04-17 10:02:15 -0700 | [diff] [blame] | 992 | } |
| 993 | |
Chris Wren | 1031c97 | 2014-07-23 13:11:45 +0000 | [diff] [blame] | 994 | public void setAuthoritativeRank(int authoritativeRank) { |
| 995 | mAuthoritativeRank = authoritativeRank; |
| 996 | } |
| 997 | |
| 998 | public int getAuthoritativeRank() { |
| 999 | return mAuthoritativeRank; |
| 1000 | } |
| 1001 | |
| 1002 | public String getGroupKey() { |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 1003 | return getSbn().getGroupKey(); |
Chris Wren | 1031c97 | 2014-07-23 13:11:45 +0000 | [diff] [blame] | 1004 | } |
Chris Wren | 4763342 | 2016-01-22 09:56:59 -0500 | [diff] [blame] | 1005 | |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 1006 | public void setOverrideGroupKey(String overrideGroupKey) { |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 1007 | getSbn().setOverrideGroupKey(overrideGroupKey); |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 1008 | } |
| 1009 | |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1010 | public NotificationChannel getChannel() { |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 1011 | return mChannel; |
Julia Reynolds | 22f02b3 | 2016-12-01 15:05:13 -0500 | [diff] [blame] | 1012 | } |
| 1013 | |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 1014 | /** |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 1015 | * @see PreferencesHelper#getIsAppImportanceLocked(String, int) |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 1016 | */ |
| 1017 | public boolean getIsAppImportanceLocked() { |
| 1018 | return mIsAppImportanceLocked; |
| 1019 | } |
| 1020 | |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 1021 | protected void updateNotificationChannel(NotificationChannel channel) { |
| 1022 | if (channel != null) { |
| 1023 | mChannel = channel; |
Julia Reynolds | 22f02b3 | 2016-12-01 15:05:13 -0500 | [diff] [blame] | 1024 | calculateImportance(); |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 1025 | calculateUserSentiment(); |
Julia Reynolds | 22f02b3 | 2016-12-01 15:05:13 -0500 | [diff] [blame] | 1026 | } |
Julia Reynolds | b5e44b7 | 2016-08-16 15:00:25 -0400 | [diff] [blame] | 1027 | } |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 1028 | |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 1029 | public void setShowBadge(boolean showBadge) { |
| 1030 | mShowBadge = showBadge; |
| 1031 | } |
| 1032 | |
Julia Reynolds | 4509ce7 | 2019-01-31 13:12:43 -0500 | [diff] [blame] | 1033 | public boolean canBubble() { |
| 1034 | return mAllowBubble; |
| 1035 | } |
| 1036 | |
| 1037 | public void setAllowBubble(boolean allow) { |
| 1038 | mAllowBubble = allow; |
| 1039 | } |
| 1040 | |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 1041 | public boolean canShowBadge() { |
| 1042 | return mShowBadge; |
| 1043 | } |
| 1044 | |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 1045 | public Light getLight() { |
| 1046 | return mLight; |
| 1047 | } |
| 1048 | |
Julia Reynolds | 0c299d4 | 2016-11-15 14:37:04 -0500 | [diff] [blame] | 1049 | public Uri getSound() { |
| 1050 | return mSound; |
| 1051 | } |
| 1052 | |
| 1053 | public long[] getVibration() { |
| 1054 | return mVibration; |
| 1055 | } |
| 1056 | |
| 1057 | public AudioAttributes getAudioAttributes() { |
| 1058 | return mAttributes; |
| 1059 | } |
Julia Reynolds | 22f02b3 | 2016-12-01 15:05:13 -0500 | [diff] [blame] | 1060 | |
| 1061 | public ArrayList<String> getPeopleOverride() { |
| 1062 | return mPeopleOverride; |
| 1063 | } |
| 1064 | |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 1065 | public void setInterruptive(boolean interruptive) { |
| 1066 | mIsInterruptive = interruptive; |
Julia Reynolds | d6ba35c | 2018-06-18 09:29:19 -0400 | [diff] [blame] | 1067 | final long now = System.currentTimeMillis(); |
| 1068 | mInterruptionTimeMs = interruptive ? now : mInterruptionTimeMs; |
| 1069 | |
| 1070 | if (interruptive) { |
| 1071 | MetricsLogger.action(getLogMaker() |
| 1072 | .setCategory(MetricsEvent.NOTIFICATION_INTERRUPTION) |
| 1073 | .setType(MetricsEvent.TYPE_OPEN) |
| 1074 | .addTaggedData(MetricsEvent.NOTIFICATION_SINCE_INTERRUPTION_MILLIS, |
| 1075 | getInterruptionMs(now))); |
| 1076 | MetricsLogger.histogram(mContext, "note_interruptive", getInterruptionMs(now)); |
| 1077 | } |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 1078 | } |
| 1079 | |
Gus Prevas | a322649 | 2018-10-23 11:10:09 -0400 | [diff] [blame] | 1080 | public void setAudiblyAlerted(boolean audiblyAlerted) { |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1081 | mLastAudiblyAlertedMs = audiblyAlerted ? System.currentTimeMillis() : -1; |
Gus Prevas | a322649 | 2018-10-23 11:10:09 -0400 | [diff] [blame] | 1082 | } |
| 1083 | |
Julia Reynolds | b3c68ff | 2018-05-22 14:58:39 -0400 | [diff] [blame] | 1084 | public void setTextChanged(boolean textChanged) { |
| 1085 | mTextChanged = textChanged; |
| 1086 | } |
| 1087 | |
| 1088 | public void setRecordedInterruption(boolean recorded) { |
| 1089 | mRecordedInterruption = recorded; |
| 1090 | } |
| 1091 | |
| 1092 | public boolean hasRecordedInterruption() { |
| 1093 | return mRecordedInterruption; |
| 1094 | } |
| 1095 | |
Julia Reynolds | 1fac86e | 2018-03-07 08:30:37 -0500 | [diff] [blame] | 1096 | public boolean isInterruptive() { |
| 1097 | return mIsInterruptive; |
| 1098 | } |
| 1099 | |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1100 | /** Returns the time the notification audibly alerted the user. */ |
| 1101 | public long getLastAudiblyAlertedMs() { |
| 1102 | return mLastAudiblyAlertedMs; |
Gus Prevas | a322649 | 2018-10-23 11:10:09 -0400 | [diff] [blame] | 1103 | } |
| 1104 | |
Julia Reynolds | 22f02b3 | 2016-12-01 15:05:13 -0500 | [diff] [blame] | 1105 | protected void setPeopleOverride(ArrayList<String> people) { |
| 1106 | mPeopleOverride = people; |
| 1107 | } |
| 1108 | |
| 1109 | public ArrayList<SnoozeCriterion> getSnoozeCriteria() { |
| 1110 | return mSnoozeCriteria; |
| 1111 | } |
| 1112 | |
| 1113 | protected void setSnoozeCriteria(ArrayList<SnoozeCriterion> snoozeCriteria) { |
| 1114 | mSnoozeCriteria = snoozeCriteria; |
| 1115 | } |
Chris Wren | 9eb5e10 | 2017-01-26 13:15:06 -0500 | [diff] [blame] | 1116 | |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 1117 | private void calculateUserSentiment() { |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 1118 | if ((getChannel().getUserLockedFields() & USER_LOCKED_IMPORTANCE) != 0 |
| 1119 | || mIsAppImportanceLocked) { |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 1120 | mUserSentiment = USER_SENTIMENT_POSITIVE; |
| 1121 | } |
| 1122 | } |
| 1123 | |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 1124 | private void setUserSentiment(int userSentiment) { |
| 1125 | mUserSentiment = userSentiment; |
| 1126 | } |
| 1127 | |
| 1128 | public int getUserSentiment() { |
| 1129 | return mUserSentiment; |
| 1130 | } |
| 1131 | |
| 1132 | public NotificationStats getStats() { |
| 1133 | return mStats; |
| 1134 | } |
| 1135 | |
| 1136 | public void recordExpanded() { |
| 1137 | mStats.setExpanded(); |
| 1138 | } |
| 1139 | |
| 1140 | public void recordDirectReplied() { |
| 1141 | mStats.setDirectReplied(); |
| 1142 | } |
| 1143 | |
| 1144 | public void recordDismissalSurface(@NotificationStats.DismissalSurface int surface) { |
| 1145 | mStats.setDismissalSurface(surface); |
| 1146 | } |
| 1147 | |
Julia Reynolds | fd4099d | 2018-08-21 11:06:06 -0400 | [diff] [blame] | 1148 | public void recordDismissalSentiment(@NotificationStats.DismissalSentiment int sentiment) { |
| 1149 | mStats.setDismissalSentiment(sentiment); |
| 1150 | } |
| 1151 | |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 1152 | public void recordSnoozed() { |
| 1153 | mStats.setSnoozed(); |
| 1154 | } |
| 1155 | |
| 1156 | public void recordViewedSettings() { |
| 1157 | mStats.setViewedSettings(); |
| 1158 | } |
| 1159 | |
Kenny Guy | 2399110 | 2018-04-05 21:18:38 +0100 | [diff] [blame] | 1160 | public void setNumSmartRepliesAdded(int noReplies) { |
| 1161 | mNumberOfSmartRepliesAdded = noReplies; |
| 1162 | } |
| 1163 | |
| 1164 | public int getNumSmartRepliesAdded() { |
| 1165 | return mNumberOfSmartRepliesAdded; |
| 1166 | } |
| 1167 | |
Gustav Sennton | d25a64d | 2018-12-07 10:58:39 +0000 | [diff] [blame] | 1168 | public void setNumSmartActionsAdded(int noActions) { |
| 1169 | mNumberOfSmartActionsAdded = noActions; |
| 1170 | } |
| 1171 | |
| 1172 | public int getNumSmartActionsAdded() { |
| 1173 | return mNumberOfSmartActionsAdded; |
| 1174 | } |
| 1175 | |
| 1176 | public void setSuggestionsGeneratedByAssistant(boolean generatedByAssistant) { |
| 1177 | mSuggestionsGeneratedByAssistant = generatedByAssistant; |
| 1178 | } |
| 1179 | |
| 1180 | public boolean getSuggestionsGeneratedByAssistant() { |
| 1181 | return mSuggestionsGeneratedByAssistant; |
| 1182 | } |
| 1183 | |
Milo Sredkov | 13d8811 | 2019-02-01 12:23:24 +0000 | [diff] [blame] | 1184 | public boolean getEditChoicesBeforeSending() { |
| 1185 | return mEditChoicesBeforeSending; |
| 1186 | } |
| 1187 | |
| 1188 | public void setEditChoicesBeforeSending(boolean editChoicesBeforeSending) { |
| 1189 | mEditChoicesBeforeSending = editChoicesBeforeSending; |
| 1190 | } |
| 1191 | |
Kenny Guy | 2399110 | 2018-04-05 21:18:38 +0100 | [diff] [blame] | 1192 | public boolean hasSeenSmartReplies() { |
| 1193 | return mHasSeenSmartReplies; |
| 1194 | } |
| 1195 | |
| 1196 | public void setSeenSmartReplies(boolean hasSeenSmartReplies) { |
| 1197 | mHasSeenSmartReplies = hasSeenSmartReplies; |
| 1198 | } |
| 1199 | |
Gustav Sennton | 44dc588 | 2018-12-13 14:38:50 +0000 | [diff] [blame] | 1200 | /** |
| 1201 | * Returns whether this notification has been visible and expanded at the same time. |
| 1202 | */ |
| 1203 | public boolean hasBeenVisiblyExpanded() { |
| 1204 | return stats.hasBeenVisiblyExpanded(); |
| 1205 | } |
| 1206 | |
Mady Mellor | 13f9bc8 | 2020-03-24 19:09:28 -0700 | [diff] [blame] | 1207 | /** |
| 1208 | * When the bubble state on a notif changes due to user action (e.g. dismiss a bubble) then |
| 1209 | * this value is set until an update or bubble change event due to user action (e.g. create |
| 1210 | * bubble from sysui) |
| 1211 | **/ |
| 1212 | public boolean isFlagBubbleRemoved() { |
| 1213 | return mFlagBubbleRemoved; |
| 1214 | } |
| 1215 | |
| 1216 | public void setFlagBubbleRemoved(boolean flagBubbleRemoved) { |
| 1217 | mFlagBubbleRemoved = flagBubbleRemoved; |
| 1218 | } |
| 1219 | |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 1220 | public void setSystemGeneratedSmartActions( |
| 1221 | ArrayList<Notification.Action> systemGeneratedSmartActions) { |
| 1222 | mSystemGeneratedSmartActions = systemGeneratedSmartActions; |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 1223 | } |
| 1224 | |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 1225 | public ArrayList<Notification.Action> getSystemGeneratedSmartActions() { |
| 1226 | return mSystemGeneratedSmartActions; |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 1227 | } |
| 1228 | |
Tony Mak | c9acf67 | 2018-07-20 13:58:24 +0200 | [diff] [blame] | 1229 | public void setSmartReplies(ArrayList<CharSequence> smartReplies) { |
| 1230 | mSmartReplies = smartReplies; |
| 1231 | } |
| 1232 | |
| 1233 | public ArrayList<CharSequence> getSmartReplies() { |
| 1234 | return mSmartReplies; |
| 1235 | } |
| 1236 | |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 1237 | /** |
Julia Reynolds | 9533413 | 2018-12-19 11:15:35 -0500 | [diff] [blame] | 1238 | * Returns whether this notification was posted by a secondary app |
| 1239 | */ |
| 1240 | public boolean isProxied() { |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 1241 | return !Objects.equals(getSbn().getPackageName(), getSbn().getOpPkg()); |
Julia Reynolds | 9533413 | 2018-12-19 11:15:35 -0500 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | /** |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 1245 | * @return all {@link Uri} that should have permission granted to whoever |
| 1246 | * will be rendering it. This list has already been vetted to only |
| 1247 | * include {@link Uri} that the enqueuing app can grant. |
| 1248 | */ |
| 1249 | public @Nullable ArraySet<Uri> getGrantableUris() { |
| 1250 | return mGrantableUris; |
| 1251 | } |
Julia Reynolds | e0d711f | 2017-09-01 08:50:47 -0400 | [diff] [blame] | 1252 | |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 1253 | /** |
| 1254 | * Collect all {@link Uri} that should have permission granted to whoever |
| 1255 | * will be rendering it. |
| 1256 | */ |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 1257 | protected void calculateGrantableUris() { |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 1258 | final Notification notification = getNotification(); |
Jeff Sharkey | 23b3118 | 2018-04-18 21:32:12 -0600 | [diff] [blame] | 1259 | notification.visitUris((uri) -> { |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 1260 | visitGrantableUri(uri, false); |
Jeff Sharkey | 23b3118 | 2018-04-18 21:32:12 -0600 | [diff] [blame] | 1261 | }); |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 1262 | |
Julia Reynolds | e0d711f | 2017-09-01 08:50:47 -0400 | [diff] [blame] | 1263 | if (notification.getChannelId() != null) { |
| 1264 | NotificationChannel channel = getChannel(); |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 1265 | if (channel != null) { |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 1266 | visitGrantableUri(channel.getSound(), (channel.getUserLockedFields() |
| 1267 | & NotificationChannel.USER_LOCKED_SOUND) != 0); |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 1268 | } |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | /** |
| 1273 | * Note the presence of a {@link Uri} that should have permission granted to |
| 1274 | * whoever will be rendering it. |
| 1275 | * <p> |
| 1276 | * If the enqueuing app has the ability to grant access, it will be added to |
| 1277 | * {@link #mGrantableUris}. Otherwise, this will either log or throw |
| 1278 | * {@link SecurityException} depending on target SDK of enqueuing app. |
| 1279 | */ |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 1280 | private void visitGrantableUri(Uri uri, boolean userOverriddenUri) { |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 1281 | if (uri == null || !ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) return; |
| 1282 | |
| 1283 | // We can't grant Uri permissions from system |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 1284 | final int sourceUid = getSbn().getUid(); |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 1285 | if (sourceUid == android.os.Process.SYSTEM_UID) return; |
| 1286 | |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 1287 | final long ident = Binder.clearCallingIdentity(); |
| 1288 | try { |
| 1289 | // This will throw SecurityException if caller can't grant |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 1290 | mUgmInternal.checkGrantUriPermission(sourceUid, null, |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 1291 | ContentProvider.getUriWithoutUserId(uri), |
| 1292 | Intent.FLAG_GRANT_READ_URI_PERMISSION, |
| 1293 | ContentProvider.getUserIdFromUri(uri, UserHandle.getUserId(sourceUid))); |
| 1294 | |
| 1295 | if (mGrantableUris == null) { |
| 1296 | mGrantableUris = new ArraySet<>(); |
| 1297 | } |
| 1298 | mGrantableUris.add(uri); |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 1299 | } catch (SecurityException e) { |
Julia Reynolds | 218871e | 2018-06-13 10:45:21 -0400 | [diff] [blame] | 1300 | if (!userOverriddenUri) { |
| 1301 | if (mTargetSdkVersion >= Build.VERSION_CODES.P) { |
| 1302 | throw e; |
| 1303 | } else { |
| 1304 | Log.w(TAG, "Ignoring " + uri + " from " + sourceUid + ": " + e.getMessage()); |
| 1305 | } |
Jeff Sharkey | 6a97cc3 | 2018-04-17 12:16:20 -0600 | [diff] [blame] | 1306 | } |
| 1307 | } finally { |
| 1308 | Binder.restoreCallingIdentity(ident); |
| 1309 | } |
Julia Reynolds | e0d711f | 2017-09-01 08:50:47 -0400 | [diff] [blame] | 1310 | } |
| 1311 | |
Chris Wren | 9eb5e10 | 2017-01-26 13:15:06 -0500 | [diff] [blame] | 1312 | public LogMaker getLogMaker(long now) { |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 1313 | LogMaker lm = getSbn().getLogMaker() |
Chris Wren | b392179 | 2017-06-01 13:34:46 -0400 | [diff] [blame] | 1314 | .addTaggedData(MetricsEvent.FIELD_NOTIFICATION_CHANNEL_IMPORTANCE, mImportance) |
Chris Wren | 9eb5e10 | 2017-01-26 13:15:06 -0500 | [diff] [blame] | 1315 | .addTaggedData(MetricsEvent.NOTIFICATION_SINCE_CREATE_MILLIS, getLifespanMs(now)) |
| 1316 | .addTaggedData(MetricsEvent.NOTIFICATION_SINCE_UPDATE_MILLIS, getFreshnessMs(now)) |
Julia Reynolds | d6ba35c | 2018-06-18 09:29:19 -0400 | [diff] [blame] | 1317 | .addTaggedData(MetricsEvent.NOTIFICATION_SINCE_VISIBLE_MILLIS, getExposureMs(now)) |
| 1318 | .addTaggedData(MetricsEvent.NOTIFICATION_SINCE_INTERRUPTION_MILLIS, |
| 1319 | getInterruptionMs(now)); |
Will Brockman | 934b8e3 | 2019-03-08 11:14:45 -0500 | [diff] [blame] | 1320 | // Record results of the calculateImportance() calculation if available. |
| 1321 | if (mImportanceExplanationCode != MetricsEvent.IMPORTANCE_EXPLANATION_UNKNOWN) { |
| 1322 | lm.addTaggedData(MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_EXPLANATION, |
| 1323 | mImportanceExplanationCode); |
| 1324 | // To avoid redundancy, we log the initial importance information only if it was |
| 1325 | // overridden. |
| 1326 | if (((mImportanceExplanationCode == MetricsEvent.IMPORTANCE_EXPLANATION_ASST) |
| 1327 | || (mImportanceExplanationCode == MetricsEvent.IMPORTANCE_EXPLANATION_SYSTEM)) |
| 1328 | && (stats.naturalImportance != IMPORTANCE_UNSPECIFIED)) { |
| 1329 | // stats.naturalImportance is due to one of the 3 sources of initial importance. |
| 1330 | lm.addTaggedData(MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_INITIAL_EXPLANATION, |
| 1331 | mInitialImportanceExplanationCode); |
| 1332 | lm.addTaggedData(MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_INITIAL, |
| 1333 | stats.naturalImportance); |
| 1334 | } |
Will Brockman | 605d61b | 2019-03-29 13:08:49 -0400 | [diff] [blame] | 1335 | } |
| 1336 | // Log Assistant override if present, whether or not importance calculation is complete. |
| 1337 | if (mAssistantImportance != IMPORTANCE_UNSPECIFIED) { |
| 1338 | lm.addTaggedData(MetricsEvent.FIELD_NOTIFICATION_IMPORTANCE_ASST, |
Will Brockman | 934b8e3 | 2019-03-08 11:14:45 -0500 | [diff] [blame] | 1339 | mAssistantImportance); |
Will Brockman | 934b8e3 | 2019-03-08 11:14:45 -0500 | [diff] [blame] | 1340 | } |
Jan Althaus | 367eb8c | 2019-05-23 11:31:42 +0200 | [diff] [blame] | 1341 | // Log the issuer of any adjustments that may have affected this notification. We only log |
| 1342 | // the hash here as NotificationItem events are frequent, and the number of NAS |
| 1343 | // implementations (and hence the chance of collisions) is low. |
| 1344 | if (mAdjustmentIssuer != null) { |
| 1345 | lm.addTaggedData(MetricsEvent.FIELD_NOTIFICATION_ASSISTANT_SERVICE_HASH, |
| 1346 | mAdjustmentIssuer.hashCode()); |
| 1347 | } |
Will Brockman | 934b8e3 | 2019-03-08 11:14:45 -0500 | [diff] [blame] | 1348 | return lm; |
Chris Wren | 9eb5e10 | 2017-01-26 13:15:06 -0500 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | public LogMaker getLogMaker() { |
| 1352 | return getLogMaker(System.currentTimeMillis()); |
| 1353 | } |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 1354 | |
Julia Reynolds | 3dfdde0 | 2018-10-08 09:17:56 -0400 | [diff] [blame] | 1355 | public LogMaker getItemLogMaker() { |
| 1356 | return getLogMaker().setCategory(MetricsEvent.NOTIFICATION_ITEM); |
| 1357 | } |
| 1358 | |
Chris Wren | 6cbf57b | 2019-12-12 15:33:21 -0500 | [diff] [blame] | 1359 | public boolean hasUndecoratedRemoteView() { |
| 1360 | Notification notification = getNotification(); |
| 1361 | Class<? extends Notification.Style> style = notification.getNotificationStyle(); |
| 1362 | boolean hasDecoratedStyle = style != null |
| 1363 | && (Notification.DecoratedCustomViewStyle.class.equals(style) |
| 1364 | || Notification.DecoratedMediaCustomViewStyle.class.equals(style)); |
| 1365 | boolean hasCustomRemoteView = notification.contentView != null |
| 1366 | || notification.bigContentView != null |
| 1367 | || notification.headsUpContentView != null; |
| 1368 | return hasCustomRemoteView && !hasDecoratedStyle; |
| 1369 | } |
| 1370 | |
Julia Reynolds | d61bdf1 | 2020-02-25 12:25:07 -0500 | [diff] [blame] | 1371 | public void setShortcutInfo(ShortcutInfo shortcutInfo) { |
| 1372 | mShortcutInfo = shortcutInfo; |
| 1373 | } |
| 1374 | |
Julia Reynolds | 138111f | 2020-02-26 11:17:39 -0500 | [diff] [blame] | 1375 | public ShortcutInfo getShortcutInfo() { |
| 1376 | return mShortcutInfo; |
| 1377 | } |
| 1378 | |
Julia Reynolds | d61bdf1 | 2020-02-25 12:25:07 -0500 | [diff] [blame] | 1379 | /** |
| 1380 | * Whether this notification is a conversation notification. |
| 1381 | */ |
Danning Chen | 10326cf | 2020-01-16 13:29:13 -0800 | [diff] [blame] | 1382 | public boolean isConversation() { |
| 1383 | Notification notification = getNotification(); |
| 1384 | if (mChannel.isDemoted() |
| 1385 | || !Notification.MessagingStyle.class.equals(notification.getNotificationStyle())) { |
| 1386 | return false; |
| 1387 | } |
Julia Reynolds | e24faa2 | 2020-04-02 12:44:47 -0400 | [diff] [blame] | 1388 | if (mShortcutInfo == null && Settings.Global.getInt(mContext.getContentResolver(), |
| 1389 | Settings.Global.REQUIRE_SHORTCUTS_FOR_CONVERSATIONS, 0) == 1) { |
Danning Chen | 10326cf | 2020-01-16 13:29:13 -0800 | [diff] [blame] | 1390 | return false; |
| 1391 | } |
| 1392 | if (mIsNotConversationOverride) { |
| 1393 | return false; |
| 1394 | } |
Danning Chen | 10326cf | 2020-01-16 13:29:13 -0800 | [diff] [blame] | 1395 | return true; |
| 1396 | } |
| 1397 | |
Julia Reynolds | 24edc00 | 2020-01-29 16:35:32 -0500 | [diff] [blame] | 1398 | StatusBarNotification getSbn() { |
| 1399 | return sbn; |
| 1400 | } |
| 1401 | |
Julia Reynolds | a33f5c4 | 2017-01-31 16:53:35 -0500 | [diff] [blame] | 1402 | @VisibleForTesting |
| 1403 | static final class Light { |
| 1404 | public final int color; |
| 1405 | public final int onMs; |
| 1406 | public final int offMs; |
| 1407 | |
| 1408 | public Light(int color, int onMs, int offMs) { |
| 1409 | this.color = color; |
| 1410 | this.onMs = onMs; |
| 1411 | this.offMs = offMs; |
| 1412 | } |
| 1413 | |
| 1414 | @Override |
| 1415 | public boolean equals(Object o) { |
| 1416 | if (this == o) return true; |
| 1417 | if (o == null || getClass() != o.getClass()) return false; |
| 1418 | |
| 1419 | Light light = (Light) o; |
| 1420 | |
| 1421 | if (color != light.color) return false; |
| 1422 | if (onMs != light.onMs) return false; |
| 1423 | return offMs == light.offMs; |
| 1424 | |
| 1425 | } |
| 1426 | |
| 1427 | @Override |
| 1428 | public int hashCode() { |
| 1429 | int result = color; |
| 1430 | result = 31 * result + onMs; |
| 1431 | result = 31 * result + offMs; |
| 1432 | return result; |
| 1433 | } |
| 1434 | |
| 1435 | @Override |
| 1436 | public String toString() { |
| 1437 | return "Light{" + |
| 1438 | "color=" + color + |
| 1439 | ", onMs=" + onMs + |
| 1440 | ", offMs=" + offMs + |
| 1441 | '}'; |
| 1442 | } |
| 1443 | } |
Chris Wren | 333a61c | 2014-05-28 16:40:57 -0400 | [diff] [blame] | 1444 | } |