Autofill sample: Fixed NPE when there are no *supported* hints.
Bug: 66417779
Test: manual
Change-Id: I8950c03037bc8f6eef6b0aeed0cf2f07600fa2ea
diff --git a/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/AutofillFieldMetadata.java b/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/AutofillFieldMetadata.java
index c857fbd..1e8427d 100644
--- a/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/AutofillFieldMetadata.java
+++ b/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/AutofillFieldMetadata.java
@@ -40,8 +40,10 @@
mAutofillOptions = view.getAutofillOptions();
mFocused = view.isFocused();
String[] hints = filterForSupportedHints(view.getAutofillHints());
- convertToStoredHintNames(hints);
- setHints(hints);
+ if (hints != null) {
+ convertToStoredHintNames(hints);
+ setHints(hints);
+ }
}
public String[] getHints() {
diff --git a/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/StructureParser.java b/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/StructureParser.java
index aaf5b16..812ba40 100644
--- a/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/StructureParser.java
+++ b/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/multidatasetservice/StructureParser.java
@@ -64,24 +64,29 @@
}
private void parseLocked(boolean forFill, ViewNode viewNode) {
- if (viewNode.getAutofillHints() != null && viewNode.getAutofillHints().length > 0) {
- if (forFill) {
- mAutofillFields.add(new AutofillFieldMetadata(viewNode));
- } else {
- FilledAutofillField filledAutofillField =
- new FilledAutofillField(viewNode.getAutofillHints());
- AutofillValue autofillValue = viewNode.getAutofillValue();
- if (autofillValue.isText()) {
- // Using toString of AutofillValue.getTextValue in order to save it to
- // SharedPreferences.
- filledAutofillField.setTextValue(autofillValue.getTextValue().toString());
- } else if (autofillValue.isDate()) {
- filledAutofillField.setDateValue(autofillValue.getDateValue());
- } else if (autofillValue.isList()) {
- filledAutofillField.setListValue(viewNode.getAutofillOptions(),
- autofillValue.getListValue());
+
+ if (viewNode.getAutofillHints() != null) {
+ String[] filteredHints = AutofillHints.filterForSupportedHints(
+ viewNode.getAutofillHints());
+ if (filteredHints != null && filteredHints.length > 0) {
+ if (forFill) {
+ mAutofillFields.add(new AutofillFieldMetadata(viewNode));
+ } else {
+ FilledAutofillField filledAutofillField =
+ new FilledAutofillField(viewNode.getAutofillHints());
+ AutofillValue autofillValue = viewNode.getAutofillValue();
+ if (autofillValue.isText()) {
+ // Using toString of AutofillValue.getTextValue in order to save it to
+ // SharedPreferences.
+ filledAutofillField.setTextValue(autofillValue.getTextValue().toString());
+ } else if (autofillValue.isDate()) {
+ filledAutofillField.setDateValue(autofillValue.getDateValue());
+ } else if (autofillValue.isList()) {
+ filledAutofillField.setListValue(viewNode.getAutofillOptions(),
+ autofillValue.getListValue());
+ }
+ mFilledAutofillFieldCollection.add(filledAutofillField);
}
- mFilledAutofillFieldCollection.add(filledAutofillField);
}
}
int childrenSize = viewNode.getChildCount();