Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0280c66d authored by Adam He's avatar Adam He
Browse files

Optimize getSanitizedValue() to cache into viewState

Change-Id: I90ec1bf0fbe1f61c29a60b26123cc5846972c73b
Fixes: 112439028
Test: atest CtsAutoFillServiceTestCases
parent edf4d227
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -1813,8 +1813,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        return sanitizers;
    }

    // TODO: this method is called a few times in the save process, we should cache its results into
    // ViewState.
    @Nullable
    private AutofillValue getSanitizedValue(
            @Nullable ArrayMap<AutofillId, InternalSanitizer> sanitizers,
@@ -1822,13 +1820,22 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
            @Nullable AutofillValue value) {
        if (sanitizers == null || value == null) return value;

        final ViewState state = mViewStates.get(id);
        AutofillValue sanitized = state == null ? null : state.getSanitizedValue();
        if (sanitized == null) {
            final InternalSanitizer sanitizer = sanitizers.get(id);
            if (sanitizer == null) {
                return value;
            }

        final AutofillValue sanitized = sanitizer.sanitize(value);
        if (sDebug) Slog.d(TAG, "Value for " + id + "(" + value + ") sanitized to " + sanitized);
            sanitized = sanitizer.sanitize(value);
            if (sDebug) {
                Slog.d(TAG, "Value for " + id + "(" + value + ") sanitized to " + sanitized);
            }
            if (state != null) {
                state.setSanitizedValue(sanitized);
            }
        }
        return sanitized;
    }