FillRequest.java revision 121e526476fb226cabf400c55a0bbfdd0781e772
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 17package android.service.autofill; 18 19import android.annotation.IntDef; 20import android.annotation.NonNull; 21import android.annotation.Nullable; 22import android.os.Bundle; 23import android.os.CancellationSignal; 24import android.os.Parcel; 25import android.os.Parcelable; 26 27import com.android.internal.util.Preconditions; 28 29import java.lang.annotation.Retention; 30import java.lang.annotation.RetentionPolicy; 31import java.util.ArrayList; 32 33/** 34 * This class represents a request to an {@link AutofillService autofill provider} 35 * to interpret the screen and provide information to the system which views are 36 * interesting for saving and what are the possible ways to fill the inputs on 37 * the screen if applicable. 38 * 39 * @see AutofillService#onFillRequest(FillRequest, CancellationSignal, FillCallback) 40 */ 41public final class FillRequest implements Parcelable { 42 /** 43 * Indicates autofill was explicitly requested by the user. 44 */ 45 public static final int FLAG_MANUAL_REQUEST = 0x1; 46 47 /** @hide */ 48 public static final int INVALID_REQUEST_ID = Integer.MIN_VALUE; 49 50 /** @hide */ 51 @IntDef( 52 flag = true, 53 value = {FLAG_MANUAL_REQUEST}) 54 @Retention(RetentionPolicy.SOURCE) 55 @interface RequestFlags{} 56 57 private final int mId; 58 private final @RequestFlags int mFlags; 59 private final @NonNull ArrayList<FillContext> mContexts; 60 private final @Nullable Bundle mClientState; 61 62 private FillRequest(@NonNull Parcel parcel) { 63 mId = parcel.readInt(); 64 mContexts = new ArrayList<>(); 65 parcel.readParcelableList(mContexts, null); 66 67 mClientState = parcel.readBundle(); 68 mFlags = parcel.readInt(); 69 } 70 71 /** @hide */ 72 public FillRequest(int id, @NonNull ArrayList<FillContext> contexts, 73 @Nullable Bundle clientState, @RequestFlags int flags) { 74 mId = id; 75 mFlags = Preconditions.checkFlagsArgument(flags, FLAG_MANUAL_REQUEST); 76 mContexts = Preconditions.checkCollectionElementsNotNull(contexts, "contexts"); 77 mClientState = clientState; 78 } 79 80 /** 81 * @return The unique id of this request. 82 */ 83 public int getId() { 84 return mId; 85 } 86 87 /** 88 * @return The flags associated with this request. 89 * 90 * @see #FLAG_MANUAL_REQUEST 91 */ 92 public @RequestFlags int getFlags() { 93 return mFlags; 94 } 95 96 /** 97 * @return The contexts associated with each previous fill request. 98 */ 99 public @NonNull ArrayList<FillContext> getFillContexts() { 100 return mContexts; 101 } 102 103 /** 104 * Gets the extra client state returned from the last {@link 105 * AutofillService#onFillRequest(FillRequest, CancellationSignal, FillCallback) 106 * fill request}. 107 * <p> 108 * Once a {@link AutofillService#onSaveRequest(SaveRequest, SaveCallback) 109 * save request} is made the client state is cleared. 110 * 111 * @return The client state. 112 */ 113 public @Nullable Bundle getClientState() { 114 return mClientState; 115 } 116 117 @Override 118 public int describeContents() { 119 return 0; 120 } 121 122 @Override 123 public void writeToParcel(Parcel parcel, int flags) { 124 parcel.writeInt(mId); 125 parcel.writeParcelableList(mContexts, flags); 126 parcel.writeBundle(mClientState); 127 parcel.writeInt(mFlags); 128 } 129 130 public static final Parcelable.Creator<FillRequest> CREATOR = 131 new Parcelable.Creator<FillRequest>() { 132 @Override 133 public FillRequest createFromParcel(Parcel parcel) { 134 return new FillRequest(parcel); 135 } 136 137 @Override 138 public FillRequest[] newArray(int size) { 139 return new FillRequest[size]; 140 } 141 }; 142} 143