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

Commit 4aed12b9 authored by Haoran Zhang's avatar Haoran Zhang
Browse files

[Webview-FillDialog Support] Fix autofill framework issue found when testing webView prorotype

There are two issues I found:

1. Instead of SparseArray.indexOf(i), framework should use SparseArray.keyOf(i) to get the virtual id for virtual views that Chrome passed in.

2. Framework should ignore case when checking whether view's autofill hints is in fill dialog supported hints. In the webview prototype, Chrome is passing "PASSWORD" as autofill hints

Also I found it's easy to create null pointer exception when referencing
AutofillHints in notifyViewReadyInner(). It's not obvious that this
array could be null also. Annotated it with @Nullable to make it obvious.

Bug:b/299532529
Test: atest CtsAutoFillServiceTestCases

Change-Id: Ie1ed6f0fbe806826a1844d85a74767ca946e55b8
parent 40ba3002
Loading
Loading
Loading
Loading
+26 −13
Original line number Diff line number Diff line
@@ -1436,7 +1436,7 @@ public final class AutofillManager {
        }
        for (int i = 0; i < infos.size(); i++) {
            final VirtualViewFillInfo info = infos.valueAt(i);
            final int virtualId = infos.indexOfKey(i);
            final int virtualId = infos.keyAt(i);
            notifyViewReadyInner(getAutofillId(view, virtualId),
                    (info == null) ? null : info.getAutofillHints());
        }
@@ -1450,9 +1450,6 @@ public final class AutofillManager {
     * @hide
     */
    public void notifyViewEnteredForFillDialog(View v) {
        if (sDebug) {
            Log.d(TAG, "notifyViewEnteredForFillDialog:" + v.getAutofillId());
        }
        if (v.isCredential()
                && mIsFillAndSaveDialogDisabledForCredentialManager) {
            if (sDebug) {
@@ -1465,11 +1462,14 @@ public final class AutofillManager {
        notifyViewReadyInner(v.getAutofillId(), v.getAutofillHints());
    }

    private void notifyViewReadyInner(AutofillId id, String[] autofillHints) {
    private void notifyViewReadyInner(AutofillId id, @Nullable String[] autofillHints) {
        if (sDebug) {
            Log.d(TAG, "notifyViewReadyInner:" + id);
        }

        if (!hasAutofillFeature()) {
            return;
        }

        synchronized (mLock) {
            if (mAllTrackedViews.contains(id)) {
                // The id is tracked and will not trigger pre-fill request again.
@@ -1511,20 +1511,32 @@ public final class AutofillManager {
                            Log.v(TAG, "not starting session: no service client");
                        }
                    }

                }
            }
        }

        if (mIsFillDialogEnabled
                || ArrayUtils.containsAny(autofillHints, mFillDialogEnabledHints)) {
        // Check if framework should send pre-fill request for fill dialog
        boolean shouldSendPreFillRequestForFillDialog = false;
        if (mIsFillDialogEnabled) {
            shouldSendPreFillRequestForFillDialog = true;
        } else if (autofillHints != null) {
            // check if supported autofill hint is present
            for (String autofillHint : autofillHints) {
                for (String filldialogEnabledHint : mFillDialogEnabledHints) {
                    if (filldialogEnabledHint.equalsIgnoreCase(autofillHint)) {
                        shouldSendPreFillRequestForFillDialog = true;
                        break;
                    }
                }
                if (shouldSendPreFillRequestForFillDialog) break;
            }
        }
        if (shouldSendPreFillRequestForFillDialog) {
            if (sDebug) {
                Log.d(TAG, "Triggering pre-emptive request for fill dialog.");
            }

            int flags = FLAG_SUPPORTS_FILL_DIALOG;
            flags |= FLAG_VIEW_NOT_FOCUSED;

            synchronized (mLock) {
                // To match the id of the IME served view, used AutofillId.NO_AUTOFILL_ID on prefill
                // request, because IME will reset the id of IME served view to 0 when activity
@@ -1535,6 +1547,7 @@ public final class AutofillManager {
                    /* bounds= */ null,  /* value= */ null, flags);
            }
        }
        return;
    }

    private boolean hasFillDialogUiFeature() {