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