Adjustment.java revision 22f02b3e4acd7c6983f4d4d58b85069d5ec920ab
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}. 45 */ 46 public static final String KEY_SNOOZE_CRITERIA = "key_snooze_criteria"; 47 48 /** 49 * Create a notification adjustment. 50 * 51 * @param pkg The package of the notification. 52 * @param key The notification key. 53 * @param signals A bundle of signals that should inform notification display, ordering, and 54 * interruptiveness. 55 * @param explanation A human-readable justification for the adjustment. 56 */ 57 public Adjustment(String pkg, String key, Bundle signals, CharSequence explanation, int user) { 58 mPackage = pkg; 59 mKey = key; 60 mSignals = signals; 61 mExplanation = explanation; 62 mUser = user; 63 } 64 65 protected Adjustment(Parcel in) { 66 if (in.readInt() == 1) { 67 mPackage = in.readString(); 68 } else { 69 mPackage = null; 70 } 71 if (in.readInt() == 1) { 72 mKey = in.readString(); 73 } else { 74 mKey = null; 75 } 76 if (in.readInt() == 1) { 77 mExplanation = in.readCharSequence(); 78 } else { 79 mExplanation = null; 80 } 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 CharSequence getExplanation() { 106 return mExplanation; 107 } 108 109 public Bundle getSignals() { 110 return mSignals; 111 } 112 113 public int getUser() { 114 return mUser; 115 } 116 117 @Override 118 public int describeContents() { 119 return 0; 120 } 121 122 @Override 123 public void writeToParcel(Parcel dest, int flags) { 124 if (mPackage != null) { 125 dest.writeInt(1); 126 dest.writeString(mPackage); 127 } else { 128 dest.writeInt(0); 129 } 130 if (mKey != null) { 131 dest.writeInt(1); 132 dest.writeString(mKey); 133 } else { 134 dest.writeInt(0); 135 } 136 if (mExplanation != null) { 137 dest.writeInt(1); 138 dest.writeCharSequence(mExplanation); 139 } else { 140 dest.writeInt(0); 141 } 142 dest.writeBundle(mSignals); 143 dest.writeInt(mUser); 144 } 145} 146