35 lines
1.5 KiB
Kotlin
35 lines
1.5 KiB
Kotlin
package se.ajpanton.notificationsmaster
|
|
|
|
import android.app.Application
|
|
import android.content.pm.PackageManager
|
|
import se.ajpanton.notificationsmaster.data.EncryptedNotificationLogStore
|
|
import se.ajpanton.notificationsmaster.settings.AppFilterSettingsStore
|
|
import se.ajpanton.notificationsmaster.settings.NotificationListenerComponentController
|
|
import se.ajpanton.notificationsmaster.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() {
|
|
NotificationListenerComponentController.synchronize(this)
|
|
}
|
|
|
|
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()
|
|
}
|
|
}
|