Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 android.service.notification; |
| 17 | |
Fabian Kozynski | 867550e | 2019-02-28 12:59:57 -0500 | [diff] [blame] | 18 | import android.annotation.NonNull; |
Julia Reynolds | 79f0277 | 2019-02-15 11:38:48 -0500 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
Julia Reynolds | eb3dca7 | 2017-07-11 10:39:58 -0400 | [diff] [blame] | 20 | import android.app.Notification; |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 21 | import android.os.Bundle; |
| 22 | import android.os.Parcel; |
| 23 | import android.os.Parcelable; |
Fabian Kozynski | 1d051c2 | 2019-02-19 13:36:07 -0500 | [diff] [blame] | 24 | import android.os.UserHandle; |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 25 | |
| 26 | /** |
Julia Reynolds | 77b2cc9 | 2016-11-08 14:41:09 -0500 | [diff] [blame] | 27 | * Ranking updates from the Assistant. |
Fabian Kozynski | 1d051c2 | 2019-02-19 13:36:07 -0500 | [diff] [blame] | 28 | * |
| 29 | * The updates are provides as a {@link Bundle} of signals, using the keys provided in this |
| 30 | * class. |
| 31 | * Each {@code KEY} specifies what type of data it supports and what kind of Adjustment it |
| 32 | * realizes on the notification rankings. |
| 33 | * |
| 34 | * Notifications affected by the Adjustment will be re-ranked if necessary. |
Julia Reynolds | d0ceefa | 2019-03-03 16:10:52 -0500 | [diff] [blame] | 35 | * |
| 36 | * @hide |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 37 | */ |
Julia Reynolds | d0ceefa | 2019-03-03 16:10:52 -0500 | [diff] [blame] | 38 | @SystemApi |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 39 | public final class Adjustment implements Parcelable { |
| 40 | private final String mPackage; |
| 41 | private final String mKey; |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 42 | private final CharSequence mExplanation; |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 43 | private final Bundle mSignals; |
Julia Reynolds | eae43fb | 2016-05-09 12:42:58 -0400 | [diff] [blame] | 44 | private final int mUser; |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 45 | |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 46 | /** |
Julia Reynolds | 22f02b3 | 2016-12-01 15:05:13 -0500 | [diff] [blame] | 47 | * Data type: ArrayList of {@code String}, where each is a representation of a |
| 48 | * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}. |
| 49 | * See {@link android.app.Notification.Builder#addPerson(String)}. |
Fabian Kozynski | b0da4bc | 2019-01-15 17:44:27 -0500 | [diff] [blame] | 50 | * @hide |
Julia Reynolds | 22f02b3 | 2016-12-01 15:05:13 -0500 | [diff] [blame] | 51 | */ |
Julia Reynolds | 79f0277 | 2019-02-15 11:38:48 -0500 | [diff] [blame] | 52 | @SystemApi |
Julia Reynolds | 22f02b3 | 2016-12-01 15:05:13 -0500 | [diff] [blame] | 53 | public static final String KEY_PEOPLE = "key_people"; |
| 54 | /** |
Julia Reynolds | 7967230 | 2017-01-12 08:30:16 -0500 | [diff] [blame] | 55 | * Parcelable {@code ArrayList} of {@link SnoozeCriterion}. These criteria may be visible to |
| 56 | * users. If a user chooses to snooze a notification until one of these criterion, the |
| 57 | * assistant will be notified via |
| 58 | * {@link NotificationAssistantService#onNotificationSnoozedUntilContext}. |
Julia Reynolds | 22f02b3 | 2016-12-01 15:05:13 -0500 | [diff] [blame] | 59 | */ |
| 60 | public static final String KEY_SNOOZE_CRITERIA = "key_snooze_criteria"; |
Julia Reynolds | eb3dca7 | 2017-07-11 10:39:58 -0400 | [diff] [blame] | 61 | /** |
| 62 | * Data type: String. Used to change what {@link Notification#getGroup() group} a notification |
| 63 | * belongs to. |
| 64 | * @hide |
| 65 | */ |
| 66 | public static final String KEY_GROUP_KEY = "key_group_key"; |
Julia Reynolds | 22f02b3 | 2016-12-01 15:05:13 -0500 | [diff] [blame] | 67 | |
| 68 | /** |
Julia Reynolds | 503ed94 | 2017-10-04 16:04:56 -0400 | [diff] [blame] | 69 | * Data type: int, one of {@link NotificationListenerService.Ranking#USER_SENTIMENT_POSITIVE}, |
| 70 | * {@link NotificationListenerService.Ranking#USER_SENTIMENT_NEUTRAL}, |
| 71 | * {@link NotificationListenerService.Ranking#USER_SENTIMENT_NEGATIVE}. Used to express how |
| 72 | * a user feels about notifications in the same {@link android.app.NotificationChannel} as |
| 73 | * the notification represented by {@link #getKey()}. |
| 74 | */ |
| 75 | public static final String KEY_USER_SENTIMENT = "key_user_sentiment"; |
| 76 | |
| 77 | /** |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 78 | * Data type: ArrayList of {@link android.app.Notification.Action}. |
Tony Mak | a471699 | 2019-01-24 15:41:59 +0000 | [diff] [blame] | 79 | * Used to suggest contextual actions for a notification. |
| 80 | * |
| 81 | * @see Notification.Action.Builder#setContextual(boolean) |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 82 | */ |
Tony Mak | a471699 | 2019-01-24 15:41:59 +0000 | [diff] [blame] | 83 | public static final String KEY_CONTEXTUAL_ACTIONS = "key_contextual_actions"; |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 84 | |
| 85 | /** |
Tony Mak | c9acf67 | 2018-07-20 13:58:24 +0200 | [diff] [blame] | 86 | * Data type: ArrayList of {@link CharSequence}. |
| 87 | * Used to suggest smart replies for a notification. |
| 88 | */ |
Tony Mak | a471699 | 2019-01-24 15:41:59 +0000 | [diff] [blame] | 89 | public static final String KEY_TEXT_REPLIES = "key_text_replies"; |
Tony Mak | c9acf67 | 2018-07-20 13:58:24 +0200 | [diff] [blame] | 90 | |
| 91 | /** |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 92 | * Data type: int, one of importance values e.g. |
| 93 | * {@link android.app.NotificationManager#IMPORTANCE_MIN}. |
| 94 | * |
Julia Reynolds | 27c0a96 | 2018-12-10 12:37:28 -0500 | [diff] [blame] | 95 | * <p> If used from |
| 96 | * {@link NotificationAssistantService#onNotificationEnqueued(StatusBarNotification)}, and |
| 97 | * received before the notification is posted, it can block a notification from appearing or |
| 98 | * silence it. Importance adjustments received too late from |
| 99 | * {@link NotificationAssistantService#onNotificationEnqueued(StatusBarNotification)} will be |
| 100 | * ignored. |
| 101 | * </p> |
| 102 | * <p>If used from |
| 103 | * {@link NotificationAssistantService#adjustNotification(Adjustment)}, it can |
| 104 | * visually demote or cancel a notification, but use this with care if they notification was |
| 105 | * recently posted because the notification may already have made noise. |
| 106 | * </p> |
Julia Reynolds | efcdff4 | 2018-08-09 09:42:56 -0400 | [diff] [blame] | 107 | */ |
| 108 | public static final String KEY_IMPORTANCE = "key_importance"; |
| 109 | |
| 110 | /** |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 111 | * Create a notification adjustment. |
| 112 | * |
| 113 | * @param pkg The package of the notification. |
| 114 | * @param key The notification key. |
Julia Reynolds | 22f02b3 | 2016-12-01 15:05:13 -0500 | [diff] [blame] | 115 | * @param signals A bundle of signals that should inform notification display, ordering, and |
| 116 | * interruptiveness. |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 117 | * @param explanation A human-readable justification for the adjustment. |
Fabian Kozynski | 1d051c2 | 2019-02-19 13:36:07 -0500 | [diff] [blame] | 118 | * @hide |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 119 | */ |
Fabian Kozynski | 1d051c2 | 2019-02-19 13:36:07 -0500 | [diff] [blame] | 120 | @SystemApi |
Julia Reynolds | 22f02b3 | 2016-12-01 15:05:13 -0500 | [diff] [blame] | 121 | public Adjustment(String pkg, String key, Bundle signals, CharSequence explanation, int user) { |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 122 | mPackage = pkg; |
| 123 | mKey = key; |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 124 | mSignals = signals; |
| 125 | mExplanation = explanation; |
Julia Reynolds | eae43fb | 2016-05-09 12:42:58 -0400 | [diff] [blame] | 126 | mUser = user; |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 127 | } |
| 128 | |
Julia Reynolds | 79f0277 | 2019-02-15 11:38:48 -0500 | [diff] [blame] | 129 | /** |
Fabian Kozynski | 1d051c2 | 2019-02-19 13:36:07 -0500 | [diff] [blame] | 130 | * Create a notification adjustment. |
| 131 | * |
| 132 | * @param pkg The package of the notification. |
| 133 | * @param key The notification key. |
| 134 | * @param signals A bundle of signals that should inform notification display, ordering, and |
| 135 | * interruptiveness. |
| 136 | * @param explanation A human-readable justification for the adjustment. |
| 137 | * @param userHandle User handle for for whose the adjustments will be applied. |
| 138 | */ |
Fabian Kozynski | 867550e | 2019-02-28 12:59:57 -0500 | [diff] [blame] | 139 | public Adjustment(@NonNull String pkg, @NonNull String key, @NonNull Bundle signals, |
| 140 | @NonNull CharSequence explanation, |
| 141 | @NonNull UserHandle userHandle) { |
Fabian Kozynski | 1d051c2 | 2019-02-19 13:36:07 -0500 | [diff] [blame] | 142 | mPackage = pkg; |
| 143 | mKey = key; |
| 144 | mSignals = signals; |
| 145 | mExplanation = explanation; |
| 146 | mUser = userHandle.getIdentifier(); |
| 147 | } |
| 148 | |
| 149 | /** |
Julia Reynolds | 79f0277 | 2019-02-15 11:38:48 -0500 | [diff] [blame] | 150 | * @hide |
| 151 | */ |
| 152 | @SystemApi |
| 153 | protected Adjustment(Parcel in) { |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 154 | if (in.readInt() == 1) { |
| 155 | mPackage = in.readString(); |
| 156 | } else { |
| 157 | mPackage = null; |
| 158 | } |
| 159 | if (in.readInt() == 1) { |
| 160 | mKey = in.readString(); |
| 161 | } else { |
| 162 | mKey = null; |
| 163 | } |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 164 | if (in.readInt() == 1) { |
| 165 | mExplanation = in.readCharSequence(); |
| 166 | } else { |
| 167 | mExplanation = null; |
| 168 | } |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 169 | mSignals = in.readBundle(); |
Julia Reynolds | eae43fb | 2016-05-09 12:42:58 -0400 | [diff] [blame] | 170 | mUser = in.readInt(); |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 171 | } |
| 172 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 173 | public static final @android.annotation.NonNull Creator<Adjustment> CREATOR = new Creator<Adjustment>() { |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 174 | @Override |
| 175 | public Adjustment createFromParcel(Parcel in) { |
| 176 | return new Adjustment(in); |
| 177 | } |
| 178 | |
| 179 | @Override |
| 180 | public Adjustment[] newArray(int size) { |
| 181 | return new Adjustment[size]; |
| 182 | } |
| 183 | }; |
| 184 | |
Fabian Kozynski | 867550e | 2019-02-28 12:59:57 -0500 | [diff] [blame] | 185 | public @NonNull String getPackage() { |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 186 | return mPackage; |
| 187 | } |
| 188 | |
Fabian Kozynski | 867550e | 2019-02-28 12:59:57 -0500 | [diff] [blame] | 189 | public @NonNull String getKey() { |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 190 | return mKey; |
| 191 | } |
| 192 | |
Fabian Kozynski | 867550e | 2019-02-28 12:59:57 -0500 | [diff] [blame] | 193 | public @NonNull CharSequence getExplanation() { |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 194 | return mExplanation; |
| 195 | } |
| 196 | |
Fabian Kozynski | 867550e | 2019-02-28 12:59:57 -0500 | [diff] [blame] | 197 | public @NonNull Bundle getSignals() { |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 198 | return mSignals; |
| 199 | } |
| 200 | |
Fabian Kozynski | 1d051c2 | 2019-02-19 13:36:07 -0500 | [diff] [blame] | 201 | /** @hide */ |
| 202 | @SystemApi |
Julia Reynolds | eae43fb | 2016-05-09 12:42:58 -0400 | [diff] [blame] | 203 | public int getUser() { |
| 204 | return mUser; |
| 205 | } |
| 206 | |
Fabian Kozynski | 867550e | 2019-02-28 12:59:57 -0500 | [diff] [blame] | 207 | public @NonNull UserHandle getUserHandle() { |
Fabian Kozynski | 1d051c2 | 2019-02-19 13:36:07 -0500 | [diff] [blame] | 208 | return UserHandle.of(mUser); |
| 209 | } |
| 210 | |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 211 | @Override |
| 212 | public int describeContents() { |
| 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | @Override |
| 217 | public void writeToParcel(Parcel dest, int flags) { |
| 218 | if (mPackage != null) { |
| 219 | dest.writeInt(1); |
| 220 | dest.writeString(mPackage); |
| 221 | } else { |
| 222 | dest.writeInt(0); |
| 223 | } |
| 224 | if (mKey != null) { |
| 225 | dest.writeInt(1); |
| 226 | dest.writeString(mKey); |
| 227 | } else { |
| 228 | dest.writeInt(0); |
| 229 | } |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 230 | if (mExplanation != null) { |
| 231 | dest.writeInt(1); |
| 232 | dest.writeCharSequence(mExplanation); |
| 233 | } else { |
| 234 | dest.writeInt(0); |
| 235 | } |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 236 | dest.writeBundle(mSignals); |
Julia Reynolds | eae43fb | 2016-05-09 12:42:58 -0400 | [diff] [blame] | 237 | dest.writeInt(mUser); |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 238 | } |
Julia Reynolds | eb3dca7 | 2017-07-11 10:39:58 -0400 | [diff] [blame] | 239 | |
| 240 | @Override |
| 241 | public String toString() { |
| 242 | return "Adjustment{" |
| 243 | + "mSignals=" + mSignals |
| 244 | + '}'; |
| 245 | } |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 246 | } |