From 6a41b922e3b6defc5b832b829e62ab54ec179dca Mon Sep 17 00:00:00 2001 From: ajp_anton Date: Mon, 27 Jul 2026 22:08:25 +0000 Subject: [PATCH] Filter group summary cancellation logs --- .../capture/GroupSummaryPolicy.kt | 12 +++++++++++- .../capture/NotificationCaptureService.kt | 2 +- .../capture/GroupSummaryPolicyTest.kt | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/se/ajpanton/notificationlog/capture/GroupSummaryPolicy.kt b/app/src/main/java/se/ajpanton/notificationlog/capture/GroupSummaryPolicy.kt index 4ea3340..e7168e8 100644 --- a/app/src/main/java/se/ajpanton/notificationlog/capture/GroupSummaryPolicy.kt +++ b/app/src/main/java/se/ajpanton/notificationlog/capture/GroupSummaryPolicy.kt @@ -1,7 +1,17 @@ package se.ajpanton.notificationlog.capture +import se.ajpanton.notificationlog.model.NotificationAction + /** Applies the global, Android-provided group-summary classification without inspecting text. */ object GroupSummaryPolicy { fun shouldLog(snapshot: NotificationSnapshot, logGroupSummaries: Boolean): Boolean = - logGroupSummaries || !snapshot.isGroupSummary + shouldLog(snapshot, action = null, logGroupSummaries) + + fun shouldLog( + snapshot: NotificationSnapshot, + action: NotificationAction?, + logGroupSummaries: Boolean, + ): Boolean = logGroupSummaries || ( + !snapshot.isGroupSummary && action != NotificationAction.GROUP_SUMMARY_CANCELLED + ) } diff --git a/app/src/main/java/se/ajpanton/notificationlog/capture/NotificationCaptureService.kt b/app/src/main/java/se/ajpanton/notificationlog/capture/NotificationCaptureService.kt index dbd05a8..c2e9649 100644 --- a/app/src/main/java/se/ajpanton/notificationlog/capture/NotificationCaptureService.kt +++ b/app/src/main/java/se/ajpanton/notificationlog/capture/NotificationCaptureService.kt @@ -85,7 +85,7 @@ class NotificationCaptureService : NotificationListenerService() { includeContents: Boolean, previousSnapshot: NotificationSnapshot? = null, ) { - if (!GroupSummaryPolicy.shouldLog(snapshot, captureSettings.logGroupSummaries)) return + if (!GroupSummaryPolicy.shouldLog(snapshot, action, captureSettings.logGroupSummaries)) return if (!allows(loggingType, snapshot.packageName)) return val appName = appName(snapshot.packageName) val retainImage = includeContents && snapshot.imageBytes != null && allows(LoggingType.IMAGE_CONTENT, snapshot.packageName) diff --git a/app/src/test/java/se/ajpanton/notificationlog/capture/GroupSummaryPolicyTest.kt b/app/src/test/java/se/ajpanton/notificationlog/capture/GroupSummaryPolicyTest.kt index b6e0b71..4cca09d 100644 --- a/app/src/test/java/se/ajpanton/notificationlog/capture/GroupSummaryPolicyTest.kt +++ b/app/src/test/java/se/ajpanton/notificationlog/capture/GroupSummaryPolicyTest.kt @@ -3,6 +3,7 @@ package se.ajpanton.notificationlog.capture import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test +import se.ajpanton.notificationlog.model.NotificationAction class GroupSummaryPolicyTest { private fun snapshot(isGroupSummary: Boolean) = NotificationSnapshot( @@ -23,4 +24,21 @@ class GroupSummaryPolicyTest { assertFalse(GroupSummaryPolicy.shouldLog(snapshot(isGroupSummary = true), logGroupSummaries = false)) assertTrue(GroupSummaryPolicy.shouldLog(snapshot(isGroupSummary = false), logGroupSummaries = false)) } + + @Test fun `group summary cancellation is hidden when group summaries are disabled`() { + assertFalse( + GroupSummaryPolicy.shouldLog( + snapshot(isGroupSummary = false), + NotificationAction.GROUP_SUMMARY_CANCELLED, + logGroupSummaries = false, + ), + ) + assertTrue( + GroupSummaryPolicy.shouldLog( + snapshot(isGroupSummary = false), + NotificationAction.GROUP_SUMMARY_CANCELLED, + logGroupSummaries = true, + ), + ) + } }