Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bbf00740 authored by TYM Tsai's avatar TYM Tsai
Browse files

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
parent 246a190e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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);
                }
            }
        }
+54 −5
Original line number Diff line number Diff line
@@ -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() {
    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");