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