Adjustment.java revision 77b2cc920fb27adaa156b463dccb0bd1b5c87eb9
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.net.Uri;
20import android.os.Bundle;
21import android.os.Parcel;
22import android.os.Parcelable;
23
24/**
25 * Ranking updates from the Assistant.
26 */
27public final class Adjustment implements Parcelable {
28    private final String mPackage;
29    private final String mKey;
30    private final int mImportance;
31    private final CharSequence mExplanation;
32    private final Uri mReference;
33    private final Bundle mSignals;
34    private final int mUser;
35
36    /**
37     * Create a notification adjustment.
38     *
39     * @param pkg The package of the notification.
40     * @param key The notification key.
41     * @param importance The recommended importance of the notification.
42     * @param signals A bundle of signals that should inform notification grouping and ordering.
43     * @param explanation A human-readable justification for the adjustment.
44     * @param reference A reference to an external object that augments the
45     *                  explanation, such as a
46     *                  {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI},
47     *                  or null.
48     */
49    public Adjustment(String pkg, String key, int importance, Bundle signals,
50            CharSequence explanation, Uri reference, int user) {
51        mPackage = pkg;
52        mKey = key;
53        mImportance = importance;
54        mSignals = signals;
55        mExplanation = explanation;
56        mReference = reference;
57        mUser = user;
58    }
59
60    protected Adjustment(Parcel in) {
61        if (in.readInt() == 1) {
62            mPackage = in.readString();
63        } else {
64            mPackage = null;
65        }
66        if (in.readInt() == 1) {
67            mKey = in.readString();
68        } else {
69            mKey = null;
70        }
71        mImportance = in.readInt();
72        if (in.readInt() == 1) {
73            mExplanation = in.readCharSequence();
74        } else {
75            mExplanation = null;
76        }
77        mReference = in.readParcelable(Uri.class.getClassLoader());
78        mSignals = in.readBundle();
79        mUser = in.readInt();
80    }
81
82    public static final Creator<Adjustment> CREATOR = new Creator<Adjustment>() {
83        @Override
84        public Adjustment createFromParcel(Parcel in) {
85            return new Adjustment(in);
86        }
87
88        @Override
89        public Adjustment[] newArray(int size) {
90            return new Adjustment[size];
91        }
92    };
93
94    public String getPackage() {
95        return mPackage;
96    }
97
98    public String getKey() {
99        return mKey;
100    }
101
102    public int getImportance() {
103        return mImportance;
104    }
105
106    public CharSequence getExplanation() {
107        return mExplanation;
108    }
109
110    public Uri getReference() {
111        return mReference;
112    }
113
114    public Bundle getSignals() {
115        return mSignals;
116    }
117
118    public int getUser() {
119        return mUser;
120    }
121
122    @Override
123    public int describeContents() {
124        return 0;
125    }
126
127    @Override
128    public void writeToParcel(Parcel dest, int flags) {
129        if (mPackage != null) {
130            dest.writeInt(1);
131            dest.writeString(mPackage);
132        } else {
133            dest.writeInt(0);
134        }
135        if (mKey != null) {
136            dest.writeInt(1);
137            dest.writeString(mKey);
138        } else {
139            dest.writeInt(0);
140        }
141        dest.writeInt(mImportance);
142        if (mExplanation != null) {
143            dest.writeInt(1);
144            dest.writeCharSequence(mExplanation);
145        } else {
146            dest.writeInt(0);
147        }
148        dest.writeParcelable(mReference, flags);
149        dest.writeBundle(mSignals);
150        dest.writeInt(mUser);
151    }
152}
153