From 49e41617ef448d801ec00d022fb20b2981283e63 Mon Sep 17 00:00:00 2001 From: Steve Elliott Date: Mon, 1 Jun 2020 14:06:31 -0400 Subject: [PATCH] Increase defensiveness of Incoming Header placement This change removes the assumption that Silent notifications won't be out of place in the ranking order. Technically, silent notifs will never HUN, and so they should always be sorted to the bottom, but we've seen situations where that is not the case. Bug: 157764732 Test: manual, atest Change-Id: Ib90f704c3b3fa290c87f8a45888424ed55d61d52 --- .../stack/NotificationSectionsManager.kt | 45 +++++++++++++------ .../NotificationSectionsManagerTest.java | 10 ++--- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSectionsManager.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSectionsManager.kt index ba7675f27cf45..0bdac39f35e90 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSectionsManager.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationSectionsManager.kt @@ -287,21 +287,17 @@ class NotificationSectionsManager @Inject internal constructor( // Is there a section discontinuity? This usually occurs due to HUNs if (prev?.entry?.bucket?.let { it > child.entry.bucket } == true) { // Remove existing headers, and move the Incoming header if necessary - if (alertingHeaderTarget != -1) { - if (showHeaders && incomingHeaderTarget != -1) { - incomingHeaderTarget = alertingHeaderTarget - } - alertingHeaderTarget = -1 - } - if (peopleHeaderTarget != -1) { - if (showHeaders && incomingHeaderTarget != -1) { - incomingHeaderTarget = peopleHeaderTarget - } - peopleHeaderTarget = -1 - } - if (showHeaders && incomingHeaderTarget == -1) { - incomingHeaderTarget = 0 + incomingHeaderTarget = when { + !showHeaders -> -1 + incomingHeaderTarget != -1 -> incomingHeaderTarget + peopleHeaderTarget != -1 -> peopleHeaderTarget + alertingHeaderTarget != -1 -> alertingHeaderTarget + gentleHeaderTarget != -1 -> gentleHeaderTarget + else -> 0 } + peopleHeaderTarget = -1 + alertingHeaderTarget = -1 + gentleHeaderTarget = -1 // Walk backwards changing all previous notifications to the Incoming // section for (j in i - 1 downTo lastIncomingIndex + 1) { @@ -323,6 +319,9 @@ class NotificationSectionsManager @Inject internal constructor( peopleHeaderTarget = i // Offset the target if there are other headers before this that // will be moved. + if (currentIncomingHeaderIdx != -1 && incomingHeaderTarget == -1) { + peopleHeaderTarget-- + } if (currentPeopleHeaderIdx != -1) { peopleHeaderTarget-- } @@ -340,6 +339,13 @@ class NotificationSectionsManager @Inject internal constructor( alertingHeaderTarget = i // Offset the target if there are other headers before this that // will be moved. + if (currentIncomingHeaderIdx != -1 && incomingHeaderTarget == -1) { + alertingHeaderTarget-- + } + if (currentPeopleHeaderIdx != -1 && peopleHeaderTarget == -1) { + // People header will be removed + alertingHeaderTarget-- + } if (currentAlertingHeaderIdx != -1) { alertingHeaderTarget-- } @@ -354,6 +360,17 @@ class NotificationSectionsManager @Inject internal constructor( gentleHeaderTarget = i // Offset the target if there are other headers before this that // will be moved. + if (currentIncomingHeaderIdx != -1 && incomingHeaderTarget == -1) { + gentleHeaderTarget-- + } + if (currentPeopleHeaderIdx != -1 && peopleHeaderTarget == -1) { + // People header will be removed + gentleHeaderTarget-- + } + if (currentAlertingHeaderIdx != -1 && alertingHeaderTarget == -1) { + // Alerting header will be removed + gentleHeaderTarget-- + } if (currentGentleHeaderIdx != -1) { gentleHeaderTarget-- } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationSectionsManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationSectionsManagerTest.java index 3dc941a0bd208..c55391a387d87 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationSectionsManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationSectionsManagerTest.java @@ -403,11 +403,11 @@ public class NotificationSectionsManagerTest extends SysuiTestCase { enablePeopleFiltering(); setupMockStack( - PERSON.headsUp(), - INCOMING_HEADER, - ALERTING.headsUp(), - PEOPLE_HEADER, - PERSON + PERSON.headsUp(), // personHeaderTarget = 0 + INCOMING_HEADER, // currentIncomingHeaderIdx = 1 + ALERTING.headsUp(), // alertingHeaderTarget = 1 + PEOPLE_HEADER, // currentPeopleHeaderIdx = 3 + PERSON // ); mSectionsManager.updateSectionBoundaries();