diff options
author | Doug Sigelbaum <sigelbaum@google.com> | 2018-02-03 00:12:34 -0800 |
---|---|---|
committer | Doug Sigelbaum <sigelbaum@google.com> | 2018-02-03 00:12:34 -0800 |
commit | 4db65579936cff3ef582e41e52a5fabe2407d3ed (patch) | |
tree | 2e56e8769950248a1cf79d651440eeb3b6c8dc22 /input/autofill | |
parent | 49bababcb16c7b4f5e275a50adbca7a4c684ff84 (diff) | |
download | android-4db65579936cff3ef582e41e52a5fabe2407d3ed.tar.gz |
Fixed many autofill service sample issues.
Including issue with providing too many autofillIds to service.
Bug: 72740101
Test: manual
Change-Id: I31e0b9b4186a8f169888ce925bc2b8a022dde058
Diffstat (limited to 'input/autofill')
10 files changed, 46 insertions, 49 deletions
diff --git a/input/autofill/AutofillFramework/afservice/src/androidTest/java/com/example/android/autofill/service/data/source/local/AutofillDaoTest.java b/input/autofill/AutofillFramework/afservice/src/androidTest/java/com/example/android/autofill/service/data/source/local/AutofillDaoTest.java index 99d618ea..c76ba435 100644 --- a/input/autofill/AutofillFramework/afservice/src/androidTest/java/com/example/android/autofill/service/data/source/local/AutofillDaoTest.java +++ b/input/autofill/AutofillFramework/afservice/src/androidTest/java/com/example/android/autofill/service/data/source/local/AutofillDaoTest.java @@ -44,7 +44,8 @@ import static org.hamcrest.Matchers.hasSize; @RunWith(AndroidJUnit4.class) public class AutofillDaoTest { private final AutofillDataset mDataset = - new AutofillDataset(UUID.randomUUID().toString(), "dataset-1"); + new AutofillDataset(UUID.randomUUID().toString(), + "dataset-1", InstrumentationRegistry.getContext().getPackageName()); private final FilledAutofillField mUsernameField = new FilledAutofillField(mDataset.getId(), View.AUTOFILL_HINT_USERNAME, "login"); private final FilledAutofillField mPasswordField = @@ -74,7 +75,7 @@ public class AutofillDaoTest { datasetWithFilledAutofillFields.filledAutofillFields = Arrays.asList(mUsernameField, mPasswordField); datasetWithFilledAutofillFields.filledAutofillFields - .sort(Comparator.comparing(FilledAutofillField::getFieldType)); + .sort(Comparator.comparing(FilledAutofillField::getFieldTypeName)); // When inserting a page's autofill fields. mDatabase.autofillDao().insertAutofillDataset(mDataset); @@ -87,7 +88,7 @@ public class AutofillDaoTest { List<DatasetWithFilledAutofillFields> loadedDatasets = mDatabase.autofillDao() .getDatasets(allHints); loadedDatasets.get(0).filledAutofillFields.sort( - Comparator.comparing(FilledAutofillField::getFieldType)); + Comparator.comparing(FilledAutofillField::getFieldTypeName)); assertThat(loadedDatasets, contains(datasetWithFilledAutofillFields)); assertThat(loadedDatasets, hasSize(1)); } diff --git a/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/AutofillHints.java b/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/AutofillHints.java index b937cc3b..d43071f2 100644 --- a/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/AutofillHints.java +++ b/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/AutofillHints.java @@ -66,9 +66,7 @@ public final class AutofillHints { date = Calendar.getInstance().getTimeInMillis(); } } - FilledAutofillField filledAutofillField = new FilledAutofillField(datasetId, - packageName, fieldTypeName, text, date, toggle); - return filledAutofillField; + return new FilledAutofillField(datasetId, fieldTypeName, text, date, toggle); } public static String getFieldTypeNameFromAutofillHints( diff --git a/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/ManualActivity.java b/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/ManualActivity.java index 26d307f5..a9acaa5a 100644 --- a/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/ManualActivity.java +++ b/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/ManualActivity.java @@ -157,11 +157,11 @@ public class ManualActivity extends AppCompatActivity { private void onFieldSelected(FilledAutofillField field, FieldType fieldType) { DatasetWithFilledAutofillFields datasetWithFilledAutofillFields = new DatasetWithFilledAutofillFields(); String newDatasetId = UUID.randomUUID().toString(); - FilledAutofillField copyOfField = new FilledAutofillField(newDatasetId, getPackageName(), + FilledAutofillField copyOfField = new FilledAutofillField(newDatasetId, field.getFieldTypeName(), field.getTextValue(), field.getDateValue(), field.getToggleValue()); String datasetName = "dataset-manual"; - AutofillDataset autofillDataset = new AutofillDataset(newDatasetId, datasetName); + AutofillDataset autofillDataset = new AutofillDataset(newDatasetId, datasetName, mPackageName); datasetWithFilledAutofillFields.filledAutofillFields = ImmutableList.of(copyOfField); datasetWithFilledAutofillFields.autofillDataset = autofillDataset; Intent intent = getIntent(); diff --git a/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/data/ClientAutofillDataBuilder.java b/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/data/ClientAutofillDataBuilder.java index 10865657..2d268337 100644 --- a/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/data/ClientAutofillDataBuilder.java +++ b/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/data/ClientAutofillDataBuilder.java @@ -56,7 +56,7 @@ public class ClientAutofillDataBuilder implements AutofillDataBuilder { new ImmutableList.Builder<>(); for (int partition : AutofillHints.PARTITIONS) { AutofillDataset autofillDataset = new AutofillDataset(UUID.randomUUID().toString(), - "dataset-" + datasetNumber + "." + partition); + "dataset-" + datasetNumber + "." + partition, mPackageName); DatasetWithFilledAutofillFields dataset = buildDatasetForPartition(autofillDataset, partition); if (dataset != null && dataset.filledAutofillFields != null) { @@ -151,7 +151,7 @@ public class ClientAutofillDataBuilder implements AutofillDataBuilder { } String datasetId = datasetWithFilledAutofillFields.autofillDataset.getId(); datasetWithFilledAutofillFields.add(new FilledAutofillField(datasetId, - mPackageName, fieldType.getTypeName(), textValue, dateValue, toggleValue)); + fieldType.getTypeName(), textValue, dateValue, toggleValue)); } else { loge("Invalid hint: %s", hint); } diff --git a/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/data/ClientViewMetadataBuilder.java b/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/data/ClientViewMetadataBuilder.java index e2e97878..40a67efb 100644 --- a/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/data/ClientViewMetadataBuilder.java +++ b/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/data/ClientViewMetadataBuilder.java @@ -80,12 +80,12 @@ public class ClientViewMetadataBuilder { if (fieldTypeWithHints != null && fieldTypeWithHints.fieldType != null) { allHints.add(hint); autofillSaveType.value |= fieldTypeWithHints.fieldType.getSaveInfo(); + autofillIds.add(root.getAutofillId()); } } } if (root.isFocused()) { focusedAutofillIds.add(root.getAutofillId()); } - autofillIds.add(root.getAutofillId()); } } diff --git a/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/data/FakeAutofillDataBuilder.java b/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/data/FakeAutofillDataBuilder.java index 69ee0421..67ee8803 100644 --- a/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/data/FakeAutofillDataBuilder.java +++ b/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/data/FakeAutofillDataBuilder.java @@ -44,7 +44,7 @@ public class FakeAutofillDataBuilder implements AutofillDataBuilder { new ImmutableList.Builder<>(); for (int partition : AutofillHints.PARTITIONS) { AutofillDataset autofillDataset = new AutofillDataset(UUID.randomUUID().toString(), - "dataset-" + datasetNumber + "." + partition); + "dataset-" + datasetNumber + "." + partition, mPackageName); DatasetWithFilledAutofillFields datasetWithFilledAutofillFields = buildCollectionForPartition(autofillDataset, partition); if (datasetWithFilledAutofillFields != null && diff --git a/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/data/adapter/ResponseAdapter.java b/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/data/adapter/ResponseAdapter.java index cd9d0ca3..0300fed6 100644 --- a/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/data/adapter/ResponseAdapter.java +++ b/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/data/adapter/ResponseAdapter.java @@ -95,7 +95,7 @@ public class ResponseAdapter { } } } - int saveType = 0; + int saveType = mClientViewMetadata.getSaveType(); AutofillId[] autofillIds = mClientViewMetadata.getAutofillIds(); if (autofillIds != null && autofillIds.length > 0) { SaveInfo saveInfo = new SaveInfo.Builder(saveType, autofillIds).build(); diff --git a/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/data/source/local/dao/AutofillDao.java b/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/data/source/local/dao/AutofillDao.java index 50ed0cdf..084532ce 100644 --- a/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/data/source/local/dao/AutofillDao.java +++ b/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/data/source/local/dao/AutofillDao.java @@ -78,7 +78,7 @@ public interface AutofillDao { @Query("SELECT DISTINCT typeName, autofillTypes, saveInfo, partition, strictExampleSet, " + "textTemplate, dateTemplate" + - " FROM FieldType, AutofillHint, ResourceIdHeuristic" + + " FROM FieldType, AutofillHint" + " WHERE FieldType.typeName = AutofillHint.fieldTypeName" + " AND AutofillHint.autofillHint IN (:autofillHints)" + " UNION " + diff --git a/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/model/AutofillDataset.java b/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/model/AutofillDataset.java index e7bd3058..6b6596c8 100644 --- a/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/model/AutofillDataset.java +++ b/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/model/AutofillDataset.java @@ -30,9 +30,15 @@ public class AutofillDataset { @ColumnInfo(name = "datasetName") private final String mDatasetName; - public AutofillDataset(@NonNull String id, @NonNull String datasetName) { + @NonNull + @ColumnInfo(name = "packageName") + private final String mPackageName; + + public AutofillDataset(@NonNull String id, @NonNull String datasetName, + @NonNull String packageName) { mId = id; mDatasetName = datasetName; + mPackageName = packageName; } @NonNull @@ -45,6 +51,11 @@ public class AutofillDataset { return mDatasetName; } + @NonNull + public String getPackageName() { + return mPackageName; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -53,13 +64,15 @@ public class AutofillDataset { AutofillDataset that = (AutofillDataset) o; if (!mId.equals(that.mId)) return false; - return mDatasetName.equals(that.mDatasetName); + if (!mDatasetName.equals(that.mDatasetName)) return false; + return mPackageName.equals(that.mPackageName); } @Override public int hashCode() { int result = mId.hashCode(); result = 31 * result + mDatasetName.hashCode(); + result = 31 * result + mPackageName.hashCode(); return result; } } diff --git a/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/model/FilledAutofillField.java b/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/model/FilledAutofillField.java index 1eed720a..85ad05ac 100644 --- a/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/model/FilledAutofillField.java +++ b/input/autofill/AutofillFramework/afservice/src/main/java/com/example/android/autofill/service/model/FilledAutofillField.java @@ -51,15 +51,10 @@ public class FilledAutofillField { @ColumnInfo(name = "fieldTypeName") private final String mFieldTypeName; - @NonNull - @ColumnInfo(name = "packageName") - private final String mPackageName; - - public FilledAutofillField(@NonNull String datasetId, @NonNull String packageName, - @NonNull String fieldTypeName, @Nullable String textValue, @Nullable Long dateValue, - @Nullable Boolean toggleValue) { + public FilledAutofillField(@NonNull String datasetId, @NonNull String fieldTypeName, + @Nullable String textValue, @Nullable Long dateValue, + @Nullable Boolean toggleValue) { mDatasetId = datasetId; - mPackageName = packageName; mFieldTypeName = fieldTypeName; mTextValue = textValue; mDateValue = dateValue; @@ -67,33 +62,32 @@ public class FilledAutofillField { } @Ignore - public FilledAutofillField(@NonNull String datasetId, @NonNull String packageName, + public FilledAutofillField(@NonNull String datasetId, @NonNull String fieldTypeName, @Nullable String textValue, @Nullable Long dateValue) { - this(datasetId, packageName, fieldTypeName, textValue, dateValue, null); + this(datasetId, fieldTypeName, textValue, dateValue, null); } @Ignore - public FilledAutofillField(@NonNull String datasetId, @NonNull String packageName, - @NonNull String fieldTypeName, @Nullable String textValue) { - this(datasetId, packageName, fieldTypeName, textValue, null, null); + public FilledAutofillField(@NonNull String datasetId, @NonNull String fieldTypeName, + @Nullable String textValue) { + this(datasetId, fieldTypeName, textValue, null, null); } @Ignore - public FilledAutofillField(@NonNull String datasetId, @NonNull String packageName, - @NonNull String fieldTypeName, @Nullable Long dateValue) { - this(datasetId, packageName, fieldTypeName, null, dateValue, null); + public FilledAutofillField(@NonNull String datasetId, @NonNull String fieldTypeName, + @Nullable Long dateValue) { + this(datasetId, fieldTypeName, null, dateValue, null); } @Ignore - public FilledAutofillField(@NonNull String datasetId, @NonNull String packageName, - @NonNull String fieldTypeName, @Nullable Boolean toggleValue) { - this(datasetId, packageName, fieldTypeName, null, null, toggleValue); + public FilledAutofillField(@NonNull String datasetId, @NonNull String fieldTypeName, + @Nullable Boolean toggleValue) { + this(datasetId, fieldTypeName, null, null, toggleValue); } @Ignore - public FilledAutofillField(@NonNull String datasetId, @NonNull String packageName, - @NonNull String fieldTypeName) { - this(datasetId, packageName, fieldTypeName, null, null, null); + public FilledAutofillField(@NonNull String datasetId, @NonNull String fieldTypeName) { + this(datasetId, fieldTypeName, null, null, null); } @NonNull @@ -121,11 +115,6 @@ public class FilledAutofillField { return mFieldTypeName; } - @NonNull - public String getPackageName() { - return mPackageName; - } - public boolean isNull() { return mTextValue == null && mDateValue == null && mToggleValue == null; } @@ -137,25 +126,21 @@ public class FilledAutofillField { FilledAutofillField that = (FilledAutofillField) o; - if (!mDatasetId.equals(that.mDatasetId)) return false; if (mTextValue != null ? !mTextValue.equals(that.mTextValue) : that.mTextValue != null) return false; if (mDateValue != null ? !mDateValue.equals(that.mDateValue) : that.mDateValue != null) return false; if (mToggleValue != null ? !mToggleValue.equals(that.mToggleValue) : that.mToggleValue != null) return false; - if (!mFieldTypeName.equals(that.mFieldTypeName)) return false; - return mPackageName.equals(that.mPackageName); + return mFieldTypeName.equals(that.mFieldTypeName); } @Override public int hashCode() { - int result = mDatasetId.hashCode(); - result = 31 * result + (mTextValue != null ? mTextValue.hashCode() : 0); + int result = mTextValue != null ? mTextValue.hashCode() : 0; result = 31 * result + (mDateValue != null ? mDateValue.hashCode() : 0); result = 31 * result + (mToggleValue != null ? mToggleValue.hashCode() : 0); result = 31 * result + mFieldTypeName.hashCode(); - result = 31 * result + mPackageName.hashCode(); return result; } } |