diff options
author | 2022-04-21 02:01:13 +0000 | |
---|---|---|
committer | 2022-04-21 02:01:13 +0000 | |
commit | bd72a95c1f61080ca489748705b302b8a703a27d (patch) | |
tree | 25a7b6616059ef7e83762ada50cca56d9b762ed1 | |
parent | 0a355570a02721adb9204d35a4331fc57104061c (diff) | |
parent | bbf0074056a2e3122aac2d06ce828f0102bfd5e4 (diff) |
Merge "Use device config to control hints allow list for fill dialog" into tm-dev
-rw-r--r-- | core/java/android/view/View.java | 4 | ||||
-rw-r--r-- | core/java/android/view/autofill/AutofillManager.java | 59 |
2 files changed, 56 insertions, 7 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 569461e81111..6de48c4c86e0 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -8207,12 +8207,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback, // becomes true where it should issue notifyViewEntered(). afm.notifyViewEntered(this); } else { - afm.enableFillRequestActivityStarted(); + afm.enableFillRequestActivityStarted(this); } } else if (!enter && !isFocused()) { afm.notifyViewExited(this); } else if (enter) { - afm.enableFillRequestActivityStarted(); + afm.enableFillRequestActivityStarted(this); } } } diff --git a/core/java/android/view/autofill/AutofillManager.java b/core/java/android/view/autofill/AutofillManager.java index b05b7916d960..07756f638d4b 100644 --- a/core/java/android/view/autofill/AutofillManager.java +++ b/core/java/android/view/autofill/AutofillManager.java @@ -488,6 +488,25 @@ public final class AutofillManager { public static final String DEVICE_CONFIG_AUTOFILL_DIALOG_ENABLED = "autofill_dialog_enabled"; + /** + * Sets the autofill hints allowed list for the fields that can trigger the fill dialog + * feature at Activity starting. + * + * The list of autofill hints is {@code ":"} colon delimited. + * + * <p>For example, a list with 3 hints {@code password}, {@code phone}, and + * {@code emailAddress}, would be {@code password:phone:emailAddress} + * + * Note: By default the password field is enabled even there is no password hint in the list + * + * @see View#setAutofillHints(String...) + * @hide + */ + public static final String DEVICE_CONFIG_AUTOFILL_DIALOG_HINTS = + "autofill_dialog_hints"; + + private static final String DIALOG_HINTS_DELIMITER = ":"; + /** @hide */ public static final int RESULT_OK = 0; /** @hide */ @@ -537,6 +556,7 @@ public final class AutofillManager { public static final int NO_SESSION = Integer.MAX_VALUE; private static final boolean HAS_FILL_DIALOG_UI_FEATURE_DEFAULT = false; + private static final String FILL_DIALOG_ENABLED_DEFAULT_HINTS = ""; private final IAutoFillManager mService; @@ -652,6 +672,8 @@ public final class AutofillManager { // Indicates whether called the showAutofillDialog() method. private boolean mShowAutofillDialogCalled = false; + private final String[] mFillDialogEnabledHints; + /** @hide */ public interface AutofillClient { /** @@ -796,8 +818,10 @@ public final class AutofillManager { DeviceConfig.NAMESPACE_AUTOFILL, DEVICE_CONFIG_AUTOFILL_DIALOG_ENABLED, HAS_FILL_DIALOG_UI_FEATURE_DEFAULT); + mFillDialogEnabledHints = getFillDialogEnabledHints(); if (sDebug) { - Log.d(TAG, "Fill dialog is enabled:" + mIsFillDialogEnabled); + Log.d(TAG, "Fill dialog is enabled:" + mIsFillDialogEnabled + + ", hints=" + Arrays.toString(mFillDialogEnabledHints)); } if (mOptions != null) { @@ -806,6 +830,19 @@ public final class AutofillManager { } } + private String[] getFillDialogEnabledHints() { + final String dialogHints = DeviceConfig.getString( + DeviceConfig.NAMESPACE_AUTOFILL, + DEVICE_CONFIG_AUTOFILL_DIALOG_HINTS, + FILL_DIALOG_ENABLED_DEFAULT_HINTS); + if (TextUtils.isEmpty(dialogHints)) { + return new String[0]; + } + + return ArrayUtils.filter(dialogHints.split(DIALOG_HINTS_DELIMITER), String[]::new, + (str) -> !TextUtils.isEmpty(str)); + } + /** * @hide */ @@ -1076,17 +1113,27 @@ public final class AutofillManager { } /** - * The view is autofillable, marked to perform a fill request after layout if + * The view have the allowed autofill hints, marked to perform a fill request after layout if * the field does not trigger a fill request. * * @hide */ - public void enableFillRequestActivityStarted() { - mRequireAutofill = true; + public void enableFillRequestActivityStarted(View v) { + if (mRequireAutofill) { + return; + } + + if (mIsFillDialogEnabled + || ArrayUtils.containsAny(v.getAutofillHints(), mFillDialogEnabledHints)) { + if (sDebug) { + Log.d(TAG, "Trigger fill request at starting"); + } + mRequireAutofill = true; + } } private boolean hasFillDialogUiFeature() { - return mIsFillDialogEnabled; + return mIsFillDialogEnabled || !ArrayUtils.isEmpty(mFillDialogEnabledHints); } /** @@ -2977,6 +3024,8 @@ public final class AutofillManager { pw.print(pfx); pw.print("compat mode enabled: "); synchronized (mLock) { pw.print(pfx); pw.print("fill dialog enabled: "); pw.println(mIsFillDialogEnabled); + pw.print(pfx); pw.print("fill dialog enabled hints: "); + pw.println(Arrays.toString(mFillDialogEnabledHints)); if (mCompatibilityBridge != null) { final String pfx2 = pfx + " "; pw.println("true"); |