Clean stale per-app storage on startup

This commit is contained in:
ajp_anton
2026-07-27 13:51:10 +00:00
parent 1e4315d3dd
commit dca86ae393
5 changed files with 70 additions and 17 deletions
@@ -0,0 +1,23 @@
package se.ajpanton.notificationlog
import android.app.Application
import android.content.pm.PackageManager
import se.ajpanton.notificationlog.data.EncryptedNotificationLogStore
import se.ajpanton.notificationlog.settings.AppFilterSettingsStore
import se.ajpanton.notificationlog.settings.PerAppEventSettingsStore
class NotificationLogApplication : Application() {
override fun onCreate() {
super.onCreate()
Thread(::removeStaleAppStorage, "notification-log-storage-cleanup").start()
}
private fun removeStaleAppStorage() {
val installedPackages = packageManager.getInstalledApplications(
PackageManager.ApplicationInfoFlags.of(0),
).mapTo(mutableSetOf()) { it.packageName }
AppFilterSettingsStore(this).removeUninstalledPackages(installedPackages)
PerAppEventSettingsStore(this).removeUninstalledPackages(installedPackages)
EncryptedNotificationLogStore(this).removeOrphanedImages()
}
}