Merge "Use device config to control hints allow list for fill dialog" into tm-dev

This commit is contained in:
TYM Tsai
2022-04-21 02:01:13 +00:00
committed by Android (Google) Code Review
2 changed files with 56 additions and 7 deletions

View File

@@ -8207,12 +8207,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
// becomes true where it should issue notifyViewEntered(). // becomes true where it should issue notifyViewEntered().
afm.notifyViewEntered(this); afm.notifyViewEntered(this);
} else { } else {
afm.enableFillRequestActivityStarted(); afm.enableFillRequestActivityStarted(this);
} }
} else if (!enter && !isFocused()) { } else if (!enter && !isFocused()) {
afm.notifyViewExited(this); afm.notifyViewExited(this);
} else if (enter) { } else if (enter) {
afm.enableFillRequestActivityStarted(); afm.enableFillRequestActivityStarted(this);
} }
} }
} }

View File

@@ -488,6 +488,25 @@ public final class AutofillManager {
public static final String DEVICE_CONFIG_AUTOFILL_DIALOG_ENABLED = public static final String DEVICE_CONFIG_AUTOFILL_DIALOG_ENABLED =
"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 */ /** @hide */
public static final int RESULT_OK = 0; public static final int RESULT_OK = 0;
/** @hide */ /** @hide */
@@ -537,6 +556,7 @@ public final class AutofillManager {
public static final int NO_SESSION = Integer.MAX_VALUE; public static final int NO_SESSION = Integer.MAX_VALUE;
private static final boolean HAS_FILL_DIALOG_UI_FEATURE_DEFAULT = false; private static final boolean HAS_FILL_DIALOG_UI_FEATURE_DEFAULT = false;
private static final String FILL_DIALOG_ENABLED_DEFAULT_HINTS = "";
private final IAutoFillManager mService; private final IAutoFillManager mService;
@@ -652,6 +672,8 @@ public final class AutofillManager {
// Indicates whether called the showAutofillDialog() method. // Indicates whether called the showAutofillDialog() method.
private boolean mShowAutofillDialogCalled = false; private boolean mShowAutofillDialogCalled = false;
private final String[] mFillDialogEnabledHints;
/** @hide */ /** @hide */
public interface AutofillClient { public interface AutofillClient {
/** /**
@@ -796,8 +818,10 @@ public final class AutofillManager {
DeviceConfig.NAMESPACE_AUTOFILL, DeviceConfig.NAMESPACE_AUTOFILL,
DEVICE_CONFIG_AUTOFILL_DIALOG_ENABLED, DEVICE_CONFIG_AUTOFILL_DIALOG_ENABLED,
HAS_FILL_DIALOG_UI_FEATURE_DEFAULT); HAS_FILL_DIALOG_UI_FEATURE_DEFAULT);
mFillDialogEnabledHints = getFillDialogEnabledHints();
if (sDebug) { 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) { 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 * @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. * the field does not trigger a fill request.
* *
* @hide * @hide
*/ */
public void enableFillRequestActivityStarted() { 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; mRequireAutofill = true;
} }
}
private boolean hasFillDialogUiFeature() { 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: "); pw.print(pfx); pw.print("compat mode enabled: ");
synchronized (mLock) { synchronized (mLock) {
pw.print(pfx); pw.print("fill dialog enabled: "); pw.println(mIsFillDialogEnabled); 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) { if (mCompatibilityBridge != null) {
final String pfx2 = pfx + " "; final String pfx2 = pfx + " ";
pw.println("true"); pw.println("true");