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

Commit 6c48fdbf authored by Lyn Han's avatar Lyn Han Committed by Android (Google) Code Review
Browse files

Merge "Log reason why HUN was allowed during avalanche" into main

parents 82df6d16 445ee4d6
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -45,7 +45,6 @@ import android.provider.Settings.Global.HEADS_UP_OFF
import android.service.notification.Flags
import com.android.internal.logging.UiEvent
import com.android.internal.logging.UiEventLogger
import com.android.internal.logging.UiEventLogger.UiEventEnum.RESERVE_NEW_UI_EVENT_ID
import com.android.internal.messages.nano.SystemMessageProto.SystemMessage
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.plugins.statusbar.StatusBarStateController
@@ -279,7 +278,8 @@ class AvalancheSuppressor(
    private val packageManager: PackageManager,
    private val uiEventLogger: UiEventLogger,
    private val context: Context,
    private val notificationManager: NotificationManager
    private val notificationManager: NotificationManager,
    private val logger: VisualInterruptionDecisionLogger
) :
    VisualInterruptionFilter(
        types = setOf(PEEK, PULSE),
@@ -354,15 +354,18 @@ class AvalancheSuppressor(

    override fun shouldSuppress(entry: NotificationEntry): Boolean {
        if (!isCooldownEnabled()) {
            logger.logAvalancheAllow("cooldown OFF")
            return false
        }
        val timeSinceAvalancheMs = systemClock.currentTimeMillis() - avalancheProvider.startTime
        val timedOut = timeSinceAvalancheMs >= avalancheProvider.timeoutMs
        if (timedOut) {
            logger.logAvalancheAllow("timedOut! timeSinceAvalancheMs=$timeSinceAvalancheMs")
            return false
        }
        val state = calculateState(entry)
        if (state != State.SUPPRESS) {
            logger.logAvalancheAllow("state=$state")
            return false
        }
        if (shouldShowEdu()) {
+9 −0
Original line number Diff line number Diff line
@@ -93,6 +93,15 @@ constructor(@NotificationInterruptLog val buffer: LogBuffer) {
            }
        )
    }

    fun logAvalancheAllow(info: String) {
        buffer.log(
            TAG,
            INFO,
            { str1 = info },
            { "AvalancheSuppressor: $str1" }
        )
    }
}

private const val TAG = "VisualInterruptionDecisionProvider"
+2 −1
Original line number Diff line number Diff line
@@ -194,7 +194,8 @@ constructor(
                    packageManager,
                    uiEventLogger,
                    context,
                    notificationManager
                    notificationManager,
                    logger
                )
            )
            avalancheProvider.register()
