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