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