Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.service.autofill; |
| 18 | |
| 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
| 21 | import android.os.Bundle; |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 22 | import android.os.Parcel; |
| 23 | import android.os.Parcelable; |
Felipe Leme | 9852897 | 2017-08-31 17:04:08 -0700 | [diff] [blame] | 24 | |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 25 | import com.android.internal.util.Preconditions; |
| 26 | |
| 27 | import java.util.ArrayList; |
| 28 | import 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 | */ |
| 36 | public final class SaveRequest implements Parcelable { |
| 37 | private final @NonNull ArrayList<FillContext> mFillContexts; |
| 38 | private final @Nullable Bundle mClientState; |
Felipe Leme | 9852897 | 2017-08-31 17:04:08 -0700 | [diff] [blame] | 39 | private final @Nullable ArrayList<String> mDatasetIds; |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 40 | |
| 41 | /** @hide */ |
| 42 | public SaveRequest(@NonNull ArrayList<FillContext> fillContexts, |
Felipe Leme | 9852897 | 2017-08-31 17:04:08 -0700 | [diff] [blame] | 43 | @Nullable Bundle clientState, @Nullable ArrayList<String> datasetIds) { |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 44 | mFillContexts = Preconditions.checkNotNull(fillContexts, "fillContexts"); |
| 45 | mClientState = clientState; |
Felipe Leme | 9852897 | 2017-08-31 17:04:08 -0700 | [diff] [blame] | 46 | mDatasetIds = datasetIds; |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | private SaveRequest(@NonNull Parcel parcel) { |
Sunny Goyal | 0e60f22 | 2017-09-21 21:39:20 -0700 | [diff] [blame] | 50 | this(parcel.createTypedArrayList(FillContext.CREATOR), |
| 51 | parcel.readBundle(), parcel.createStringArrayList()); |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /** |
Felipe Leme | 8d7f7f4 | 2018-07-31 16:14:39 -0700 | [diff] [blame] | 55 | * 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 Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 61 | * @return The contexts associated with each previous fill request. |
| 62 | */ |
| 63 | public @NonNull List<FillContext> getFillContexts() { |
| 64 | return mFillContexts; |
| 65 | } |
| 66 | |
| 67 | /** |
Felipe Leme | d37f53e | 2017-12-07 10:41:10 -0800 | [diff] [blame] | 68 | * Gets the latest client state bundle set by the service in a |
| 69 | * {@link FillResponse.Builder#setClientState(Bundle) fill response}. |
Felipe Leme | a937238 | 2017-10-09 14:42:36 -0700 | [diff] [blame] | 70 | * |
| 71 | * <p><b>Note:</b> Prior to Android {@link android.os.Build.VERSION_CODES#P}, only client state |
Felipe Leme | d37f53e | 2017-12-07 10:41:10 -0800 | [diff] [blame] | 72 | * bundles set by {@link FillResponse.Builder#setClientState(Bundle)} were considered. On |
Felipe Leme | a937238 | 2017-10-09 14:42:36 -0700 | [diff] [blame] | 73 | * 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 Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 77 | * |
| 78 | * @return The client state. |
| 79 | */ |
| 80 | public @Nullable Bundle getClientState() { |
| 81 | return mClientState; |
| 82 | } |
| 83 | |
Felipe Leme | 9852897 | 2017-08-31 17:04:08 -0700 | [diff] [blame] | 84 | /** |
| 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 Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 92 | @Override |
| 93 | public int describeContents() { |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public void writeToParcel(Parcel parcel, int flags) { |
Sunny Goyal | 0e60f22 | 2017-09-21 21:39:20 -0700 | [diff] [blame] | 99 | parcel.writeTypedList(mFillContexts, flags); |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 100 | parcel.writeBundle(mClientState); |
Felipe Leme | 9852897 | 2017-08-31 17:04:08 -0700 | [diff] [blame] | 101 | parcel.writeStringList(mDatasetIds); |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 102 | } |
| 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 | } |