[content-capture] remove span support, fix leaks

Bug: 239080094

Test: CtsContentCaptureServiceTestCases, FrameworkCoreTests
Change-Id: Ib9ec7b48e2d907af3d7a7669178ef4853dce8de9
This commit is contained in:
Felix Oghina
2023-03-31 13:50:58 +00:00
parent c9285e0921
commit 24b59f178b
2 changed files with 14 additions and 16 deletions

View File

@@ -46,8 +46,6 @@ import android.os.IBinder.DeathRecipient;
import android.os.RemoteException;
import android.text.Selection;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.util.LocalLog;
import android.util.Log;
@@ -740,7 +738,10 @@ 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);
CharSequence trimmed = TextUtils.trimToParcelableSize(text);
final CharSequence eventText = trimmed != null && trimmed == text
? trimmed.toString()
: trimmed;
final int composingStart;
final int composingEnd;
@@ -761,16 +762,6 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
.setSelectionIndex(startIndex, endIndex)));
}
private CharSequence stringOrSpannedStringWithoutNoCopySpans(CharSequence source) {
if (source == null) {
return null;
} else if (source instanceof Spanned) {
return new SpannableString(source, /* ignoreNoCopySpan= */ true);
} else {
return source.toString();
}
}
/** Public because is also used by ViewRootImpl */
public void notifyViewInsetsChanged(int sessionId, @NonNull Insets viewInsets) {
mHandler.post(() -> sendEvent(new ContentCaptureEvent(sessionId, TYPE_VIEW_INSETS_CHANGED)

View File

@@ -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);