Loading core/java/android/app/assist/AssistStructure.java +16 −2 Original line number Original line Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.os.PooledStringWriter; import android.os.RemoteException; import android.os.RemoteException; import android.os.SystemClock; import android.os.SystemClock; import android.service.autofill.FillRequest; import android.service.autofill.FillRequest; import android.text.Spanned; import android.text.TextUtils; import android.text.TextUtils; import android.util.Log; import android.util.Log; import android.util.Pair; import android.util.Pair; Loading Loading @@ -1557,6 +1558,10 @@ public class AssistStructure implements Parcelable { /** /** * Returns any text associated with the node that is displayed to the user, or null * Returns any text associated with the node that is displayed to the user, or null * if there is none. * 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 @Nullable public CharSequence getText() { public CharSequence getText() { Loading Loading @@ -1996,14 +2001,16 @@ public class AssistStructure implements Parcelable { @Override @Override public void setText(CharSequence text) { public void setText(CharSequence text) { ViewNodeText t = getNodeText(); 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; t.mTextSelectionStart = t.mTextSelectionEnd = -1; } } @Override @Override public void setText(CharSequence text, int selectionStart, int selectionEnd) { public void setText(CharSequence text, int selectionStart, int selectionEnd) { ViewNodeText t = getNodeText(); 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.mTextSelectionStart = selectionStart; t.mTextSelectionEnd = selectionEnd; t.mTextSelectionEnd = selectionEnd; } } Loading Loading @@ -2222,6 +2229,13 @@ public class AssistStructure implements Parcelable { public void setHtmlInfo(@NonNull HtmlInfo htmlInfo) { public void setHtmlInfo(@NonNull HtmlInfo htmlInfo) { mNode.mHtmlInfo = 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 { private static final class HtmlInfoNode extends HtmlInfo implements Parcelable { Loading Loading
core/java/android/app/assist/AssistStructure.java +16 −2 Original line number Original line Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.os.PooledStringWriter; import android.os.RemoteException; import android.os.RemoteException; import android.os.SystemClock; import android.os.SystemClock; import android.service.autofill.FillRequest; import android.service.autofill.FillRequest; import android.text.Spanned; import android.text.TextUtils; import android.text.TextUtils; import android.util.Log; import android.util.Log; import android.util.Pair; import android.util.Pair; Loading Loading @@ -1557,6 +1558,10 @@ public class AssistStructure implements Parcelable { /** /** * Returns any text associated with the node that is displayed to the user, or null * Returns any text associated with the node that is displayed to the user, or null * if there is none. * 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 @Nullable public CharSequence getText() { public CharSequence getText() { Loading Loading @@ -1996,14 +2001,16 @@ public class AssistStructure implements Parcelable { @Override @Override public void setText(CharSequence text) { public void setText(CharSequence text) { ViewNodeText t = getNodeText(); 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; t.mTextSelectionStart = t.mTextSelectionEnd = -1; } } @Override @Override public void setText(CharSequence text, int selectionStart, int selectionEnd) { public void setText(CharSequence text, int selectionStart, int selectionEnd) { ViewNodeText t = getNodeText(); 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.mTextSelectionStart = selectionStart; t.mTextSelectionEnd = selectionEnd; t.mTextSelectionEnd = selectionEnd; } } Loading Loading @@ -2222,6 +2229,13 @@ public class AssistStructure implements Parcelable { public void setHtmlInfo(@NonNull HtmlInfo htmlInfo) { public void setHtmlInfo(@NonNull HtmlInfo htmlInfo) { mNode.mHtmlInfo = 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 { private static final class HtmlInfoNode extends HtmlInfo implements Parcelable { Loading