Merge "[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" into udc-dev

This commit is contained in:
Simranjit Kohli
2023-03-18 18:31:33 +00:00
committed by Android (Google) Code Review
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; 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. * Creates a new {@link Dataset} instance.
* *
@@ -1391,37 +1421,20 @@ public final class Dataset implements Parcelable {
builder.setContent(ids.get(0), fieldContent); builder.setContent(ids.get(0), fieldContent);
} }
final int inlinePresentationsSize = inlinePresentations.size(); final int inlinePresentationsSize = inlinePresentations.size();
for (int i = 0; i < ids.size(); i++) {
if (ids.size() == 0 && autofillDatatypes.size() > 0) { final AutofillId id = ids.get(i);
for (int i = 0; i < autofillDatatypes.size(); i++) { final String datatype = autofillDatatypes.get(i);
final String datatype = autofillDatatypes.get(i); final AutofillValue value = values.get(i);
final AutofillValue value = values.get(i); final RemoteViews fieldPresentation = presentations.get(i);
final RemoteViews fieldPresentation = presentations.get(i); final RemoteViews fieldDialogPresentation = dialogPresentations.get(i);
final RemoteViews fieldDialogPresentation = dialogPresentations.get(i); final InlinePresentation fieldInlinePresentation =
final InlinePresentation fieldInlinePresentation = i < inlinePresentationsSize ? inlinePresentations.get(i) : null;
i < inlinePresentationsSize ? inlinePresentations.get(i) : null; final InlinePresentation fieldInlineTooltipPresentation =
final InlinePresentation fieldInlineTooltipPresentation = i < inlinePresentationsSize ? inlineTooltipPresentations.get(i) : null;
i < inlinePresentationsSize ? inlineTooltipPresentations.get(i) : null; final DatasetFieldFilter filter = filters.get(i);
final DatasetFieldFilter filter = filters.get(i); builder.createFromParcel(id, datatype, value, fieldPresentation,
builder.setLifeTheUniverseAndEverything( fieldInlinePresentation, fieldInlineTooltipPresentation, filter,
datatype, value, fieldPresentation, fieldInlinePresentation, fieldDialogPresentation);
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);
}
} }
builder.setAuthentication(authentication); builder.setAuthentication(authentication);
builder.setId(datasetId); builder.setId(datasetId);

View File

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

View File

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