Home | History | Annotate | Download | only in autofill
      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.Parcel;
     23 import android.os.Parcelable;
     24 
     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     private final @Nullable ArrayList<String> mDatasetIds;
     40 
     41     /** @hide */
     42     public SaveRequest(@NonNull ArrayList<FillContext> fillContexts,
     43             @Nullable Bundle clientState, @Nullable ArrayList<String> datasetIds) {
     44         mFillContexts = Preconditions.checkNotNull(fillContexts, "fillContexts");
     45         mClientState = clientState;
     46         mDatasetIds = datasetIds;
     47     }
     48 
     49     private SaveRequest(@NonNull Parcel parcel) {
     50         this(parcel.createTypedArrayList(FillContext.CREATOR),
     51                 parcel.readBundle(), parcel.createStringArrayList());
     52     }
     53 
     54     /**
     55      * @return The contexts associated with each previous fill request.
     56      */
     57     public @NonNull List<FillContext> getFillContexts() {
     58         return mFillContexts;
     59     }
     60 
     61     /**
     62      * Gets the latest client state bundle set by the service in a
     63      * {@link FillResponse.Builder#setClientState(Bundle) fill response}.
     64      *
     65      * <p><b>Note:</b> Prior to Android {@link android.os.Build.VERSION_CODES#P}, only client state
     66      * bundles set by {@link FillResponse.Builder#setClientState(Bundle)} were considered. On
     67      * Android {@link android.os.Build.VERSION_CODES#P} and higher, bundles set in the result of
     68      * an authenticated request through the
     69      * {@link android.view.autofill.AutofillManager#EXTRA_CLIENT_STATE} extra are
     70      * also considered (and take precedence when set).
     71      *
     72      * @return The client state.
     73      */
     74     public @Nullable Bundle getClientState() {
     75         return mClientState;
     76     }
     77 
     78     /**
     79      * Gets the ids of the datasets selected by the user, in the order in which they were selected.
     80      */
     81     @Nullable
     82     public List<String> getDatasetIds() {
     83         return mDatasetIds;
     84     }
     85 
     86     @Override
     87     public int describeContents() {
     88         return 0;
     89     }
     90 
     91     @Override
     92     public void writeToParcel(Parcel parcel, int flags) {
     93         parcel.writeTypedList(mFillContexts, flags);
     94         parcel.writeBundle(mClientState);
     95         parcel.writeStringList(mDatasetIds);
     96     }
     97 
     98     public static final Creator<SaveRequest> CREATOR =
     99             new Creator<SaveRequest>() {
    100         @Override
    101         public SaveRequest createFromParcel(Parcel parcel) {
    102             return new SaveRequest(parcel);
    103         }
    104 
    105         @Override
    106         public SaveRequest[] newArray(int size) {
    107             return new SaveRequest[size];
    108         }
    109     };
    110 }
    111