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

Commit 50f5ce8b authored by Felix Oghina's avatar Felix Oghina
Browse files

[content-capture] ensure memory-safe charsequences

When parceling CharSequences, we need to both remove NoCopySpans and
trim to max parcelable size. Fixing a couple of places that only do one
of these operations.

Bug: 239080094

Test: CtsContentCaptureServiceTestCases, FrameworkCoreTests

Change-Id: If6a52a8c9804d06d95b39ceff52c4db076e9b49c
parent c0f2e40e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -740,7 +740,8 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
        // Since the same CharSequence instance may be reused in the TextView, we need to make
        // a copy of its content so that its value will not be changed by subsequent updates
        // in the TextView.
        final CharSequence eventText = stringOrSpannedStringWithoutNoCopySpans(text);
        final CharSequence eventText =
                TextUtils.trimToParcelableSize(stringOrSpannedStringWithoutNoCopySpans(text));

        final int composingStart;
        final int composingEnd;
+10 −3
Original line number Diff line number Diff line
@@ -1052,14 +1052,21 @@ public final class ViewNode extends AssistStructure.ViewNode {
        }

        void writeToParcel(Parcel out, boolean simple) {
            TextUtils.writeToParcel(mText, out, 0);
            CharSequence text = TextUtils.trimToParcelableSize(mText);
            TextUtils.writeToParcel(text, out, 0);
            out.writeFloat(mTextSize);
            out.writeInt(mTextStyle);
            out.writeInt(mTextColor);
            if (!simple) {
                int selectionStart = text != null
                        ? Math.min(mTextSelectionStart, text.length())
                        : mTextSelectionStart;
                int selectionEnd = text != null
                        ? Math.min(mTextSelectionEnd, text.length())
                        : mTextSelectionEnd;
                out.writeInt(mTextBackgroundColor);
                out.writeInt(mTextSelectionStart);
                out.writeInt(mTextSelectionEnd);
                out.writeInt(selectionStart);
                out.writeInt(selectionEnd);
                out.writeIntArray(mLineCharOffsets);
                out.writeIntArray(mLineBaselines);
                out.writeString(mHint);
+2 −1
Original line number Diff line number Diff line
@@ -13531,7 +13531,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
    @Nullable
    public AutofillValue getAutofillValue() {
        if (isTextEditable()) {
            final CharSequence text = TextUtils.trimToParcelableSize(getText());
            final CharSequence text =
                    TextUtils.trimToParcelableSize(TextUtils.trimNoCopySpans(getText()));
            return AutofillValue.forText(text);
        }
        return null;