diff --git a/app/src/main/java/se/ajpanton/notificationlog/NotificationLogApplication.kt b/app/src/main/java/se/ajpanton/notificationlog/NotificationLogApplication.kt index 4e03957..6d7fde5 100644 --- a/app/src/main/java/se/ajpanton/notificationlog/NotificationLogApplication.kt +++ b/app/src/main/java/se/ajpanton/notificationlog/NotificationLogApplication.kt @@ -4,14 +4,32 @@ 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.LoggingRuleStore +import se.ajpanton.notificationlog.settings.LoggingType +import se.ajpanton.notificationlog.settings.NotificationListenerComponentController import se.ajpanton.notificationlog.settings.PerAppEventSettingsStore class NotificationLogApplication : Application() { override fun onCreate() { super.onCreate() + synchronizeListenerComponent() Thread(::removeStaleAppStorage, "notification-log-storage-cleanup").start() } + /** + * Clearing app data resets rule preferences but deliberately does not reset + * PackageManager's enabled/disabled state for the listener component. + * Reconcile it before the UI starts so fresh default rules can bind again. + */ + private fun synchronizeListenerComponent() { + val rules = LoggingRuleStore(this) + NotificationListenerComponentController.update( + this, + LoggingType.entries.map(rules::ruleFor), + PerAppEventSettingsStore(this).hasEnabledEventOverride(), + ) + } + private fun removeStaleAppStorage() { val installedPackages = packageManager.getInstalledApplications( PackageManager.ApplicationInfoFlags.of(0),