Adjustment.java revision e46bb37acf6d3cfb9974672ace93f5381f70ad99
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 38 public static final String GROUP_KEY_OVERRIDE_KEY = "group_key_override"; 39 public static final String NEEDS_AUTOGROUPING_KEY = "autogroup_needed"; 40 41 /** 42 * Create a notification adjustment. 43 * 44 * @param pkg The package of the notification. 45 * @param key The notification key. 46 * @param importance The recommended importance of the notification. 47 * @param signals A bundle of signals that should inform notification grouping and ordering. 48 * @param explanation A human-readable justification for the adjustment. 49 * @param reference A reference to an external object that augments the 50 * explanation, such as a 51 * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}, 52 * or null. 53 */ 54 public Adjustment(String pkg, String key, int importance, Bundle signals, 55 CharSequence explanation, Uri reference) { 56 mPackage = pkg; 57 mKey = key; 58 mImportance = importance; 59 mSignals = signals; 60 mExplanation = explanation; 61 mReference = reference; 62 } 63 64 protected Adjustment(Parcel in) { 65 if (in.readInt() == 1) { 66 mPackage = in.readString(); 67 } else { 68 mPackage = null; 69 } 70 if (in.readInt() == 1) { 71 mKey = in.readString(); 72 } else { 73 mKey = null; 74 } 75 mImportance = in.readInt(); 76 if (in.readInt() == 1) { 77 mExplanation = in.readCharSequence(); 78 } else { 79 mExplanation = null; 80 } 81 mReference = in.readParcelable(Uri.class.getClassLoader()); 82 mSignals = in.readBundle(); 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 @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 dest.writeInt(mImportance); 141 if (mExplanation != null) { 142 dest.writeInt(1); 143 dest.writeCharSequence(mExplanation); 144 } else { 145 dest.writeInt(0); 146 } 147 dest.writeParcelable(mReference, flags); 148 dest.writeBundle(mSignals); 149 } 150} 151