From f3385d197075d10659b388982b3d59c73adaa967 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 3 Aug 2023 06:09:51 +0000 Subject: Strips spans from AssistStructure text When a new view becomes visible on the screen, the view notifies AutofillManager about its visibility. AutofillManager then requests the activity to compile an AssistStructure object which will contain the view hierarchy of the activity as well as texts contained inside all the views. If there are Span text fields that contain custom implementation of ClickableSpan, these spans are also copied over during the construction of the AssistStructure. By keeping the references to the ClickableSpan, it causes memory leak when the AssistStructure object outlives the activity. Test: atest CtsAutoFillServiceTestCases, atest CtsAssistTestCases, atest android.widget.cts.TextViewTest Bug: 146100180 (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:e42d05e3d01f4c3b8aa7bce29086cd968970b4ec) Merged-In: I1fd97d9d6fdc569d14529347fcb85da409c3c1ff Change-Id: I1fd97d9d6fdc569d14529347fcb85da409c3c1ff --- core/java/android/app/assist/AssistStructure.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/core/java/android/app/assist/AssistStructure.java b/core/java/android/app/assist/AssistStructure.java index 6e49e956fe7e..27b8239edd4d 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; @@ -1556,6 +1557,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. + * + *

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() { @@ -1995,14 +2000,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; } @@ -2221,6 +2228,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 { -- cgit v1.2.3 From f0f29bfad31ceaee242b046769860327fd33f710 Mon Sep 17 00:00:00 2001 From: Tingting Zhang Date: Tue, 10 Oct 2023 09:46:35 +0800 Subject: perf: add exit app animation boost for apps exit. CRs-Fixed: 3622453 Change-Id: Ia3799ea1a6452de81ab621997c8f708284e75bf7 --- core/java/android/util/BoostFramework.java | 2 ++ services/core/java/com/android/server/wm/TaskFragment.java | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/core/java/android/util/BoostFramework.java b/core/java/android/util/BoostFramework.java index 7bab65a86802..bcd50d9e9b36 100644 --- a/core/java/android/util/BoostFramework.java +++ b/core/java/android/util/BoostFramework.java @@ -107,6 +107,8 @@ public class BoostFramework { public static final int VENDOR_HINT_DRAG_END = 0x00001052; //Ime Launch Boost Hint public static final int VENDOR_HINT_IME_LAUNCH_EVENT = 0x0000109F; + //App exit animation boost + public static final int VENDOR_HINT_EXIT_ANIM_BOOST = 0x000010A9; //feedback hints public static final int VENDOR_FEEDBACK_WORKLOAD_TYPE = 0x00001601; diff --git a/services/core/java/com/android/server/wm/TaskFragment.java b/services/core/java/com/android/server/wm/TaskFragment.java index e1e5261071c7..d58e3eb0a17d 100644 --- a/services/core/java/com/android/server/wm/TaskFragment.java +++ b/services/core/java/com/android/server/wm/TaskFragment.java @@ -1397,6 +1397,10 @@ class TaskFragment extends WindowContainer { dc.prepareAppTransition(TRANSIT_NONE); } else { dc.prepareAppTransition(TRANSIT_OPEN); + // Exit app animation boost + if (next != null && mPerf != null) { + mPerf.perfHint(BoostFramework.VENDOR_HINT_EXIT_ANIM_BOOST, next.packageName); + } } } -- cgit v1.2.3