diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-09-20 20:03:20 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-09-20 20:03:20 +0000 |
commit | 53047fb33f4f3d676a4c3bbf05121987dd59dd5a (patch) | |
tree | 5814cb5a047c0b70c7789b3ca6901347a0dc129b | |
parent | 72a29c5fbf3d1e50ac1b4271b0244cce8cf78072 (diff) | |
parent | 0d032cd0c447cd50e9db394f42ac84746cafea93 (diff) | |
download | base-53047fb33f4f3d676a4c3bbf05121987dd59dd5a.tar.gz |
Merge cherrypicks of ['googleplex-android-review.googlesource.com/24304450'] into rvc-platform-release.android-platform-11.0.0_r36
Change-Id: I517aa34c569a44d5b65d611b580e6176a7108d7c
-rw-r--r-- | core/java/android/app/assist/AssistStructure.java | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/core/java/android/app/assist/AssistStructure.java b/core/java/android/app/assist/AssistStructure.java index 22d8c87e9268..542f7f49a11b 100644 --- a/core/java/android/app/assist/AssistStructure.java +++ b/core/java/android/app/assist/AssistStructure.java @@ -22,6 +22,7 @@ import android.os.PooledStringWriter; import android.os.RemoteException; import android.os.SystemClock; import android.service.autofill.FillRequest; +import android.text.Spanned; import android.text.TextUtils; import android.util.Log; import android.util.Pair; @@ -1491,6 +1492,10 @@ public class AssistStructure implements Parcelable { /** * Returns any text associated with the node that is displayed to the user, or null * if there is none. + * + * <p> The text will be stripped of any spans that could potentially contain reference to + * the activity context, to avoid memory leak. If the text contained a span, a plain + * string version of the text will be returned. */ @Nullable public CharSequence getText() { @@ -1860,14 +1865,16 @@ public class AssistStructure implements Parcelable { @Override public void setText(CharSequence text) { ViewNodeText t = getNodeText(); - t.mText = TextUtils.trimNoCopySpans(text); + // Strip spans from the text to avoid memory leak + t.mText = TextUtils.trimToParcelableSize(stripAllSpansFromText(text)); t.mTextSelectionStart = t.mTextSelectionEnd = -1; } @Override public void setText(CharSequence text, int selectionStart, int selectionEnd) { ViewNodeText t = getNodeText(); - t.mText = TextUtils.trimNoCopySpans(text); + // Strip spans from the text to avoid memory leak + t.mText = stripAllSpansFromText(text); t.mTextSelectionStart = selectionStart; t.mTextSelectionEnd = selectionEnd; } @@ -2081,6 +2088,13 @@ public class AssistStructure implements Parcelable { public void setHtmlInfo(@NonNull HtmlInfo htmlInfo) { mNode.mHtmlInfo = htmlInfo; } + + private CharSequence stripAllSpansFromText(CharSequence text) { + if (text instanceof Spanned) { + return text.toString(); + } + return text; + } } private static final class HtmlInfoNode extends HtmlInfo implements Parcelable { |