1 /*
2  * Copyright (C) 2019 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 
17 package android.app;
18 
19 import android.net.Uri;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 
23 /**
24  * Stores historical input from a RemoteInput attached to a Notification.
25  *
26  * History items represent either a text message (specified by providing a CharSequence,
27  * or a media message (specified by providing a URI and a MIME type). Media messages must also
28  * include text to insert when the image cannot be loaded, ex. when URI read permission has not been
29  * granted correctly.
30  *
31  * @hide
32  */
33 public class RemoteInputHistoryItem implements Parcelable {
34     private CharSequence mText;
35     private String mMimeType;
36     private Uri mUri;
37 
RemoteInputHistoryItem(String mimeType, Uri uri, CharSequence backupText)38     public RemoteInputHistoryItem(String mimeType, Uri uri, CharSequence backupText) {
39         this.mMimeType = mimeType;
40         this.mUri = uri;
41         this.mText = Notification.safeCharSequence(backupText);
42     }
43 
RemoteInputHistoryItem(CharSequence text)44     public RemoteInputHistoryItem(CharSequence text) {
45         this.mText = Notification.safeCharSequence(text);
46     }
47 
RemoteInputHistoryItem(Parcel in)48     protected RemoteInputHistoryItem(Parcel in) {
49         mText = in.readCharSequence();
50         mMimeType = in.readStringNoHelper();
51         mUri = in.readParcelable(Uri.class.getClassLoader(), android.net.Uri.class);
52     }
53 
54     public static final Creator<RemoteInputHistoryItem> CREATOR =
55             new Creator<RemoteInputHistoryItem>() {
56                 @Override
57                 public RemoteInputHistoryItem createFromParcel(Parcel in) {
58                     return new RemoteInputHistoryItem(in);
59                 }
60 
61                 @Override
62                 public RemoteInputHistoryItem[] newArray(int size) {
63                     return new RemoteInputHistoryItem[size];
64                 }
65             };
66 
getText()67     public CharSequence getText() {
68         return mText;
69     }
70 
getMimeType()71     public String getMimeType() {
72         return mMimeType;
73     }
74 
getUri()75     public Uri getUri() {
76         return mUri;
77     }
78 
79     @Override
describeContents()80     public int describeContents() {
81         return 0;
82     }
83 
84     @Override
writeToParcel(Parcel dest, int flags)85     public void writeToParcel(Parcel dest, int flags) {
86         dest.writeCharSequence(mText);
87         dest.writeStringNoHelper(mMimeType);
88         dest.writeParcelable(mUri, flags);
89     }
90 }
91