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

Commit 5793a835 authored by Haoran Zhang's avatar Haoran Zhang Committed by Android (Google) Code Review
Browse files

Merge "Suppress fill and save dialog for activities that have credman field."

parents b4121be2 5b3f33ab
Loading
Loading
Loading
Loading
+28 −7
Original line number Diff line number Diff line
@@ -123,6 +123,12 @@ public final class FillRequest implements Parcelable {
     */
    public static final @RequestFlags int FLAG_PCC_DETECTION = 0x200;

    /**
     * Indicate whether the screen has credman field
     * @hide
     */
    public static final @RequestFlags int FLAG_SCREEN_HAS_CREDMAN_FIELD = 0x400;

    /** @hide */
    public static final int INVALID_REQUEST_ID = Integer.MIN_VALUE;

@@ -236,7 +242,8 @@ public final class FillRequest implements Parcelable {
        FLAG_SUPPORTS_FILL_DIALOG,
        FLAG_IME_SHOWING,
        FLAG_RESET_FILL_DIALOG_STATE,
        FLAG_PCC_DETECTION
        FLAG_PCC_DETECTION,
        FLAG_SCREEN_HAS_CREDMAN_FIELD
    })
    @Retention(RetentionPolicy.SOURCE)
    @DataClass.Generated.Member
@@ -268,6 +275,8 @@ public final class FillRequest implements Parcelable {
                    return "FLAG_RESET_FILL_DIALOG_STATE";
            case FLAG_PCC_DETECTION:
                    return "FLAG_PCC_DETECTION";
            case FLAG_SCREEN_HAS_CREDMAN_FIELD:
                    return "FLAG_SCREEN_HAS_CREDMAN_FIELD";
            default: return Integer.toHexString(value);
        }
    }
