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      * Data type: int, one of {@link NotificationListenerService.Ranking#USER_SENTIMENT_POSITIVE},
     60      * {@link NotificationListenerService.Ranking#USER_SENTIMENT_NEUTRAL},
     61      * {@link NotificationListenerService.Ranking#USER_SENTIMENT_NEGATIVE}. Used to express how
     62      * a user feels about notifications in the same {@link android.app.NotificationChannel} as
     63      * the notification represented by {@link #getKey()}.
     64      */
     65     public static final String KEY_USER_SENTIMENT = "key_user_sentiment";
     66 
     67     /**
     68      * Create a notification adjustment.
     69      *
     70      * @param pkg The package of the notification.
     71      * @param key The notification key.
     72      * @param signals A bundle of signals that should inform notification display, ordering, and
     73      *                interruptiveness.
     74      * @param explanation A human-readable justification for the adjustment.
     75      */
     76     public Adjustment(String pkg, String key, Bundle signals, CharSequence explanation, int user) {
     77         mPackage = pkg;
     78         mKey = key;
     79         mSignals = signals;
     80         mExplanation = explanation;
     81         mUser = user;
     82     }
     83 
     84     protected Adjustment(Parcel in) {
     85         if (in.readInt() == 1) {
     86             mPackage = in.readString();
     87         } else {
     88             mPackage = null;
     89         }
     90         if (in.readInt() == 1) {
     91             mKey = in.readString();
     92         } else {
     93             mKey = null;
     94         }
     95         if (in.readInt() == 1) {
     96             mExplanation = in.readCharSequence();
     97         } else {
     98             mExplanation = null;
     99         }
    100         mSignals = in.readBundle();
    101         mUser = in.readInt();
    102     }
    103 
    104     public static final Creator<Adjustment> CREATOR = new Creator<Adjustment>() {
    105         @Override
    106         public Adjustment createFromParcel(Parcel in) {
    107             return new Adjustment(in);
    108         }
    109 
    110         @Override
    111         public Adjustment[] newArray(int size) {
    112             return new Adjustment[size];
    113         }
    114     };
    115 
    116     public String getPackage() {
    117         return mPackage;
    118     }
    119 
    120     public String getKey() {
    121         return mKey;
    122     }
    123 
    124     public CharSequence getExplanation() {
    125         return mExplanation;
    126     }
    127 
    128     public Bundle getSignals() {
    129         return mSignals;
    130     }
    131 
    132     public int getUser() {
    133         return mUser;
    134     }
    135 
    136     @Override
    137     public int describeContents() {
    138         return 0;
    139     }
    140 
    141     @Override
    142     public void writeToParcel(Parcel dest, int flags) {
    143         if (mPackage != null) {
    144             dest.writeInt(1);
    145             dest.writeString(mPackage);
    146         } else {
    147             dest.writeInt(0);
    148         }
    149         if (mKey != null) {
    150             dest.writeInt(1);
    151             dest.writeString(mKey);
    152         } else {
    153             dest.writeInt(0);
    154         }
    155         if (mExplanation != null) {
    156             dest.writeInt(1);
    157             dest.writeCharSequence(mExplanation);
    158         } else {
    159             dest.writeInt(0);
    160         }
    161         dest.writeBundle(mSignals);
    162         dest.writeInt(mUser);
    163     }
    164 
    165     @Override
    166     public String toString() {
    167         return "Adjustment{"
    168                 + "mSignals=" + mSignals
    169                 + '}';
    170     }
    171 }
    172