blob: c9b5b5529111b76c1b1be25b6bd0c00f06b7114b [file] [log] [blame]
Svet Ganov013efe12017-04-13 21:56:16 -07001/*
2 * Copyright (C) 2017 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
17package android.service.autofill;
18
19import android.annotation.NonNull;
20import android.annotation.Nullable;
21import android.os.Bundle;
Svet Ganov013efe12017-04-13 21:56:16 -070022import android.os.Parcel;
23import android.os.Parcelable;
Felipe Leme98528972017-08-31 17:04:08 -070024
Svet Ganov013efe12017-04-13 21:56:16 -070025import com.android.internal.util.Preconditions;
26
27import java.util.ArrayList;
28import java.util.List;
29
30/**
31 * This class represents a request to an {@link AutofillService
32 * autofill provider} to save applicable data entered by the user.
33 *
34 * @see AutofillService#onSaveRequest(SaveRequest, SaveCallback)
35 */
36public final class SaveRequest implements Parcelable {
37 private final @NonNull ArrayList<FillContext> mFillContexts;
38 private final @Nullable Bundle mClientState;
Felipe Leme98528972017-08-31 17:04:08 -070039 private final @Nullable ArrayList<String> mDatasetIds;
Svet Ganov013efe12017-04-13 21:56:16 -070040
41 /** @hide */
42 public SaveRequest(@NonNull ArrayList<FillContext> fillContexts,
Felipe Leme98528972017-08-31 17:04:08 -070043 @Nullable Bundle clientState, @Nullable ArrayList<String> datasetIds) {
Svet Ganov013efe12017-04-13 21:56:16 -070044 mFillContexts = Preconditions.checkNotNull(fillContexts, "fillContexts");
45 mClientState = clientState;
Felipe Leme98528972017-08-31 17:04:08 -070046 mDatasetIds = datasetIds;
Svet Ganov013efe12017-04-13 21:56:16 -070047 }
48
49 private SaveRequest(@NonNull Parcel parcel) {
Sunny Goyal0e60f222017-09-21 21:39:20 -070050 this(parcel.createTypedArrayList(FillContext.CREATOR),
51 parcel.readBundle(), parcel.createStringArrayList());
Svet Ganov013efe12017-04-13 21:56:16 -070052 }
53
54 /**
Felipe Leme8d7f7f42018-07-31 16:14:39 -070055 * Gets the contexts associated with each previous fill request.
56 *
57 * <p><b>Note:</b> Starting on Android {@link android.os.Build.VERSION_CODES#Q}, it could also
58 * include contexts from requests whose {@link SaveInfo} had the
59 * {@link SaveInfo#FLAG_DELAY_SAVE} flag.
60 *
Svet Ganov013efe12017-04-13 21:56:16 -070061 * @return The contexts associated with each previous fill request.
62 */
63 public @NonNull List<FillContext> getFillContexts() {
64 return mFillContexts;
65 }
66
67 /**
Felipe Lemed37f53e2017-12-07 10:41:10 -080068 * Gets the latest client state bundle set by the service in a
69 * {@link FillResponse.Builder#setClientState(Bundle) fill response}.
Felipe Lemea9372382017-10-09 14:42:36 -070070 *
71 * <p><b>Note:</b> Prior to Android {@link android.os.Build.VERSION_CODES#P}, only client state
Felipe Lemed37f53e2017-12-07 10:41:10 -080072 * bundles set by {@link FillResponse.Builder#setClientState(Bundle)} were considered. On
Felipe Lemea9372382017-10-09 14:42:36 -070073 * Android {@link android.os.Build.VERSION_CODES#P} and higher, bundles set in the result of
74 * an authenticated request through the
75 * {@link android.view.autofill.AutofillManager#EXTRA_CLIENT_STATE} extra are
76 * also considered (and take precedence when set).
Svet Ganov013efe12017-04-13 21:56:16 -070077 *
78 * @return The client state.
79 */
80 public @Nullable Bundle getClientState() {
81 return mClientState;
82 }
83
Felipe Leme98528972017-08-31 17:04:08 -070084 /**
85 * Gets the ids of the datasets selected by the user, in the order in which they were selected.
86 */
87 @Nullable
88 public List<String> getDatasetIds() {
89 return mDatasetIds;
90 }
91
Svet Ganov013efe12017-04-13 21:56:16 -070092 @Override
93 public int describeContents() {
94 return 0;
95 }
96
97 @Override
98 public void writeToParcel(Parcel parcel, int flags) {
Sunny Goyal0e60f222017-09-21 21:39:20 -070099 parcel.writeTypedList(mFillContexts, flags);
Svet Ganov013efe12017-04-13 21:56:16 -0700100 parcel.writeBundle(mClientState);
Felipe Leme98528972017-08-31 17:04:08 -0700101 parcel.writeStringList(mDatasetIds);
Svet Ganov013efe12017-04-13 21:56:16 -0700102 }
103
104 public static final Creator<SaveRequest> CREATOR =
105 new Creator<SaveRequest>() {
106 @Override
107 public SaveRequest createFromParcel(Parcel parcel) {
108 return new SaveRequest(parcel);
109 }
110
111 @Override
112 public SaveRequest[] newArray(int size) {
113 return new SaveRequest[size];
114 }
115 };
116}