2 * Copyright (C) 2017 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.service.autofill;
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.os.Bundle;
23 import android.os.CancellationSignal;
24 import android.os.Parcel;
25 import android.os.Parcelable;
26 import android.view.View;
28 import com.android.internal.util.Preconditions;
30 import java.lang.annotation.Retention;
31 import java.lang.annotation.RetentionPolicy;
32 import java.util.ArrayList;
33 import java.util.List;
36 * This class represents a request to an autofill service
37 * to interpret the screen and provide information to the system which views are
38 * interesting for saving and what are the possible ways to fill the inputs on
39 * the screen if applicable.
41 * @see AutofillService#onFillRequest(FillRequest, CancellationSignal, FillCallback)
43 public final class FillRequest implements Parcelable {
46 * Indicates autofill was explicitly requested by the user.
48 * <p>Users typically make an explicit request to autofill a screen in two situations:
50 * <li>The app disabled autofill (using {@link View#setImportantForAutofill(int)}.
51 * <li>The service could not figure out how to autofill a screen (but the user knows the
52 * service has data for that app).
55 * <p>This flag is particularly useful for the second case. For example, the service could offer
56 * a complex UI where the user can map which screen views belong to each user data, or it could
57 * offer a simpler UI where the user picks the data for just the view used to trigger the
58 * request (that would be the view whose
59 * {@link android.app.assist.AssistStructure.ViewNode#isFocused()} method returns {@code true}).
61 * <p>An explicit autofill request is triggered when the
62 * {@link android.view.autofill.AutofillManager#requestAutofill(View)} or
63 * {@link android.view.autofill.AutofillManager#requestAutofill(View, int, android.graphics.Rect)}
64 * is called. For example, standard {@link android.widget.TextView} views that use
65 * an {@link android.widget.Editor} shows an {@code AUTOFILL} option in the overflow menu that
66 * triggers such request.
68 public static final int FLAG_MANUAL_REQUEST = 0x1;
71 public static final int INVALID_REQUEST_ID = Integer.MIN_VALUE;
76 value = {FLAG_MANUAL_REQUEST})
77 @Retention(RetentionPolicy.SOURCE)
78 @interface RequestFlags{}
80 private final int mId;
81 private final @RequestFlags int mFlags;
82 private final @NonNull ArrayList<FillContext> mContexts;
83 private final @Nullable Bundle mClientState;
85 private FillRequest(@NonNull Parcel parcel) {
86 mId = parcel.readInt();
87 mContexts = new ArrayList<>();
88 parcel.readParcelableList(mContexts, null);
90 mClientState = parcel.readBundle();
91 mFlags = parcel.readInt();
95 public FillRequest(int id, @NonNull ArrayList<FillContext> contexts,
96 @Nullable Bundle clientState, @RequestFlags int flags) {
98 mFlags = Preconditions.checkFlagsArgument(flags, FLAG_MANUAL_REQUEST);
99 mContexts = Preconditions.checkCollectionElementsNotNull(contexts, "contexts");
100 mClientState = clientState;
104 * Gets the unique id of this request.
111 * Gets the flags associated with this request.
113 * @see #FLAG_MANUAL_REQUEST
115 public @RequestFlags int getFlags() {
120 * Gets the contexts associated with each previous fill request.
122 public @NonNull List<FillContext> getFillContexts() {
127 * Gets the extra client state returned from the last {@link
128 * AutofillService#onFillRequest(FillRequest, CancellationSignal, FillCallback)
129 * fill request}, so the service can use it for state management.
131 * <p>Once a {@link AutofillService#onSaveRequest(SaveRequest, SaveCallback)
132 * save request} is made, the client state is cleared.
134 * @return The client state.
136 public @Nullable Bundle getClientState() {
141 public int describeContents() {
146 public void writeToParcel(Parcel parcel, int flags) {
147 parcel.writeInt(mId);
148 parcel.writeParcelableList(mContexts, flags);
149 parcel.writeBundle(mClientState);
150 parcel.writeInt(mFlags);
153 public static final Parcelable.Creator<FillRequest> CREATOR =
154 new Parcelable.Creator<FillRequest>() {
156 public FillRequest createFromParcel(Parcel parcel) {
157 return new FillRequest(parcel);
161 public FillRequest[] newArray(int size) {
162 return new FillRequest[size];