Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 33d3b546 authored by Steve Elliott's avatar Steve Elliott
Browse files

Rework Incoming section logic

We cannot assign notifications to the HUNing section during sort and
filter in NotifRankMan, because we don't know if those Notifications
can be placed there at that time. The VisStabMan can decide that they
cannot be moved, and so NotifSecMan can get confused when it sees
BUCKET_HEADS_UP in the middle of the shade.

In an ideal world, VisStabMan would inform the sort performed by
NotifRankMan, as opposed to "shooting it down" after the fact. The
main issue here is that NotifRankMan and NotifSecMan are logically
related (Notification ordering) but VisStabMan can throw a wrench in
that relationship.

Also I took the liberty of converting NotifSecMan to Kotlin. :-)

Fixes: 153554168
Test: atest, manual
Change-Id: I4d1d38eaf4eaac69542c7c115040e76ff95cc1c9
parent 7c133319
Loading
Loading
Loading
Loading
+1 −17
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import com.android.systemui.statusbar.notification.people.PeopleNotificationIden
import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier.Companion.TYPE_NON_PERSON
import com.android.systemui.statusbar.notification.stack.BUCKET_ALERTING
import com.android.systemui.statusbar.notification.stack.BUCKET_FOREGROUND_SERVICE
import com.android.systemui.statusbar.notification.stack.BUCKET_HEADS_UP
import com.android.systemui.statusbar.notification.stack.BUCKET_PEOPLE
import com.android.systemui.statusbar.notification.stack.BUCKET_SILENT
import com.android.systemui.statusbar.notification.stack.PriorityBucket
@@ -138,23 +137,8 @@ open class NotificationRankingManager @Inject constructor(
                .filterNot(notifFilter::shouldFilterOut)
                .sortedWith(rankingComparator)
                .toList()
        assignBuckets(filtered)
        return filtered
    }

    private fun assignBuckets(entries: List<NotificationEntry>) {
        entries.forEach { it.bucket = getBucketForEntry(it) }
        if (!usePeopleFiltering) {
            // If we don't have a Conversation section, just assign buckets normally based on the
            // content.
            return
        }
        // If HUNs are not continuous with the top section, break out into a new Incoming section.
        entries.asReversed().asSequence().zipWithNext().forEach { (next, entry) ->
            if (entry.isRowHeadsUp && entry.bucket > next.bucket) {
                entry.bucket = BUCKET_HEADS_UP
            }
        }
        return filtered
    }

    @PriorityBucket
