From 7c8dbf71bb9d2322a50d81c9eb54282fd522e449 Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Fri, 8 Jun 2018 17:54:40 -0700 Subject: [PATCH] Log when a autofill is disabled in a view because of a parent's importance. Such log helps diagnosing when app developers explicitly disabled autofill. Bug: 79607009 Test: manual verification Change-Id: I551f1cb2bd61068317677ced9bd32a6057f7dc62 --- core/java/android/view/View.java | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 4ec07fcc72c72..964ee5eee06d5 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -787,6 +787,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ protected static final String VIEW_LOG_TAG = "View"; + /** + * The logging tag used by this class when logging verbose, autofill-related messages. + */ + // NOTE: We cannot use android.view.autofill.Helper.sVerbose because that variable is not + // set if a session is not started. + private static final String AUTOFILL_LOG_TAG = "View.Autofill"; + /** * When set to true, apps will draw debugging information about their layouts. * @@ -7979,10 +7986,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, private void onProvideVirtualStructureCompat(ViewStructure structure, boolean forAutofill) { final AccessibilityNodeProvider provider = getAccessibilityNodeProvider(); if (provider != null) { - if (android.view.autofill.Helper.sVerbose && forAutofill) { - Log.v(VIEW_LOG_TAG, "onProvideVirtualStructureCompat() for " + this); + if (forAutofill && Log.isLoggable(AUTOFILL_LOG_TAG, Log.VERBOSE)) { + Log.v(AUTOFILL_LOG_TAG, "onProvideVirtualStructureCompat() for " + this); } - final AccessibilityNodeInfo info = createAccessibilityNodeInfo(); structure.setChildCount(1); final ViewStructure root = structure.newChild(0); @@ -8220,8 +8226,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ public void setAutofillId(@Nullable AutofillId id) { // TODO(b/37566627): add unit / CTS test for all possible combinations below - if (android.view.autofill.Helper.sVerbose) { - Log.v(VIEW_LOG_TAG, "setAutofill(): from " + mAutofillId + " to " + id); + if (Log.isLoggable(AUTOFILL_LOG_TAG, Log.VERBOSE)) { + Log.v(AUTOFILL_LOG_TAG, "setAutofill(): from " + mAutofillId + " to " + id); } if (isAttachedToWindow()) { throw new IllegalStateException("Cannot set autofill id when view is attached"); @@ -8424,6 +8430,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback, final int parentImportance = ((View) parent).getImportantForAutofill(); if (parentImportance == IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS || parentImportance == IMPORTANT_FOR_AUTOFILL_YES_EXCLUDE_DESCENDANTS) { + if (Log.isLoggable(AUTOFILL_LOG_TAG, Log.VERBOSE)) { + Log.v(AUTOFILL_LOG_TAG, "View (autofillId=" + getAutofillViewId() + ", " + + getClass() + ") is not important for autofill because parent " + + parent + "'s importance is " + parentImportance); + } return false; } parent = parent.getParent(); @@ -18637,10 +18648,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, if ((mPrivateFlags3 & PFLAG3_AUTOFILLID_EXPLICITLY_SET) != 0) { // Ignore when view already set it through setAutofillId(); - if (android.view.autofill.Helper.sDebug) { - Log.d(VIEW_LOG_TAG, "onRestoreInstanceState(): not setting autofillId to " - + baseState.mAutofillViewId + " because view explicitly set it to " - + mAutofillId); + if (Log.isLoggable(AUTOFILL_LOG_TAG, Log.DEBUG)) { + Log.d(AUTOFILL_LOG_TAG, "onRestoreInstanceState(): not setting autofillId " + + "to " + baseState.mAutofillViewId + " because view explicitly set" + + " it to " + mAutofillId); } } else { mAutofillViewId = baseState.mAutofillViewId;