Avoid inactive listener work and eager image encoding

This commit is contained in:
ajp_anton
2026-07-27 22:51:17 +00:00
parent ebb05acc02
commit f31a7c8efe
11 changed files with 78 additions and 39 deletions
@@ -13,7 +13,6 @@ class GroupSummaryPolicyTest {
hasImage = false,
isGroupSummary = isGroupSummary,
isRoutine = false,
imageBytes = null,
)
@Test fun `enabled group-summary logging retains summaries`() {
@@ -7,7 +7,7 @@ import org.junit.Test
class NotificationChangeClassifierTest {
private fun snapshot(text: String, routine: Boolean = false) = NotificationSnapshot(
key = "key", packageName = "example.app", textContents = text, hasImage = false,
isGroupSummary = false, isRoutine = routine, imageBytes = null,
isGroupSummary = false, isRoutine = routine,
)
@Test fun `text change is an edit`() {
@@ -5,20 +5,28 @@ import org.junit.Assert.assertTrue
import org.junit.Test
class NotificationListenerPolicyTest {
@Test fun `listener runs when any logging type is enabled`() {
assertTrue(NotificationListenerPolicy.shouldRun(listOf(LoggingRule(enabled = false), LoggingRule(enabled = true))))
@Test fun `listener runs when any event logging type is enabled`() {
assertTrue(NotificationListenerPolicy.shouldRun(rules(LoggingType.EDITS to true)))
}
@Test fun `listener stays off when every logging type is disabled`() {
assertFalse(NotificationListenerPolicy.shouldRun(LoggingType.entries.map { LoggingRule(enabled = false) }))
assertFalse(NotificationListenerPolicy.shouldRun(rules()))
}
@Test fun `content settings alone do not keep the listener active`() {
assertFalse(NotificationListenerPolicy.shouldRun(rules(LoggingType.TEXT_CONTENT to true, LoggingType.IMAGE_CONTENT to true)))
}
@Test fun `listener runs for an enabled per-app event override`() {
assertTrue(
NotificationListenerPolicy.shouldRun(
LoggingType.entries.map { LoggingRule(enabled = false) },
rules(),
hasEnabledEventOverride = true,
),
)
}
private fun rules(vararg enabled: Pair<LoggingType, Boolean>) = LoggingType.entries.associateWith { type ->
LoggingRule(enabled = enabled.firstOrNull { it.first == type }?.second ?: false)
}
}