From 77cb4d2cd02d23464fdfd61745b98030d17faa9f Mon Sep 17 00:00:00 2001 From: Selim Cinek Date: Fri, 2 Jun 2017 13:43:41 -0700 Subject: [PATCH] Fixed an issue where would could be left with empty notifications If the state between systemui and the notification manager got out of sync, we would not immediately remove the notifications when using clear all. This could lead to holes in the notification shade temporarily. While this isn't a fix, it helps avoiding these ugly states, similarly to how we already do it when manually swiping. This also improves that only notifications that are visible are actually participating in the clear all animations instead of all of them. Test: manual, hit clear all observe animations / normal clearing Bug: 62171447 Change-Id: I83d0f3cb0bae4bc43bf35d3f9399cebc05259680 --- .../systemui/statusbar/phone/StatusBar.java | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index 07ab6876e42bd..e3ac9fe68709a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -473,6 +473,7 @@ public class StatusBar extends SystemUI implements DemoMode, int mSystemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE; private final Rect mLastFullscreenStackBounds = new Rect(); private final Rect mLastDockedStackBounds = new Rect(); + private final Rect mTmpRect = new Rect(); // last value sent to window manager private int mLastDispatchedSystemUiVisibility = ~View.SYSTEM_UI_FLAG_VISIBLE; @@ -1370,20 +1371,33 @@ public class StatusBar extends SystemUI implements DemoMode, int numChildren = mStackScroller.getChildCount(); final ArrayList viewsToHide = new ArrayList(numChildren); + final ArrayList viewsToRemove = new ArrayList<>(numChildren); for (int i = 0; i < numChildren; i++) { final View child = mStackScroller.getChildAt(i); if (child instanceof ExpandableNotificationRow) { - if (mStackScroller.canChildBeDismissed(child)) { - if (child.getVisibility() == View.VISIBLE) { - viewsToHide.add(child); - } - } ExpandableNotificationRow row = (ExpandableNotificationRow) child; + boolean parentVisible = false; + boolean hasClipBounds = child.getClipBounds(mTmpRect); + if (mStackScroller.canChildBeDismissed(child)) { + viewsToRemove.add(row); + if (child.getVisibility() == View.VISIBLE + && (!hasClipBounds || mTmpRect.height() > 0)) { + viewsToHide.add(child); + parentVisible = true; + } + } else if (child.getVisibility() == View.VISIBLE + && (!hasClipBounds || mTmpRect.height() > 0)) { + parentVisible = true; + } List children = row.getNotificationChildren(); - if (row.areChildrenExpanded() && children != null) { + if (children != null) { for (ExpandableNotificationRow childRow : children) { - if (mStackScroller.canChildBeDismissed(childRow)) { - if (childRow.getVisibility() == View.VISIBLE) { + viewsToRemove.add(childRow); + if (parentVisible && row.areChildrenExpanded() + && mStackScroller.canChildBeDismissed(childRow)) { + hasClipBounds = childRow.getClipBounds(mTmpRect); + if (childRow.getVisibility() == View.VISIBLE + && (!hasClipBounds || mTmpRect.height() > 0)) { viewsToHide.add(childRow); } } @@ -1391,7 +1405,7 @@ public class StatusBar extends SystemUI implements DemoMode, } } } - if (viewsToHide.isEmpty()) { + if (viewsToRemove.isEmpty()) { animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE); return; } @@ -1400,6 +1414,13 @@ public class StatusBar extends SystemUI implements DemoMode, @Override public void run() { mStackScroller.setDismissAllInProgress(false); + for (ExpandableNotificationRow rowToRemove : viewsToRemove) { + if (mStackScroller.canChildBeDismissed(rowToRemove)) { + removeNotification(rowToRemove.getEntry().key, null); + } else { + rowToRemove.resetTranslation(); + } + } try { mBarService.onClearAllNotifications(mCurrentUserId); } catch (Exception ex) { }