From d9b18355771a2e7a08617903f0e04cea4f041095 Mon Sep 17 00:00:00 2001 From: Lucas Dupin Date: Thu, 3 Feb 2022 16:49:47 -0800 Subject: [PATCH] Reduce cost of FooterView#showHistory FooterView#showHistory could take up to 3ms to execute due to resource fetching. The strings are now cached and we abort earlier when possible. Now the method is executed withing 800us Bug: 210432290 Test: atest FooterViewTest Test: https://ui.perfetto.dev/#!/?s=cf1a328f424429fd30f131cd31c7d17c8ff412eb5ae1cfeec272c5f2d5a1c5e Change-Id: If09c47646e168e8dded17b59be8573d0a9386eb9 --- .../notification/row/FooterView.java | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/FooterView.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/FooterView.java index 0b6d7594ce504..7d035a78450a3 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/FooterView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/FooterView.java @@ -35,6 +35,10 @@ public class FooterView extends StackScrollerDecorView { private FooterViewButton mClearAllButton; private FooterViewButton mManageButton; private boolean mShowHistory; + // String cache, for performance reasons. + // Reading them from a Resources object can be quite slow sometimes. + private String mManageNotificationText; + private String mManageNotificationHistoryText; public FooterView(Context context, AttributeSet attrs) { super(context, attrs); @@ -68,6 +72,8 @@ public class FooterView extends StackScrollerDecorView { super.onFinishInflate(); mClearAllButton = (FooterViewButton) findSecondaryView(); mManageButton = findViewById(R.id.manage_text); + updateResources(); + updateText(); } public void setManageButtonClickListener(OnClickListener listener) { @@ -86,15 +92,20 @@ public class FooterView extends StackScrollerDecorView { } public void showHistory(boolean showHistory) { + if (mShowHistory == showHistory) { + return; + } mShowHistory = showHistory; + updateText(); + } + + private void updateText() { if (mShowHistory) { - mManageButton.setText(R.string.manage_notifications_history_text); - mManageButton.setContentDescription( - mContext.getString(R.string.manage_notifications_history_text)); + mManageButton.setText(mManageNotificationHistoryText); + mManageButton.setContentDescription(mManageNotificationHistoryText); } else { - mManageButton.setText(R.string.manage_notifications_text); - mManageButton.setContentDescription( - mContext.getString(R.string.manage_notifications_text)); + mManageButton.setText(mManageNotificationText); + mManageButton.setContentDescription(mManageNotificationText); } } @@ -109,7 +120,8 @@ public class FooterView extends StackScrollerDecorView { mClearAllButton.setText(R.string.clear_all_notifications_text); mClearAllButton.setContentDescription( mContext.getString(R.string.accessibility_clear_all)); - showHistory(mShowHistory); + updateResources(); + updateText(); } /** @@ -124,6 +136,12 @@ public class FooterView extends StackScrollerDecorView { mManageButton.setTextColor(textColor); } + private void updateResources() { + mManageNotificationText = getContext().getString(R.string.manage_notifications_text); + mManageNotificationHistoryText = getContext() + .getString(R.string.manage_notifications_history_text); + } + @Override public ExpandableViewState createExpandableViewState() { return new FooterViewState();