Loading core/java/android/service/autofill/InternalSanitizer.java +5 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.service.autofill; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.TestApi; import android.os.Parcelable; import android.view.autofill.AutofillValue; Loading @@ -32,7 +33,11 @@ public abstract class InternalSanitizer implements Sanitizer, Parcelable { /** * Sanitizes an {@link AutofillValue}. * * @return sanitized value or {@code null} if value could not be sanitized (for example: didn't * match regex, it's an invalid type, regex failed, etc). * * @hide */ @Nullable public abstract AutofillValue sanitize(@NonNull AutofillValue value); } core/java/android/service/autofill/SaveInfo.java +5 −0 Original line number Diff line number Diff line Loading @@ -613,6 +613,11 @@ public final class SaveInfo implements Parcelable { * usernameId, passwordId); * </pre> * * <p>The sanitizer can also be used as an alternative for a * {@link #setValidator(Validator) validator}&mdashif any of the {@code ids} is a * {@link #SaveInfo.Builder(int, AutofillId[]) required id} and the {@code sanitizer} fail * for it, then the save UI is not shown. * * @param sanitizer an implementation provided by the Android System. * @param ids id of fields whose value will be sanitized. * @return this builder. Loading core/java/android/service/autofill/TextValueSanitizer.java +11 −3 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package android.service.autofill; import static android.view.autofill.Helper.sDebug; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.TestApi; import android.os.Parcel; import android.os.Parcelable; Loading Loading @@ -62,24 +63,31 @@ public final class TextValueSanitizer extends InternalSanitizer implements /** @hide */ @Override @TestApi @Nullable public AutofillValue sanitize(@NonNull AutofillValue value) { if (value == null) { Slog.w(TAG, "sanitize() called with null value"); return null; } if (!value.isText()) return value; if (!value.isText()) { if (sDebug) Slog.d(TAG, "sanitize() called with non-text value: " + value); return null; } final CharSequence text = value.getTextValue(); try { final Matcher matcher = mRegex.matcher(text); if (!matcher.matches()) return value; if (!matcher.matches()) { if (sDebug) Slog.d(TAG, "sanitize(): " + mRegex + " failed for " + value); return null; } final CharSequence sanitized = matcher.replaceAll(mSubst); return AutofillValue.forText(sanitized); } catch (Exception e) { Slog.w(TAG, "Exception evaluating " + mRegex + "/" + mSubst + ": " + e); return value; return null; } } Loading services/autofill/java/com/android/server/autofill/Session.java +23 −6 Original line number Diff line number Diff line Loading @@ -1167,7 +1167,16 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState break; } } value = getSanitizedValue(sanitizers, id, value); if (value == null) { if (sDebug) { Slog.d(TAG, "value of required field " + id + " failed sanitization"); } allRequiredAreNotEmpty = false; break; } viewState.setSanitizedValue(value); currentValues.put(id, value); final AutofillValue filledValue = viewState.getAutofilledValue(); Loading Loading @@ -1337,7 +1346,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState return sanitizers; } @NonNull @Nullable private AutofillValue getSanitizedValue( @Nullable ArrayMap<AutofillId, InternalSanitizer> sanitizers, @NonNull AutofillId id, Loading Loading @@ -1431,10 +1440,10 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState if (sVerbose) Slog.v(TAG, "callSaveLocked(): updating " + context); for (int viewStateNum = 0; viewStateNum < mViewStates.size(); viewStateNum++) { final ViewState state = mViewStates.valueAt(viewStateNum); final ViewState viewState = mViewStates.valueAt(viewStateNum); final AutofillId id = state.id; final AutofillValue value = state.getCurrentValue(); final AutofillId id = viewState.id; final AutofillValue value = viewState.getCurrentValue(); if (value == null) { if (sVerbose) Slog.v(TAG, "callSaveLocked(): skipping " + id); continue; Loading @@ -1446,9 +1455,17 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } if (sVerbose) Slog.v(TAG, "callSaveLocked(): updating " + id + " to " + value); final AutofillValue sanitizedValue = getSanitizedValue(sanitizers, id, value); AutofillValue sanitizedValue = viewState.getSanitizedValue(); if (sanitizedValue == null) { // Field is optional and haven't been sanitized yet. sanitizedValue = getSanitizedValue(sanitizers, id, value); } if (sanitizedValue != null) { node.updateAutofillValue(sanitizedValue); } else if (sDebug) { Slog.d(TAG, "Not updating field " + id + " because it failed sanitization"); } } // Sanitize structure before it's sent to service. Loading services/autofill/java/com/android/server/autofill/ViewState.java +11 −0 Original line number Diff line number Diff line Loading @@ -76,6 +76,7 @@ final class ViewState { private FillResponse mResponse; private AutofillValue mCurrentValue; private AutofillValue mAutofilledValue; private AutofillValue mSanitizedValue; private Rect mVirtualBounds; private int mState; private String mDatasetId; Loading Loading @@ -116,6 +117,15 @@ final class ViewState { mAutofilledValue = value; } @Nullable AutofillValue getSanitizedValue() { return mSanitizedValue; } void setSanitizedValue(@Nullable AutofillValue value) { mSanitizedValue = value; } @Nullable FillResponse getResponse() { return mResponse; Loading Loading @@ -218,6 +228,7 @@ final class ViewState { } pw.print(prefix); pw.print("currentValue:" ); pw.println(mCurrentValue); pw.print(prefix); pw.print("autofilledValue:" ); pw.println(mAutofilledValue); pw.print(prefix); pw.print("sanitizedValue:" ); pw.println(mSanitizedValue); pw.print(prefix); pw.print("virtualBounds:" ); pw.println(mVirtualBounds); } } No newline at end of file Loading
core/java/android/service/autofill/InternalSanitizer.java +5 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.service.autofill; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.TestApi; import android.os.Parcelable; import android.view.autofill.AutofillValue; Loading @@ -32,7 +33,11 @@ public abstract class InternalSanitizer implements Sanitizer, Parcelable { /** * Sanitizes an {@link AutofillValue}. * * @return sanitized value or {@code null} if value could not be sanitized (for example: didn't * match regex, it's an invalid type, regex failed, etc). * * @hide */ @Nullable public abstract AutofillValue sanitize(@NonNull AutofillValue value); }
core/java/android/service/autofill/SaveInfo.java +5 −0 Original line number Diff line number Diff line Loading @@ -613,6 +613,11 @@ public final class SaveInfo implements Parcelable { * usernameId, passwordId); * </pre> * * <p>The sanitizer can also be used as an alternative for a * {@link #setValidator(Validator) validator}&mdashif any of the {@code ids} is a * {@link #SaveInfo.Builder(int, AutofillId[]) required id} and the {@code sanitizer} fail * for it, then the save UI is not shown. * * @param sanitizer an implementation provided by the Android System. * @param ids id of fields whose value will be sanitized. * @return this builder. Loading
core/java/android/service/autofill/TextValueSanitizer.java +11 −3 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package android.service.autofill; import static android.view.autofill.Helper.sDebug; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.TestApi; import android.os.Parcel; import android.os.Parcelable; Loading Loading @@ -62,24 +63,31 @@ public final class TextValueSanitizer extends InternalSanitizer implements /** @hide */ @Override @TestApi @Nullable public AutofillValue sanitize(@NonNull AutofillValue value) { if (value == null) { Slog.w(TAG, "sanitize() called with null value"); return null; } if (!value.isText()) return value; if (!value.isText()) { if (sDebug) Slog.d(TAG, "sanitize() called with non-text value: " + value); return null; } final CharSequence text = value.getTextValue(); try { final Matcher matcher = mRegex.matcher(text); if (!matcher.matches()) return value; if (!matcher.matches()) { if (sDebug) Slog.d(TAG, "sanitize(): " + mRegex + " failed for " + value); return null; } final CharSequence sanitized = matcher.replaceAll(mSubst); return AutofillValue.forText(sanitized); } catch (Exception e) { Slog.w(TAG, "Exception evaluating " + mRegex + "/" + mSubst + ": " + e); return value; return null; } } Loading
services/autofill/java/com/android/server/autofill/Session.java +23 −6 Original line number Diff line number Diff line Loading @@ -1167,7 +1167,16 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState break; } } value = getSanitizedValue(sanitizers, id, value); if (value == null) { if (sDebug) { Slog.d(TAG, "value of required field " + id + " failed sanitization"); } allRequiredAreNotEmpty = false; break; } viewState.setSanitizedValue(value); currentValues.put(id, value); final AutofillValue filledValue = viewState.getAutofilledValue(); Loading Loading @@ -1337,7 +1346,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState return sanitizers; } @NonNull @Nullable private AutofillValue getSanitizedValue( @Nullable ArrayMap<AutofillId, InternalSanitizer> sanitizers, @NonNull AutofillId id, Loading Loading @@ -1431,10 +1440,10 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState if (sVerbose) Slog.v(TAG, "callSaveLocked(): updating " + context); for (int viewStateNum = 0; viewStateNum < mViewStates.size(); viewStateNum++) { final ViewState state = mViewStates.valueAt(viewStateNum); final ViewState viewState = mViewStates.valueAt(viewStateNum); final AutofillId id = state.id; final AutofillValue value = state.getCurrentValue(); final AutofillId id = viewState.id; final AutofillValue value = viewState.getCurrentValue(); if (value == null) { if (sVerbose) Slog.v(TAG, "callSaveLocked(): skipping " + id); continue; Loading @@ -1446,9 +1455,17 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } if (sVerbose) Slog.v(TAG, "callSaveLocked(): updating " + id + " to " + value); final AutofillValue sanitizedValue = getSanitizedValue(sanitizers, id, value); AutofillValue sanitizedValue = viewState.getSanitizedValue(); if (sanitizedValue == null) { // Field is optional and haven't been sanitized yet. sanitizedValue = getSanitizedValue(sanitizers, id, value); } if (sanitizedValue != null) { node.updateAutofillValue(sanitizedValue); } else if (sDebug) { Slog.d(TAG, "Not updating field " + id + " because it failed sanitization"); } } // Sanitize structure before it's sent to service. Loading
services/autofill/java/com/android/server/autofill/ViewState.java +11 −0 Original line number Diff line number Diff line Loading @@ -76,6 +76,7 @@ final class ViewState { private FillResponse mResponse; private AutofillValue mCurrentValue; private AutofillValue mAutofilledValue; private AutofillValue mSanitizedValue; private Rect mVirtualBounds; private int mState; private String mDatasetId; Loading Loading @@ -116,6 +117,15 @@ final class ViewState { mAutofilledValue = value; } @Nullable AutofillValue getSanitizedValue() { return mSanitizedValue; } void setSanitizedValue(@Nullable AutofillValue value) { mSanitizedValue = value; } @Nullable FillResponse getResponse() { return mResponse; Loading Loading @@ -218,6 +228,7 @@ final class ViewState { } pw.print(prefix); pw.print("currentValue:" ); pw.println(mCurrentValue); pw.print(prefix); pw.print("autofilledValue:" ); pw.println(mAutofilledValue); pw.print(prefix); pw.print("sanitizedValue:" ); pw.println(mSanitizedValue); pw.print(prefix); pw.print("virtualBounds:" ); pw.println(mVirtualBounds); } } No newline at end of file