+21 −32
Original line number Diff line number Diff line
@@ -98,16 +98,20 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
    // instead of VisualInterruptionDecisionProviderTestBase
    // because avalanche code is based on the suppression refactor.

    private fun getAvalancheSuppressor() : AvalancheSuppressor {
        return AvalancheSuppressor(
            avalancheProvider, systemClock, settingsInteractor, packageManager,
            uiEventLogger, context, notificationManager, logger
        )
    }

    @Test
    fun testAvalancheFilter_suppress_hasNotSeenEdu_showEduHun() {
        setAllowedEmergencyPkg(false)
        whenever(avalancheProvider.timeoutMs).thenReturn(20)
        whenever(avalancheProvider.startTime).thenReturn(whenAgo(10))

        val avalancheSuppressor = AvalancheSuppressor(
            avalancheProvider, systemClock, settingsInteractor, packageManager,
            uiEventLogger, context, notificationManager
        )
        val avalancheSuppressor = getAvalancheSuppressor()
        avalancheSuppressor.hasSeenEdu = false

        withFilter(avalancheSuppressor) {
@@ -128,10 +132,7 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        whenever(avalancheProvider.timeoutMs).thenReturn(20)
        whenever(avalancheProvider.startTime).thenReturn(whenAgo(10))

        val avalancheSuppressor = AvalancheSuppressor(
            avalancheProvider, systemClock, settingsInteractor, packageManager,
            uiEventLogger, context, notificationManager
        )
        val avalancheSuppressor = getAvalancheSuppressor()
        avalancheSuppressor.hasSeenEdu = true

        withFilter(avalancheSuppressor) {
@@ -151,8 +152,7 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            AvalancheSuppressor(avalancheProvider, systemClock, settingsInteractor, packageManager,
                    uiEventLogger, context, notificationManager)
            getAvalancheSuppressor()
        ) {
            ensurePeekState()
            assertShouldHeadsUp(
@@ -171,8 +171,7 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            AvalancheSuppressor(avalancheProvider, systemClock, settingsInteractor, packageManager,
                    uiEventLogger, context, notificationManager)
            getAvalancheSuppressor()
        ) {
            ensurePeekState()
            assertShouldNotHeadsUp(
@@ -191,8 +190,7 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            AvalancheSuppressor(avalancheProvider, systemClock, settingsInteractor, packageManager,
                    uiEventLogger, context, notificationManager)
            getAvalancheSuppressor()
        ) {
            ensurePeekState()
            assertShouldHeadsUp(
@@ -209,8 +207,7 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            AvalancheSuppressor(avalancheProvider, systemClock, settingsInteractor, packageManager,
                    uiEventLogger, context, notificationManager)
            getAvalancheSuppressor()
        ) {
            ensurePeekState()
            assertShouldHeadsUp(
@@ -227,8 +224,7 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            AvalancheSuppressor(avalancheProvider, systemClock, settingsInteractor, packageManager,
                    uiEventLogger, context, notificationManager)
            getAvalancheSuppressor()
        ) {
            ensurePeekState()
            assertShouldHeadsUp(
@@ -245,8 +241,7 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            AvalancheSuppressor(avalancheProvider, systemClock, settingsInteractor, packageManager,
                    uiEventLogger, context, notificationManager)
            getAvalancheSuppressor()
        ) {
            ensurePeekState()
            assertShouldHeadsUp(
@@ -263,8 +258,7 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            AvalancheSuppressor(avalancheProvider, systemClock, settingsInteractor, packageManager,
                uiEventLogger, context, notificationManager)
            getAvalancheSuppressor()
        ) {
            ensurePeekState()
            assertShouldHeadsUp(
@@ -281,8 +275,7 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            AvalancheSuppressor(avalancheProvider, systemClock, settingsInteractor, packageManager,
                uiEventLogger, context, notificationManager)
            getAvalancheSuppressor()
        ) {
            ensurePeekState()
            assertShouldHeadsUp(
@@ -300,8 +293,7 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            AvalancheSuppressor(avalancheProvider, systemClock, settingsInteractor, packageManager,
                uiEventLogger, context, notificationManager)
            getAvalancheSuppressor()
        ) {
            ensurePeekState()
            assertShouldHeadsUp(
@@ -318,8 +310,7 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            AvalancheSuppressor(avalancheProvider, systemClock, settingsInteractor, packageManager,
                    uiEventLogger, context, notificationManager)
            getAvalancheSuppressor()
        ) {
            assertFsiNotSuppressed()
        }
@@ -330,8 +321,7 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            AvalancheSuppressor(avalancheProvider, systemClock, settingsInteractor, packageManager,
                    uiEventLogger, context, notificationManager)
            getAvalancheSuppressor()
        ) {
            ensurePeekState()
            assertShouldHeadsUp(
@@ -359,8 +349,7 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        setAllowedEmergencyPkg(true)

        withFilter(
            AvalancheSuppressor(avalancheProvider, systemClock, settingsInteractor, packageManager,
                    uiEventLogger, context, notificationManager)
            getAvalancheSuppressor()
        ) {
            ensurePeekState()
            assertShouldHeadsUp(
+1 −0
Original line number Diff line number Diff line
@@ -139,6 +139,7 @@ abstract class VisualInterruptionDecisionProviderTestBase : SysuiTestCase() {
    protected val settingsInteractor: NotificationSettingsInteractor = mock()
    protected val packageManager: PackageManager = mock()
    protected val notificationManager: NotificationManager = mock()
    protected val logger: VisualInterruptionDecisionLogger = mock()
    protected abstract val provider: VisualInterruptionDecisionProvider

    private val neverSuppresses = object : NotificationInterruptSuppressor {}