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