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

Commit 1e35071f authored by lyn's avatar lyn
Browse files

Move useful debug logcat to logbuffer

Bug: 394681782
Test: adb
Flag: com.android.systemui.notification_avalanche_throttle_hun
Change-Id: I786b9ffc5d5d96ded4eeb1795d24022cc571ea4c
parent 2b25943f
Loading
Loading
Loading
Loading
+25 −24
Original line number Original line Diff line number Diff line
@@ -269,8 +269,10 @@ constructor(
        }
        }
        nextList.sort()
        nextList.sort()
        val entryList = showingList + nextList
        val entryList = showingList + nextList
        val thisKey = getKey(entry)
        if (entryList.isEmpty()) {
        if (entryList.isEmpty()) {
            log { "No avalanche HUNs, use default ms: $autoDismissMs" }
            headsUpManagerLogger.logAvalancheDuration(
                thisKey, autoDismissMs, "No avalanche HUNs, use default", nextKey = "")
            return autoDismissMs
            return autoDismissMs
        }
        }
        // entryList.indexOf(entry) returns -1 even when the entry is in entryList
        // entryList.indexOf(entry) returns -1 even when the entry is in entryList
@@ -281,27 +283,29 @@ constructor(
            }
            }
        }
        }
        if (thisEntryIndex == -1) {
        if (thisEntryIndex == -1) {
            log { "Untracked entry, use default ms: $autoDismissMs" }
            headsUpManagerLogger.logAvalancheDuration(
                thisKey, autoDismissMs, "Untracked entry, use default", nextKey = "")
            return autoDismissMs
            return autoDismissMs
        }
        }
        val nextEntryIndex = thisEntryIndex + 1
        val nextEntryIndex = thisEntryIndex + 1

        // If last entry, use default duration
        if (nextEntryIndex >= entryList.size) {
        if (nextEntryIndex >= entryList.size) {
            log { "Last entry, use default ms: $autoDismissMs" }
            headsUpManagerLogger.logAvalancheDuration(
                thisKey, autoDismissMs, "Last entry, use default", nextKey = "")
            return autoDismissMs
            return autoDismissMs
        }
        }
        val nextEntry = entryList[nextEntryIndex]
        val nextEntry = entryList[nextEntryIndex]
        val nextKey = getKey(nextEntry)
        if (nextEntry.compareNonTimeFields(entry) == -1) {
        if (nextEntry.compareNonTimeFields(entry) == -1) {
            // Next entry is higher priority
            headsUpManagerLogger.logAvalancheDuration(
            log { "Next entry is higher priority: 500ms" }
                thisKey, 500, "LOWER priority than next: ", nextKey)
            return 500
            return 500
        } else if (nextEntry.compareNonTimeFields(entry) == 0) {
        } else if (nextEntry.compareNonTimeFields(entry) == 0) {
            // Next entry is same priority
            headsUpManagerLogger.logAvalancheDuration(
            log { "Next entry is same priority: 1000ms" }
                thisKey, 1000, "SAME priority as next: ", nextKey)
            return 1000
            return 1000
        } else {
        } else {
            log { "Next entry is lower priority, use default ms: $autoDismissMs" }
            headsUpManagerLogger.logAvalancheDuration(
                thisKey, autoDismissMs, "HIGHER priority than next: ", nextKey)
            return autoDismissMs
            return autoDismissMs
        }
        }
    }
    }
@@ -355,25 +359,28 @@ constructor(
    }
    }


    private fun showNow(entry: HeadsUpEntry, runnableList: MutableList<Runnable>) {
    private fun showNow(entry: HeadsUpEntry, runnableList: MutableList<Runnable>) {
        log { "SHOW: " + getKey(entry) }
        headsUpManagerLogger.logAvalancheStage("show", getKey(entry))

        uiEventLogger.log(ThrottleEvent.AVALANCHE_THROTTLING_HUN_SHOWN)
        uiEventLogger.log(ThrottleEvent.AVALANCHE_THROTTLING_HUN_SHOWN)
        headsUpEntryShowing = entry
        headsUpEntryShowing = entry


        runnableList.forEach {
        runnableList.forEach { runnable ->
            if (it in debugRunnableLabelMap) {
            if (debug) {
                log { "RUNNABLE: ${debugRunnableLabelMap[it]}" }
                debugRunnableLabelMap[runnable]?.let { label ->
                    headsUpManagerLogger.logAvalancheStage("run", label)
                    // Remove label after logging to avoid memory leak
                    debugRunnableLabelMap.remove(runnable)
                }
                }
            it.run()
            }
            runnable.run()
        }
        }
    }
    }


    private fun showNext() {
    private fun showNext() {
        log { "SHOW NEXT" }
        headsUpManagerLogger.logAvalancheStage("show next",  key = "")
        headsUpEntryShowing = null
        headsUpEntryShowing = null


        if (nextList.isEmpty()) {
        if (nextList.isEmpty()) {
            log { "NO MORE TO SHOW" }
            headsUpManagerLogger.logAvalancheStage("no more",  key = "")
            previousHunKey = ""
            previousHunKey = ""
            return
            return
        }
        }
@@ -424,12 +431,6 @@ constructor(


    // Methods below are for logging only ==========================================================
    // Methods below are for logging only ==========================================================


    private inline fun log(s: () -> String) {
        if (debug) {
            Log.d(tag, s())
        }
    }

    private fun getStateStr(): String {
    private fun getStateStr(): String {
        return "\navalanche state:" +
        return "\navalanche state:" +
            "\n\tshowing: [${getKey(headsUpEntryShowing)}]" +
            "\n\tshowing: [${getKey(headsUpEntryShowing)}]" +
+28 −2
Original line number Original line Diff line number Diff line
@@ -71,7 +71,7 @@ constructor(@NotificationHeadsUpLog private val buffer: LogBuffer) {
                str3 = outcome
                str3 = outcome
                bool1 = isEnabled
                bool1 = isEnabled
            },
            },
            { "$str1\n\t=> AC[isEnabled:$bool1] update: $str2\n\t=> $str3" },
            { "$str1\n\t=> AC[enabled:$bool1] update: $str2\n\t=> $str3" },
        )
        )
    }
    }


@@ -90,7 +90,33 @@ constructor(@NotificationHeadsUpLog private val buffer: LogBuffer) {
                str3 = outcome
                str3 = outcome
                bool1 = isEnabled
                bool1 = isEnabled
            },
            },
            { "$str1\n\t=> AC[isEnabled:$bool1] delete: $str2\n\t=> $str3" },
            { "$str1\n\t=> AC[enabled:$bool1] delete: $str2\n\t=> $str3" },
        )
    }

    fun logAvalancheStage(stage: String, key: String) {
        buffer.log(
            TAG,
            INFO,
            {
                str1 = stage
                str2 = key
            },
            { "[AC] $str1 $str2" },
        )
    }

    fun logAvalancheDuration(thisKey: String, duration: Int, reason: String, nextKey: String) {
        buffer.log(
            TAG,
            INFO,
            {
                str1 = thisKey
                int1 = duration
                str2 = reason
                str3 = nextKey
            },
            { "[AC] $str1 | $int1 ms | $str2 $str3" },
        )
        )
    }
    }