Restore listener after clearing app data
This commit is contained in:
@@ -4,14 +4,32 @@ import android.app.Application
|
|||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import se.ajpanton.notificationlog.data.EncryptedNotificationLogStore
|
import se.ajpanton.notificationlog.data.EncryptedNotificationLogStore
|
||||||
import se.ajpanton.notificationlog.settings.AppFilterSettingsStore
|
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
|
import se.ajpanton.notificationlog.settings.PerAppEventSettingsStore
|
||||||
|
|
||||||
class NotificationLogApplication : Application() {
|
class NotificationLogApplication : Application() {
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
synchronizeListenerComponent()
|
||||||
Thread(::removeStaleAppStorage, "notification-log-storage-cleanup").start()
|
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() {
|
private fun removeStaleAppStorage() {
|
||||||
val installedPackages = packageManager.getInstalledApplications(
|
val installedPackages = packageManager.getInstalledApplications(
|
||||||
PackageManager.ApplicationInfoFlags.of(0),
|
PackageManager.ApplicationInfoFlags.of(0),
|
||||||
|
|||||||
Reference in New Issue
Block a user