• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
22 import android.content.IntentSender;
23 import android.os.Bundle;
24 import android.os.Parcel;
25 import android.os.Parcelable;
26 import android.view.View;
27 import android.view.inputmethod.InlineSuggestionsRequest;
28 
29 import com.android.internal.util.DataClass;
30 import com.android.internal.util.Preconditions;
31 
32 import java.lang.annotation.Retention;
33 import java.lang.annotation.RetentionPolicy;
34 import java.util.ArrayList;
35 import java.util.List;
36 
37 /**
38  * This class represents a request to an autofill service
39  * to interpret the screen and provide information to the system which views are
40  * interesting for saving and what are the possible ways to fill the inputs on
41  * the screen if applicable.
42  *
43  * @see AutofillService#onFillRequest(FillRequest, android.os.CancellationSignal, FillCallback)
44  */
45 @DataClass(
46         genToString = true,
47         genHiddenConstructor = true,
48         genHiddenConstDefs = true)
49 public final class FillRequest implements Parcelable {
50 
51     /**
52      * Indicates autofill was explicitly requested by the user.
53      *
54      * <p>Users typically make an explicit request to autofill a screen in two situations:
55      * <ul>
56      *   <li>The app disabled autofill (using {@link View#setImportantForAutofill(int)}.
57      *   <li>The service could not figure out how to autofill a screen (but the user knows the
58      *       service has data for that app).
59      * </ul>
60      *
61      * <p>This flag is particularly useful for the second case. For example, the service could offer
62      * a complex UI where the user can map which screen views belong to each user data, or it could
63      * offer a simpler UI where the user picks the data for just the view used to trigger the
64      * request (that would be the view whose
65      * {@link android.app.assist.AssistStructure.ViewNode#isFocused()} method returns {@code true}).
66      *
67      * <p>An explicit autofill request is triggered when the
68      * {@link android.view.autofill.AutofillManager#requestAutofill(View)} or
69      * {@link android.view.autofill.AutofillManager#requestAutofill(View, int, android.graphics.Rect)}
70      * is called. For example, standard {@link android.widget.TextView} views show an
71      * {@code AUTOFILL} option in the overflow menu that triggers such request.
72      */
73     public static final @RequestFlags int FLAG_MANUAL_REQUEST = 0x1;
74 
75     /**
76      * Indicates this request was made using
77      * <a href="AutofillService.html#CompatibilityMode">compatibility mode</a>.
78      */
79     public static final @RequestFlags int FLAG_COMPATIBILITY_MODE_REQUEST = 0x2;
80 
81     /**
82      * Indicates the request came from a password field.
83      *
84      * (TODO: b/141703197) Temporary fix for augmented autofill showing passwords.
85      *
86      * @hide
87      */
88     public static final @RequestFlags int FLAG_PASSWORD_INPUT_TYPE = 0x4;
89 
90     /**
91      * Indicates the view was not focused.
92      *
93      * <p><b>Note:</b> Defines the flag value to 0x10, because the flag value 0x08 has been defined
94      * in {@link AutofillManager}.</p>
95      *
96      * @hide
97      */
98     public static final @RequestFlags int FLAG_VIEW_NOT_FOCUSED = 0x10;
99 
100     // The flag value 0x20 has been used.
101 
102     /**
103      * Indicates the request supports fill dialog presentation for the fields, the
104      * system will send the request when the activity just started.
105      */
106     public static final @RequestFlags int FLAG_SUPPORTS_FILL_DIALOG = 0x40;
107 
108     /**
109      * Indicates the ime is showing while request coming.
110      * @hide
111      */
112     public static final @RequestFlags int FLAG_IME_SHOWING = 0x80;
113 
114     /**
115      * Indicates whether autofill session should reset the fill dialog state.
116      * @hide
117      */
118     public static final @RequestFlags int FLAG_RESET_FILL_DIALOG_STATE = 0x100;
119 
120     /** @hide */
121     public static final int INVALID_REQUEST_ID = Integer.MIN_VALUE;
122 
123     /**
124      * Gets the unique id of this request.
125      */
126     private final int mId;
127 
128     /**
129      * Gets the contexts associated with each previous fill request.
130      *
131      * <p><b>Note:</b> Starting on Android {@link android.os.Build.VERSION_CODES#Q}, it could also
132      * include contexts from requests whose {@link SaveInfo} had the
133      * {@link SaveInfo#FLAG_DELAY_SAVE} flag.
134      */
135     private final @NonNull List<FillContext> mFillContexts;
136 
137     /**
138      * Gets the latest client state bundle set by the service in a
139      * {@link FillResponse.Builder#setClientState(Bundle) fill response}.
140      *
141      * <p><b>Note:</b> Prior to Android {@link android.os.Build.VERSION_CODES#P}, only client state
142      * bundles set by {@link FillResponse.Builder#setClientState(Bundle)} were considered. On
143      * Android {@link android.os.Build.VERSION_CODES#P} and higher, bundles set in the result of
144      * an authenticated request through the
145      * {@link android.view.autofill.AutofillManager#EXTRA_CLIENT_STATE} extra are
146      * also considered (and take precedence when set).
147      *
148      * @return The client state.
149      */
150     private final @Nullable Bundle mClientState;
151 
152     /**
153      * Gets the flags associated with this request.
154      *
155      * @return any combination of {@link #FLAG_MANUAL_REQUEST},
156      *         {@link #FLAG_SUPPORTS_FILL_DIALOG} and
157      *         {@link #FLAG_COMPATIBILITY_MODE_REQUEST}.
158      *
159      */
160     private final @RequestFlags int mFlags;
161 
162     /**
163      * Gets the {@link InlineSuggestionsRequest} associated
164      * with this request.
165      *
166      * <p>Autofill Framework will send a {@code @non-null} {@link InlineSuggestionsRequest} if
167      * currently inline suggestions are supported and can be displayed. If the Autofill service
168      * wants to show inline suggestions, they may return {@link Dataset} with valid
169      * {@link InlinePresentation}.</p>
170      *
171      * <p>The Autofill Service must set supportsInlineSuggestions in its XML to enable support
172      * for inline suggestions.</p>
173      *
174      * @return the suggestionspec
175      */
176     private final @Nullable InlineSuggestionsRequest mInlineSuggestionsRequest;
177 
178     /**
179      * Gets the {@link IntentSender} to send a delayed fill response.
180      *
181      * <p>The autofill service must first indicate that it wants to return a delayed
182      * {@link FillResponse} by setting {@link FillResponse#FLAG_DELAY_FILL} in a successful
183      * fill response. Then it can use this IntentSender to send an Intent with extra
184      * {@link AutofillService#EXTRA_FILL_RESPONSE} with the delayed response.</p>
185      *
186      * <p>Note that this may be null if a delayed fill response is not supported for
187      * this fill request.</p>
188      */
189     private final @Nullable IntentSender mDelayedFillIntentSender;
190 
onConstructed()191     private void onConstructed() {
192         Preconditions.checkCollectionElementsNotNull(mFillContexts, "contexts");
193     }
194 
195 
196 
197     // Code below generated by codegen v1.0.23.
198     //
199     // DO NOT MODIFY!
200     // CHECKSTYLE:OFF Generated code
201     //
202     // To regenerate run:
203     // $ codegen $ANDROID_BUILD_TOP/./frameworks/base/core/java/android/service/autofill/FillRequest.java
204     //
205     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
206     //   Settings > Editor > Code Style > Formatter Control
207     //@formatter:off
208 
209 
210     /** @hide */
211     @IntDef(flag = true, prefix = "FLAG_", value = {
212         FLAG_MANUAL_REQUEST,
213         FLAG_COMPATIBILITY_MODE_REQUEST,
214         FLAG_PASSWORD_INPUT_TYPE,
215         FLAG_VIEW_NOT_FOCUSED,
216         FLAG_SUPPORTS_FILL_DIALOG,
217         FLAG_IME_SHOWING,
218         FLAG_RESET_FILL_DIALOG_STATE
219     })
220     @Retention(RetentionPolicy.SOURCE)
221     @DataClass.Generated.Member
222     public @interface RequestFlags {}
223 
224     /** @hide */
225     @DataClass.Generated.Member
requestFlagsToString(@equestFlags int value)226     public static String requestFlagsToString(@RequestFlags int value) {
227         return com.android.internal.util.BitUtils.flagsToString(
228                 value, FillRequest::singleRequestFlagsToString);
229     }
230 
231     @DataClass.Generated.Member
singleRequestFlagsToString(@equestFlags int value)232     static String singleRequestFlagsToString(@RequestFlags int value) {
233         switch (value) {
234             case FLAG_MANUAL_REQUEST:
235                     return "FLAG_MANUAL_REQUEST";
236             case FLAG_COMPATIBILITY_MODE_REQUEST:
237                     return "FLAG_COMPATIBILITY_MODE_REQUEST";
238             case FLAG_PASSWORD_INPUT_TYPE:
239                     return "FLAG_PASSWORD_INPUT_TYPE";
240             case FLAG_VIEW_NOT_FOCUSED:
241                     return "FLAG_VIEW_NOT_FOCUSED";
242             case FLAG_SUPPORTS_FILL_DIALOG:
243                     return "FLAG_SUPPORTS_FILL_DIALOG";
244             case FLAG_IME_SHOWING:
245                     return "FLAG_IME_SHOWING";
246             case FLAG_RESET_FILL_DIALOG_STATE:
247                     return "FLAG_RESET_FILL_DIALOG_STATE";
248             default: return Integer.toHexString(value);
249         }
250     }
251 
252     /**
253      * Creates a new FillRequest.
254      *
255      * @param id
256      *   Gets the unique id of this request.
257      * @param fillContexts
258      *   Gets the contexts associated with each previous fill request.
259      *
260      *   <p><b>Note:</b> Starting on Android {@link android.os.Build.VERSION_CODES#Q}, it could also
261      *   include contexts from requests whose {@link SaveInfo} had the
262      *   {@link SaveInfo#FLAG_DELAY_SAVE} flag.
263      * @param clientState
264      *   Gets the latest client state bundle set by the service in a
265      *   {@link FillResponse.Builder#setClientState(Bundle) fill response}.
266      *
267      *   <p><b>Note:</b> Prior to Android {@link android.os.Build.VERSION_CODES#P}, only client state
268      *   bundles set by {@link FillResponse.Builder#setClientState(Bundle)} were considered. On
269      *   Android {@link android.os.Build.VERSION_CODES#P} and higher, bundles set in the result of
270      *   an authenticated request through the
271      *   {@link android.view.autofill.AutofillManager#EXTRA_CLIENT_STATE} extra are
272      *   also considered (and take precedence when set).
273      * @param flags
274      *   Gets the flags associated with this request.
275      *
276      *   @return any combination of {@link #FLAG_MANUAL_REQUEST},
277      *           {@link #FLAG_SUPPORTS_FILL_DIALOG} and
278      *           {@link #FLAG_COMPATIBILITY_MODE_REQUEST}.
279      * @param inlineSuggestionsRequest
280      *   Gets the {@link InlineSuggestionsRequest} associated
281      *   with this request.
282      *
283      *   <p>Autofill Framework will send a {@code @non-null} {@link InlineSuggestionsRequest} if
284      *   currently inline suggestions are supported and can be displayed. If the Autofill service
285      *   wants to show inline suggestions, they may return {@link Dataset} with valid
286      *   {@link InlinePresentation}.</p>
287      *
288      *   <p>The Autofill Service must set supportsInlineSuggestions in its XML to enable support
289      *   for inline suggestions.</p>
290      * @param delayedFillIntentSender
291      *   Gets the {@link IntentSender} to send a delayed fill response.
292      *
293      *   <p>The autofill service must first indicate that it wants to return a delayed
294      *   {@link FillResponse} by setting {@link FillResponse#FLAG_DELAY_FILL} in a successful
295      *   fill response. Then it can use this IntentSender to send an Intent with extra
296      *   {@link AutofillService#EXTRA_FILL_RESPONSE} with the delayed response.</p>
297      *
298      *   <p>Note that this may be null if a delayed fill response is not supported for
299      *   this fill request.</p>
300      * @hide
301      */
302     @DataClass.Generated.Member
FillRequest( int id, @NonNull List<FillContext> fillContexts, @Nullable Bundle clientState, @RequestFlags int flags, @Nullable InlineSuggestionsRequest inlineSuggestionsRequest, @Nullable IntentSender delayedFillIntentSender)303     public FillRequest(
304             int id,
305             @NonNull List<FillContext> fillContexts,
306             @Nullable Bundle clientState,
307             @RequestFlags int flags,
308             @Nullable InlineSuggestionsRequest inlineSuggestionsRequest,
309             @Nullable IntentSender delayedFillIntentSender) {
310         this.mId = id;
311         this.mFillContexts = fillContexts;
312         com.android.internal.util.AnnotationValidations.validate(
313                 NonNull.class, null, mFillContexts);
314         this.mClientState = clientState;
315         this.mFlags = flags;
316 
317         Preconditions.checkFlagsArgument(
318                 mFlags,
319                 FLAG_MANUAL_REQUEST
320                         | FLAG_COMPATIBILITY_MODE_REQUEST
321                         | FLAG_PASSWORD_INPUT_TYPE
322                         | FLAG_VIEW_NOT_FOCUSED
323                         | FLAG_SUPPORTS_FILL_DIALOG
324                         | FLAG_IME_SHOWING
325                         | FLAG_RESET_FILL_DIALOG_STATE);
326         this.mInlineSuggestionsRequest = inlineSuggestionsRequest;
327         this.mDelayedFillIntentSender = delayedFillIntentSender;
328 
329         onConstructed();
330     }
331 
332     /**
333      * Gets the unique id of this request.
334      */
335     @DataClass.Generated.Member
getId()336     public int getId() {
337         return mId;
338     }
339 
340     /**
341      * Gets the contexts associated with each previous fill request.
342      *
343      * <p><b>Note:</b> Starting on Android {@link android.os.Build.VERSION_CODES#Q}, it could also
344      * include contexts from requests whose {@link SaveInfo} had the
345      * {@link SaveInfo#FLAG_DELAY_SAVE} flag.
346      */
347     @DataClass.Generated.Member
getFillContexts()348     public @NonNull List<FillContext> getFillContexts() {
349         return mFillContexts;
350     }
351 
352     /**
353      * Gets the latest client state bundle set by the service in a
354      * {@link FillResponse.Builder#setClientState(Bundle) fill response}.
355      *
356      * <p><b>Note:</b> Prior to Android {@link android.os.Build.VERSION_CODES#P}, only client state
357      * bundles set by {@link FillResponse.Builder#setClientState(Bundle)} were considered. On
358      * Android {@link android.os.Build.VERSION_CODES#P} and higher, bundles set in the result of
359      * an authenticated request through the
360      * {@link android.view.autofill.AutofillManager#EXTRA_CLIENT_STATE} extra are
361      * also considered (and take precedence when set).
362      *
363      * @return The client state.
364      */
365     @DataClass.Generated.Member
getClientState()366     public @Nullable Bundle getClientState() {
367         return mClientState;
368     }
369 
370     /**
371      * Gets the flags associated with this request.
372      *
373      * @return any combination of {@link #FLAG_MANUAL_REQUEST},
374      *         {@link #FLAG_SUPPORTS_FILL_DIALOG} and
375      *         {@link #FLAG_COMPATIBILITY_MODE_REQUEST}.
376      */
377     @DataClass.Generated.Member
getFlags()378     public @RequestFlags int getFlags() {
379         return mFlags;
380     }
381 
382     /**
383      * Gets the {@link InlineSuggestionsRequest} associated
384      * with this request.
385      *
386      * <p>Autofill Framework will send a {@code @non-null} {@link InlineSuggestionsRequest} if
387      * currently inline suggestions are supported and can be displayed. If the Autofill service
388      * wants to show inline suggestions, they may return {@link Dataset} with valid
389      * {@link InlinePresentation}.</p>
390      *
391      * <p>The Autofill Service must set supportsInlineSuggestions in its XML to enable support
392      * for inline suggestions.</p>
393      *
394      * @return the suggestionspec
395      */
396     @DataClass.Generated.Member
getInlineSuggestionsRequest()397     public @Nullable InlineSuggestionsRequest getInlineSuggestionsRequest() {
398         return mInlineSuggestionsRequest;
399     }
400 
401     /**
402      * Gets the {@link IntentSender} to send a delayed fill response.
403      *
404      * <p>The autofill service must first indicate that it wants to return a delayed
405      * {@link FillResponse} by setting {@link FillResponse#FLAG_DELAY_FILL} in a successful
406      * fill response. Then it can use this IntentSender to send an Intent with extra
407      * {@link AutofillService#EXTRA_FILL_RESPONSE} with the delayed response.</p>
408      *
409      * <p>Note that this may be null if a delayed fill response is not supported for
410      * this fill request.</p>
411      */
412     @DataClass.Generated.Member
getDelayedFillIntentSender()413     public @Nullable IntentSender getDelayedFillIntentSender() {
414         return mDelayedFillIntentSender;
415     }
416 
417     @Override
418     @DataClass.Generated.Member
toString()419     public String toString() {
420         // You can override field toString logic by defining methods like:
421         // String fieldNameToString() { ... }
422 
423         return "FillRequest { " +
424                 "id = " + mId + ", " +
425                 "fillContexts = " + mFillContexts + ", " +
426                 "clientState = " + mClientState + ", " +
427                 "flags = " + requestFlagsToString(mFlags) + ", " +
428                 "inlineSuggestionsRequest = " + mInlineSuggestionsRequest + ", " +
429                 "delayedFillIntentSender = " + mDelayedFillIntentSender +
430         " }";
431     }
432 
433     @Override
434     @DataClass.Generated.Member
writeToParcel(@onNull Parcel dest, int flags)435     public void writeToParcel(@NonNull Parcel dest, int flags) {
436         // You can override field parcelling by defining methods like:
437         // void parcelFieldName(Parcel dest, int flags) { ... }
438 
439         byte flg = 0;
440         if (mClientState != null) flg |= 0x4;
441         if (mInlineSuggestionsRequest != null) flg |= 0x10;
442         if (mDelayedFillIntentSender != null) flg |= 0x20;
443         dest.writeByte(flg);
444         dest.writeInt(mId);
445         dest.writeParcelableList(mFillContexts, flags);
446         if (mClientState != null) dest.writeBundle(mClientState);
447         dest.writeInt(mFlags);
448         if (mInlineSuggestionsRequest != null) dest.writeTypedObject(mInlineSuggestionsRequest, flags);
449         if (mDelayedFillIntentSender != null) dest.writeTypedObject(mDelayedFillIntentSender, flags);
450     }
451 
452     @Override
453     @DataClass.Generated.Member
describeContents()454     public int describeContents() { return 0; }
455 
456     /** @hide */
457     @SuppressWarnings({"unchecked", "RedundantCast"})
458     @DataClass.Generated.Member
FillRequest(@onNull Parcel in)459     /* package-private */ FillRequest(@NonNull Parcel in) {
460         // You can override field unparcelling by defining methods like:
461         // static FieldType unparcelFieldName(Parcel in) { ... }
462 
463         byte flg = in.readByte();
464         int id = in.readInt();
465         List<FillContext> fillContexts = new ArrayList<>();
466         in.readParcelableList(fillContexts, FillContext.class.getClassLoader());
467         Bundle clientState = (flg & 0x4) == 0 ? null : in.readBundle();
468         int flags = in.readInt();
469         InlineSuggestionsRequest inlineSuggestionsRequest = (flg & 0x10) == 0 ? null : (InlineSuggestionsRequest) in.readTypedObject(InlineSuggestionsRequest.CREATOR);
470         IntentSender delayedFillIntentSender = (flg & 0x20) == 0 ? null : (IntentSender) in.readTypedObject(IntentSender.CREATOR);
471 
472         this.mId = id;
473         this.mFillContexts = fillContexts;
474         com.android.internal.util.AnnotationValidations.validate(
475                 NonNull.class, null, mFillContexts);
476         this.mClientState = clientState;
477         this.mFlags = flags;
478 
479         Preconditions.checkFlagsArgument(
480                 mFlags,
481                 FLAG_MANUAL_REQUEST
482                         | FLAG_COMPATIBILITY_MODE_REQUEST
483                         | FLAG_PASSWORD_INPUT_TYPE
484                         | FLAG_VIEW_NOT_FOCUSED
485                         | FLAG_SUPPORTS_FILL_DIALOG
486                         | FLAG_IME_SHOWING
487                         | FLAG_RESET_FILL_DIALOG_STATE);
488         this.mInlineSuggestionsRequest = inlineSuggestionsRequest;
489         this.mDelayedFillIntentSender = delayedFillIntentSender;
490 
491         onConstructed();
492     }
493 
494     @DataClass.Generated.Member
495     public static final @NonNull Parcelable.Creator<FillRequest> CREATOR
496             = new Parcelable.Creator<FillRequest>() {
497         @Override
498         public FillRequest[] newArray(int size) {
499             return new FillRequest[size];
500         }
501 
502         @Override
503         public FillRequest createFromParcel(@NonNull Parcel in) {
504             return new FillRequest(in);
505         }
506     };
507 
508     @DataClass.Generated(
509             time = 1663290803064L,
510             codegenVersion = "1.0.23",
511             sourceFile = "frameworks/base/core/java/android/service/autofill/FillRequest.java",
512             inputSignatures = "public static final @android.service.autofill.FillRequest.RequestFlags int FLAG_MANUAL_REQUEST\npublic static final @android.service.autofill.FillRequest.RequestFlags int FLAG_COMPATIBILITY_MODE_REQUEST\npublic static final @android.service.autofill.FillRequest.RequestFlags int FLAG_PASSWORD_INPUT_TYPE\npublic static final @android.service.autofill.FillRequest.RequestFlags int FLAG_VIEW_NOT_FOCUSED\npublic static final @android.service.autofill.FillRequest.RequestFlags int FLAG_SUPPORTS_FILL_DIALOG\npublic static final @android.service.autofill.FillRequest.RequestFlags int FLAG_IME_SHOWING\npublic static final @android.service.autofill.FillRequest.RequestFlags int FLAG_RESET_FILL_DIALOG_STATE\npublic static final  int INVALID_REQUEST_ID\nprivate final  int mId\nprivate final @android.annotation.NonNull java.util.List<android.service.autofill.FillContext> mFillContexts\nprivate final @android.annotation.Nullable android.os.Bundle mClientState\nprivate final @android.service.autofill.FillRequest.RequestFlags int mFlags\nprivate final @android.annotation.Nullable android.view.inputmethod.InlineSuggestionsRequest mInlineSuggestionsRequest\nprivate final @android.annotation.Nullable android.content.IntentSender mDelayedFillIntentSender\nprivate  void onConstructed()\nclass FillRequest extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genToString=true, genHiddenConstructor=true, genHiddenConstDefs=true)")
513     @Deprecated
__metadata()514     private void __metadata() {}
515 
516 
517     //@formatter:on
518     // End of generated code
519 
520 }
521