Adjustment.java revision 1327d3c3fabc9b4ffeb20e589f7b2350567b681f
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 */
16package android.service.notification;
17
18import android.annotation.SystemApi;
19import android.annotation.TestApi;
20import android.app.NotificationChannel;
21import android.os.Bundle;
22import android.os.Parcel;
23import android.os.Parcelable;
24
25/**
26 * Ranking updates from the Assistant.
27 * @hide
28 */
29@SystemApi
30@TestApi
31public final class Adjustment implements Parcelable {
32    private final String mPackage;
33    private final String mKey;
34    private final CharSequence mExplanation;
35    private final Bundle mSignals;
36    private final int mUser;
37
38    /**
39     * Data type: {@code String}. See {@link NotificationChannel#getId()}.
40     */
41    public static final String KEY_CHANNEL_ID = "key_channel_id";
42    /**
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)}.
46     */
47    public static final String KEY_PEOPLE = "key_people";
48    /**
49     * Parcelable {@code ArrayList} of {@link SnoozeCriterion}. These criteria may be visible to
50     * users. If a user chooses to snooze a notification until one of these criterion, the
51     * assistant will be notified via
52     * {@link NotificationAssistantService#onNotificationSnoozedUntilContext}.
53     */
54    public static final String KEY_SNOOZE_CRITERIA = "key_snooze_criteria";
55
56    /**
57     * Create a notification adjustment.
58     *
59     * @param pkg The package of the notification.
60     * @param key The notification key.
61     * @param signals A bundle of signals that should inform notification display, ordering, and
62     *                interruptiveness.
63     * @param explanation A human-readable justification for the adjustment.
64     */
65    public Adjustment(String pkg, String key, Bundle signals, CharSequence explanation, int user) {
66        mPackage = pkg;
67        mKey = key;
68        mSignals = signals;
69        mExplanation = explanation;
70        mUser = user;
71    }
72
73    protected Adjustment(Parcel in) {
74        if (in.readInt() == 1) {
75            mPackage = in.readString();
76        } else {
77            mPackage = null;
78        }
79        if (in.readInt() == 1) {
80            mKey = in.readString();
81        } else {
82            mKey = null;
83        }
84        if (in.readInt() == 1) {
85            mExplanation = in.readCharSequence();
86        } else {
87            mExplanation = null;
88        }
89        mSignals = in.readBundle();
90        mUser = in.readInt();
91    }
92
93    public static final Creator<Adjustment> CREATOR = new Creator<Adjustment>() {
94        @Override
95        public Adjustment createFromParcel(Parcel in) {
96            return new Adjustment(in);
97        }
98
99        @Override
100        public Adjustment[] newArray(int size) {
101            return new Adjustment[size];
102        }
103    };
104
105    public String getPackage() {
106        return mPackage;
107    }
108
109    public String getKey() {
110        return mKey;
111    }
112
113    public CharSequence getExplanation() {
114        return mExplanation;
115    }
116
117    public Bundle getSignals() {
118        return mSignals;
119    }
120
121    public int getUser() {
122        return mUser;
123    }
124
125    @Override
126    public int describeContents() {
127        return 0;
128    }
129
130    @Override
131    public void writeToParcel(Parcel dest, int flags) {
132        if (mPackage != null) {
133            dest.writeInt(1);
134            dest.writeString(mPackage);
135        } else {
136            dest.writeInt(0);
137        }
138        if (mKey != null) {
139            dest.writeInt(1);
140            dest.writeString(mKey);
141        } else {
142            dest.writeInt(0);
143        }
144        if (mExplanation != null) {
145            dest.writeInt(1);
146            dest.writeCharSequence(mExplanation);
147        } else {
148            dest.writeInt(0);
149        }
150        dest.writeBundle(mSignals);
151        dest.writeInt(mUser);
152    }
153}
154