Suppress routine notification updates

This commit is contained in:
ajp_anton
2026-07-23 09:52:24 +00:00
parent 4b26f3369e
commit f698871e9a
4 changed files with 20 additions and 1 deletions
@@ -45,7 +45,8 @@ class NotificationCaptureService : NotificationListenerService() {
val previous = activeNotifications.put(snapshot.key, snapshot) val previous = activeNotifications.put(snapshot.key, snapshot)
when { when {
previous == null -> record(snapshot, NotificationAction.APPEARED, LoggingType.APPEARING, includeContents = true) previous == null -> record(snapshot, NotificationAction.APPEARED, LoggingType.APPEARING, includeContents = true)
previous.textContents != snapshot.textContents || previous.hasImage != snapshot.hasImage -> (previous.textContents != snapshot.textContents || previous.hasImage != snapshot.hasImage) &&
!(snapshot.isRoutine && ruleStore.ruleFor(LoggingType.EDITS).ignoreRoutineUpdates) ->
record(snapshot, NotificationAction.EDITED, LoggingType.EDITS, includeContents = true) record(snapshot, NotificationAction.EDITED, LoggingType.EDITS, includeContents = true)
} }
} }
@@ -9,6 +9,7 @@ data class NotificationSnapshot(
val packageName: String, val packageName: String,
val textContents: String?, val textContents: String?,
val hasImage: Boolean, val hasImage: Boolean,
val isRoutine: Boolean,
) )
object NotificationContents { object NotificationContents {
@@ -36,6 +37,8 @@ object NotificationContents {
hasImage = sbn.notification.extras?.let { hasImage = sbn.notification.extras?.let {
it.containsKey(Notification.EXTRA_PICTURE) || it.containsKey(Notification.EXTRA_PICTURE_ICON) it.containsKey(Notification.EXTRA_PICTURE) || it.containsKey(Notification.EXTRA_PICTURE_ICON)
} == true, } == true,
isRoutine = sbn.notification.extras?.getBoolean(Notification.EXTRA_SHOW_CHRONOMETER, false) == true ||
sbn.notification.extras?.containsKey(Notification.EXTRA_PROGRESS) == true,
) )
private fun CharSequence.addTo(parts: MutableSet<String>) { private fun CharSequence.addTo(parts: MutableSet<String>) {
@@ -31,6 +31,11 @@ class LoggingRuleStore(context: Context) {
} }
} }
fun copy(from: LoggingType, targets: Set<LoggingType>) {
val source = ruleFor(from)
targets.filterNot { it == from }.forEach { save(it, source.copy(selectedPackages = source.selectedPackages.toSet())) }
}
private fun key(type: LoggingType, suffix: String) = "${type.name.lowercase()}.$suffix" private fun key(type: LoggingType, suffix: String) = "${type.name.lowercase()}.$suffix"
private companion object { private companion object {
@@ -0,0 +1,10 @@
package se.ajpanton.notificationlog.settings
import org.junit.Assert.assertTrue
import org.junit.Test
class LoggingRuleTest {
@Test fun `routine updates default to ignored`() {
assertTrue(LoggingRule().ignoreRoutineUpdates)
}
}