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; 22 import android.os.CancellationSignal; 23 import android.os.Parcel; 24 import android.os.Parcelable; 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; 39 40 /** @hide */ 41 public SaveRequest(@NonNull ArrayList<FillContext> fillContexts, 42 @Nullable Bundle clientState) { 43 mFillContexts = Preconditions.checkNotNull(fillContexts, "fillContexts"); 44 mClientState = clientState; 45 } 46 47 private SaveRequest(@NonNull Parcel parcel) { 48 this(parcel.readTypedArrayList(null), parcel.readBundle()); 49 } 50 51 /** 52 * @return The contexts associated with each previous fill request. 53 */ 54 public @NonNull List<FillContext> getFillContexts() { 55 return mFillContexts; 56 } 57 58 /** 59 * Gets the extra client state returned from the last {@link 60 * AutofillService#onFillRequest(FillRequest, CancellationSignal, FillCallback)} 61 * fill request}. 62 * 63 * @return The client state. 64 */ 65 public @Nullable Bundle getClientState() { 66 return mClientState; 67 } 68 69 @Override 70 public int describeContents() { 71 return 0; 72 } 73 74 @Override 75 public void writeToParcel(Parcel parcel, int flags) { 76 parcel.writeTypedArrayList(mFillContexts, flags); 77 parcel.writeBundle(mClientState); 78 } 79 80 public static final Creator<SaveRequest> CREATOR = 81 new Creator<SaveRequest>() { 82 @Override 83 public SaveRequest createFromParcel(Parcel parcel) { 84 return new SaveRequest(parcel); 85 } 86 87 @Override 88 public SaveRequest[] newArray(int size) { 89 return new SaveRequest[size]; 90 } 91 }; 92 } 93