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

Commit 3f77862c authored by Lyn's avatar Lyn
Browse files

Log UiEvents for visual suppression during avalanche

Bug: 330610050
Test: make statsd_testdrive && $ANDROID_HOST_OUT/bin/statsd_testdrive -terse 90
Change-Id: Idd4e06d17d7037ab85837a90b4f458360e080c28
parent 9d07129e
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -21,9 +21,9 @@ import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.util.Log
import com.android.internal.logging.UiEventLogger
import com.android.systemui.broadcast.BroadcastDispatcher
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.util.time.SystemClock
import javax.inject.Inject

// Class to track avalanche trigger event time.
@@ -33,6 +33,7 @@ class AvalancheProvider
constructor(
        private val broadcastDispatcher: BroadcastDispatcher,
        private val logger: VisualInterruptionDecisionLogger,
        private val uiEventLogger: UiEventLogger,
) {
    val TAG = "AvalancheProvider"
    val timeoutMs = 120000
@@ -56,6 +57,7 @@ constructor(
                    return
                }
                Log.d(TAG, "broadcastReceiver received intent.action=" + intent.action)
                uiEventLogger.log(AvalancheSuppressor.AvalancheEvent.START);
                startTime = System.currentTimeMillis()
            }
        }
+50 −5
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ import android.os.PowerManager
import android.provider.Settings
import android.provider.Settings.Global.HEADS_UP_NOTIFICATIONS_ENABLED
import android.provider.Settings.Global.HEADS_UP_OFF
import com.android.internal.logging.UiEventLogger
import com.android.internal.logging.UiEvent;
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.settings.UserTracker
@@ -232,12 +234,12 @@ class AlertKeyguardVisibilitySuppressor(
    override fun shouldSuppress(entry: NotificationEntry) =
        keyguardNotificationVisibilityProvider.shouldHideNotification(entry)
}

