From 8e36f0a26e27eb70198d9518ba091c34c328dab8 Mon Sep 17 00:00:00 2001 From: yingleiw Date: Thu, 27 Aug 2020 14:54:30 -0700 Subject: [PATCH] Add accessibility manager enabled check in progressbar formatStateDescription() in onProgressRefresh() is causing performance degradation with accessibility off. Note that stateDescription is set in onInitializeAccessibilityNodeInfo to ensure that accessibility always get the update-to-date stateDescription. Otherwise, stateDescription might be stale on first accessibility focus and the user might get wrong information. Fix: b/166215147 Test: tested with talkback enabled from the beginning or from the middle. Change-Id: I9fb99b479b172d87c8d0fa1b8765dab53445b993 (cherry picked from commit fc9d9b800f0d2b39b42a82b5f6b88abd5f712228) --- core/java/android/widget/ProgressBar.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/java/android/widget/ProgressBar.java b/core/java/android/widget/ProgressBar.java index 970d70cf1fb4c..f56c357c57a8c 100644 --- a/core/java/android/widget/ProgressBar.java +++ b/core/java/android/widget/ProgressBar.java @@ -52,6 +52,7 @@ import android.view.View; import android.view.ViewDebug; import android.view.ViewHierarchyEncoder; import android.view.accessibility.AccessibilityEvent; +import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityNodeInfo; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; @@ -306,9 +307,6 @@ public class ProgressBar extends View { setMax(a.getInt(R.styleable.ProgressBar_max, mMax)); setProgress(a.getInt(R.styleable.ProgressBar_progress, mProgress)); - // onProgressRefresh() is only called when the progress changes. So we should set - // stateDescription during initialization here. - super.setStateDescription(formatStateDescription(mProgress)); setSecondaryProgress(a.getInt( R.styleable.ProgressBar_secondaryProgress, mSecondaryProgress)); @@ -1601,7 +1599,8 @@ public class ProgressBar extends View { } void onProgressRefresh(float scale, boolean fromUser, int progress) { - if (mCustomStateDescription == null) { + if (AccessibilityManager.getInstance(mContext).isEnabled() + && mCustomStateDescription == null) { super.setStateDescription(formatStateDescription(mProgress)); } } @@ -2325,6 +2324,7 @@ public class ProgressBar extends View { AccessibilityNodeInfo.RangeInfo.RANGE_TYPE_INT, getMin(), getMax(), getProgress()); info.setRangeInfo(rangeInfo); + info.setStateDescription(formatStateDescription(mProgress)); } }