diff options
author | Felipe Leme <felipeal@google.com> | 2018-05-31 13:08:32 -0700 |
---|---|---|
committer | Felipe Leme <felipeal@google.com> | 2018-06-01 14:09:09 -0700 |
commit | a11aaddb31311a249dc89e36b0e6b64c84e65357 (patch) | |
tree | a9a9b86901071f0c3c2376486cd162e44e82b287 | |
parent | ac809dc4a36ffe94818052ebf8ea7e7d96fb4b35 (diff) |
Document AutofillValue.forText() thread safety...
...and logs a warning when it's not called from the UI thread.
Fixes: 79159377
Test: atest CtsAutoFillServiceTestCases
Change-Id: I2976dbe294db695796a2a9db9600a333ffb66f26
-rw-r--r-- | core/java/android/view/autofill/AutofillValue.java | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/core/java/android/view/autofill/AutofillValue.java b/core/java/android/view/autofill/AutofillValue.java index 8e649de52c97..186a97dd2592 100644 --- a/core/java/android/view/autofill/AutofillValue.java +++ b/core/java/android/view/autofill/AutofillValue.java @@ -21,12 +21,15 @@ import static android.view.View.AUTOFILL_TYPE_LIST; import static android.view.View.AUTOFILL_TYPE_TEXT; import static android.view.View.AUTOFILL_TYPE_TOGGLE; import static android.view.autofill.Helper.sDebug; +import static android.view.autofill.Helper.sVerbose; import android.annotation.NonNull; import android.annotation.Nullable; +import android.os.Looper; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; +import android.util.Log; import android.view.View; import com.android.internal.util.Preconditions; @@ -41,6 +44,9 @@ import java.util.Objects; * {@link View#getAutofillType()}. */ public final class AutofillValue implements Parcelable { + + private static final String TAG = "AutofillValue"; + private final @View.AutofillType int mType; private final @NonNull Object mValue; @@ -256,8 +262,15 @@ public final class AutofillValue implements Parcelable { * Creates a new {@link AutofillValue} to autofill a {@link View} representing a text field. * * <p>See {@link View#AUTOFILL_TYPE_TEXT} for more info. + * + * <p><b>Note:</b> This method is not thread safe and can throw an exception if the + * {@code value} is modified by a different thread before it returns. */ public static AutofillValue forText(@Nullable CharSequence value) { + if (sVerbose && !Looper.getMainLooper().isCurrentThread()) { + Log.v(TAG, "forText() not called on main thread: " + Thread.currentThread()); + } + return value == null ? null : new AutofillValue(AUTOFILL_TYPE_TEXT, TextUtils.trimNoCopySpans(value)); } |