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

Commit 979f5db7 authored by Lyn Han's avatar Lyn Han
Browse files

Log and forget dropped HUNs instead of storing them

Fixes: 394186480
Test: adb
Flag: com.android.systemui.notification_avalanche_throttle_hun
Change-Id: I5889ab10c1e987bf074c9ea8b740fdea98c4f8c1
parent c9306254
Loading
Loading
Loading
Loading
+0 −26
Original line number Diff line number Diff line
@@ -233,32 +233,6 @@ class AvalancheControllerTest : SysuiTestCase() {
        Mockito.verify(runnableMock, Mockito.times(0)).run()
    }

    @Test
    fun testDelete_wasDropped_removedFromDropSet() {
        // Entry was dropped
        val headsUpEntry = createHeadsUpEntry(id = 0)
        mAvalancheController.debugDropSet.add(headsUpEntry)

        // Delete
        mAvalancheController.delete(headsUpEntry, runnableMock!!, "testLabel")

        // Entry was removed from dropSet
        assertThat(mAvalancheController.debugDropSet.contains(headsUpEntry)).isFalse()
    }

    @Test
    fun testDelete_wasDropped_runnableNotRun() {
        // Entry was dropped
        val headsUpEntry = createHeadsUpEntry(id = 0)
        mAvalancheController.debugDropSet.add(headsUpEntry)

        // Delete
        mAvalancheController.delete(headsUpEntry, runnableMock!!, "testLabel")

        // Runnable was not run
        Mockito.verify(runnableMock, Mockito.times(0)).run()
    }

    @Test
    fun testDelete_isShowing_runnableRun() {
        // Entry is showing
+8 −20
Original line number Diff line number Diff line
@@ -88,10 +88,6 @@ constructor(
    // Map of Runnable to label for debugging only
    private val debugRunnableLabelMap: MutableMap<Runnable, String> = HashMap()

    // HeadsUpEntry we did not show at all because they are not the top priority hun in their batch
    // For debugging only
    @VisibleForTesting var debugDropSet: MutableSet<HeadsUpEntry> = HashSet()

    enum class ThrottleEvent(private val id: Int) : UiEventLogger.UiEventEnum {
        @UiEvent(doc = "HUN was shown.") AVALANCHE_THROTTLING_HUN_SHOWN(1821),
        @UiEvent(doc = "HUN was dropped to show higher priority HUNs.")
@@ -235,9 +231,6 @@ constructor(
            if (entry in nextList) nextList.remove(entry)
            uiEventLogger.log(ThrottleEvent.AVALANCHE_THROTTLING_HUN_REMOVED)
            outcome = "remove from next. ${getStateStr()}"
        } else if (entry in debugDropSet) {
            debugDropSet.remove(entry)
            outcome = "remove from dropset. ${getStateStr()}"
        } else if (isShowing(entry)) {
            previousHunKey = getKey(headsUpEntryShowing)
            // Show the next HUN before removing this one, so that we don't tell listeners
@@ -249,7 +242,8 @@ constructor(
            outcome = "remove showing. ${getStateStr()}"
        } else {
            runnable.run()
            outcome = "run runnable for untracked shown HUN. ${getStateStr()}"
            outcome = "run runnable for untracked HUN " +
                    "(was dropped or shown when AC was disabled). ${getStateStr()}"
        }
        headsUpManagerLogger.logAvalancheDelete(caller, isEnabled(), getKey(entry), outcome)
    }
@@ -401,9 +395,13 @@ constructor(
                    debugRunnableLabelMap.remove(r)
                }
            }
            debugDropSet.addAll(listToDrop)
            val queue = ArrayList<String>()
            for (entry in listToDrop) {
                queue.add("[${getKey(entry)}]")
            }
            val dropList = java.lang.String.join("\n", queue)
            headsUpManagerLogger.logDroppedHuns(dropList)
        }

        clearNext()
        showNow(headsUpEntryShowing!!, headsUpEntryShowingRunnableList)
    }
@@ -438,20 +436,10 @@ constructor(
            "\n\tprevious: [$previousHunKey]" +
            "\n\tnext list: $nextListStr" +
            "\n\tnext map: $nextMapStr" +
            "\n\tdropped: $dropSetStr" +
            "\nBHUM.mHeadsUpEntryMap: " +
            baseEntryMapStr()
    }

    private val dropSetStr: String
        get() {
            val queue = ArrayList<String>()
            for (entry in debugDropSet) {
                queue.add("[${getKey(entry)}]")
            }
            return java.lang.String.join("\n", queue)
        }

    private val nextListStr: String
        get() {
            val queue = ArrayList<String>()
+4 −0
Original line number Diff line number Diff line
@@ -323,6 +323,10 @@ constructor(@NotificationHeadsUpLog private val buffer: LogBuffer) {
    fun logRemoveEntryAfterExpand(entry: NotificationEntry) {
        buffer.log(TAG, VERBOSE, { str1 = entry.logKey }, { "remove entry after expand: $str1" })
    }

    fun logDroppedHuns(entryList: String) {
        buffer.log(TAG, VERBOSE, { str1 = entryList }, { "[AC] Drop HUNs: $str1" })
    }
}

private const val TAG = "HeadsUpManager"