blob: 5b3930ab63362551411d8236144ddaf34455580a [file] [log] [blame]
Winson Chungfbbb1582018-11-13 16:09:01 -08001/*
2 * Copyright (C) 2018 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
Felipe Leme749b8892018-12-03 16:30:30 -080017package android.service.contentcapture;
Winson Chungfbbb1582018-11-13 16:09:01 -080018
19import android.annotation.NonNull;
20import android.annotation.Nullable;
21import android.annotation.SystemApi;
Felipe Leme19652c02019-02-04 13:01:29 -080022import android.annotation.TestApi;
Winson Chungfbbb1582018-11-13 16:09:01 -080023import android.app.assist.AssistContent;
24import android.app.assist.AssistStructure;
25import android.os.Bundle;
26import android.os.Parcel;
27import android.os.Parcelable;
28
29/**
30 * A container class for data taken from a snapshot of an activity.
31 *
32 * @hide
33 */
34@SystemApi
Felipe Leme19652c02019-02-04 13:01:29 -080035@TestApi
Winson Chungfbbb1582018-11-13 16:09:01 -080036public final class SnapshotData implements Parcelable {
37
38 private final @NonNull Bundle mAssistData;
39 private final @NonNull AssistStructure mAssistStructure;
40 private final @Nullable AssistContent mAssistContent;
41
42 /**
43 * Creates a new instance.
44 *
45 * @hide
46 */
47 public SnapshotData(@NonNull Bundle assistData, @NonNull AssistStructure assistStructure,
48 @Nullable AssistContent assistContent) {
49 mAssistData = assistData;
50 mAssistStructure = assistStructure;
51 mAssistContent = assistContent;
52 }
53
54 SnapshotData(@NonNull Parcel parcel) {
55 mAssistData = parcel.readBundle();
56 mAssistStructure = parcel.readParcelable(null);
57 mAssistContent = parcel.readParcelable(null);
58 }
59
60 /**
61 * Returns the assist data for this snapshot.
62 */
Felipe Lemece6877b2019-02-28 09:02:26 -080063 @NonNull
Winson Chungfbbb1582018-11-13 16:09:01 -080064 public Bundle getAssistData() {
65 return mAssistData;
66 }
67
68 /**
69 * Returns the assist structure for this snapshot.
70 */
Felipe Lemece6877b2019-02-28 09:02:26 -080071 @NonNull
Winson Chungfbbb1582018-11-13 16:09:01 -080072 public AssistStructure getAssistStructure() {
73 return mAssistStructure;
74 }
75
76 /**
77 * Returns the assist context for this snapshot.
78 */
Felipe Lemece6877b2019-02-28 09:02:26 -080079 @Nullable
Winson Chungfbbb1582018-11-13 16:09:01 -080080 public AssistContent getAssistContent() {
81 return mAssistContent;
82 }
83
84 @Override
85 public int describeContents() {
86 return 0;
87 }
88
89 @Override
90 public void writeToParcel(@NonNull Parcel parcel, int flags) {
91 parcel.writeBundle(mAssistData);
92 parcel.writeParcelable(mAssistStructure, flags);
93 parcel.writeParcelable(mAssistContent, flags);
94 }
95
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070096 public static final @android.annotation.NonNull Creator<SnapshotData> CREATOR =
Winson Chungfbbb1582018-11-13 16:09:01 -080097 new Creator<SnapshotData>() {
98
99 @Override
Felipe Lemece6877b2019-02-28 09:02:26 -0800100 @NonNull
Winson Chungfbbb1582018-11-13 16:09:01 -0800101 public SnapshotData createFromParcel(@NonNull Parcel parcel) {
102 return new SnapshotData(parcel);
103 }
104
105 @Override
Felipe Lemece6877b2019-02-28 09:02:26 -0800106 @NonNull
Winson Chungfbbb1582018-11-13 16:09:01 -0800107 public SnapshotData[] newArray(int size) {
108 return new SnapshotData[size];
109 }
110 };
111}