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