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

Commit a8fce3b2 authored by Felipe Leme's avatar Felipe Leme Committed by Siyamed Sinir
Browse files

Don't copy NoCopySpans for assist and autofill

For AssistStructure, and AutofillValue, create a copy of the text in 
setText and forText methods if it is a Spanned.

Fixes: 36838999
Test: cts-tradefed run cts -m CtsAutoFillServiceTestCases
Test: cts-tradefed run cts -m CtsAssistTestCases
Test: cts-tradefed run cts --test android.widget.cts.TextViewTest -m \
      CtsWidgetTestCases

Change-Id: I52e780fa9baa17c375d3945dc714171f41fd7db5
parent dce4dfc6
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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;
        }
+16 −0
Original line number Diff line number Diff line
@@ -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;
+3 −1
Original line number Diff line number Diff line
@@ -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));
    }

    /**