Complete secure log viewing and retention

This commit is contained in:
ajp_anton
2026-07-23 11:42:56 +00:00
parent 0091eb5d49
commit 8621a30225
6 changed files with 293 additions and 94 deletions
@@ -91,10 +91,17 @@ class NotificationCaptureService : NotificationListenerService() {
writeExecutor.execute {
try {
if (retainImage) {
imageStore.save(entry.imageId!!, snapshot.imageBytes!!)
try {
imageStore.save(entry.imageId!!, snapshot.imageBytes!!)
} catch (error: Exception) {
Log.w(TAG, "Could not retain notification image; keeping the text event", error)
logStore.append(entry.copy(imageId = null))
return@execute
}
}
logStore.append(entry)
} catch (error: Exception) {
entry.imageId?.let(imageStore::delete)
Log.e(TAG, "Could not persist notification log entry", error)
}
}
@@ -107,7 +114,10 @@ class NotificationCaptureService : NotificationListenerService() {
val image = snapshot.hasImage && NotificationRuleEvaluator.allows(
ruleStore.ruleFor(LoggingType.IMAGE_CONTENT), snapshot.packageName,
)
return listOfNotNull(text, if (image) "[image]" else null).joinToString("").ifEmpty { null }
return listOfNotNull(text, if (image) "[image]" else null)
.joinToString("")
.take(MAX_CONTENT_CHARACTERS)
.ifEmpty { null }
}
private fun appName(packageName: String): String = try {
@@ -147,5 +157,6 @@ class NotificationCaptureService : NotificationListenerService() {
private companion object {
const val TAG = "NotificationCapture"
const val MAX_CONTENT_CHARACTERS = 16_000
}
}