[Autofill PCC]: Fix Dataset creation from parcel.

When creating Dataset from parcel, it's possible to have null values in ids
and datatypes. This was causing crash. This CL fixes that.
Test: atest android.autofillservice.cts.unittests.DatasetTest
Manually tested regular flows.
Bug: 272405954

Change-Id: Ic51456933345079dc73be28dd454df9ed7fdce04
This commit is contained in:
Simranjit Kohli
2023-03-09 10:03:53 -08:00
parent b7c94668f4
commit 803ba02e78
3 changed files with 57 additions and 38 deletions

View File

@@ -1260,6 +1260,36 @@ public final class Dataset implements Parcelable {
return mFieldIds.size() - 1;
}
private void createFromParcel(
@Nullable AutofillId id, @Nullable String datatype,
@Nullable AutofillValue value, @Nullable RemoteViews presentation,
@Nullable InlinePresentation inlinePresentation,
@Nullable InlinePresentation tooltip,
@Nullable DatasetFieldFilter filter,
@Nullable RemoteViews dialogPresentation) {
if (id != null) {
final int existingIdx = mFieldIds.indexOf(id);
if (existingIdx >= 0) {
mFieldValues.set(existingIdx, value);
mFieldPresentations.set(existingIdx, presentation);
mFieldDialogPresentations.set(existingIdx, dialogPresentation);
mFieldInlinePresentations.set(existingIdx, inlinePresentation);
mFieldInlineTooltipPresentations.set(existingIdx, tooltip);
mFieldFilters.set(existingIdx, filter);
return;
}
}
mFieldIds.add(id);
mAutofillDatatypes.add(datatype);
mFieldValues.add(value);
mFieldPresentations.add(presentation);
mFieldDialogPresentations.add(dialogPresentation);
mFieldInlinePresentations.add(inlinePresentation);
mFieldInlineTooltipPresentations.add(tooltip);
mFieldFilters.add(filter);
return;
}
/**
* Creates a new {@link Dataset} instance.
*
@@ -1391,37 +1421,20 @@ public final class Dataset implements Parcelable {
builder.setContent(ids.get(0), fieldContent);
}
final int inlinePresentationsSize = inlinePresentations.size();
if (ids.size() == 0 && autofillDatatypes.size() > 0) {
for (int i = 0; i < autofillDatatypes.size(); i++) {
final String datatype = autofillDatatypes.get(i);
final AutofillValue value = values.get(i);
final RemoteViews fieldPresentation = presentations.get(i);
final RemoteViews fieldDialogPresentation = dialogPresentations.get(i);
final InlinePresentation fieldInlinePresentation =
i < inlinePresentationsSize ? inlinePresentations.get(i) : null;
final InlinePresentation fieldInlineTooltipPresentation =
i < inlinePresentationsSize ? inlineTooltipPresentations.get(i) : null;
final DatasetFieldFilter filter = filters.get(i);
builder.setLifeTheUniverseAndEverything(
datatype, value, fieldPresentation, fieldInlinePresentation,
fieldInlineTooltipPresentation, filter, fieldDialogPresentation);
}
} else {
for (int i = 0; i < ids.size(); i++) {
final AutofillId id = ids.get(i);
final AutofillValue value = values.get(i);
final RemoteViews fieldPresentation = presentations.get(i);
final RemoteViews fieldDialogPresentation = dialogPresentations.get(i);
final InlinePresentation fieldInlinePresentation =
i < inlinePresentationsSize ? inlinePresentations.get(i) : null;
final InlinePresentation fieldInlineTooltipPresentation =
i < inlinePresentationsSize ? inlineTooltipPresentations.get(i) : null;
final DatasetFieldFilter filter = filters.get(i);
builder.setLifeTheUniverseAndEverything(id, value, fieldPresentation,
fieldInlinePresentation, fieldInlineTooltipPresentation, filter,
fieldDialogPresentation);
}
for (int i = 0; i < ids.size(); i++) {
final AutofillId id = ids.get(i);
final String datatype = autofillDatatypes.get(i);
final AutofillValue value = values.get(i);
final RemoteViews fieldPresentation = presentations.get(i);
final RemoteViews fieldDialogPresentation = dialogPresentations.get(i);
final InlinePresentation fieldInlinePresentation =
i < inlinePresentationsSize ? inlinePresentations.get(i) : null;
final InlinePresentation fieldInlineTooltipPresentation =
i < inlinePresentationsSize ? inlineTooltipPresentations.get(i) : null;
final DatasetFieldFilter filter = filters.get(i);
builder.createFromParcel(id, datatype, value, fieldPresentation,
fieldInlinePresentation, fieldInlineTooltipPresentation, filter,
fieldDialogPresentation);
}
builder.setAuthentication(authentication);
builder.setId(datasetId);

View File

@@ -1641,7 +1641,7 @@ public final class AutofillManager {
mForAugmentedAutofillOnly = false;
}
if ((flags & FLAG_SUPPORTS_FILL_DIALOG) != 0) {
if ((flags & FLAG_SUPPORTS_FILL_DIALOG) != 0 && view != null) {
flags |= FLAG_RESET_FILL_DIALOG_STATE;
}
@@ -2940,8 +2940,10 @@ public final class AutofillManager {
mFillableIds = new ArraySet<>(fillableIds.length);
}
for (AutofillId id : fillableIds) {
id.resetSessionId();
mFillableIds.add(id);
if (id != null) {
id.resetSessionId();
mFillableIds.add(id);
}
}
}
@@ -2966,8 +2968,10 @@ public final class AutofillManager {
}
if (trackedIds != null) {
for (AutofillId id : trackedIds) {
id.resetSessionId();
allFillableIds.add(id);
if (id != null) {
id.resetSessionId();
allFillableIds.add(id);
}
}
}

View File

@@ -4346,8 +4346,10 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
for (int j = 0; j < fieldIds.size(); j++) {
final AutofillId id = fieldIds.get(j);
if (trackedViews == null || !trackedViews.contains(id)) {
fillableIds = ArrayUtils.add(fillableIds, id);
if (id != null) {
if (trackedViews == null || !trackedViews.contains(id)) {
fillableIds = ArrayUtils.add(fillableIds, id);
}
}
}
}