Route notification alerts through playback

This commit is contained in:
ajp_anton
2026-08-18 01:32:56 +00:00
parent 0089f839e3
commit 6aab879dbd
14 changed files with 251 additions and 32 deletions
@@ -0,0 +1,50 @@
package se.ajpanton.notificationsmaster.alerts
import android.content.ComponentName
import android.content.pm.PackageManager
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Test
import se.ajpanton.notificationsmaster.capture.NotificationCaptureService
import se.ajpanton.notificationsmaster.settings.LoggingRule
import se.ajpanton.notificationsmaster.settings.LoggingRuleStore
import se.ajpanton.notificationsmaster.settings.LoggingType
class AlertListenerPolicyDeviceTest {
private val context = InstrumentationRegistry.getInstrumentation().targetContext
private val component = ComponentName(context, NotificationCaptureService::class.java)
@After
fun restoreDefaults() {
LoggingType.entries.forEach { LoggingRuleStore(context).save(it, LoggingRule()) }
AlertConfigurationStore(context).save(AlertConfiguration())
}
@Test
fun alertRuleKeepsListenerEnabledWithoutLogging() {
LoggingType.entries.forEach { LoggingRuleStore(context).save(it, LoggingRule(enabled = false)) }
val profile = AlertProfile("profile", "Profile", vibrationPattern = listOf(0, 10))
val configuration = AlertConfiguration(
profiles = listOf(profile),
rules = listOf(
AlertRule(
"rule", "example.app", 0, setOf(AlertSource.NOTIFICATION_POST),
outcome = AlertOutcome.PLAY_PROFILE, profileId = profile.id,
),
),
)
AlertConfigurationStore(context).save(configuration)
assertEquals(
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
context.packageManager.getComponentEnabledSetting(component),
)
AlertConfigurationStore(context).save(AlertConfiguration())
assertEquals(
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
context.packageManager.getComponentEnabledSetting(component),
)
}
}