From 37cb62c9ca8582079cdeaf170fb634954aeef7f5 Mon Sep 17 00:00:00 2001 From: Haoran Zhang Date: Tue, 7 Mar 2023 22:59:15 +0000 Subject: [PATCH] Adding two experiment flags to definie the condition to include views in assist structure (AS). Flag 1: Add AutofillType != NONE views into AS Flag 2: Add all views into AS Both flags are default OFF and will be used to evaluate the impact of AssistStructure generating. Currently, only "importantForAutofill" and "not important views that pass the heuristic" will be included.`` bug:272129221 Change-Id: I64890a56df40b394714506ce58be23f0967fbcae --- core/java/android/view/ViewGroup.java | 21 +++++++++- .../view/autofill/AutofillFeatureFlags.java | 40 +++++++++++++++++++ .../view/autofill/AutofillManager.java | 26 ++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java index 46ae3ea218904..f5e4da86bfea8 100644 --- a/core/java/android/view/ViewGroup.java +++ b/core/java/android/view/ViewGroup.java @@ -66,6 +66,7 @@ import android.view.animation.AnimationUtils; import android.view.animation.LayoutAnimationController; import android.view.animation.Transformation; import android.view.autofill.AutofillId; +import android.view.autofill.AutofillManager; import android.view.autofill.Helper; import android.view.inspector.InspectableProperty; import android.view.inspector.InspectableProperty.EnumEntry; @@ -3709,6 +3710,20 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager return children; } + private AutofillManager getAutofillManager() { + return mContext.getSystemService(AutofillManager.class); + } + + private boolean shouldIncludeAllChildrenViewWithAutofillTypeNotNone(AutofillManager afm) { + if (afm == null) return false; + return afm.shouldIncludeAllChildrenViewsWithAutofillTypeNotNoneInAssistStructure(); + } + + private boolean shouldIncludeAllChildrenViews(AutofillManager afm){ + if (afm == null) return false; + return afm.shouldIncludeAllChildrenViewInAssistStructure(); + } + /** @hide */ private void populateChildrenForAutofill(ArrayList list, @AutofillFlags int flags) { final int childrenCount = mChildrenCount; @@ -3718,6 +3733,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager final ArrayList preorderedList = buildOrderedChildList(); final boolean customOrder = preorderedList == null && isChildrenDrawingOrderEnabled(); + final AutofillManager afm = getAutofillManager(); for (int i = 0; i < childrenCount; i++) { final int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder); final View child = (preorderedList == null) @@ -3725,7 +3741,10 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager if ((flags & AUTOFILL_FLAG_INCLUDE_NOT_IMPORTANT_VIEWS) != 0 || child.isImportantForAutofill() || (child.isMatchingAutofillableHeuristics() - && !child.isActivityDeniedForAutofillForUnimportantView())) { + && !child.isActivityDeniedForAutofillForUnimportantView()) + || (shouldIncludeAllChildrenViewWithAutofillTypeNotNone(afm) + && child.getAutofillType() != AUTOFILL_TYPE_NONE) + || shouldIncludeAllChildrenViews(afm)){ list.add(child); } else if (child instanceof ViewGroup) { ((ViewGroup) child).populateChildrenForAutofill(list, flags); diff --git a/core/java/android/view/autofill/AutofillFeatureFlags.java b/core/java/android/view/autofill/AutofillFeatureFlags.java index e51eff42fed5a..4aa612c526fef 100644 --- a/core/java/android/view/autofill/AutofillFeatureFlags.java +++ b/core/java/android/view/autofill/AutofillFeatureFlags.java @@ -193,6 +193,24 @@ public class AutofillFeatureFlags { public static final String DEVICE_CONFIG_SHOULD_ENABLE_AUTOFILL_ON_ALL_VIEW_TYPES = "should_enable_autofill_on_all_view_types"; + /** + * Whether include all autofill type not none views in assist structure + * + * @hide + */ + public static final String + DEVICE_CONFIG_INCLUDE_ALL_AUTOFILL_TYPE_NOT_NONE_VIEWS_IN_ASSIST_STRUCTURE = + "include_all_autofill_type_not_none_views_in_assist_structure"; + + /** + * Whether include all views in assist structure + * + * @hide + */ + public static final String + DEVICE_CONFIG_INCLUDE_ALL_VIEWS_IN_ASSIST_STRUCTURE = + "include_all_views_in_assist_structure"; + // END AUTOFILL FOR ALL APPS FLAGS // @@ -398,6 +416,28 @@ public class AutofillFeatureFlags { DeviceConfig.NAMESPACE_AUTOFILL, DEVICE_CONFIG_PACKAGE_AND_ACTIVITY_ALLOWLIST_FOR_TRIGGERING_FILL_REQUEST, ""); } + /** + * Whether include all views that have autofill type not none in assist structure. + * + * @hide + */ + public static boolean shouldIncludeAllViewsAutofillTypeNotNoneInAssistStructrue() { + return DeviceConfig.getBoolean( + DeviceConfig.NAMESPACE_AUTOFILL, + DEVICE_CONFIG_INCLUDE_ALL_AUTOFILL_TYPE_NOT_NONE_VIEWS_IN_ASSIST_STRUCTURE, false); + } + + /** + * Whether include all views in assist structure. + * + * @hide + */ + public static boolean shouldIncludeAllChildrenViewInAssistStructure() { + return DeviceConfig.getBoolean( + DeviceConfig.NAMESPACE_AUTOFILL, + DEVICE_CONFIG_INCLUDE_ALL_VIEWS_IN_ASSIST_STRUCTURE, false); + } + // START AUTOFILL PCC CLASSIFICATION FUNCTIONS diff --git a/core/java/android/view/autofill/AutofillManager.java b/core/java/android/view/autofill/AutofillManager.java index cc8ab10720838..1ef7afc8615b5 100644 --- a/core/java/android/view/autofill/AutofillManager.java +++ b/core/java/android/view/autofill/AutofillManager.java @@ -707,6 +707,12 @@ public final class AutofillManager { // An allowed activity set read from device config private Set mAllowedActivitySet = new ArraySet<>(); + // Indicate whether should include all view with autofill type not none in assist structure + private boolean mShouldIncludeAllViewsWithAutofillTypeNotNoneInAssistStructure; + + // Indicate whether should include all view in assist structure + private boolean mShouldIncludeAllChildrenViewInAssistStructure; + // Indicates whether called the showAutofillDialog() method. private boolean mShowAutofillDialogCalled = false; @@ -913,6 +919,12 @@ public final class AutofillManager { mAllowedActivitySet = getDeniedOrAllowedActivitySetFromString( allowlistString, packageName); } + + mShouldIncludeAllViewsWithAutofillTypeNotNoneInAssistStructure + = AutofillFeatureFlags.shouldIncludeAllViewsAutofillTypeNotNoneInAssistStructrue(); + + mShouldIncludeAllChildrenViewInAssistStructure + = AutofillFeatureFlags.shouldIncludeAllChildrenViewInAssistStructure(); } /** @@ -962,6 +974,20 @@ public final class AutofillManager { return listString.indexOf(packageName + ":") != -1; } + /** + * @hide + */ + public boolean shouldIncludeAllChildrenViewsWithAutofillTypeNotNoneInAssistStructure() { + return mShouldIncludeAllViewsWithAutofillTypeNotNoneInAssistStructure; + } + + /** + * @hide + */ + public boolean shouldIncludeAllChildrenViewInAssistStructure() { + return mShouldIncludeAllChildrenViewInAssistStructure; + } + /** * Get the denied or allowed activitiy names under specified package from the list string and * set it in fields accordingly