Filter group summary cancellation logs
This commit is contained in:
@@ -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
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user