diff options
| author | 2023-10-03 17:02:26 +0000 | |
|---|---|---|
| committer | 2023-10-03 17:02:26 +0000 | |
| commit | 107d801e5e0cebe0c4e47d61601daf7ce359b34f (patch) | |
| tree | 8c494086b835058ec676c8bff057e052a7cc5564 | |
| parent | 65381a4fccfec76464ef4c4fe6632f68594ec5eb (diff) | |
| parent | 88e349078c1cbe8c9c2fd5d1cf1c1a7bc5af4040 (diff) | |
Merge "[Autofill Brute Force] Change max user input eligible for autofill suggestion from a constant to flag." into main
6 files changed, 89 insertions, 17 deletions
diff --git a/core/java/android/view/autofill/AutofillFeatureFlags.java b/core/java/android/view/autofill/AutofillFeatureFlags.java index f543cab322bb..334c2b779f1a 100644 --- a/core/java/android/view/autofill/AutofillFeatureFlags.java +++ b/core/java/android/view/autofill/AutofillFeatureFlags.java @@ -255,6 +255,16 @@ public class AutofillFeatureFlags { // END AUTOFILL PCC CLASSIFICATION FLAGS + /** + * Define the max input length for autofill to show suggesiton UI + * + * E.g. if flag is set to 3, autofill will only show suggestions when user inputs less than 3 + * characters + * + * @hide + */ + public static final String DEVICE_CONFIG_MAX_INPUT_LENGTH_FOR_AUTOFILL = + "max_input_length_for_autofill"; /** * Sets a value of delay time to show up the inline tooltip view. @@ -295,6 +305,10 @@ public class AutofillFeatureFlags { DEFAULT_AFAA_SHOULD_INCLUDE_ALL_AUTOFILL_TYPE_NOT_NONE_VIEWS_IN_ASSIST_STRUCTURE = true; // END AUTOFILL FOR ALL APPS DEFAULTS + /** + * @hide + */ + public static final int DEFAULT_MAX_INPUT_LENGTH_FOR_AUTOFILL = 3; private AutofillFeatureFlags() {}; /** diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java index cad8fcf39b32..c7b53c55d89b 100644 --- a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java +++ b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java @@ -223,6 +223,9 @@ public final class AutofillManagerService @GuardedBy("mFlagLock") private String mPccProviderHints; + @GuardedBy("mFlagLock") + private int mMaxInputLengthForAutofill; + // Default flag values for Autofill PCC private static final String DEFAULT_PCC_FEATURE_PROVIDER_HINTS = ""; @@ -694,6 +697,10 @@ public final class AutofillManagerService DeviceConfig.NAMESPACE_AUTOFILL, AutofillFeatureFlags.DEVICE_CONFIG_AUTOFILL_PCC_FEATURE_PROVIDER_HINTS, DEFAULT_PCC_FEATURE_PROVIDER_HINTS); + mMaxInputLengthForAutofill = DeviceConfig.getInt( + DeviceConfig.NAMESPACE_AUTOFILL, + AutofillFeatureFlags.DEVICE_CONFIG_MAX_INPUT_LENGTH_FOR_AUTOFILL, + AutofillFeatureFlags.DEFAULT_MAX_INPUT_LENGTH_FOR_AUTOFILL); if (verbose) { Slog.v(mTag, "setDeviceConfigProperties() for PCC: " + "mPccClassificationEnabled=" + mPccClassificationEnabled @@ -988,6 +995,15 @@ public final class AutofillManagerService } } + /** + * Return the max suggestion length + */ + public int getMaxInputLengthForAutofill() { + synchronized (mFlagLock) { + return mMaxInputLengthForAutofill; + } + } + @Nullable @VisibleForTesting static Map<String, String[]> getAllowedCompatModePackages(String setting) { diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java index 4e5b0589446a..0220deca18c1 100644 --- a/services/autofill/java/com/android/server/autofill/Session.java +++ b/services/autofill/java/com/android/server/autofill/Session.java @@ -4596,7 +4596,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState getUiForShowing().showFillUi(filledId, response, filterText, mService.getServicePackageName(), mComponentName, - targetLabel, targetIcon, this, mContext, id, mCompatMode); + targetLabel, targetIcon, this, mContext, id, mCompatMode, + mService.getMaster().getMaxInputLengthForAutofill()); synchronized (mLock) { mPresentationStatsEventLogger.maybeSetCountShown( @@ -4856,7 +4857,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState public void onInflate() { Session.this.onShown(UI_TYPE_INLINE); } - }); + }, mService.getMaster().getMaxInputLengthForAutofill()); return mInlineSessionController.setInlineFillUiLocked(inlineFillUi); } diff --git a/services/autofill/java/com/android/server/autofill/ui/AutoFillUI.java b/services/autofill/java/com/android/server/autofill/ui/AutoFillUI.java index d479dfb512ca..602855da7ddf 100644 --- a/services/autofill/java/com/android/server/autofill/ui/AutoFillUI.java +++ b/services/autofill/java/com/android/server/autofill/ui/AutoFillUI.java @@ -204,12 +204,14 @@ public final class AutoFillUI { * @param context context with the proper state (like display id) to show the UI * @param sessionId id of the autofill session * @param compatMode whether the app is being autofilled in compatibility mode. + * @param maxInputLengthForAutofill max user input to provide suggestion */ public void showFillUi(@NonNull AutofillId focusedId, @NonNull FillResponse response, @Nullable String filterText, @Nullable String servicePackageName, @NonNull ComponentName componentName, @NonNull CharSequence serviceLabel, @NonNull Drawable serviceIcon, @NonNull AutoFillUiCallback callback, - @NonNull Context context, int sessionId, boolean compatMode) { + @NonNull Context context, int sessionId, boolean compatMode, + int maxInputLengthForAutofill) { if (sDebug) { final int size = filterText == null ? 0 : filterText.length(); Slogf.d(TAG, "showFillUi(): id=%s, filter=%d chars, displayId=%d", focusedId, size, @@ -229,7 +231,8 @@ public final class AutoFillUI { } hideAllUiThread(callback); mFillUi = new FillUi(context, response, focusedId, filterText, mOverlayControl, - serviceLabel, serviceIcon, mUiModeMgr.isNightMode(), new FillUi.Callback() { + serviceLabel, serviceIcon, mUiModeMgr.isNightMode(), maxInputLengthForAutofill, + new FillUi.Callback() { @Override public void onResponsePicked(FillResponse response) { log.setType(MetricsEvent.TYPE_DETAIL); diff --git a/services/autofill/java/com/android/server/autofill/ui/FillUi.java b/services/autofill/java/com/android/server/autofill/ui/FillUi.java index 0a8fe62a6617..b2716ecc0cfc 100644 --- a/services/autofill/java/com/android/server/autofill/ui/FillUi.java +++ b/services/autofill/java/com/android/server/autofill/ui/FillUi.java @@ -127,6 +127,8 @@ final class FillUi { private final int mThemeId; + private int mMaxInputLengthForAutofill; + public static boolean isFullScreen(Context context) { if (sFullScreenMode != null) { if (sVerbose) Slog.v(TAG, "forcing full-screen mode to " + sFullScreenMode); @@ -138,7 +140,8 @@ final class FillUi { FillUi(@NonNull Context context, @NonNull FillResponse response, @NonNull AutofillId focusedViewId, @Nullable String filterText, @NonNull OverlayControl overlayControl, @NonNull CharSequence serviceLabel, - @NonNull Drawable serviceIcon, boolean nightMode, @NonNull Callback callback) { + @NonNull Drawable serviceIcon, boolean nightMode, int maxInputLengthForAutofill, + @NonNull Callback callback) { if (sVerbose) { Slogf.v(TAG, "nightMode: %b displayId: %d", nightMode, context.getDisplayId()); } @@ -146,6 +149,7 @@ final class FillUi { mCallback = callback; mFullScreen = isFullScreen(context); mContext = new ContextThemeWrapper(context, mThemeId); + mMaxInputLengthForAutofill = maxInputLengthForAutofill; final LayoutInflater inflater = LayoutInflater.from(mContext); @@ -432,10 +436,11 @@ final class FillUi { Slog.d(TAG, "No dataset matches filter with " + size + " chars"); } mCallback.requestHideFillUi(); - } else if (size > 3) { - // Do not show suggestion if user entered four or more characters + } else if (size > mMaxInputLengthForAutofill) { + // Do not show suggestion if user entered more than the maximum suggesiton length if (sDebug) { - Slog.d(TAG, "Not showing fill UI because user entered more than 3 characters"); + Slog.d(TAG, "Not showing fill UI because user entered more than " + + mMaxInputLengthForAutofill + " characters"); } mCallback.requestHideFillUi(); } else { diff --git a/services/autofill/java/com/android/server/autofill/ui/InlineFillUi.java b/services/autofill/java/com/android/server/autofill/ui/InlineFillUi.java index 24eab0b78c86..c734680009c6 100644 --- a/services/autofill/java/com/android/server/autofill/ui/InlineFillUi.java +++ b/services/autofill/java/com/android/server/autofill/ui/InlineFillUi.java @@ -98,6 +98,11 @@ public final class InlineFillUi { } /** + * If user enters more characters than this length, the autofill suggestion won't be shown. + */ + private int mMaxInputLengthForAutofill = Integer.MAX_VALUE; + + /** * Encapsulates various arguments used by {@link #forAutofill} and {@link #forAugmentedAutofill} */ public static class InlineFillUiInfo { @@ -128,20 +133,22 @@ public final class InlineFillUi { @NonNull public static InlineFillUi forAutofill(@NonNull InlineFillUiInfo inlineFillUiInfo, @NonNull FillResponse response, - @NonNull InlineSuggestionUiCallback uiCallback) { + @NonNull InlineSuggestionUiCallback uiCallback, int maxInputLengthForAutofill) { if (response.getAuthentication() != null && response.getInlinePresentation() != null) { InlineSuggestion inlineAuthentication = InlineSuggestionFactory.createInlineAuthentication(inlineFillUiInfo, response, uiCallback); - return new InlineFillUi(inlineFillUiInfo, inlineAuthentication); + return new InlineFillUi(inlineFillUiInfo, inlineAuthentication, + maxInputLengthForAutofill); } else if (response.getDatasets() != null) { SparseArray<Pair<Dataset, InlineSuggestion>> inlineSuggestions = InlineSuggestionFactory.createInlineSuggestions(inlineFillUiInfo, InlineSuggestionInfo.SOURCE_AUTOFILL, response.getDatasets(), uiCallback); - return new InlineFillUi(inlineFillUiInfo, inlineSuggestions); + return new InlineFillUi(inlineFillUiInfo, inlineSuggestions, + maxInputLengthForAutofill); } - return new InlineFillUi(inlineFillUiInfo, new SparseArray<>()); + return new InlineFillUi(inlineFillUiInfo, new SparseArray<>(), maxInputLengthForAutofill); } /** @@ -157,6 +164,9 @@ public final class InlineFillUi { return new InlineFillUi(inlineFillUiInfo, inlineSuggestions); } + /** + * Used by augmented autofill + */ private InlineFillUi(@Nullable InlineFillUiInfo inlineFillUiInfo, @NonNull SparseArray<Pair<Dataset, InlineSuggestion>> inlineSuggestions) { mAutofillId = inlineFillUiInfo.mFocusedId; @@ -171,13 +181,36 @@ public final class InlineFillUi { mFilterText = inlineFillUiInfo.mFilterText; } + /** + * Used by normal autofill + */ + private InlineFillUi(@Nullable InlineFillUiInfo inlineFillUiInfo, + @NonNull SparseArray<Pair<Dataset, InlineSuggestion>> inlineSuggestions, + int maxInputLengthForAutofill) { + mAutofillId = inlineFillUiInfo.mFocusedId; + int size = inlineSuggestions.size(); + mDatasets = new ArrayList<>(size); + mInlineSuggestions = new ArrayList<>(size); + for (int i = 0; i < size; i++) { + Pair<Dataset, InlineSuggestion> value = inlineSuggestions.valueAt(i); + mDatasets.add(value.first); + mInlineSuggestions.add(value.second); + } + mFilterText = inlineFillUiInfo.mFilterText; + mMaxInputLengthForAutofill = maxInputLengthForAutofill; + } + + /** + * Used by normal autofill + */ private InlineFillUi(@NonNull InlineFillUiInfo inlineFillUiInfo, - @NonNull InlineSuggestion inlineSuggestion) { + @NonNull InlineSuggestion inlineSuggestion, int maxInputLengthForAutofill) { mAutofillId = inlineFillUiInfo.mFocusedId; mDatasets = null; mInlineSuggestions = new ArrayList<>(); mInlineSuggestions.add(inlineSuggestion); mFilterText = inlineFillUiInfo.mFilterText; + mMaxInputLengthForAutofill = maxInputLengthForAutofill; } /** @@ -217,11 +250,11 @@ public final class InlineFillUi { return new InlineSuggestionsResponse(inlineSuggestions); } - // Do not show suggestion if user entered four or more characters - if (!TextUtils.isEmpty(mFilterText) && mFilterText.length() > 3) { + // Do not show inline suggestion if user entered more than a certain number of characters. + if (!TextUtils.isEmpty(mFilterText) && mFilterText.length() > mMaxInputLengthForAutofill) { if (sVerbose) { - Slog.v(TAG, "Not showing inline suggestion because user entered more than 3 " - + "characters"); + Slog.v(TAG, "Not showing inline suggestion when user entered more than " + + mMaxInputLengthForAutofill + " characters"); } return new InlineSuggestionsResponse(inlineSuggestions); } |