diff options
author | Jorim Jaggi <jjaggi@google.com> | 2016-01-19 16:32:17 -0800 |
---|---|---|
committer | The Android Automerger <android-build@google.com> | 2016-01-21 18:14:44 -0800 |
commit | 4276d402de3a19bbd77b6d44fc9e22bca28f8589 (patch) | |
tree | 5483f9c5bc2ddfc00caff830e14b103b922f1aa6 /packages/SystemUI/src/com | |
parent | fd0b32d750b6306e94a12a25a54e299ae6142fc2 (diff) | |
download | frameworks_base-4276d402de3a19bbd77b6d44fc9e22bca28f8589.zip frameworks_base-4276d402de3a19bbd77b6d44fc9e22bca28f8589.tar.gz frameworks_base-4276d402de3a19bbd77b6d44fc9e22bca28f8589.tar.bz2 |
Fix SystemUI animator leak
When there was a state change or layout when there was an animation
set as the mobile icon in the status bar, we never stopped the old
animation, which was infinite. This was using more and more CPU because
the animations never got stopped.
To fix this, we don't update the drawable when a layout happens and we
stop the previous animation when replacing the icon.
Bug: 26616870
Change-Id: If501155d1a99d587e50a1b77ebb03a21c940662b
Diffstat (limited to 'packages/SystemUI/src/com')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/SignalClusterView.java | 54 |
1 files changed, 38 insertions, 16 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/SignalClusterView.java b/packages/SystemUI/src/com/android/systemui/statusbar/SignalClusterView.java index cc30882..68e483c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/SignalClusterView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/SignalClusterView.java @@ -351,10 +351,13 @@ public class SignalClusterView for (PhoneState state : mPhoneStates) { if (state.mMobile != null) { + state.maybeStopAnimatableDrawable(state.mMobile); state.mMobile.setImageDrawable(null); + state.mLastMobileStrengthId = -1; } if (state.mMobileType != null) { state.mMobileType.setImageDrawable(null); + state.mLastMobileTypeId = -1; } } @@ -486,6 +489,8 @@ public class SignalClusterView private final int mSubId; private boolean mMobileVisible = false; private int mMobileStrengthId = 0, mMobileTypeId = 0; + private int mLastMobileStrengthId = -1; + private int mLastMobileTypeId = -1; private boolean mIsMobileTypeIconWide; private String mMobileDescription, mMobileTypeDescription; @@ -508,25 +513,16 @@ public class SignalClusterView public boolean apply(boolean isSecondaryIcon) { if (mMobileVisible && !mIsAirplaneMode) { - mMobile.setImageResource(mMobileStrengthId); - Drawable mobileDrawable = mMobile.getDrawable(); - if (mobileDrawable instanceof Animatable) { - Animatable ad = (Animatable) mobileDrawable; - if (!ad.isRunning()) { - ad.start(); - } + if (mLastMobileStrengthId != mMobileStrengthId) { + updateAnimatableIcon(mMobile, mMobileStrengthId); + updateAnimatableIcon(mMobileDark, mMobileStrengthId); + mLastMobileStrengthId = mMobileStrengthId; } - mMobileDark.setImageResource(mMobileStrengthId); - Drawable mobileDarkDrawable = mMobileDark.getDrawable(); - if (mobileDarkDrawable instanceof Animatable) { - Animatable ad = (Animatable) mobileDarkDrawable; - if (!ad.isRunning()) { - ad.start(); - } + if (mLastMobileTypeId != mMobileTypeId) { + mMobileType.setImageResource(mMobileTypeId); + mLastMobileTypeId = mMobileTypeId; } - - mMobileType.setImageResource(mMobileTypeId); mMobileGroup.setContentDescription(mMobileTypeDescription + " " + mMobileDescription); mMobileGroup.setVisibility(View.VISIBLE); @@ -550,6 +546,32 @@ public class SignalClusterView return mMobileVisible; } + private void updateAnimatableIcon(ImageView view, int resId) { + maybeStopAnimatableDrawable(view); + view.setImageResource(resId); + maybeStartAnimatableDrawable(view); + } + + private void maybeStopAnimatableDrawable(ImageView view) { + Drawable drawable = view.getDrawable(); + if (drawable instanceof Animatable) { + Animatable ad = (Animatable) drawable; + if (ad.isRunning()) { + ad.stop(); + } + } + } + + private void maybeStartAnimatableDrawable(ImageView view) { + Drawable drawable = view.getDrawable(); + if (drawable instanceof Animatable) { + Animatable ad = (Animatable) drawable; + if (!ad.isRunning()) { + ad.start(); + } + } + } + public void populateAccessibilityEvent(AccessibilityEvent event) { if (mMobileVisible && mMobileGroup != null && mMobileGroup.getContentDescription() != null) { |