This does not prevent this field from being auto-filled if an auto-fill operation is + * triggered from a different view.
+ * * Use with {@link #setAutoFillMode(int)} and {@code * android:autoFillMode}. */ @@ -6523,7 +6527,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback, if (isAutoFillable()) { AutoFillManager afm = getAutoFillManager(); if (afm != null) { - afm.focusChanged(this, gainFocus); + boolean adjGainFocus = gainFocus; + if (adjGainFocus && getResolvedAutoFillMode() == AUTO_FILL_MODE_MANUAL) { + adjGainFocus = false; + } + + afm.focusChanged(this, adjGainFocus); } } @@ -9306,6 +9315,30 @@ public class View implements Drawable.Callback, KeyEvent.Callback, return (mPrivateFlags3 & PFLAG3_AUTO_FILL_MODE_MASK) >> PFLAG3_AUTO_FILL_MODE_SHIFT; } + /** + * Returns the resolved auto-fill mode for this view. + * + * This is the same as {@link #getAutoFillMode()} but if the mode is + * {@link #AUTO_FILL_MODE_INHERIT} the parents auto-fill mode will be returned. + * + * @return One of {@link #AUTO_FILL_MODE_AUTO}, or {@link #AUTO_FILL_MODE_MANUAL}. + * + * @hide + */ + public @AutoFillMode int getResolvedAutoFillMode() { + @AutoFillMode int autoFillMode = getAutoFillMode(); + + if (autoFillMode == AUTO_FILL_MODE_INHERIT) { + if (mParent == null) { + throw new IllegalStateException("View is detached, cannot resolve autoFillMode"); + } else { + return mParent.getResolvedAutoFillMode(); + } + } else { + return autoFillMode; + } + } + /** * Find the nearest view in the specified direction that can take focus. * This does not actually give focus to that view. diff --git a/core/java/android/view/ViewParent.java b/core/java/android/view/ViewParent.java index cc11cb8205d5d..cdfd61bee083b 100644 --- a/core/java/android/view/ViewParent.java +++ b/core/java/android/view/ViewParent.java @@ -659,4 +659,17 @@ public interface ViewParent { * @return true if the action was consumed by this ViewParent */ public boolean onNestedPrePerformAccessibilityAction(View target, int action, Bundle arguments); + + /** + * Return the resolved auto-fill mode. + * + * @return The resolved auto-fill mode + * + * @see View#getResolvedAutoFillMode() + * + * @hide + */ + default @View.AutoFillMode int getResolvedAutoFillMode() { + return View.AUTO_FILL_MODE_AUTO; + } } diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 8031f1934088d..d2d6620cd56cd 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -2289,12 +2289,14 @@