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

Commit a8526c89 authored by Jeff DeCew's avatar Jeff DeCew Committed by Android (Google) Code Review
Browse files

Merge "ktfmt files" into main

parents b69195f6 3c48c462
Loading
Loading
Loading
Loading
+48 −54
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.eq
import com.android.systemui.util.mockito.withArgCaptor
import com.android.systemui.util.time.FakeSystemClock
import java.util.function.Consumer
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
@@ -81,11 +82,9 @@ import org.mockito.Mockito.mock
import org.mockito.Mockito.never
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
import org.mockito.Mockito.`when` as whenever
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.argumentCaptor
import java.util.function.Consumer
import org.mockito.Mockito.`when` as whenever


@SmallTest
@RunWith(AndroidJUnit4::class)
@@ -112,14 +111,19 @@ class HeadsUpCoordinatorTest : SysuiTestCase() {

    private val notifPipeline: NotifPipeline = mock(NotifPipeline::class.java)
    private val logger = HeadsUpCoordinatorLogger(logcatLogBuffer(), verbose = true)
    private val interruptLogger: VisualInterruptionDecisionLogger = mock(VisualInterruptionDecisionLogger::class.java)
    private val interruptLogger: VisualInterruptionDecisionLogger =
        mock(VisualInterruptionDecisionLogger::class.java)
    private val headsUpManager = kosmos.mockHeadsUpManager
    private val headsUpViewBinder: HeadsUpViewBinder = mock(HeadsUpViewBinder::class.java)
    private val visualInterruptionDecisionProvider: VisualInterruptionDecisionProvider = mock(VisualInterruptionDecisionProvider::class.java)
    private val remoteInputManager: NotificationRemoteInputManager = mock(NotificationRemoteInputManager::class.java)
    private val endLifetimeExtension: OnEndLifetimeExtensionCallback = mock(OnEndLifetimeExtensionCallback::class.java)
    private val visualInterruptionDecisionProvider: VisualInterruptionDecisionProvider =
        mock(VisualInterruptionDecisionProvider::class.java)
    private val remoteInputManager: NotificationRemoteInputManager =
        mock(NotificationRemoteInputManager::class.java)
    private val endLifetimeExtension: OnEndLifetimeExtensionCallback =
        mock(OnEndLifetimeExtensionCallback::class.java)
    private val headerController: NodeController = mock(NodeController::class.java)
    private val launchFullScreenIntentProvider: LaunchFullScreenIntentProvider = mock(LaunchFullScreenIntentProvider::class.java)
    private val launchFullScreenIntentProvider: LaunchFullScreenIntentProvider =
        mock(LaunchFullScreenIntentProvider::class.java)
    private val flags: NotifPipelineFlags = mock(NotifPipelineFlags::class.java)

    private lateinit var entry: NotificationEntry
@@ -196,45 +200,36 @@ class HeadsUpCoordinatorTest : SysuiTestCase() {
        notifLifetimeExtender.setCallback(endLifetimeExtension)
        entry = NotificationEntryBuilder().build()
        // Same summary we can use for either set of children
        groupSummary = kosmos.buildSummaryNotificationEntry {
            modifyNotification(context)
                .setGroupAlertBehavior(GROUP_ALERT_ALL)
                .setWhen(500)
        groupSummary =
            kosmos.buildSummaryNotificationEntry {
                modifyNotification(context).setGroupAlertBehavior(GROUP_ALERT_ALL).setWhen(500)
            }
        // One set of children with GROUP_ALERT_SUMMARY
        groupPriority = kosmos.buildChildNotificationEntry() {
            modifyNotification(context)
                .setGroupAlertBehavior(GROUP_ALERT_SUMMARY)
                .setWhen(400)
            updateSbn {
                setTag("priority")
            }
        groupPriority =
            kosmos.buildChildNotificationEntry() {
                modifyNotification(context).setGroupAlertBehavior(GROUP_ALERT_SUMMARY).setWhen(400)
                updateSbn { setTag("priority") }
            }
        groupSibling1 = kosmos.buildChildNotificationEntry() {
            modifyNotification(context)
                .setGroupAlertBehavior(GROUP_ALERT_SUMMARY)
                .setWhen(300)
        groupSibling1 =
            kosmos.buildChildNotificationEntry() {
                modifyNotification(context).setGroupAlertBehavior(GROUP_ALERT_SUMMARY).setWhen(300)
            }
        groupSibling2 = kosmos.buildChildNotificationEntry() {
            modifyNotification(context)
                .setGroupAlertBehavior(GROUP_ALERT_SUMMARY)
                .setWhen(200)
        groupSibling2 =
            kosmos.buildChildNotificationEntry() {
                modifyNotification(context).setGroupAlertBehavior(GROUP_ALERT_SUMMARY).setWhen(200)
            }
        // Another set of children with GROUP_ALERT_ALL
        groupChild1 = kosmos.buildChildNotificationEntry() {
            modifyNotification(context)
                .setGroupAlertBehavior(GROUP_ALERT_ALL)
                .setWhen(350)
        groupChild1 =
            kosmos.buildChildNotificationEntry() {
                modifyNotification(context).setGroupAlertBehavior(GROUP_ALERT_ALL).setWhen(350)
            }
        groupChild2 = kosmos.buildChildNotificationEntry() {
            modifyNotification(context)
                .setGroupAlertBehavior(GROUP_ALERT_ALL)
                .setWhen(250)
        groupChild2 =
            kosmos.buildChildNotificationEntry() {
                modifyNotification(context).setGroupAlertBehavior(GROUP_ALERT_ALL).setWhen(250)
            }
        groupChild3 = kosmos.buildChildNotificationEntry() {
            modifyNotification(context)
                .setGroupAlertBehavior(GROUP_ALERT_ALL)
                .setWhen(150)
        groupChild3 =
            kosmos.buildChildNotificationEntry() {
                modifyNotification(context).setGroupAlertBehavior(GROUP_ALERT_ALL).setWhen(150)
            }
        // Set the default HUN decision
        setDefaultShouldHeadsUp(false)
@@ -967,9 +962,9 @@ class HeadsUpCoordinatorTest : SysuiTestCase() {
    private fun helpTestNoTransferToBundleChildForChannel(channelId: String) {
        // Set up for normal alert transfer from summary to child
        // but here child is classified so it should not happen
        val bundleChild = kosmos.buildChildNotificationEntry() {
            modifyNotification(context)
                .setGroupAlertBehavior(GROUP_ALERT_SUMMARY)
        val bundleChild =
            kosmos.buildChildNotificationEntry() {
                modifyNotification(context).setGroupAlertBehavior(GROUP_ALERT_SUMMARY)
                setChannel(NotificationChannel(channelId, channelId, IMPORTANCE_LOW))
            }
        setShouldHeadsUp(bundleChild, true)
@@ -990,8 +985,7 @@ class HeadsUpCoordinatorTest : SysuiTestCase() {

        // Capture last param
        val decision = withArgCaptor {
            verify(interruptLogger)
                .logDecision(capture(), capture(), capture())
            verify(interruptLogger).logDecision(capture(), capture(), capture())
        }
        assertFalse(decision.shouldInterrupt)
        assertEquals(decision.logReason, "disqualified-transfer-target")
+2 −4
Original line number Diff line number Diff line
@@ -86,10 +86,8 @@ constructor(
        val eventLogData: EventLogData?
    }

    class DecisionImpl(
        override val shouldInterrupt: Boolean,
        override val logReason: String,
    ) : Decision
    class DecisionImpl(override val shouldInterrupt: Boolean, override val logReason: String) :
        Decision

    private data class LoggableDecision
    private constructor(
+31 −56
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.interruption.VisualInterruptionType.BUBBLE
import com.android.systemui.statusbar.notification.interruption.VisualInterruptionType.PEEK
import com.android.systemui.statusbar.notification.interruption.VisualInterruptionType.PULSE
import java.util.Optional
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.any
@@ -41,7 +42,6 @@ import org.mockito.Mockito.times
import org.mockito.Mockito.verify
import org.mockito.Mockito.`when`
import org.mockito.kotlin.whenever
import java.util.Optional

@SmallTest
@RunWith(AndroidJUnit4::class)
@@ -70,7 +70,7 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
            Optional.of(bubbles),
            context,
            notificationManager,
            settingsInteractor
            settingsInteractor,
        )
    }

@@ -100,8 +100,14 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro

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

@@ -151,9 +157,7 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
    fun testAvalancheFilter_duringAvalanche_allowConversationFromAfterEvent() {
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            getAvalancheSuppressor()
        ) {
        withFilter(getAvalancheSuppressor()) {
            ensurePeekState()
            assertShouldHeadsUp(
                buildEntry {
@@ -170,9 +174,7 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
    fun testAvalancheFilter_duringAvalanche_suppressConversationFromBeforeEvent() {
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            getAvalancheSuppressor()
        ) {
        withFilter(getAvalancheSuppressor()) {
            ensurePeekState()
            assertShouldNotHeadsUp(
                buildEntry {
@@ -189,9 +191,7 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
    fun testAvalancheFilter_duringAvalanche_allowHighPriorityConversation() {
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            getAvalancheSuppressor()
        ) {
        withFilter(getAvalancheSuppressor()) {
            ensurePeekState()
            assertShouldHeadsUp(
                buildEntry {
@@ -206,9 +206,7 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
    fun testAvalancheFilter_duringAvalanche_allowCall() {
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            getAvalancheSuppressor()
        ) {
        withFilter(getAvalancheSuppressor()) {
            ensurePeekState()
            assertShouldHeadsUp(
                buildEntry {
@@ -223,9 +221,7 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
    fun testAvalancheFilter_duringAvalanche_allowCategoryReminder() {
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            getAvalancheSuppressor()
        ) {
        withFilter(getAvalancheSuppressor()) {
            ensurePeekState()
            assertShouldHeadsUp(
                buildEntry {
@@ -240,9 +236,7 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
    fun testAvalancheFilter_duringAvalanche_allowCategoryEvent() {
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            getAvalancheSuppressor()
        ) {
        withFilter(getAvalancheSuppressor()) {
            ensurePeekState()
            assertShouldHeadsUp(
                buildEntry {
@@ -257,9 +251,7 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
    fun testAvalancheFilter_duringAvalanche_allowCategoryAlarm() {
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            getAvalancheSuppressor()
        ) {
        withFilter(getAvalancheSuppressor()) {
            ensurePeekState()
            assertShouldHeadsUp(
                buildEntry {
@@ -274,15 +266,12 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
    fun testAvalancheFilter_duringAvalanche_allowCategoryCarEmergency() {
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            getAvalancheSuppressor()
        ) {
        withFilter(getAvalancheSuppressor()) {
            ensurePeekState()
            assertShouldHeadsUp(
                buildEntry {
                    importance = NotificationManager.IMPORTANCE_HIGH
                    category = CATEGORY_CAR_EMERGENCY

                }
            )
        }
@@ -292,9 +281,7 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
    fun testAvalancheFilter_duringAvalanche_allowCategoryCarWarning() {
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            getAvalancheSuppressor()
        ) {
        withFilter(getAvalancheSuppressor()) {
            ensurePeekState()
            assertShouldHeadsUp(
                buildEntry {
@@ -309,20 +296,14 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
    fun testAvalancheFilter_duringAvalanche_allowFsi() {
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            getAvalancheSuppressor()
        ) {
            assertFsiNotSuppressed()
        }
        withFilter(getAvalancheSuppressor()) { assertFsiNotSuppressed() }
    }

    @Test
    fun testAvalancheFilter_duringAvalanche_allowColorized() {
        avalancheProvider.startTime = whenAgo(10)

        withFilter(
            getAvalancheSuppressor()
        ) {
        withFilter(getAvalancheSuppressor()) {
            ensurePeekState()
            assertShouldHeadsUp(
                buildEntry {
@@ -337,9 +318,10 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro
        `when`(
                packageManager.checkPermission(
                    org.mockito.Mockito.eq(permission.RECEIVE_EMERGENCY_BROADCAST),
                anyString()
                    anyString(),
                )
            )
        ).thenReturn(if (allow) PERMISSION_GRANTED else PERMISSION_DENIED)
            .thenReturn(if (allow) PERMISSION_GRANTED else PERMISSION_DENIED)
    }

    @Test
@@ -348,19 +330,12 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro

        setAllowedEmergencyPkg(true)

        withFilter(
            getAvalancheSuppressor()
        ) {
        withFilter(getAvalancheSuppressor()) {
            ensurePeekState()
            assertShouldHeadsUp(
                buildEntry {
                    importance = NotificationManager.IMPORTANCE_HIGH
                }
            )
            assertShouldHeadsUp(buildEntry { importance = NotificationManager.IMPORTANCE_HIGH })
        }
    }


    @Test
    fun testPeekCondition_suppressesOnlyPeek() {
        withCondition(TestCondition(types = setOf(PEEK)) { true }) {
@@ -516,14 +491,14 @@ class VisualInterruptionDecisionProviderImplTest : VisualInterruptionDecisionPro

    private class TestCondition(
        types: Set<VisualInterruptionType>,
        val onShouldSuppress: () -> Boolean
        val onShouldSuppress: () -> Boolean,
    ) : VisualInterruptionCondition(types = types, reason = "test condition") {
        override fun shouldSuppress(): Boolean = onShouldSuppress()
    }

    private class TestFilter(
        types: Set<VisualInterruptionType>,
        val onShouldSuppress: (NotificationEntry) -> Boolean = { true }
        val onShouldSuppress: (NotificationEntry) -> Boolean = { true },
    ) : VisualInterruptionFilter(types = types, reason = "test filter") {
        override fun shouldSuppress(entry: NotificationEntry) = onShouldSuppress(entry)
    }