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