Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 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.IntDef; |
| 20 | import android.annotation.NonNull; |
| 21 | import android.annotation.Nullable; |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 22 | import android.os.Bundle; |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 23 | import android.os.Parcel; |
| 24 | import android.os.Parcelable; |
Felipe Leme | 2ef19c1 | 2017-06-05 11:32:32 -0700 | [diff] [blame] | 25 | import android.view.View; |
Philip P. Moltmann | 121e526 | 2017-04-25 13:33:41 -0700 | [diff] [blame] | 26 | |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 27 | import com.android.internal.util.Preconditions; |
| 28 | |
| 29 | import java.lang.annotation.Retention; |
| 30 | import java.lang.annotation.RetentionPolicy; |
Philip P. Moltmann | 121e526 | 2017-04-25 13:33:41 -0700 | [diff] [blame] | 31 | import java.util.ArrayList; |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 32 | import java.util.List; |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
Felipe Leme | 2ef19c1 | 2017-06-05 11:32:32 -0700 | [diff] [blame] | 35 | * This class represents a request to an autofill service |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 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 | * |
Felipe Leme | a012d7e | 2017-09-06 15:19:11 -0700 | [diff] [blame] | 40 | * @see AutofillService#onFillRequest(FillRequest, android.os.CancellationSignal, FillCallback) |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 41 | */ |
| 42 | public final class FillRequest implements Parcelable { |
Felipe Leme | 2ef19c1 | 2017-06-05 11:32:32 -0700 | [diff] [blame] | 43 | |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 44 | /** |
| 45 | * Indicates autofill was explicitly requested by the user. |
Felipe Leme | 2ef19c1 | 2017-06-05 11:32:32 -0700 | [diff] [blame] | 46 | * |
| 47 | * <p>Users typically make an explicit request to autofill a screen in two situations: |
| 48 | * <ul> |
| 49 | * <li>The app disabled autofill (using {@link View#setImportantForAutofill(int)}. |
| 50 | * <li>The service could not figure out how to autofill a screen (but the user knows the |
| 51 | * service has data for that app). |
| 52 | * </ul> |
| 53 | * |
| 54 | * <p>This flag is particularly useful for the second case. For example, the service could offer |
| 55 | * a complex UI where the user can map which screen views belong to each user data, or it could |
| 56 | * offer a simpler UI where the user picks the data for just the view used to trigger the |
| 57 | * request (that would be the view whose |
| 58 | * {@link android.app.assist.AssistStructure.ViewNode#isFocused()} method returns {@code true}). |
| 59 | * |
| 60 | * <p>An explicit autofill request is triggered when the |
| 61 | * {@link android.view.autofill.AutofillManager#requestAutofill(View)} or |
| 62 | * {@link android.view.autofill.AutofillManager#requestAutofill(View, int, android.graphics.Rect)} |
Jeff Sharkey | 67f9d50 | 2017-08-05 13:49:13 -0600 | [diff] [blame] | 63 | * is called. For example, standard {@link android.widget.TextView} views show an |
| 64 | * {@code AUTOFILL} option in the overflow menu that triggers such request. |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 65 | */ |
| 66 | public static final int FLAG_MANUAL_REQUEST = 0x1; |
| 67 | |
Felipe Leme | eacd74d | 2018-08-02 10:36:34 -0700 | [diff] [blame] | 68 | /** |
| 69 | * Indicates this request was made using |
| 70 | * <a href="AutofillService.html#CompatibilityMode">compatibility mode</a>. |
| 71 | */ |
| 72 | public static final int FLAG_COMPATIBILITY_MODE_REQUEST = 0x2; |
| 73 | |
Felipe Leme | a7de402 | 2019-02-19 17:16:45 -0800 | [diff] [blame] | 74 | // Private flags below start from the highest-significative bit (0x80000000) |
| 75 | /** |
| 76 | * Request was only triggered for augmented autofill. |
| 77 | * |
| 78 | * @hide |
| 79 | */ |
| 80 | public static final int FLAG_AUGMENTED_AUTOFILL_REQUEST = 0x80000000; |
| 81 | |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 82 | /** @hide */ |
Philip P. Moltmann | c761963 | 2017-04-25 11:57:37 -0700 | [diff] [blame] | 83 | public static final int INVALID_REQUEST_ID = Integer.MIN_VALUE; |
| 84 | |
| 85 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 86 | @IntDef(flag = true, prefix = { "FLAG_" }, value = { |
Felipe Leme | eacd74d | 2018-08-02 10:36:34 -0700 | [diff] [blame] | 87 | FLAG_MANUAL_REQUEST, FLAG_COMPATIBILITY_MODE_REQUEST |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 88 | }) |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 89 | @Retention(RetentionPolicy.SOURCE) |
| 90 | @interface RequestFlags{} |
| 91 | |
| 92 | private final int mId; |
| 93 | private final @RequestFlags int mFlags; |
Philip P. Moltmann | 121e526 | 2017-04-25 13:33:41 -0700 | [diff] [blame] | 94 | private final @NonNull ArrayList<FillContext> mContexts; |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 95 | private final @Nullable Bundle mClientState; |
| 96 | |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 97 | private FillRequest(@NonNull Parcel parcel) { |
| 98 | mId = parcel.readInt(); |
Philip P. Moltmann | 121e526 | 2017-04-25 13:33:41 -0700 | [diff] [blame] | 99 | mContexts = new ArrayList<>(); |
| 100 | parcel.readParcelableList(mContexts, null); |
| 101 | |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 102 | mClientState = parcel.readBundle(); |
| 103 | mFlags = parcel.readInt(); |
| 104 | } |
| 105 | |
Philip P. Moltmann | 2f517c2 | 2017-04-21 16:33:52 -0700 | [diff] [blame] | 106 | /** @hide */ |
Philip P. Moltmann | 121e526 | 2017-04-25 13:33:41 -0700 | [diff] [blame] | 107 | public FillRequest(int id, @NonNull ArrayList<FillContext> contexts, |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 108 | @Nullable Bundle clientState, @RequestFlags int flags) { |
| 109 | mId = id; |
Felipe Leme | eacd74d | 2018-08-02 10:36:34 -0700 | [diff] [blame] | 110 | mFlags = Preconditions.checkFlagsArgument(flags, |
| 111 | FLAG_MANUAL_REQUEST | FLAG_COMPATIBILITY_MODE_REQUEST); |
Philip P. Moltmann | 121e526 | 2017-04-25 13:33:41 -0700 | [diff] [blame] | 112 | mContexts = Preconditions.checkCollectionElementsNotNull(contexts, "contexts"); |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 113 | mClientState = clientState; |
| 114 | } |
| 115 | |
| 116 | /** |
Felipe Leme | 2ef19c1 | 2017-06-05 11:32:32 -0700 | [diff] [blame] | 117 | * Gets the unique id of this request. |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 118 | */ |
| 119 | public int getId() { |
| 120 | return mId; |
| 121 | } |
| 122 | |
| 123 | /** |
Felipe Leme | 2ef19c1 | 2017-06-05 11:32:32 -0700 | [diff] [blame] | 124 | * Gets the flags associated with this request. |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 125 | * |
Felipe Leme | a7de402 | 2019-02-19 17:16:45 -0800 | [diff] [blame] | 126 | * @return any combination of {@link #FLAG_MANUAL_REQUEST} and |
| 127 | * {@link #FLAG_COMPATIBILITY_MODE_REQUEST}. |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 128 | */ |
| 129 | public @RequestFlags int getFlags() { |
| 130 | return mFlags; |
| 131 | } |
| 132 | |
| 133 | /** |
Felipe Leme | 2ef19c1 | 2017-06-05 11:32:32 -0700 | [diff] [blame] | 134 | * Gets the contexts associated with each previous fill request. |
Felipe Leme | c7ee7af | 2018-08-27 12:36:16 -0700 | [diff] [blame] | 135 | * |
| 136 | * <p><b>Note:</b> Starting on Android {@link android.os.Build.VERSION_CODES#Q}, it could also |
| 137 | * include contexts from requests whose {@link SaveInfo} had the |
| 138 | * {@link SaveInfo#FLAG_DELAY_SAVE} flag. |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 139 | */ |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 140 | public @NonNull List<FillContext> getFillContexts() { |
Philip P. Moltmann | 121e526 | 2017-04-25 13:33:41 -0700 | [diff] [blame] | 141 | return mContexts; |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Felipe Leme | a012d7e | 2017-09-06 15:19:11 -0700 | [diff] [blame] | 144 | @Override |
| 145 | public String toString() { |
| 146 | return "FillRequest: [id=" + mId + ", flags=" + mFlags + ", ctxts= " + mContexts + "]"; |
| 147 | } |
| 148 | |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 149 | /** |
Felipe Leme | d37f53e | 2017-12-07 10:41:10 -0800 | [diff] [blame] | 150 | * Gets the latest client state bundle set by the service in a |
| 151 | * {@link FillResponse.Builder#setClientState(Bundle) fill response}. |
Felipe Leme | 2ef19c1 | 2017-06-05 11:32:32 -0700 | [diff] [blame] | 152 | * |
Felipe Leme | d37f53e | 2017-12-07 10:41:10 -0800 | [diff] [blame] | 153 | * <p><b>Note:</b> Prior to Android {@link android.os.Build.VERSION_CODES#P}, only client state |
| 154 | * bundles set by {@link FillResponse.Builder#setClientState(Bundle)} were considered. On |
| 155 | * Android {@link android.os.Build.VERSION_CODES#P} and higher, bundles set in the result of |
| 156 | * an authenticated request through the |
| 157 | * {@link android.view.autofill.AutofillManager#EXTRA_CLIENT_STATE} extra are |
| 158 | * also considered (and take precedence when set). |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 159 | * |
| 160 | * @return The client state. |
| 161 | */ |
| 162 | public @Nullable Bundle getClientState() { |
| 163 | return mClientState; |
| 164 | } |
| 165 | |
| 166 | @Override |
| 167 | public int describeContents() { |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | @Override |
| 172 | public void writeToParcel(Parcel parcel, int flags) { |
| 173 | parcel.writeInt(mId); |
Philip P. Moltmann | 121e526 | 2017-04-25 13:33:41 -0700 | [diff] [blame] | 174 | parcel.writeParcelableList(mContexts, flags); |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 175 | parcel.writeBundle(mClientState); |
| 176 | parcel.writeInt(mFlags); |
| 177 | } |
| 178 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame^] | 179 | public static final @android.annotation.NonNull Parcelable.Creator<FillRequest> CREATOR = |
Svet Ganov | 013efe1 | 2017-04-13 21:56:16 -0700 | [diff] [blame] | 180 | new Parcelable.Creator<FillRequest>() { |
| 181 | @Override |
| 182 | public FillRequest createFromParcel(Parcel parcel) { |
| 183 | return new FillRequest(parcel); |
| 184 | } |
| 185 | |
| 186 | @Override |
| 187 | public FillRequest[] newArray(int size) { |
| 188 | return new FillRequest[size]; |
| 189 | } |
| 190 | }; |
| 191 | } |