[Autofill PCC] : Maintain suggestion ordering

Honour the order of the suggestions provided by the provider.
Using LinkedHashMap/LinkedHashSet to maintain the order.

Bug: 293174020
Bug: 293313411
Test: atest CtsAutoFillServiceTestCases
Change-Id: I1edf7da9bc289bbb2a1ec2f0457b5060cafe1456
This commit is contained in:
Simranjit Kohli
2023-08-09 18:55:18 -07:00
parent ded5b9df80
commit eaf8ec91af

View File

@@ -189,6 +189,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@@ -1780,11 +1781,11 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
*/
private static class DatasetComputationContainer {
// List of all autofill ids that have a corresponding datasets
Set<AutofillId> mAutofillIds = new ArraySet<>();
Set<AutofillId> mAutofillIds = new LinkedHashSet<>();
// Set of datasets. Kept separately, to be able to be used directly for composing
// FillResponse.
Set<Dataset> mDatasets = new LinkedHashSet<>();
ArrayMap<AutofillId, Set<Dataset>> mAutofillIdToDatasetMap = new ArrayMap<>();
Map<AutofillId, Set<Dataset>> mAutofillIdToDatasetMap = new LinkedHashMap<>();
public String toString() {
final StringBuilder builder = new StringBuilder("DatasetComputationContainer[");
@@ -1822,7 +1823,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
// for now to keep safe. TODO(b/266379948): Revisit this logic.
Set<Dataset> datasets = c2.mAutofillIdToDatasetMap.get(id);
Set<Dataset> copyDatasets = new ArraySet<>(datasets);
Set<Dataset> copyDatasets = new LinkedHashSet<>(datasets);
c1.mAutofillIds.add(id);
c1.mAutofillIdToDatasetMap.put(id, copyDatasets);
c1.mDatasets.addAll(copyDatasets);
@@ -1849,9 +1850,9 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
}
List<Dataset> datasets = response.getDatasets();
if (datasets == null) return;
ArrayMap<AutofillId, Set<Dataset>> autofillIdToDatasetMap = new ArrayMap<>();
Map<AutofillId, Set<Dataset>> autofillIdToDatasetMap = new LinkedHashMap<>();
Set<Dataset> eligibleDatasets = new LinkedHashSet<>();
Set<AutofillId> eligibleAutofillIds = new ArraySet<>();
Set<AutofillId> eligibleAutofillIds = new LinkedHashSet<>();
for (Dataset dataset : response.getDatasets()) {
if (dataset.getFieldIds() == null || dataset.getFieldIds().isEmpty()) continue;
@DatasetEligibleReason int pickReason = globalPickReason;
@@ -1927,7 +1928,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
eligibleAutofillIds.add(id);
Set<Dataset> datasetForIds = autofillIdToDatasetMap.get(id);
if (datasetForIds == null) {
datasetForIds = new ArraySet<>();
datasetForIds = new LinkedHashSet<>();
}
datasetForIds.add(dataset);
autofillIdToDatasetMap.put(id, datasetForIds);
@@ -1944,17 +1945,17 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
if (datasets == null) return;
synchronized (mLock) {
ArrayMap<String, Set<AutofillId>> hintsToAutofillIdMap =
Map<String, Set<AutofillId>> hintsToAutofillIdMap =
mClassificationState.mHintsToAutofillIdMap;
// TODO(266379948): Handle group hints too.
ArrayMap<String, Set<AutofillId>> groupHintsToAutofillIdMap =
Map<String, Set<AutofillId>> groupHintsToAutofillIdMap =
mClassificationState.mGroupHintsToAutofillIdMap;
ArrayMap<AutofillId, Set<Dataset>> map = new ArrayMap<>();
Map<AutofillId, Set<Dataset>> map = new LinkedHashMap<>();
Set<Dataset> eligibleDatasets = new LinkedHashSet<>();
Set<AutofillId> eligibleAutofillIds = new ArraySet<>();
Set<AutofillId> eligibleAutofillIds = new LinkedHashSet<>();
for (int i = 0; i < datasets.size(); i++) {
@@ -1970,7 +1971,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
ArrayList<InlinePresentation> fieldInlinePresentations = new ArrayList<>();
ArrayList<InlinePresentation> fieldInlineTooltipPresentations = new ArrayList<>();
ArrayList<Dataset.DatasetFieldFilter> fieldFilters = new ArrayList<>();
Set<AutofillId> datasetAutofillIds = new ArraySet<>();
Set<AutofillId> datasetAutofillIds = new LinkedHashSet<>();
for (int j = 0; j < dataset.getAutofillDatatypes().size(); j++) {
if (dataset.getAutofillDatatypes().get(j) == null) {
@@ -2032,7 +2033,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
if (map.containsKey(autofillId)) {
newDatasets = map.get(autofillId);
} else {
newDatasets = new ArraySet<>();
newDatasets = new LinkedHashSet<>();
}
newDatasets.add(newDataset);
map.put(autofillId, newDatasets);