From 85845b8458d8a6950b4ac87bcd59cbfb85680525 Mon Sep 17 00:00:00 2001 From: Selim Cinek Date: Wed, 25 Apr 2018 13:10:57 +0800 Subject: Fixed a leak of preDrawlisteners when an icon was animating when detached Test: add notification, observe clipping on icons still normally Change-Id: I5b2eec3988c645b66185f2890ab0cb8910ddeacd Fixes: 73961798 --- .../systemui/statusbar/NotificationShelf.java | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java index 44136c58875d..d3caf0351d03 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java @@ -407,13 +407,14 @@ public class NotificationShelf extends ActivatableNotificationView implements boolean needsContinuousClipping = ViewState.isAnimatingY(icon) && !mAmbientState.isDark(); boolean isContinuousClipping = icon.getTag(TAG_CONTINUOUS_CLIPPING) != null; if (needsContinuousClipping && !isContinuousClipping) { + final ViewTreeObserver observer = icon.getViewTreeObserver(); ViewTreeObserver.OnPreDrawListener predrawListener = new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { boolean animatingY = ViewState.isAnimatingY(icon); - if (!animatingY || !icon.isAttachedToWindow()) { - icon.getViewTreeObserver().removeOnPreDrawListener(this); + if (!animatingY) { + observer.removeOnPreDrawListener(this); icon.setTag(TAG_CONTINUOUS_CLIPPING, null); return true; } @@ -421,7 +422,20 @@ public class NotificationShelf extends ActivatableNotificationView implements return true; } }; - icon.getViewTreeObserver().addOnPreDrawListener(predrawListener); + observer.addOnPreDrawListener(predrawListener); + icon.addOnAttachStateChangeListener(new OnAttachStateChangeListener() { + @Override + public void onViewAttachedToWindow(View v) { + } + + @Override + public void onViewDetachedFromWindow(View v) { + if (v == icon) { + observer.removeOnPreDrawListener(predrawListener); + icon.setTag(TAG_CONTINUOUS_CLIPPING, null); + } + } + }); icon.setTag(TAG_CONTINUOUS_CLIPPING, predrawListener); } } -- cgit v1.2.3-59-g8ed1b