That could result in an inconsistent, confusing UI. For example, if the
successfully description for a credit card was "Exp. date: 04/20", one with a
failure could be "Exp. date: /20" - it's better to not show a custom description
in these cases.
Test: CtsAutoFillServiceTestCases pass
Test: CustomDescriptionTest.failFirstFailAll
Test: CustomDescriptionTest.failSecondFailAll
Bug:
62534917
Change-Id: I6554e3470ead2f84d7ef8715192d863c01ab1190
}
public final class CharSequenceTransformation implements android.os.Parcelable android.service.autofill.Transformation {
- method public void apply(android.service.autofill.ValueFinder, android.widget.RemoteViews, int);
+ method public void apply(android.service.autofill.ValueFinder, android.widget.RemoteViews, int) throws java.lang.Exception;
method public int describeContents();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.service.autofill.CharSequenceTransformation> CREATOR;
}
public final class ImageTransformation implements android.os.Parcelable android.service.autofill.Transformation {
- method public void apply(android.service.autofill.ValueFinder, android.widget.RemoteViews, int);
+ method public void apply(android.service.autofill.ValueFinder, android.widget.RemoteViews, int) throws java.lang.Exception;
method public int describeContents();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.service.autofill.ImageTransformation> CREATOR;
@Override
@TestApi
public void apply(@NonNull ValueFinder finder, @NonNull RemoteViews parentTemplate,
- int childViewId) {
+ int childViewId) throws Exception {
final StringBuilder converted = new StringBuilder();
final int size = mFields.size();
if (sDebug) Log.d(TAG, size + " multiple fields on id " + childViewId);
for (int i = 0; i < size; i++) {
final AutofillId id = mFields.keyAt(i);
- final Pair<Pattern, String> regex = mFields.valueAt(i);
+ final Pair<Pattern, String> field = mFields.valueAt(i);
final String value = finder.findByAutofillId(id);
if (value == null) {
Log.w(TAG, "No value for id " + id);
}
try {
// replaceAll throws an exception if the subst is invalid
- final String convertedValue = regex.first.matcher(value).replaceAll(regex.second);
+ final String convertedValue = field.first.matcher(value).replaceAll(field.second);
converted.append(convertedValue);
} catch (Exception e) {
- // Do not log full exception to avoid leaks
- Log.w(TAG, "Cannot apply " + regex.first.pattern() + "->" + regex.second + " to "
+ // Do not log full exception to avoid PII leaking
+ Log.w(TAG, "Cannot apply " + field.first.pattern() + "->" + field.second + " to "
+ "field with autofill id" + id + ": " + e.getClass());
+ throw e;
}
}
parentTemplate.setCharSequence(childViewId, "setText", converted);
try {
transformation.apply(finder, mPresentation, id);
} catch (Exception e) {
- Log.e(TAG, "Could not apply transformation " + transformation + ". "
+ // Do not log full exception to avoid PII leaking
+ Log.e(TAG, "Could not apply transformation " + transformation + ": "
+ e.getClass());
+ return null;
}
}
}
@TestApi
@Override
public void apply(@NonNull ValueFinder finder, @NonNull RemoteViews parentTemplate,
- int childViewId) {
+ int childViewId) throws Exception {
final String value = finder.findByAutofillId(mId);
if (value == null) {
Log.w(TAG, "No view for id " + mId);
}
for (int i = 0; i < size; i++) {
- Pair<Pattern, Integer> regex = mOptions.get(i);
- if (regex.first.matcher(value).matches()) {
- Log.d(TAG, "Found match at " + i + ": " + regex);
- parentTemplate.setImageViewResource(childViewId, regex.second);
- return;
+ final Pair<Pattern, Integer> option = mOptions.get(i);
+ try {
+ if (option.first.matcher(value).matches()) {
+ Log.d(TAG, "Found match at " + i + ": " + option);
+ parentTemplate.setImageViewResource(childViewId, option.second);
+ return;
+ }
+ } catch (Exception e) {
+ // Do not log full exception to avoid PII leaking
+ Log.w(TAG, "Error matching regex #" + i + "(" + option.first.pattern() + ") on id "
+ + option.second + ": " + e.getClass());
+ throw e;
+
}
}
- Log.w(TAG, "No match for " + value);
+ if (sDebug) Log.d(TAG, "No match for " + value);
}
/**
* @hide
*/
abstract void apply(@NonNull ValueFinder finder, @NonNull RemoteViews template,
- int childViewId);
+ int childViewId) throws Exception;
}