aboutsummaryrefslogtreecommitdiff
path: root/input
diff options
context:
space:
mode:
authorFelipe Leme <felipeal@google.com>2018-09-26 11:34:33 -0700
committerFelipe Leme <felipeal@google.com>2018-09-26 13:48:02 -0700
commit9b05e1f8630faacc352c880496eab2d4e9ac44a7 (patch)
tree641fd2953c1f37098ec5ada115e77409aaf894ca /input
parent4dc2b9ef3a282cfcbc915621b4404ec4583b81a3 (diff)
downloadandroid-9b05e1f8630faacc352c880496eab2d4e9ac44a7.tar.gz
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
Diffstat (limited to 'input')
-rw-r--r--input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/simple/BasicService.java26
-rw-r--r--input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/simple/HeuristicsService.java14
2 files changed, 22 insertions, 18 deletions
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 16937e74..2b952e78 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 @@ public final class BasicService extends AutofillService {
private void addAutofillableFields(@NonNull Map<String, AutofillId> fields,
@NonNull ViewNode node) {
String[] hints = node.getAutofillHints();
- if (hints == null) return;
-
- // 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 (hints != null) {
+ // 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");
+ }
}
}
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 5931d4e4..2cc65729 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 @@ public class HeuristicsService extends AutofillService {
// 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 @@ public class HeuristicsService extends AutofillService {
}
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 @@ public class HeuristicsService extends AutofillService {
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 @@ public class HeuristicsService extends AutofillService {
* @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 @@ public class HeuristicsService extends AutofillService {
// 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,