+26 −5
Original line number Diff line number Diff line
@@ -52,14 +52,35 @@ class NotificationSectionsLogger @Inject constructor(
            { "$int1: other ($str1)" }
    )

    fun logHeadsUp(position: Int) = logPosition(position, "Heads Up")
    fun logConversation(position: Int) = logPosition(position, "Conversation")
    fun logAlerting(position: Int) = logPosition(position, "Alerting")
    fun logSilent(position: Int) = logPosition(position, "Silent")
    fun logForegroundService(position: Int) = logPosition(position, "Foreground Service")
    fun logHeadsUp(position: Int, isHeadsUp: Boolean) =
            logPosition(position, "Heads Up", isHeadsUp)
    fun logConversation(position: Int, isHeadsUp: Boolean) =
            logPosition(position, "Conversation", isHeadsUp)
    fun logAlerting(position: Int, isHeadsUp: Boolean) =
            logPosition(position, "Alerting", isHeadsUp)
    fun logSilent(position: Int, isHeadsUp: Boolean) =
            logPosition(position, "Silent", isHeadsUp)
    fun logForegroundService(position: Int, isHeadsUp: Boolean) =
            logPosition(position, "Foreground Service", isHeadsUp)

    fun logStr(str: String) = logBuffer.log(TAG, LogLevel.DEBUG, { str1 = str }, { "$str1" })

    private fun logPosition(position: Int, label: String, isHeadsUp: Boolean) {
        val headsUpTag = if (isHeadsUp) " (HUN)" else ""
        logBuffer.log(
                TAG,
                LogLevel.DEBUG,
                {
                    int1 = position
                    str1 = label
                    str2 = headsUpTag
                },
                {
                    "$int1: $str1$str2"
                }
        )
    }

    private fun logPosition(position: Int, label: String) = logBuffer.log(
            TAG,
            LogLevel.DEBUG,
+58 −50
Original line number Diff line number Diff line
@@ -206,11 +206,14 @@ class NotificationSectionsManager @Inject internal constructor(
            child === alertingHeaderView -> logger.logAlertingHeader(i)
            child === silentHeaderView -> logger.logSilentHeader(i)
            child !is ExpandableNotificationRow -> logger.logOther(i, child.javaClass)
            else -> when (child.entry.bucket) {
                BUCKET_HEADS_UP -> logger.logHeadsUp(i)
                BUCKET_PEOPLE -> logger.logConversation(i)
                BUCKET_ALERTING -> logger.logAlerting(i)
                BUCKET_SILENT -> logger.logSilent(i)
            else -> {
                val isHeadsUp = child.isHeadsUp
                when (child.entry.bucket) {
                    BUCKET_HEADS_UP -> logger.logHeadsUp(i, isHeadsUp)
                    BUCKET_PEOPLE -> logger.logConversation(i, isHeadsUp)
                    BUCKET_ALERTING -> logger.logAlerting(i, isHeadsUp)
                    BUCKET_SILENT -> logger.logSilent(i, isHeadsUp)
                }
            }
        }
    }
@@ -242,7 +245,7 @@ class NotificationSectionsManager @Inject internal constructor(

        var peopleNotifsPresent = false
        var currentMediaControlsIdx = -1
        var mediaControlsTarget = if (usingMediaControls) 0 else -1
        val mediaControlsTarget = if (usingMediaControls) 0 else -1
        var currentIncomingHeaderIdx = -1
        var incomingHeaderTarget = -1
        var currentPeopleHeaderIdx = -1
@@ -253,10 +256,12 @@ class NotificationSectionsManager @Inject internal constructor(
        var gentleHeaderTarget = -1

        var lastNotifIndex = 0
        var lastIncomingIndex = -1
        var prev: ExpandableNotificationRow? = null

        parent.children.forEachIndexed { i, child ->
            // Track the existing positions of the headers
        for ((i, child) in parent.children.withIndex()) {
            when {
                // Track the existing positions of the headers
                child === incomingHeaderView -> {
                    logger.logIncomingHeader(i)
                    currentIncomingHeaderIdx = i
@@ -280,41 +285,40 @@ class NotificationSectionsManager @Inject internal constructor(
                child !is ExpandableNotificationRow -> logger.logOther(i, child.javaClass)
                else -> {
                    lastNotifIndex = i
                    when (child.entry.bucket) {
                        BUCKET_HEADS_UP -> {
                            logger.logHeadsUp(i)
                            if (showHeaders && incomingHeaderTarget == -1) {
                                incomingHeaderTarget = i
                                // Offset the target if there are other headers before this that
                                // will be moved.
                                if (currentIncomingHeaderIdx != -1) {
                                    incomingHeaderTarget--
                                }
                                if (currentMediaControlsIdx != -1) {
                                    incomingHeaderTarget--
                                }
                                if (currentPeopleHeaderIdx != -1) {
                                    incomingHeaderTarget--
                    // 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
                            }
                                if (currentAlertingHeaderIdx != -1) {
                                    incomingHeaderTarget--
                            alertingHeaderTarget = -1
                        }
                                if (currentGentleHeaderIdx != -1) {
                                    incomingHeaderTarget--
                        if (peopleHeaderTarget != -1) {
                            if (showHeaders && incomingHeaderTarget != -1) {
                                incomingHeaderTarget = peopleHeaderTarget
                            }
                            peopleHeaderTarget = -1
                        }
                            if (mediaControlsTarget != -1) {
                                mediaControlsTarget++
                        if (showHeaders && incomingHeaderTarget == -1) {
                            incomingHeaderTarget = 0
                        }
                        // Walk backwards changing all previous notifications to the Incoming
                        // section
                        for (j in i - 1 downTo lastIncomingIndex + 1) {
                            val prevChild = parent.getChildAt(j)
                            if (prevChild is ExpandableNotificationRow) {
                                prevChild.entry.bucket = BUCKET_HEADS_UP
                            }
                        BUCKET_FOREGROUND_SERVICE -> {
                            logger.logForegroundService(i)
                            if (mediaControlsTarget != -1) {
                                mediaControlsTarget++
                        }
                        // Track the new bottom of the Incoming section
                        lastIncomingIndex = i - 1
                    }
                    val isHeadsUp = child.isHeadsUp
                    when (child.entry.bucket) {
                        BUCKET_FOREGROUND_SERVICE -> logger.logForegroundService(i, isHeadsUp)
                        BUCKET_PEOPLE -> {
                            logger.logConversation(i)
                            logger.logConversation(i, isHeadsUp)
                            peopleNotifsPresent = true
                            if (showHeaders && peopleHeaderTarget == -1) {
                                peopleHeaderTarget = i
@@ -332,7 +336,7 @@ class NotificationSectionsManager @Inject internal constructor(
                            }
                        }
                        BUCKET_ALERTING -> {
                            logger.logAlerting(i)
                            logger.logAlerting(i, isHeadsUp)
                            if (showHeaders && usingPeopleFiltering && alertingHeaderTarget == -1) {
                                alertingHeaderTarget = i
                                // Offset the target if there are other headers before this that
@@ -346,7 +350,7 @@ class NotificationSectionsManager @Inject internal constructor(
                            }
                        }
                        BUCKET_SILENT -> {
                            logger.logSilent(i)
                            logger.logSilent(i, isHeadsUp)
                            if (showHeaders && gentleHeaderTarget == -1) {
                                gentleHeaderTarget = i
                                // Offset the target if there are other headers before this that
@@ -358,6 +362,8 @@ class NotificationSectionsManager @Inject internal constructor(
                        }
                        else -> throw IllegalStateException("Cannot find section bucket for view")
                    }

                    prev = child
                }
            }
        }
@@ -393,12 +399,12 @@ class NotificationSectionsManager @Inject internal constructor(
        peopleHeaderView?.let {
            adjustHeaderVisibilityAndPosition(peopleHeaderTarget, it, currentPeopleHeaderIdx)
        }
        mediaControlsView?.let {
            adjustViewPosition(mediaControlsTarget, it, currentMediaControlsIdx)
        }
        incomingHeaderView?.let {
            adjustHeaderVisibilityAndPosition(incomingHeaderTarget, it, currentIncomingHeaderIdx)
        }
        mediaControlsView?.let {
            adjustViewPosition(mediaControlsTarget, it, currentMediaControlsIdx)
        }

        logger.logStr("Final order:")
        logShadeContents()
@@ -575,14 +581,16 @@ class NotificationSectionsManager @Inject internal constructor(
@IntDef(
        prefix = ["BUCKET_"],
        value = [
            BUCKET_HEADS_UP, BUCKET_FOREGROUND_SERVICE, BUCKET_MEDIA_CONTROLS, BUCKET_PEOPLE,
            BUCKET_ALERTING, BUCKET_SILENT
            BUCKET_UNKNOWN, BUCKET_MEDIA_CONTROLS, BUCKET_HEADS_UP, BUCKET_FOREGROUND_SERVICE,
            BUCKET_PEOPLE, BUCKET_ALERTING, BUCKET_SILENT
        ]
)
annotation class PriorityBucket
const val BUCKET_HEADS_UP = 0
const val BUCKET_FOREGROUND_SERVICE = 1
const val BUCKET_MEDIA_CONTROLS = 2
const val BUCKET_PEOPLE = 3
const val BUCKET_ALERTING = 4
const val BUCKET_SILENT = 5

const val BUCKET_UNKNOWN = 0
const val BUCKET_MEDIA_CONTROLS = 1
const val BUCKET_HEADS_UP = 2
const val BUCKET_FOREGROUND_SERVICE = 3
const val BUCKET_PEOPLE = 4
const val BUCKET_ALERTING = 5
const val BUCKET_SILENT = 6
+219 −95

File changed.

Preview size limit exceeded, changes collapsed.