@@ -284,10 +293,15 @@ public final class FillRequest implements Parcelable {
     *   include contexts from requests whose {@link SaveInfo} had the
     *   {@link SaveInfo#FLAG_DELAY_SAVE} flag.
     * @param hints
     *   Autofill Provider should return data for the autofill hints requested here,
     *   Sends a list of datatypes for the Autofill Provider.
     *
     *   If this is populated, Autofill Provider should return data
     *   for the autofill hints requested here,
     *   even though the Autofill Provider may not have detected these types.
     *   The hints would be part of HintConstants:
     *   https://developer.android.com/reference/androidx/autofill/HintConstants
     *
     *   This is populated if the platform's field detection is enabled.
     * @param clientState
     *   Gets the latest client state bundle set by the service in a
     *   {@link FillResponse.Builder#setClientState(Bundle) fill response}.
@@ -355,7 +369,8 @@ public final class FillRequest implements Parcelable {
                        | FLAG_SUPPORTS_FILL_DIALOG
                        | FLAG_IME_SHOWING
                        | FLAG_RESET_FILL_DIALOG_STATE
                        | FLAG_PCC_DETECTION);
                        | FLAG_PCC_DETECTION
                        | FLAG_SCREEN_HAS_CREDMAN_FIELD);
        this.mInlineSuggestionsRequest = inlineSuggestionsRequest;
        this.mDelayedFillIntentSender = delayedFillIntentSender;

@@ -383,10 +398,15 @@ public final class FillRequest implements Parcelable {
    }

    /**
     * Autofill Provider should return data for the autofill hints requested here,
     * Sends a list of datatypes for the Autofill Provider.
     *
     * If this is populated, Autofill Provider should return data
     * for the autofill hints requested here,
     * even though the Autofill Provider may not have detected these types.
     * The hints would be part of HintConstants:
     * https://developer.android.com/reference/androidx/autofill/HintConstants
     *
     * This is populated if the platform's field detection is enabled.
     */
    @DataClass.Generated.Member
    public @NonNull List<String> getHints() {
@@ -536,7 +556,8 @@ public final class FillRequest implements Parcelable {
                        | FLAG_SUPPORTS_FILL_DIALOG
                        | FLAG_IME_SHOWING
                        | FLAG_RESET_FILL_DIALOG_STATE
                        | FLAG_PCC_DETECTION);
                        | FLAG_PCC_DETECTION
                        | FLAG_SCREEN_HAS_CREDMAN_FIELD);
        this.mInlineSuggestionsRequest = inlineSuggestionsRequest;
        this.mDelayedFillIntentSender = delayedFillIntentSender;

@@ -558,10 +579,10 @@ public final class FillRequest implements Parcelable {
    };

    @DataClass.Generated(
            time = 1675711417112L,
            time = 1682097266850L,
            codegenVersion = "1.0.23",
            sourceFile = "frameworks/base/core/java/android/service/autofill/FillRequest.java",
            inputSignatures = "public static final @android.service.autofill.FillRequest.RequestFlags int FLAG_MANUAL_REQUEST\npublic static final @android.service.autofill.FillRequest.RequestFlags int FLAG_COMPATIBILITY_MODE_REQUEST\npublic static final @android.service.autofill.FillRequest.RequestFlags int FLAG_PASSWORD_INPUT_TYPE\npublic static final @android.service.autofill.FillRequest.RequestFlags int FLAG_VIEW_NOT_FOCUSED\npublic static final @android.service.autofill.FillRequest.RequestFlags int FLAG_SUPPORTS_FILL_DIALOG\npublic static final @android.service.autofill.FillRequest.RequestFlags int FLAG_IME_SHOWING\npublic static final @android.service.autofill.FillRequest.RequestFlags int FLAG_RESET_FILL_DIALOG_STATE\npublic static final @android.service.autofill.FillRequest.RequestFlags int FLAG_PCC_DETECTION\npublic static final  int INVALID_REQUEST_ID\nprivate final  int mId\nprivate final @android.annotation.NonNull java.util.List<android.service.autofill.FillContext> mFillContexts\nprivate final @android.annotation.NonNull java.util.List<java.lang.String> mHints\nprivate final @android.annotation.Nullable android.os.Bundle mClientState\nprivate final @android.service.autofill.FillRequest.RequestFlags int mFlags\nprivate final @android.annotation.Nullable android.view.inputmethod.InlineSuggestionsRequest mInlineSuggestionsRequest\nprivate final @android.annotation.Nullable android.content.IntentSender mDelayedFillIntentSender\nprivate  void onConstructed()\nclass FillRequest extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genToString=true, genHiddenConstructor=true, genHiddenConstDefs=true)")
            inputSignatures = "public static final @android.service.autofill.FillRequest.RequestFlags int FLAG_MANUAL_REQUEST\npublic static final @android.service.autofill.FillRequest.RequestFlags int FLAG_COMPATIBILITY_MODE_REQUEST\npublic static final @android.service.autofill.FillRequest.RequestFlags int FLAG_PASSWORD_INPUT_TYPE\npublic static final @android.service.autofill.FillRequest.RequestFlags int FLAG_VIEW_NOT_FOCUSED\npublic static final @android.service.autofill.FillRequest.RequestFlags int FLAG_SUPPORTS_FILL_DIALOG\npublic static final @android.service.autofill.FillRequest.RequestFlags int FLAG_IME_SHOWING\npublic static final @android.service.autofill.FillRequest.RequestFlags int FLAG_RESET_FILL_DIALOG_STATE\npublic static final @android.service.autofill.FillRequest.RequestFlags int FLAG_PCC_DETECTION\npublic static final @android.service.autofill.FillRequest.RequestFlags int FLAG_SCREEN_HAS_CREDMAN_FIELD\npublic static final  int INVALID_REQUEST_ID\nprivate final  int mId\nprivate final @android.annotation.NonNull java.util.List<android.service.autofill.FillContext> mFillContexts\nprivate final @android.annotation.NonNull java.util.List<java.lang.String> mHints\nprivate final @android.annotation.Nullable android.os.Bundle mClientState\nprivate final @android.service.autofill.FillRequest.RequestFlags int mFlags\nprivate final @android.annotation.Nullable android.view.inputmethod.InlineSuggestionsRequest mInlineSuggestionsRequest\nprivate final @android.annotation.Nullable android.content.IntentSender mDelayedFillIntentSender\nprivate  void onConstructed()\nclass FillRequest extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genToString=true, genHiddenConstructor=true, genHiddenConstDefs=true)")
    @Deprecated
    private void __metadata() {}

+0 −5
Original line number Diff line number Diff line
@@ -10411,11 +10411,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            return false;
        }
        // Disable triggering autofill if the view is integrated with CredentialManager.
        if (afm.shouldIgnoreCredentialViews() && isCredential()) {
            return false;
        }
        // Check whether view is not part of an activity. If it's not, return false.
        if (getAutofillViewId() <= LAST_APP_AUTOFILL_ID) {
            return false;
+11 −35
Original line number Diff line number Diff line
@@ -99,7 +99,6 @@ public class AutofillFeatureFlags {
            "autofill_dialog_hints";

    // START CREDENTIAL MANAGER FLAGS //

    /**
     * Indicates whether credential manager tagged views should be ignored from autofill structures.
     * This flag is further gated by {@link #DEVICE_CONFIG_AUTOFILL_CREDENTIAL_MANAGER_ENABLED}
@@ -116,22 +115,13 @@ public class AutofillFeatureFlags {
            "autofill_credential_manager_enabled";

    /**
     * Indicates whether credential manager tagged views should suppress fill dialog.
     * This flag is further gated by {@link #DEVICE_CONFIG_AUTOFILL_CREDENTIAL_MANAGER_ENABLED}
     *
     * @hide
     */
    public static final String DEVICE_CONFIG_AUTOFILL_CREDENTIAL_MANAGER_SUPPRESS_FILL_DIALOG =
            "autofill_credential_manager_suppress_fill_dialog";

    /**
     * Indicates whether credential manager tagged views should suppress save dialog.
     * Indicates whether credential manager tagged views should suppress fill and save dialog.
     * This flag is further gated by {@link #DEVICE_CONFIG_AUTOFILL_CREDENTIAL_MANAGER_ENABLED}
     *
     * @hide
     */
    public static final String DEVICE_CONFIG_AUTOFILL_CREDENTIAL_MANAGER_SUPPRESS_SAVE_DIALOG =
            "autofill_credential_manager_suppress_save_dialog";
    public static final String DEVICE_CONFIG_AUTOFILL_CREDENTIAL_MANAGER_SUPPRESS_FILL_AND_SAVE_DIALOG =
            "autofill_credential_manager_suppress_fill_and_save_dialog";
    // END CREDENTIAL MANAGER FLAGS //

    // START AUTOFILL FOR ALL APPS FLAGS //
@@ -272,9 +262,7 @@ public class AutofillFeatureFlags {
    // CREDENTIAL MANAGER DEFAULTS
    // Credential manager is enabled by default so as to allow testing by app developers
    private static final boolean DEFAULT_CREDENTIAL_MANAGER_ENABLED = true;
    private static final boolean DEFAULT_CREDENTIAL_MANAGER_IGNORE_VIEWS = true;
    private static final boolean DEFAULT_CREDENTIAL_MANAGER_SUPPRESS_FILL_DIALOG = false;
    private static final boolean DEFAULT_CREDENTIAL_MANAGER_SUPPRESS_SAVE_DIALOG = false;
    private static final boolean DEFAULT_CREDENTIAL_MANAGER_SUPPRESS_FILL_AND_SAVE_DIALOG = true;
    // END CREDENTIAL MANAGER DEFAULTS


@@ -328,6 +316,7 @@ public class AutofillFeatureFlags {
                (str) -> !TextUtils.isEmpty(str));
    }

    /* starts credman flag getter function */
    /**
     * Whether the Credential Manager feature is enabled or not
     *
@@ -340,31 +329,18 @@ public class AutofillFeatureFlags {
                DEFAULT_CREDENTIAL_MANAGER_ENABLED);
    }

    /**
     * Whether credential manager tagged views should be ignored for autofill structure.
     *
     * @hide
     */
    public static boolean shouldIgnoreCredentialViews() {
        return isCredentialManagerEnabled()
                && DeviceConfig.getBoolean(
                DeviceConfig.NAMESPACE_AUTOFILL,
                DEVICE_CONFIG_AUTOFILL_CREDENTIAL_MANAGER_IGNORE_VIEWS,
                DEFAULT_CREDENTIAL_MANAGER_IGNORE_VIEWS);
    }

    /**
     * Whether credential manager tagged views should not trigger fill dialog requests.
     *
     * @hide
     */
    public static boolean isFillDialogDisabledForCredentialManager() {
        return isCredentialManagerEnabled()
                && DeviceConfig.getBoolean(
    public static boolean isFillAndSaveDialogDisabledForCredentialManager() {
        return isCredentialManagerEnabled() && DeviceConfig.getBoolean(
                    DeviceConfig.NAMESPACE_AUTOFILL,
                DEVICE_CONFIG_AUTOFILL_CREDENTIAL_MANAGER_SUPPRESS_FILL_DIALOG,
                DEFAULT_CREDENTIAL_MANAGER_SUPPRESS_FILL_DIALOG);
                    DEVICE_CONFIG_AUTOFILL_CREDENTIAL_MANAGER_SUPPRESS_FILL_AND_SAVE_DIALOG,
                    DEFAULT_CREDENTIAL_MANAGER_SUPPRESS_FILL_AND_SAVE_DIALOG);
    }
    /* ends credman flag getter function */

    /**
     * Whether triggering fill request on unimportant view is enabled.
+28 −8
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.service.autofill.FillRequest.FLAG_MANUAL_REQUEST;
import static android.service.autofill.FillRequest.FLAG_PASSWORD_INPUT_TYPE;
import static android.service.autofill.FillRequest.FLAG_PCC_DETECTION;
import static android.service.autofill.FillRequest.FLAG_RESET_FILL_DIALOG_STATE;
import static android.service.autofill.FillRequest.FLAG_SCREEN_HAS_CREDMAN_FIELD;
import static android.service.autofill.FillRequest.FLAG_SUPPORTS_FILL_DIALOG;
import static android.service.autofill.FillRequest.FLAG_VIEW_NOT_FOCUSED;
import static android.view.ContentInfo.SOURCE_AUTOFILL;
@@ -665,6 +666,8 @@ public final class AutofillManager {
    @GuardedBy("mLock")
    @Nullable private Executor mRequestCallbackExecutor;

    private boolean mScreenHasCredmanField;

    /**
     * Indicates whether there is already a field to do a fill request after
     * the activity started.
@@ -680,6 +683,8 @@ public final class AutofillManager {

    private final boolean mIsFillDialogEnabled;

    private final boolean mIsFillAndSaveDialogDisabledForCredentialManager;

    // Indicate whether trigger fill request on unimportant views is enabled
    private boolean mIsTriggerFillRequestOnUnimportantViewEnabled = false;

@@ -876,7 +881,10 @@ public final class AutofillManager {

        mIsFillDialogEnabled = AutofillFeatureFlags.isFillDialogEnabled();
        mFillDialogEnabledHints = AutofillFeatureFlags.getFillDialogEnabledHints();
        mShouldIgnoreCredentialViews = AutofillFeatureFlags.shouldIgnoreCredentialViews();

        mIsFillAndSaveDialogDisabledForCredentialManager =
            AutofillFeatureFlags.isFillAndSaveDialogDisabledForCredentialManager();

        if (sDebug) {
            Log.d(TAG, "Fill dialog is enabled:" + mIsFillDialogEnabled
                    + ", hints=" + Arrays.toString(mFillDialogEnabledHints));
@@ -1443,12 +1451,12 @@ public final class AutofillManager {
        if (infos.size() == 0) {
            throw new IllegalArgumentException("No VirtualViewInfo found");
        }
        if (AutofillFeatureFlags.isFillDialogDisabledForCredentialManager()
                && view.isCredential()) {
        if (view.isCredential() && mIsFillAndSaveDialogDisabledForCredentialManager) {
            if (sDebug) {
                Log.d(TAG, "Ignoring Fill Dialog request since important for credMan:"
                        + view.getAutofillId().toString());
            }
            mScreenHasCredmanField = true;
            return;
        }
        for (int i = 0; i < infos.size(); i++) {
@@ -1470,12 +1478,13 @@ public final class AutofillManager {
        if (sDebug) {
            Log.d(TAG, "notifyViewEnteredForFillDialog:" + v.getAutofillId());
        }
        if (AutofillFeatureFlags.isFillDialogDisabledForCredentialManager()
                && v.isCredential()) {
        if (v.isCredential()
                && mIsFillAndSaveDialogDisabledForCredentialManager) {
            if (sDebug) {
                Log.d(TAG, "Ignoring Fill Dialog request since important for credMan:"
                        + v.getAutofillId().toString());
                        + v.getAutofillId());
            }
            mScreenHasCredmanField = true;
            return;
        }
        notifyViewReadyInner(v.getAutofillId(), v.getAutofillHints());
@@ -1535,7 +1544,7 @@ public final class AutofillManager {
        if (mIsFillDialogEnabled
                || ArrayUtils.containsAny(autofillHints, mFillDialogEnabledHints)) {
            if (sDebug) {
                Log.d(TAG, "Trigger fill request when the view is ready.");
                Log.d(TAG, "Triggering pre-emptive request for fill dialog.");
            }

            int flags = FLAG_SUPPORTS_FILL_DIALOG;
@@ -1772,6 +1781,15 @@ public final class AutofillManager {
                flags |= FLAG_PASSWORD_INPUT_TYPE;
            }

            // Update session when screen has credman field
            if (AutofillFeatureFlags.isFillAndSaveDialogDisabledForCredentialManager()
                    && mScreenHasCredmanField) {
                flags |= FLAG_SCREEN_HAS_CREDMAN_FIELD;
                if (sVerbose) {
                    Log.v(TAG, "updating session with flag screen has credman view");
                }
            }

            flags |= getImeStateFlag(view);

            if (!isActiveLocked()) {
@@ -2523,6 +2541,7 @@ public final class AutofillManager {
        mIsFillRequested.set(false);
        mShowAutofillDialogCalled = false;
        mFillDialogTriggerIds = null;
        mScreenHasCredmanField = false;
        mAllTrackedViews.clear();
        if (resetEnteredIds) {
            mEnteredIds = null;
@@ -3636,7 +3655,8 @@ public final class AutofillManager {
    private boolean shouldShowAutofillDialog(View view, AutofillId id) {
        if (!hasFillDialogUiFeature()
                || mShowAutofillDialogCalled
                || mFillDialogTriggerIds == null) {
                || mFillDialogTriggerIds == null
                || mScreenHasCredmanField) {
            return false;
        }

+0 −16
Original line number Diff line number Diff line
@@ -59,16 +59,6 @@ public class AutofillFeatureFlagsTest {
        assertThat(AutofillFeatureFlags.isCredentialManagerEnabled()).isTrue();
    }

    @Test
    public void testShouldIgnoreCredentialManagerViews() {
        setCredentialManagerEnabled(false);
        setIgnoreCredentialManagerViews(true);
        // Overall feature is disabled, so we shouldn't ignore views.
        assertThat(AutofillFeatureFlags.shouldIgnoreCredentialViews()).isFalse();
        setCredentialManagerEnabled(true);
        assertThat(AutofillFeatureFlags.shouldIgnoreCredentialViews()).isTrue();
    }

    private static void setFillDialogHints(String value) {
        setDeviceConfig(
                AutofillFeatureFlags.DEVICE_CONFIG_AUTOFILL_DIALOG_HINTS,
@@ -81,12 +71,6 @@ public class AutofillFeatureFlagsTest {
                String.valueOf(value));
    }

    private static void setIgnoreCredentialManagerViews(boolean value) {
        setDeviceConfig(
                AutofillFeatureFlags.DEVICE_CONFIG_AUTOFILL_CREDENTIAL_MANAGER_IGNORE_VIEWS,
                String.valueOf(value));
    }

    private static void setDeviceConfig(String key, String value) {
        DeviceConfig.setProperty(
                DeviceConfig.NAMESPACE_AUTOFILL, key, value, /* makeDefault */ false);
Loading