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