aboutsummaryrefslogtreecommitdiff
path: root/input
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2017-05-17 09:15:34 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-05-17 09:15:35 +0000
commit6292073e1583dce79c69004ce54078d8e3c312de (patch)
tree0b2105e67db7edfe78a49c25a8ffee8d1eaab1b0 /input
parent33431972f8528211649f53d3f953074d7599ff85 (diff)
parent54df3170ef4408540cbfc54568027b1f3a5191f4 (diff)
downloadandroid-6292073e1583dce79c69004ce54078d8e3c312de.tar.gz
Merge "Ensure autofill sample service doesn't build empty datasets." into oc-dev
Diffstat (limited to 'input')
-rw-r--r--input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/service/AutofillHelper.java12
-rw-r--r--input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/service/model/AutofillField.java10
-rw-r--r--input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/service/model/ClientFormData.java33
-rw-r--r--input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/service/model/SavedAutofillValue.java24
4 files changed, 52 insertions, 27 deletions
diff --git a/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/service/AutofillHelper.java b/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/service/AutofillHelper.java
index aebbd54a..460729e6 100644
--- a/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/service/AutofillHelper.java
+++ b/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/service/AutofillHelper.java
@@ -46,8 +46,12 @@ public final class AutofillHelper {
AutofillFieldsCollection autofillFields, ClientFormData clientFormData) {
Dataset.Builder datasetBuilder = new Dataset.Builder
(newRemoteViews(context.getPackageName(), clientFormData.getDatasetName()));
- clientFormData.applyToFields(autofillFields, datasetBuilder);
- return datasetBuilder.build();
+ boolean setValueAtLeastOnce = clientFormData.applyToFields(autofillFields, datasetBuilder);
+ if (setValueAtLeastOnce) {
+ return datasetBuilder.build();
+ } else {
+ return null;
+ }
}
public static RemoteViews newRemoteViews(String packageName, String remoteViewsText) {
@@ -78,7 +82,9 @@ public final class AutofillHelper {
responseBuilder.addDataset(datasetBuilder.build());
} else {
Dataset dataset = newDataset(context, autofillFields, clientFormData);
- responseBuilder.addDataset(dataset);
+ if (dataset != null) {
+ responseBuilder.addDataset(dataset);
+ }
}
}
}
diff --git a/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/service/model/AutofillField.java b/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/service/model/AutofillField.java
index 30794bfb..4d4de2bc 100644
--- a/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/service/model/AutofillField.java
+++ b/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/service/model/AutofillField.java
@@ -30,7 +30,6 @@ public class AutofillField {
private int mSaveType = 0;
private String[] mHints;
private AutofillId mId;
- private AutofillValue mValue;
private int mAutofillType;
private String[] mAutofillOptions;
private boolean mFocused;
@@ -38,16 +37,11 @@ public class AutofillField {
public AutofillField(AssistStructure.ViewNode view) {
mId = view.getAutofillId();
setHints(view.getAutofillHints());
- mValue = view.getAutofillValue();
mAutofillType = view.getAutofillType();
mAutofillOptions = view.getAutofillOptions();
mFocused = view.isFocused();
}
- public AutofillValue getValue() {
- return mValue;
- }
-
public String[] getHints() {
return mHints;
}
@@ -73,10 +67,6 @@ public class AutofillField {
return mAutofillType;
}
- public void setAutofillType(int autofillType) {
- this.mAutofillType = autofillType;
- }
-
public int getAutofillOptionIndex(String value) {
for (int i = 0; i < mAutofillOptions.length; i++) {
if (mAutofillOptions[i].equals(value)) {
diff --git a/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/service/model/ClientFormData.java b/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/service/model/ClientFormData.java
index 7a3e7ac1..aa57e935 100644
--- a/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/service/model/ClientFormData.java
+++ b/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/service/model/ClientFormData.java
@@ -101,8 +101,9 @@ public final class ClientFormData {
* Populates a {@link Dataset.Builder} with appropriate values for each {@link AutofillId}
* in a {@code AutofillFieldsCollection}.
*/
- public void applyToFields(AutofillFieldsCollection autofillFieldsCollection,
+ public boolean applyToFields(AutofillFieldsCollection autofillFieldsCollection,
Dataset.Builder datasetBuilder) {
+ boolean setValueAtLeastOnce = false;
List<String> allHints = autofillFieldsCollection.getAllHints();
for (int hintIndex = 0; hintIndex < allHints.size(); hintIndex++) {
String hint = allHints.get(hintIndex);
@@ -114,22 +115,35 @@ public final class ClientFormData {
AutofillField autofillField = autofillFields.get(autofillFieldIndex);
AutofillId autofillId = autofillField.getId();
int autofillType = autofillField.getAutofillType();
+ SavedAutofillValue savedAutofillValue = hintMap.get(hint);
switch (autofillType) {
case View.AUTOFILL_TYPE_LIST:
- int listValue = autofillField.getAutofillOptionIndex(hintMap.get(hint).getTextValue());
- datasetBuilder.setValue(autofillId, AutofillValue.forList(listValue));
+ int listValue = autofillField.getAutofillOptionIndex(savedAutofillValue.getTextValue());
+ if (listValue != -1) {
+ datasetBuilder.setValue(autofillId, AutofillValue.forList(listValue));
+ setValueAtLeastOnce = true;
+ }
break;
case View.AUTOFILL_TYPE_DATE:
- long dateValue = hintMap.get(hint).getDateValue();
- datasetBuilder.setValue(autofillId, AutofillValue.forDate(dateValue));
+ long dateValue = savedAutofillValue.getDateValue();
+ if (dateValue != -1) {
+ datasetBuilder.setValue(autofillId, AutofillValue.forDate(dateValue));
+ setValueAtLeastOnce = true;
+ }
break;
case View.AUTOFILL_TYPE_TEXT:
- String textValue = hintMap.get(hint).getTextValue();
- datasetBuilder.setValue(autofillId, AutofillValue.forText(textValue));
+ String textValue = savedAutofillValue.getTextValue();
+ if (textValue != null) {
+ datasetBuilder.setValue(autofillId, AutofillValue.forText(textValue));
+ setValueAtLeastOnce = true;
+ }
break;
case View.AUTOFILL_TYPE_TOGGLE:
- boolean toggleValue = hintMap.get(hint).getToggleValue();
- datasetBuilder.setValue(autofillId, AutofillValue.forToggle(toggleValue));
+ if (savedAutofillValue.hasToggleValue()) {
+ boolean toggleValue = savedAutofillValue.getToggleValue();
+ datasetBuilder.setValue(autofillId, AutofillValue.forToggle(toggleValue));
+ setValueAtLeastOnce = true;
+ }
break;
case View.AUTOFILL_TYPE_NONE:
default:
@@ -138,6 +152,7 @@ public final class ClientFormData {
}
}
}
+ return setValueAtLeastOnce;
}
public JSONObject toJson() {
diff --git a/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/service/model/SavedAutofillValue.java b/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/service/model/SavedAutofillValue.java
index 88d4fd43..73e0c81e 100644
--- a/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/service/model/SavedAutofillValue.java
+++ b/input/autofill/AutofillFramework/Application/src/main/java/com/example/android/autofillframework/service/model/SavedAutofillValue.java
@@ -25,10 +25,14 @@ import org.json.JSONObject;
public class SavedAutofillValue {
private static final String TAG = "SavedAutofillValue";
private String textValue = null;
- private Long dateValue = null;
- private Boolean toggleValue = null;
+ private Long dateValue = -1L;
+ private Boolean toggleValue = false;
+ private boolean hasToggleValue = false;
public static SavedAutofillValue fromJson(JSONObject jsonObject) {
+ if (jsonObject == null) {
+ return null;
+ }
try {
SavedAutofillValue savedAutofillValue = new SavedAutofillValue();
@@ -36,8 +40,8 @@ public class SavedAutofillValue {
!jsonObject.isNull("textValue") ? jsonObject.getString("textValue") : null;
savedAutofillValue.dateValue =
!jsonObject.isNull("dateValue") ? jsonObject.getLong("dateValue") : null;
- savedAutofillValue.toggleValue =
- !jsonObject.isNull("toggleValue") ? jsonObject.getBoolean("toggleValue") : null;
+ savedAutofillValue.setToggleValue
+ (!jsonObject.isNull("toggleValue") ? jsonObject.getBoolean("toggleValue") : null);
return savedAutofillValue;
} catch (JSONException e) {
Log.e(TAG, e.getMessage());
@@ -92,8 +96,18 @@ public class SavedAutofillValue {
return toggleValue;
}
+ public void setToggleValue(Boolean toggleValue) {
+ this.toggleValue = toggleValue;
+ hasToggleValue = toggleValue != null;
+ }
+
+
public boolean isNull() {
- return textValue == null && dateValue == null && toggleValue == null;
+ return textValue == null && dateValue == -1L && !hasToggleValue;
+ }
+
+ public boolean hasToggleValue() {
+ return hasToggleValue;
}
@Override