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

Commit 2bcd489a authored by Alex Salo's avatar Alex Salo
Browse files

Make WebViews eligible for Autofill For All Apps (AFAA)

AFAA, when enabled, ignores isImportantForAutofill flag on a View subclass. However, it only does so when view.getAutofillType() is something other than NONE. Autofill type could be a TEXT or DATE etc, so that EditTexts are of type TEXT, for example. A WebView is not of any type since it's just a system for hosting other components. Therefore this fix skips the autofillType check for a WebView.

Note that we need to always treat a WebView as important for autofill, otherwise all its contents (e.g. children views like EditTexts within the WebView) would be skipped entirely during the detection stage. (Note that for this reason WebView's isImportantForAutofill property is already `true` by default.)

Change-Id: Iade54fac30a6ff21ab58bf838d4e4845ebe8b686
Fix: 286195872
Test: atest CtsAssistTestCases
parent b5197666
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ import android.view.inspector.InspectableProperty.EnumEntry;
import android.view.translation.TranslationCapability;
import android.view.translation.TranslationSpec.DataFormat;
import android.view.translation.ViewTranslationRequest;
import android.webkit.WebView;
import android.window.OnBackInvokedDispatcher;

import com.android.internal.R;
@@ -3725,6 +3726,11 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        return afm.shouldIncludeAllChildrenViewInAssistStructure();
    }

    private boolean shouldAlwaysIncludeWebview(AutofillManager afm) {
        if (afm == null) return false;
        return afm.shouldAlwaysIncludeWebviewInAssistStructure();
    }

    /** @hide */
    private void populateChildrenForAutofill(ArrayList<View> list, @AutofillFlags int flags) {
        final int childrenCount = mChildrenCount;
@@ -3741,6 +3747,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
                    ? mChildren[childIndex] : preorderedList.get(childIndex);
            if ((flags & AUTOFILL_FLAG_INCLUDE_NOT_IMPORTANT_VIEWS) != 0
                    || child.isImportantForAutofill()
                    || (child instanceof WebView && shouldAlwaysIncludeWebview(afm))
                    || (child.isMatchingAutofillableHeuristics()
                        && !child.isActivityDeniedForAutofillForUnimportantView())
                    || (shouldIncludeAllChildrenViewWithAutofillTypeNotNone(afm)
+18 −0
Original line number Diff line number Diff line
@@ -209,6 +209,17 @@ public class AutofillFeatureFlags {
        DEVICE_CONFIG_INCLUDE_ALL_VIEWS_IN_ASSIST_STRUCTURE =
            "include_all_views_in_assist_structure";

    /**
     * Whether to always include WebView in assist structure. WebView is a container view that
     * providers "virtual" views. We want to always include such a container view since it can
     * contain arbitrary views in it, some of which could be fillable.
     *
     * @hide
     */
    public static final String
            DEVICE_CONFIG_ALWAYS_INCLUDE_WEBVIEW_IN_ASSIST_STRUCTURE =
            "always_include_webview_in_assist_structure";

    // END AUTOFILL FOR ALL APPS FLAGS //


@@ -441,6 +452,13 @@ public class AutofillFeatureFlags {
            DEVICE_CONFIG_INCLUDE_ALL_VIEWS_IN_ASSIST_STRUCTURE, false);
    }

    /** @hide */
    public static boolean shouldAlwaysIncludeWebviewInAssistStructure() {
        return DeviceConfig.getBoolean(
            DeviceConfig.NAMESPACE_AUTOFILL,
                DEVICE_CONFIG_ALWAYS_INCLUDE_WEBVIEW_IN_ASSIST_STRUCTURE, true);
    }


    /**
     * Whether should enable multi-line filter
+13 −0
Original line number Diff line number Diff line
@@ -728,6 +728,9 @@ public final class AutofillManager {
    // Indicate whether should include all view in assist structure
    private boolean mShouldIncludeAllChildrenViewInAssistStructure;

    // Indicate whether WebView should always be included in the assist structure
    private boolean mShouldAlwaysIncludeWebviewInAssistStructure;

    // Indicates whether called the showAutofillDialog() method.
    private boolean mShowAutofillDialogCalled = false;

@@ -946,6 +949,9 @@ public final class AutofillManager {

        mShouldIncludeAllChildrenViewInAssistStructure
            = AutofillFeatureFlags.shouldIncludeAllChildrenViewInAssistStructure();

        mShouldAlwaysIncludeWebviewInAssistStructure =
                AutofillFeatureFlags.shouldAlwaysIncludeWebviewInAssistStructure();
    }

    /**
@@ -1023,6 +1029,13 @@ public final class AutofillManager {
        return mShouldIncludeAllChildrenViewInAssistStructure;
    }

    /**
     * @hide
     */
    public boolean shouldAlwaysIncludeWebviewInAssistStructure() {
        return mShouldAlwaysIncludeWebviewInAssistStructure;
    }

    /**
     * Get the denied or allowed activitiy names under specified package from the list string and
     * set it in fields accordingly