Adjustment.java revision 8f488d3f2f754bc6e8f4e87f40031a3f6a0b00db
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 Ranker.
26 *
27 * @hide
28 */
29@SystemApi
30public final class Adjustment implements Parcelable {
31    private final String mPackage;
32    private final String mKey;
33    private final int mImportance;
34    private final CharSequence mExplanation;
35    private final Uri mReference;
36    private final Bundle mSignals;
37    private final int mUser;
38
39    /**
40     * Create a notification adjustment.
41     *
42     * @param pkg The package of the notification.
43     * @param key The notification key.
44     * @param importance The recommended importance of the notification.
45     * @param signals A bundle of signals that should inform notification grouping and ordering.
46     * @param explanation A human-readable justification for the adjustment.
47     * @param reference A reference to an external object that augments the
48     *                  explanation, such as a
49     *                  {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI},
50     *                  or null.
51     */
52    public Adjustment(String pkg, String key, int importance, Bundle signals,
53            CharSequence explanation, Uri reference, int user) {
54        mPackage = pkg;
55        mKey = key;
56        mImportance = importance;
57        mSignals = signals;
58        mExplanation = explanation;
59        mReference = reference;
60        mUser = user;
61    }
62
63    protected Adjustment(Parcel in) {
64        if (in.readInt() == 1) {
65            mPackage = in.readString();
66        } else {
67            mPackage = null;
68        }
69        if (in.readInt() == 1) {
70            mKey = in.readString();
71        } else {
72            mKey = null;
73        }
74        mImportance = in.readInt();
75        if (in.readInt() == 1) {
76            mExplanation = in.readCharSequence();
77        } else {
78            mExplanation = null;
79        }
80        mReference = in.readParcelable(Uri.class.getClassLoader());
81        mSignals = in.readBundle();
82        mUser = in.readInt();
83    }
84
85    public static final Creator<Adjustment> CREATOR = new Creator<Adjustment>() {
86        @Override
87        public Adjustment createFromParcel(Parcel in) {
88            return new Adjustment(in);
89        }
90
91        @Override
92        public Adjustment[] newArray(int size) {
93            return new Adjustment[size];
94        }
95    };
96
97    public String getPackage() {
98        return mPackage;
99    }
100
101    public String getKey() {
102        return mKey;
103    }
104
105    public int getImportance() {
106        return mImportance;
107    }
108
109    public CharSequence getExplanation() {
110        return mExplanation;
111    }
112
113    public Uri getReference() {
114        return mReference;
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        dest.writeInt(mImportance);
145        if (mExplanation != null) {
146            dest.writeInt(1);
147            dest.writeCharSequence(mExplanation);
148        } else {
149            dest.writeInt(0);
150        }
151        dest.writeParcelable(mReference, flags);
152        dest.writeBundle(mSignals);
153        dest.writeInt(mUser);
154    }
155}
156