diff options
| -rw-r--r-- | core/java/android/app/assist/AssistStructure.java | 4 | ||||
| -rw-r--r-- | core/java/android/text/TextUtils.java | 16 | ||||
| -rw-r--r-- | core/java/android/view/autofill/AutofillValue.java | 4 |
3 files changed, 21 insertions, 3 deletions
diff --git a/core/java/android/app/assist/AssistStructure.java b/core/java/android/app/assist/AssistStructure.java index d5ebe00bc8d3..7261dfa09bb4 100644 --- a/core/java/android/app/assist/AssistStructure.java +++ b/core/java/android/app/assist/AssistStructure.java @@ -1559,14 +1559,14 @@ public class AssistStructure implements Parcelable { @Override public void setText(CharSequence text) { ViewNodeText t = getNodeText(); - t.mText = text; + t.mText = TextUtils.trimNoCopySpans(text); t.mTextSelectionStart = t.mTextSelectionEnd = -1; } @Override public void setText(CharSequence text, int selectionStart, int selectionEnd) { ViewNodeText t = getNodeText(); - t.mText = text; + t.mText = TextUtils.trimNoCopySpans(text); t.mTextSelectionStart = selectionStart; t.mTextSelectionEnd = selectionEnd; } diff --git a/core/java/android/text/TextUtils.java b/core/java/android/text/TextUtils.java index 081deebaed77..91f43d632dfd 100644 --- a/core/java/android/text/TextUtils.java +++ b/core/java/android/text/TextUtils.java @@ -1921,6 +1921,22 @@ public class TextUtils { return false; } + /** + * If the {@code charSequence} is instance of {@link Spanned}, creates a new copy and + * {@link NoCopySpan}'s are removed from the copy. Otherwise the given {@code charSequence} is + * returned as it is. + * + * @hide + */ + @Nullable + public static CharSequence trimNoCopySpans(@Nullable CharSequence charSequence) { + if (charSequence != null && charSequence instanceof Spanned) { + // SpannableStringBuilder copy constructor trims NoCopySpans. + return new SpannableStringBuilder(charSequence); + } + return charSequence; + } + private static Object sLock = new Object(); private static char[] sTemp = null; diff --git a/core/java/android/view/autofill/AutofillValue.java b/core/java/android/view/autofill/AutofillValue.java index b57dab56318e..3beae11cf38c 100644 --- a/core/java/android/view/autofill/AutofillValue.java +++ b/core/java/android/view/autofill/AutofillValue.java @@ -26,6 +26,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.os.Parcel; import android.os.Parcelable; +import android.text.TextUtils; import android.view.View; import com.android.internal.util.Preconditions; @@ -257,7 +258,8 @@ public final class AutofillValue implements Parcelable { * <p>See {@link View#AUTOFILL_TYPE_TEXT} for more info. */ public static AutofillValue forText(@Nullable CharSequence value) { - return value == null ? null : new AutofillValue(AUTOFILL_TYPE_TEXT, value); + return value == null ? null : new AutofillValue(AUTOFILL_TYPE_TEXT, + TextUtils.trimNoCopySpans(value)); } /** |