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