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