FillRequest.java revision 013efe173e56612a910ebd8576480ce4ef005e3c
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.app.assist.AssistStructure; 23import android.os.Bundle; 24import android.os.CancellationSignal; 25import android.os.Parcel; 26import android.os.Parcelable; 27import com.android.internal.util.Preconditions; 28 29import java.lang.annotation.Retention; 30import java.lang.annotation.RetentionPolicy; 31import java.util.concurrent.atomic.AtomicInteger; 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 private static AtomicInteger sIdCounter = new AtomicInteger(); 43 44 /** 45 * Indicates autofill was explicitly requested by the user. 46 */ 47 public static final int FLAG_MANUAL_REQUEST = 0x1; 48 49 /** @hide */ 50 @IntDef( 51 flag = true, 52 value = {FLAG_MANUAL_REQUEST}) 53 @Retention(RetentionPolicy.SOURCE) 54 @interface RequestFlags{} 55 56 private final int mId; 57 private final @RequestFlags int mFlags; 58 private final @NonNull AssistStructure mStructure; 59 private final @Nullable Bundle mClientState; 60 61 /** @hide */ 62 public FillRequest(@NonNull AssistStructure structure, 63 @Nullable Bundle clientState, @RequestFlags int flags) { 64 this(sIdCounter.incrementAndGet(), structure, clientState, flags); 65 } 66 67 private FillRequest(@NonNull Parcel parcel) { 68 mId = parcel.readInt(); 69 mStructure = parcel.readParcelable(null); 70 mClientState = parcel.readBundle(); 71 mFlags = parcel.readInt(); 72 } 73 74 private FillRequest(int id, @NonNull AssistStructure structure, 75 @Nullable Bundle clientState, @RequestFlags int flags) { 76 mId = id; 77 mFlags = Preconditions.checkFlagsArgument(flags, FLAG_MANUAL_REQUEST); 78 mStructure = Preconditions.checkNotNull(structure, "structure"); 79 mClientState = clientState; 80 } 81 82 /** 83 * @return The unique id of this request. 84 */ 85 public int getId() { 86 return mId; 87 } 88 89 /** 90 * @return The flags associated with this request. 91 * 92 * @see #FLAG_MANUAL_REQUEST 93 */ 94 public @RequestFlags int getFlags() { 95 return mFlags; 96 } 97 98 /** 99 * @return The structure capturing the UI state. 100 */ 101 public @NonNull AssistStructure getStructure() { 102 return mStructure; 103 } 104 105 /** 106 * Gets the extra client state returned from the last {@link 107 * AutofillService#onFillRequest(FillRequest, CancellationSignal, FillCallback) 108 * fill request}. 109 * <p> 110 * Once a {@link AutofillService#onSaveRequest(SaveRequest, SaveCallback) 111 * save request} is made the client state is cleared. 112 * 113 * @return The client state. 114 */ 115 public @Nullable Bundle getClientState() { 116 return mClientState; 117 } 118 119 @Override 120 public int describeContents() { 121 return 0; 122 } 123 124 @Override 125 public void writeToParcel(Parcel parcel, int flags) { 126 parcel.writeInt(mId); 127 parcel.writeParcelable(mStructure, flags); 128 parcel.writeBundle(mClientState); 129 parcel.writeInt(mFlags); 130 } 131 132 public static final Parcelable.Creator<FillRequest> CREATOR = 133 new Parcelable.Creator<FillRequest>() { 134 @Override 135 public FillRequest createFromParcel(Parcel parcel) { 136 return new FillRequest(parcel); 137 } 138 139 @Override 140 public FillRequest[] newArray(int size) { 141 return new FillRequest[size]; 142 } 143 }; 144} 145