blob: bddc5ef3dd2de0520a8e1c4e9ceadeebf8790ac1 [file] [log] [blame]
Julia Reynoldse46bb372016-03-17 11:05:58 -04001/*
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 */
16package android.service.notification;
17
Julia Reynolds79f02772019-02-15 11:38:48 -050018import android.annotation.SystemApi;
Julia Reynoldseb3dca72017-07-11 10:39:58 -040019import android.app.Notification;
Julia Reynoldse46bb372016-03-17 11:05:58 -040020import android.os.Bundle;
21import android.os.Parcel;
22import android.os.Parcelable;
Fabian Kozynski1d051c22019-02-19 13:36:07 -050023import android.os.UserHandle;
Julia Reynoldse46bb372016-03-17 11:05:58 -040024
25/**
Julia Reynolds77b2cc92016-11-08 14:41:09 -050026 * Ranking updates from the Assistant.
Fabian Kozynski1d051c22019-02-19 13:36:07 -050027 *
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 Reynoldse46bb372016-03-17 11:05:58 -040034 */
Julia Reynoldse46bb372016-03-17 11:05:58 -040035public final class Adjustment implements Parcelable {
36 private final String mPackage;
37 private final String mKey;
Julia Reynoldse46bb372016-03-17 11:05:58 -040038 private final CharSequence mExplanation;
Julia Reynoldse46bb372016-03-17 11:05:58 -040039 private final Bundle mSignals;
Julia Reynoldseae43fb2016-05-09 12:42:58 -040040 private final int mUser;
Julia Reynoldse46bb372016-03-17 11:05:58 -040041
Julia Reynoldse46bb372016-03-17 11:05:58 -040042 /**
Julia Reynolds22f02b32016-12-01 15:05:13 -050043 * 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 Kozynskib0da4bc2019-01-15 17:44:27 -050046 * @hide
Julia Reynolds22f02b32016-12-01 15:05:13 -050047 */
Julia Reynolds79f02772019-02-15 11:38:48 -050048 @SystemApi
Julia Reynolds22f02b32016-12-01 15:05:13 -050049 public static final String KEY_PEOPLE = "key_people";
50 /**
Julia Reynolds79672302017-01-12 08:30:16 -050051 * 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 Reynolds22f02b32016-12-01 15:05:13 -050055 */
56 public static final String KEY_SNOOZE_CRITERIA = "key_snooze_criteria";
Julia Reynoldseb3dca72017-07-11 10:39:58 -040057 /**
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 Reynolds22f02b32016-12-01 15:05:13 -050063
64 /**
Julia Reynolds503ed942017-10-04 16:04:56 -040065 * 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 Mak628cb932018-06-19 18:30:41 +010074 * Data type: ArrayList of {@link android.app.Notification.Action}.
Tony Maka4716992019-01-24 15:41:59 +000075 * Used to suggest contextual actions for a notification.
76 *
77 * @see Notification.Action.Builder#setContextual(boolean)
Tony Mak628cb932018-06-19 18:30:41 +010078 */
Tony Maka4716992019-01-24 15:41:59 +000079 public static final String KEY_CONTEXTUAL_ACTIONS = "key_contextual_actions";
Tony Mak628cb932018-06-19 18:30:41 +010080
81 /**
Tony Makc9acf672018-07-20 13:58:24 +020082 * Data type: ArrayList of {@link CharSequence}.
83 * Used to suggest smart replies for a notification.
84 */
Tony Maka4716992019-01-24 15:41:59 +000085 public static final String KEY_TEXT_REPLIES = "key_text_replies";
Tony Makc9acf672018-07-20 13:58:24 +020086
87 /**
Julia Reynoldsefcdff42018-08-09 09:42:56 -040088 * Data type: int, one of importance values e.g.
89 * {@link android.app.NotificationManager#IMPORTANCE_MIN}.
90 *
Julia Reynolds27c0a962018-12-10 12:37:28 -050091 * <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 Reynoldsefcdff42018-08-09 09:42:56 -0400103 */
104 public static final String KEY_IMPORTANCE = "key_importance";
105
106 /**
Julia Reynoldse46bb372016-03-17 11:05:58 -0400107 * Create a notification adjustment.
108 *
109 * @param pkg The package of the notification.
110 * @param key The notification key.
Julia Reynolds22f02b32016-12-01 15:05:13 -0500111 * @param signals A bundle of signals that should inform notification display, ordering, and
112 * interruptiveness.
Julia Reynoldse46bb372016-03-17 11:05:58 -0400113 * @param explanation A human-readable justification for the adjustment.
Fabian Kozynski1d051c22019-02-19 13:36:07 -0500114 * @hide
Julia Reynoldse46bb372016-03-17 11:05:58 -0400115 */
Fabian Kozynski1d051c22019-02-19 13:36:07 -0500116 @SystemApi
Julia Reynolds22f02b32016-12-01 15:05:13 -0500117 public Adjustment(String pkg, String key, Bundle signals, CharSequence explanation, int user) {
Julia Reynoldse46bb372016-03-17 11:05:58 -0400118 mPackage = pkg;
119 mKey = key;
Julia Reynoldse46bb372016-03-17 11:05:58 -0400120 mSignals = signals;
121 mExplanation = explanation;
Julia Reynoldseae43fb2016-05-09 12:42:58 -0400122 mUser = user;
Julia Reynoldse46bb372016-03-17 11:05:58 -0400123 }
124
Julia Reynolds79f02772019-02-15 11:38:48 -0500125 /**
Fabian Kozynski1d051c22019-02-19 13:36:07 -0500126 * 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 Reynolds79f02772019-02-15 11:38:48 -0500145 * @hide
146 */
147 @SystemApi
148 protected Adjustment(Parcel in) {
Julia Reynoldse46bb372016-03-17 11:05:58 -0400149 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 Reynoldse46bb372016-03-17 11:05:58 -0400159 if (in.readInt() == 1) {
160 mExplanation = in.readCharSequence();
161 } else {
162 mExplanation = null;
163 }
Julia Reynoldse46bb372016-03-17 11:05:58 -0400164 mSignals = in.readBundle();
Julia Reynoldseae43fb2016-05-09 12:42:58 -0400165 mUser = in.readInt();
Julia Reynoldse46bb372016-03-17 11:05:58 -0400166 }
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 Reynoldse46bb372016-03-17 11:05:58 -0400188 public CharSequence getExplanation() {
189 return mExplanation;
190 }
191
Julia Reynoldse46bb372016-03-17 11:05:58 -0400192 public Bundle getSignals() {
193 return mSignals;
194 }
195
Fabian Kozynski1d051c22019-02-19 13:36:07 -0500196 /** @hide */
197 @SystemApi
Julia Reynoldseae43fb2016-05-09 12:42:58 -0400198 public int getUser() {
199 return mUser;
200 }
201
Fabian Kozynski1d051c22019-02-19 13:36:07 -0500202 public UserHandle getUserHandle() {
203 return UserHandle.of(mUser);
204 }
205
Julia Reynoldse46bb372016-03-17 11:05:58 -0400206 @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 Reynoldse46bb372016-03-17 11:05:58 -0400225 if (mExplanation != null) {
226 dest.writeInt(1);
227 dest.writeCharSequence(mExplanation);
228 } else {
229 dest.writeInt(0);
230 }
Julia Reynoldse46bb372016-03-17 11:05:58 -0400231 dest.writeBundle(mSignals);
Julia Reynoldseae43fb2016-05-09 12:42:58 -0400232 dest.writeInt(mUser);
Julia Reynoldse46bb372016-03-17 11:05:58 -0400233 }
Julia Reynoldseb3dca72017-07-11 10:39:58 -0400234
235 @Override
236 public String toString() {
237 return "Adjustment{"
238 + "mSignals=" + mSignals
239 + '}';
240 }
Julia Reynoldse46bb372016-03-17 11:05:58 -0400241}