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

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

Merge "Log UiEvents for visual suppression during avalanche" into main

parents 13c7e05e 3f77862c
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
@@ -241,12 +243,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),
@@ -266,6 +268,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
@@ -287,41 +327,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
@@ -178,7 +178,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
@@ -91,7 +91,8 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        avalancheProvider.startTime = whenAgo(10)

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

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

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

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

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

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

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

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

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