summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TYM Tsai <tymtsai@google.com> 2022-02-17 22:56:25 +0800
committer TYM Tsai <tymtsai@google.com> 2022-04-20 02:13:28 +0800
commitbbf0074056a2e3122aac2d06ce828f0102bfd5e4 (patch)
treedbb653260e32d2be389e833a57bf11c14614d753
parent246a190e0354e4379621f8fac2e3fbef9e936f4b (diff)
Use device config to control hints allow list for fill dialog
For the performance consideration, we don't prefer to trigger a FillRequest for autofill dialog at the Activity starting. We only do that if one of the fields is a password or contains the allowed AutofillHints for fill dialog. Bug: 219844915 Test: set device config, check whether do a fill request at starting Change-Id: I8cc8c99d1f0e716ad293fa612f65aa2a8d23b028
-rw-r--r--core/java/android/view/View.java4
-rw-r--r--core/java/android/view/autofill/AutofillManager.java59
2 files changed, 56 insertions, 7 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 7d823b1c100d..e87f47bc3544 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -8206,12 +8206,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");