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

Commit 00209d94 authored by Ahaan Ugale's avatar Ahaan Ugale
Browse files

API to show autofill dialog.

This allows a UI Toolkit to display the autofill dialog instead of an
input method, if autofill suggestions are already available when the
user focuses on a view.

The dialog typically covers the input method, so it is undesirable to
show the input method under it.

Bug: 210926084
Test: atest android.autofillservice.cts.dialog.DialogTest
Change-Id: Ib982b0fcc271ed3fa2bf43ebe2f9baf494ec82ef
parent 7691138d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -52411,6 +52411,8 @@ package android.view.autofill {
    method public void requestAutofill(@NonNull android.view.View, int, @NonNull android.graphics.Rect);
    method public void setAutofillRequestCallback(@NonNull java.util.concurrent.Executor, @NonNull android.view.autofill.AutofillRequestCallback);
    method public void setUserData(@Nullable android.service.autofill.UserData);
    method public boolean showAutofillDialog(@NonNull android.view.View);
    method public boolean showAutofillDialog(@NonNull android.view.View, int);
    method public void unregisterCallback(@Nullable android.view.autofill.AutofillManager.AutofillCallback);
    field public static final String EXTRA_ASSIST_STRUCTURE = "android.view.autofill.extra.ASSIST_STRUCTURE";
    field public static final String EXTRA_AUTHENTICATION_RESULT = "android.view.autofill.extra.AUTHENTICATION_RESULT";
+43 −3
Original line number Diff line number Diff line
@@ -3100,11 +3100,51 @@ public final class AutofillManager {
    }

    /**
     * Checks the id of autofill whether supported the fill dialog.
     * If autofill suggestions for a dialog-style UI are available for {@code view}, shows a dialog
     * allowing the user to select a suggestion and returns {@code true}.
     * <p>
     * The dialog may not be available if the autofill service does not support it, or if the
     * autofill request has not returned a response yet.
     * <p>
     * It is recommended to call this method the first time a user focuses on an autofill-able form,
     * and to avoid showing the input method if the dialog is shown. If this method returns
     * {@code false}, you should then instead show the input method (assuming that is how the
     * view normally handles the focus event). If the user re-focuses on the view, you should not
     * call this method again so as to not disrupt usage of the input method.
     *
     * @param view the view for which to show autofill suggestions. This is typically a view
     *             receiving a focus event. The autofill suggestions shown will include content for
     *             related views as well.
     * @return {@code true} if the autofill dialog is being shown
     */
    // TODO(b/210926084): Consider whether to include the one-time show logic within this method.
    public boolean showAutofillDialog(@NonNull View view) {
        Objects.requireNonNull(view);
        if (shouldShowAutofillDialog(view.getAutofillId())) {
            // If the id matches a trigger id, this will trigger the fill dialog.
            notifyViewEntered(view);
            return true;
        }
        return false;
    }

    /**
     * Like {@link #showAutofillDialog(View)} but for virtual views.
     *
     * @hide
     * @param virtualId id identifying the virtual child inside the parent view.
     */
    public boolean isShowFillDialog(AutofillId id) {
    // TODO(b/210926084): Consider whether to include the one-time show logic within this method.
    public boolean showAutofillDialog(@NonNull View view, int virtualId) {
        Objects.requireNonNull(view);
        if (shouldShowAutofillDialog(getAutofillId(view, virtualId))) {
            // If the id matches a trigger id, this will trigger the fill dialog.
            notifyViewEntered(view, virtualId, /* bounds= */ null, /* flags= */ 0);
            return true;
        }
        return false;
    }

    private boolean shouldShowAutofillDialog(AutofillId id) {
        if (!hasFillDialogUiFeature() || mFillDialogTriggerIds == null) {
            return false;
        }