Fixed basic autofill services broken on previous CLs.

HeuristicsService: don't generate generic hint on non-autofillable fields,
  otherwise it will never trigger Save because it would be expecting changes
  on fields like buttons.
BasicService: scan children as well.

Bug: 114236837
Test: manual verification

Change-Id: I87c335737386f040fec4b036203756cbcaec752c
diff --git a/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/simple/BasicService.java b/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/simple/BasicService.java
index 16937e7..2b952e7 100644
--- a/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/simple/BasicService.java
+++ b/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/simple/BasicService.java
@@ -142,19 +142,19 @@
     private void addAutofillableFields(@NonNull Map<String, AutofillId> fields,
             @NonNull ViewNode node) {
         String[] hints = node.getAutofillHints();
-        if (hints == null) return;
+        if (hints != null) {
+            // We're simple, we only care about the first hint
+            String hint = hints[0].toLowerCase();
 
-        // We're simple, we only care about the first hint
-        String hint = hints[0].toLowerCase();
-
-        if (hint != null) {
-            AutofillId id = node.getAutofillId();
-            if (!fields.containsKey(hint)) {
-                Log.v(TAG, "Setting hint '" + hint + "' on " + id);
-                fields.put(hint, id);
-            } else {
-                Log.v(TAG, "Ignoring hint '" + hint + "' on " + id
-                        + " because it was already set");
+            if (hint != null) {
+                AutofillId id = node.getAutofillId();
+                if (!fields.containsKey(hint)) {
+                    Log.v(TAG, "Setting hint '" + hint + "' on " + id);
+                    fields.put(hint, id);
+                } else {
+                    Log.v(TAG, "Ignoring hint '" + hint + "' on " + id
+                            + " because it was already set");
+                }
             }
         }
         int childrenSize = node.getChildCount();
diff --git a/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/simple/HeuristicsService.java b/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/simple/HeuristicsService.java
index 5931d4e..2cc6572 100644
--- a/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/simple/HeuristicsService.java
+++ b/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/simple/HeuristicsService.java
@@ -184,7 +184,7 @@
         // Then try some rudimentary heuristics based on other node properties
 
         String viewHint = node.getHint();
-        String hint = inferHint(viewHint);
+        String hint = inferHint(node, viewHint);
         if (hint != null) {
             Log.d(TAG, "Found hint using view hint(" + viewHint + "): " + hint);
             return hint;
@@ -193,7 +193,7 @@
         }
 
         String resourceId = node.getIdEntry();
-        hint = inferHint(resourceId);
+        hint = inferHint(node, resourceId);
         if (hint != null) {
             Log.d(TAG, "Found hint using resourceId(" + resourceId + "): " + hint);
             return hint;
@@ -204,7 +204,7 @@
         CharSequence text = node.getText();
         CharSequence className = node.getClassName();
         if (text != null && className != null && className.toString().contains("EditText")) {
-            hint = inferHint(text.toString());
+            hint = inferHint(node, text.toString());
             if (hint != null) {
                 // NODE: text should not be logged, as it could contain PII
                 Log.d(TAG, "Found hint using text(" + text + "): " + hint);
@@ -223,7 +223,7 @@
      * @return standard autofill hint, or {@code null} when it could not be inferred.
      */
     @Nullable
-    protected String inferHint(@Nullable String string) {
+    protected String inferHint(ViewNode node, @Nullable String string) {
         if (string == null) return null;
 
         string = string.toLowerCase();
@@ -243,7 +243,11 @@
         // developers visualize when autofill is triggered when it shouldn't (for example, in a
         // chat conversation window), so they can mark the root view of such activities with
         // android:importantForAutofill=noExcludeDescendants
-        return string;
+        if (node.isEnabled() && node.getAutofillType() != View.AUTOFILL_TYPE_NONE) {
+            Log.v(TAG, "Falling back to " + string);
+            return string;
+        }
+        return null;
     }
 
     static FillResponse createResponse(@NonNull Context context,