class AvalancheSuppressor(
    private val avalancheProvider: AvalancheProvider,
    private val systemClock: SystemClock,
    private val systemSettings: SystemSettings,
    private val packageManager: PackageManager,
    private val uiEventLogger: UiEventLogger,
) :
    VisualInterruptionFilter(
        types = setOf(PEEK, PULSE),
@@ -257,6 +259,44 @@ class AvalancheSuppressor(
        SUPPRESS
    }

     enum class AvalancheEvent(private val id: Int) : UiEventLogger.UiEventEnum {
         @UiEvent(doc = "An avalanche event occurred but this notification was suppressed by a " +
                 "non-avalanche suppressor.")
         START(1802),

         @UiEvent(doc = "HUN was suppressed in avalanche.")
         SUPPRESS(1803),

         @UiEvent(doc = "HUN allowed during avalanche because it is high priority.")
         ALLOW_CONVERSATION_AFTER_AVALANCHE(1804),

         @UiEvent(doc = "HUN allowed during avalanche because it is a high priority conversation.")
         ALLOW_HIGH_PRIORITY_CONVERSATION_ANY_TIME(1805),

         @UiEvent(doc = "HUN allowed during avalanche because it is a call.")
         ALLOW_CALLSTYLE(1806),

         @UiEvent(doc = "HUN allowed during avalanche because it is a calendar notification.")
         ALLOW_CATEGORY_REMINDER(1807),

         @UiEvent(doc = "HUN allowed during avalanche because it is a calendar notification.")
         ALLOW_CATEGORY_EVENT(1808),

         @UiEvent(doc = "HUN allowed during avalanche because it has a full screen intent and " +
                 "the full screen intent permission is granted.")
         ALLOW_FSI_WITH_PERMISSION_ON(1809),

         @UiEvent(doc = "HUN allowed during avalanche because it is colorized.")
         ALLOW_COLORIZED(1810),

         @UiEvent(doc = "HUN allowed during avalanche because it is an emergency notification.")
         ALLOW_EMERGENCY(1811);

        override fun getId(): Int {
            return id
        }
    }

    override fun shouldSuppress(entry: NotificationEntry): Boolean {
        if (!isCooldownEnabled()) {
            return false
@@ -278,41 +318,46 @@ class AvalancheSuppressor(
            entry.ranking.isConversation &&
                entry.sbn.notification.getWhen() > avalancheProvider.startTime
        ) {
            uiEventLogger.log(AvalancheEvent.ALLOW_CONVERSATION_AFTER_AVALANCHE)
            return State.ALLOW_CONVERSATION_AFTER_AVALANCHE
        }

        if (entry.channel?.isImportantConversation == true) {
            uiEventLogger.log(AvalancheEvent.ALLOW_HIGH_PRIORITY_CONVERSATION_ANY_TIME)
            return State.ALLOW_HIGH_PRIORITY_CONVERSATION_ANY_TIME
        }

        if (entry.sbn.notification.isStyle(Notification.CallStyle::class.java)) {
            uiEventLogger.log(AvalancheEvent.ALLOW_CALLSTYLE)
            return State.ALLOW_CALLSTYLE
        }

        if (entry.sbn.notification.category == CATEGORY_REMINDER) {
            uiEventLogger.log(AvalancheEvent.ALLOW_CATEGORY_REMINDER)
            return State.ALLOW_CATEGORY_REMINDER
        }

        if (entry.sbn.notification.category == CATEGORY_EVENT) {
            uiEventLogger.log(AvalancheEvent.ALLOW_CATEGORY_EVENT)
            return State.ALLOW_CATEGORY_EVENT
        }

        if (entry.sbn.notification.fullScreenIntent != null) {
            uiEventLogger.log(AvalancheEvent.ALLOW_FSI_WITH_PERMISSION_ON)
            return State.ALLOW_FSI_WITH_PERMISSION_ON
        }

        if (entry.sbn.notification.isColorized) {
            return State.ALLOW_COLORIZED
        }
        if (entry.sbn.notification.isColorized) {
            uiEventLogger.log(AvalancheEvent.ALLOW_COLORIZED)
            return State.ALLOW_COLORIZED
        }
        if (
            packageManager.checkPermission(RECEIVE_EMERGENCY_BROADCAST, entry.sbn.packageName) ==
                PERMISSION_GRANTED
        ) {
            uiEventLogger.log(AvalancheEvent.ALLOW_EMERGENCY)
            return State.ALLOW_EMERGENCY
        }
        uiEventLogger.log(AvalancheEvent.SUPPRESS)
        return State.SUPPRESS
    }

+2 −1
Original line number Diff line number Diff line
@@ -175,7 +175,8 @@ constructor(

        if (NotificationAvalancheSuppression.isEnabled) {
            addFilter(
                AvalancheSuppressor(avalancheProvider, systemClock, systemSettings, packageManager)
                AvalancheSuppressor(avalancheProvider, systemClock, systemSettings, packageManager,
                        uiEventLogger)
            )
            avalancheProvider.register()
        }
+18 −9
Original line number Diff line number Diff line
@@ -89,7 +89,8 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            AvalancheSuppressor(avalancheProvider, systemClock, systemSettings, packageManager)
            AvalancheSuppressor(avalancheProvider, systemClock, systemSettings, packageManager,
                    uiEventLogger)
        ) {
            ensurePeekState()
            assertShouldHeadsUp(
@@ -108,7 +109,8 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            AvalancheSuppressor(avalancheProvider, systemClock, systemSettings, packageManager)
            AvalancheSuppressor(avalancheProvider, systemClock, systemSettings, packageManager,
                    uiEventLogger)
        ) {
            ensurePeekState()
            assertShouldNotHeadsUp(
@@ -127,7 +129,8 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            AvalancheSuppressor(avalancheProvider, systemClock, systemSettings, packageManager)
            AvalancheSuppressor(avalancheProvider, systemClock, systemSettings, packageManager,
                    uiEventLogger)
        ) {
            ensurePeekState()
            assertShouldHeadsUp(
@@ -144,7 +147,8 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            AvalancheSuppressor(avalancheProvider, systemClock, systemSettings, packageManager)
            AvalancheSuppressor(avalancheProvider, systemClock, systemSettings, packageManager,
                    uiEventLogger)
        ) {
            ensurePeekState()
            assertShouldHeadsUp(
@@ -161,7 +165,8 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            AvalancheSuppressor(avalancheProvider, systemClock, systemSettings, packageManager)
            AvalancheSuppressor(avalancheProvider, systemClock, systemSettings, packageManager,
                    uiEventLogger)
        ) {
            ensurePeekState()
            assertShouldHeadsUp(
@@ -178,7 +183,8 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            AvalancheSuppressor(avalancheProvider, systemClock, systemSettings, packageManager)
            AvalancheSuppressor(avalancheProvider, systemClock, systemSettings, packageManager,
                    uiEventLogger)
        ) {
            ensurePeekState()
            assertShouldHeadsUp(
@@ -195,7 +201,8 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            AvalancheSuppressor(avalancheProvider, systemClock, systemSettings, packageManager)
            AvalancheSuppressor(avalancheProvider, systemClock, systemSettings, packageManager,
                    uiEventLogger)
        ) {
            assertFsiNotSuppressed()
        }
@@ -206,7 +213,8 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            AvalancheSuppressor(avalancheProvider, systemClock, systemSettings, packageManager)
            AvalancheSuppressor(avalancheProvider, systemClock, systemSettings, packageManager,
                    uiEventLogger)
        ) {
            ensurePeekState()
            assertShouldHeadsUp(
@@ -230,7 +238,8 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        ).thenReturn(PERMISSION_GRANTED)

        withFilter(
            AvalancheSuppressor(avalancheProvider, systemClock, systemSettings, packageManager)
            AvalancheSuppressor(avalancheProvider, systemClock, systemSettings, packageManager,
                    uiEventLogger)
        ) {
            ensurePeekState()
            assertShouldHeadsUp(