Home | History | Annotate | Download | only in notification
      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  */
     16 package android.service.notification;
     17 
     18 import android.annotation.SystemApi;
     19 import android.annotation.TestApi;
     20 import android.app.Notification;
     21 import android.os.Bundle;
     22 import android.os.Parcel;
     23 import android.os.Parcelable;
     24 
     25 /**
     26  * Ranking updates from the Assistant.
     27  * @hide
     28  */
     29 @SystemApi
     30 @TestApi
     31 public 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      * Data type: String. Used to change what {@link Notification#getGroup() group} a notification
     53      * belongs to.
     54      * @hide
     55      */
     56     public static final String KEY_GROUP_KEY = "key_group_key";
     57 
     58     /**
     59      * Create a notification adjustment.
     60      *
     61      * @param pkg The package of the notification.
     62      * @param key The notification key.
     63      * @param signals A bundle of signals that should inform notification display, ordering, and
     64      *                interruptiveness.
     65      * @param explanation A human-readable justification for the adjustment.
     66      */
     67     public Adjustment(String pkg, String key, Bundle signals, CharSequence explanation, int user) {
     68         mPackage = pkg;
     69         mKey = key;
     70         mSignals = signals;
     71         mExplanation = explanation;
     72         mUser = user;
     73     }
     74 
     75     protected Adjustment(Parcel in) {
     76         if (in.readInt() == 1) {
     77             mPackage = in.readString();
     78         } else {
     79             mPackage = null;
     80         }
     81         if (in.readInt() == 1) {
     82             mKey = in.readString();
     83         } else {
     84             mKey = null;
     85         }
     86         if (in.readInt() == 1) {
     87             mExplanation = in.readCharSequence();
     88         } else {
     89             mExplanation = null;
     90         }
     91         mSignals = in.readBundle();
     92         mUser = in.readInt();
     93     }
     94 
     95     public static final Creator<Adjustment> CREATOR = new Creator<Adjustment>() {
     96         @Override
     97         public Adjustment createFromParcel(Parcel in) {
     98             return new Adjustment(in);
     99         }
    100 
    101         @Override
    102         public Adjustment[] newArray(int size) {
    103             return new Adjustment[size];
    104         }
    105     };
    106 
    107     public String getPackage() {
    108         return mPackage;
    109     }
    110 
    111     public String getKey() {
    112         return mKey;
    113     }
    114 
    115     public CharSequence getExplanation() {
    116         return mExplanation;
    117     }
    118 
    119     public Bundle getSignals() {
    120         return mSignals;
    121     }
    122 
    123     public int getUser() {
    124         return mUser;
    125     }
    126 
    127     @Override
    128     public int describeContents() {
    129         return 0;
    130     }
    131 
    132     @Override
    133     public void writeToParcel(Parcel dest, int flags) {
    134         if (mPackage != null) {
    135             dest.writeInt(1);
    136             dest.writeString(mPackage);
    137         } else {
    138             dest.writeInt(0);
    139         }
    140         if (mKey != null) {
    141             dest.writeInt(1);
    142             dest.writeString(mKey);
    143         } else {
    144             dest.writeInt(0);
    145         }
    146         if (mExplanation != null) {
    147             dest.writeInt(1);
    148             dest.writeCharSequence(mExplanation);
    149         } else {
    150             dest.writeInt(0);
    151         }
    152         dest.writeBundle(mSignals);
    153         dest.writeInt(mUser);
    154     }
    155 
    156     @Override
    157     public String toString() {
    158         return "Adjustment{"
    159                 + "mSignals=" + mSignals
    160                 + '}';
    161     }
    162 }
    163