blob: 1cdb62fe89349565f5176ab929391872fba0efce [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
Fabian Kozynski867550e2019-02-28 12:59:57 -050018import android.annotation.NonNull;
Julia Reynolds79f02772019-02-15 11:38:48 -050019import android.annotation.SystemApi;
Julia Reynoldseb3dca72017-07-11 10:39:58 -040020import android.app.Notification;
Julia Reynoldse46bb372016-03-17 11:05:58 -040021import android.os.Bundle;
22import android.os.Parcel;
23import android.os.Parcelable;
Fabian Kozynski1d051c22019-02-19 13:36:07 -050024import android.os.UserHandle;
Julia Reynoldse46bb372016-03-17 11:05:58 -040025
26/**
Julia Reynolds77b2cc92016-11-08 14:41:09 -050027 * Ranking updates from the Assistant.
Fabian Kozynski1d051c22019-02-19 13:36:07 -050028 *
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 Reynoldsd0ceefa2019-03-03 16:10:52 -050035 *
36 * @hide
Julia Reynoldse46bb372016-03-17 11:05:58 -040037 */
Julia Reynoldsd0ceefa2019-03-03 16:10:52 -050038@SystemApi
Julia Reynoldse46bb372016-03-17 11:05:58 -040039public final class Adjustment implements Parcelable {
40 private final String mPackage;
41 private final String mKey;
Julia Reynoldse46bb372016-03-17 11:05:58 -040042 private final CharSequence mExplanation;
Julia Reynoldse46bb372016-03-17 11:05:58 -040043 private final Bundle mSignals;
Julia Reynoldseae43fb2016-05-09 12:42:58 -040044 private final int mUser;
Julia Reynoldse46bb372016-03-17 11:05:58 -040045
Julia Reynoldse46bb372016-03-17 11:05:58 -040046 /**
Julia Reynolds22f02b32016-12-01 15:05:13 -050047 * 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 Kozynskib0da4bc2019-01-15 17:44:27 -050050 * @hide
Julia Reynolds22f02b32016-12-01 15:05:13 -050051 */
Julia Reynolds79f02772019-02-15 11:38:48 -050052 @SystemApi
Julia Reynolds22f02b32016-12-01 15:05:13 -050053 public static final String KEY_PEOPLE = "key_people";
54 /**
Julia Reynolds79672302017-01-12 08:30:16 -050055 * 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 Reynolds22f02b32016-12-01 15:05:13 -050059 */
60 public static final String KEY_SNOOZE_CRITERIA = "key_snooze_criteria";
Julia Reynoldseb3dca72017-07-11 10:39:58 -040061 /**
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 Reynolds22f02b32016-12-01 15:05:13 -050067
68 /**
Julia Reynolds503ed942017-10-04 16:04:56 -040069 * 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 Mak628cb932018-06-19 18:30:41 +010078 * Data type: ArrayList of {@link android.app.Notification.Action}.
Tony Maka4716992019-01-24 15:41:59 +000079 * Used to suggest contextual actions for a notification.
80 *
81 * @see Notification.Action.Builder#setContextual(boolean)
Tony Mak628cb932018-06-19 18:30:41 +010082 */
Tony Maka4716992019-01-24 15:41:59 +000083 public static final String KEY_CONTEXTUAL_ACTIONS = "key_contextual_actions";
Tony Mak628cb932018-06-19 18:30:41 +010084
85 /**
Tony Makc9acf672018-07-20 13:58:24 +020086 * Data type: ArrayList of {@link CharSequence}.
87 * Used to suggest smart replies for a notification.
88 */
Tony Maka4716992019-01-24 15:41:59 +000089 public static final String KEY_TEXT_REPLIES = "key_text_replies";
Tony Makc9acf672018-07-20 13:58:24 +020090
91 /**
Julia Reynoldsefcdff42018-08-09 09:42:56 -040092 * Data type: int, one of importance values e.g.
93 * {@link android.app.NotificationManager#IMPORTANCE_MIN}.
94 *
Julia Reynolds27c0a962018-12-10 12:37:28 -050095 * <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 Reynoldsefcdff42018-08-09 09:42:56 -0400107 */
108 public static final String KEY_IMPORTANCE = "key_importance";
109
110 /**
Julia Reynoldse46bb372016-03-17 11:05:58 -0400111 * Create a notification adjustment.
112 *
113 * @param pkg The package of the notification.
114 * @param key The notification key.
Julia Reynolds22f02b32016-12-01 15:05:13 -0500115 * @param signals A bundle of signals that should inform notification display, ordering, and
116 * interruptiveness.
Julia Reynoldse46bb372016-03-17 11:05:58 -0400117 * @param explanation A human-readable justification for the adjustment.
Fabian Kozynski1d051c22019-02-19 13:36:07 -0500118 * @hide
Julia Reynoldse46bb372016-03-17 11:05:58 -0400119 */
Fabian Kozynski1d051c22019-02-19 13:36:07 -0500120 @SystemApi
Julia Reynolds22f02b32016-12-01 15:05:13 -0500121 public Adjustment(String pkg, String key, Bundle signals, CharSequence explanation, int user) {
Julia Reynoldse46bb372016-03-17 11:05:58 -0400122 mPackage = pkg;
123 mKey = key;
Julia Reynoldse46bb372016-03-17 11:05:58 -0400124 mSignals = signals;
125 mExplanation = explanation;
Julia Reynoldseae43fb2016-05-09 12:42:58 -0400126 mUser = user;
Julia Reynoldse46bb372016-03-17 11:05:58 -0400127 }
128
Julia Reynolds79f02772019-02-15 11:38:48 -0500129 /**
Fabian Kozynski1d051c22019-02-19 13:36:07 -0500130 * 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 Kozynski867550e2019-02-28 12:59:57 -0500139 public Adjustment(@NonNull String pkg, @NonNull String key, @NonNull Bundle signals,
140 @NonNull CharSequence explanation,
141 @NonNull UserHandle userHandle) {
Fabian Kozynski1d051c22019-02-19 13:36:07 -0500142 mPackage = pkg;
143 mKey = key;
144 mSignals = signals;
145 mExplanation = explanation;
146 mUser = userHandle.getIdentifier();
147 }
148
149 /**
Julia Reynolds79f02772019-02-15 11:38:48 -0500150 * @hide
151 */
152 @SystemApi
153 protected Adjustment(Parcel in) {
Julia Reynoldse46bb372016-03-17 11:05:58 -0400154 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 Reynoldse46bb372016-03-17 11:05:58 -0400164 if (in.readInt() == 1) {
165 mExplanation = in.readCharSequence();
166 } else {
167 mExplanation = null;
168 }
Julia Reynoldse46bb372016-03-17 11:05:58 -0400169 mSignals = in.readBundle();
Julia Reynoldseae43fb2016-05-09 12:42:58 -0400170 mUser = in.readInt();
Julia Reynoldse46bb372016-03-17 11:05:58 -0400171 }
172
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700173 public static final @android.annotation.NonNull Creator<Adjustment> CREATOR = new Creator<Adjustment>() {
Julia Reynoldse46bb372016-03-17 11:05:58 -0400174 @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 Kozynski867550e2019-02-28 12:59:57 -0500185 public @NonNull String getPackage() {
Julia Reynoldse46bb372016-03-17 11:05:58 -0400186 return mPackage;
187 }
188
Fabian Kozynski867550e2019-02-28 12:59:57 -0500189 public @NonNull String getKey() {
Julia Reynoldse46bb372016-03-17 11:05:58 -0400190 return mKey;
191 }
192
Fabian Kozynski867550e2019-02-28 12:59:57 -0500193 public @NonNull CharSequence getExplanation() {
Julia Reynoldse46bb372016-03-17 11:05:58 -0400194 return mExplanation;
195 }
196
Fabian Kozynski867550e2019-02-28 12:59:57 -0500197 public @NonNull Bundle getSignals() {
Julia Reynoldse46bb372016-03-17 11:05:58 -0400198 return mSignals;
199 }
200
Fabian Kozynski1d051c22019-02-19 13:36:07 -0500201 /** @hide */
202 @SystemApi
Julia Reynoldseae43fb2016-05-09 12:42:58 -0400203 public int getUser() {
204 return mUser;
205 }
206
Fabian Kozynski867550e2019-02-28 12:59:57 -0500207 public @NonNull UserHandle getUserHandle() {
Fabian Kozynski1d051c22019-02-19 13:36:07 -0500208 return UserHandle.of(mUser);
209 }
210
Julia Reynoldse46bb372016-03-17 11:05:58 -0400211 @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 Reynoldse46bb372016-03-17 11:05:58 -0400230 if (mExplanation != null) {
231 dest.writeInt(1);
232 dest.writeCharSequence(mExplanation);
233 } else {
234 dest.writeInt(0);
235 }
Julia Reynoldse46bb372016-03-17 11:05:58 -0400236 dest.writeBundle(mSignals);
Julia Reynoldseae43fb2016-05-09 12:42:58 -0400237 dest.writeInt(mUser);
Julia Reynoldse46bb372016-03-17 11:05:58 -0400238 }
Julia Reynoldseb3dca72017-07-11 10:39:58 -0400239
240 @Override
241 public String toString() {
242 return "Adjustment{"
243 + "mSignals=" + mSignals
244 + '}';
245 }
Julia Reynoldse46bb372016-03-17 11:05:58 -0400246}