diff --git a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt index 6fa9e40f4..02728244e 100644 --- a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt +++ b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt @@ -16,6 +16,7 @@ import kotlinx.coroutines.Deferred import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.async +import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import mozilla.appservices.Megazord import mozilla.components.concept.push.PushProcessor @@ -110,6 +111,19 @@ open class FenixApplication : Application() { registerActivityLifecycleCallbacks(visibilityLifecycleCallback) components.core.sessionManager.register(NotificationSessionObserver(this)) + + if ((System.currentTimeMillis() - this.settings.lastPlacesStorageMaintenance) > ONE_DAY_MILLIS) { + runStorageMaintenance() + } + } + + private fun runStorageMaintenance() { + GlobalScope.launch(Dispatchers.IO) { + // Bookmarks and history storage sit on top of the same db file so we only need to + // run maintenance on one - arbitrarily using bookmarks. + components.core.bookmarksStorage.runMaintenance() + } + this.settings.lastPlacesStorageMaintenance = System.currentTimeMillis() } private fun registerRxExceptionHandling() { @@ -288,9 +302,14 @@ open class FenixApplication : Application() { .detectActivityLeaks() .detectFileUriExposure() .penaltyLog() - if (SDK_INT >= Build.VERSION_CODES.O) builder = builder.detectContentUriWithoutPermission() + if (SDK_INT >= Build.VERSION_CODES.O) builder = + builder.detectContentUriWithoutPermission() if (SDK_INT >= Build.VERSION_CODES.P) builder = builder.detectNonSdkApiUsage() StrictMode.setVmPolicy(builder.build()) } } + + companion object { + private const val ONE_DAY_MILLIS = 24 * 60 * 60 * 1000 + } } diff --git a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt index 026e82a09..5c3a3506c 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -16,6 +16,7 @@ import mozilla.components.support.ktx.android.content.PreferencesHolder import mozilla.components.support.ktx.android.content.booleanPreference import mozilla.components.support.ktx.android.content.floatPreference import mozilla.components.support.ktx.android.content.intPreference +import mozilla.components.support.ktx.android.content.longPreference import mozilla.components.support.ktx.android.content.stringPreference import org.mozilla.fenix.BuildConfig import org.mozilla.fenix.Config @@ -268,6 +269,11 @@ class Settings private constructor( default = true ) + var lastPlacesStorageMaintenance by longPreference( + appContext.getPreferenceKey(R.string.pref_key_last_maintenance), + default = 0 + ) + fun addSearchWidgetInstalled(count: Int) { val key = appContext.getPreferenceKey(R.string.pref_key_search_widget_installed) val newValue = preferences.getInt(key, 0) + count diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index a935fb88d..9fe6d7796 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -25,6 +25,7 @@ pref_key_delete_permissions_on_quit pref_key_delete_browsing_data_on_quit_categories + pref_key_last_maintenance pref_key_help pref_key_rate pref_key_feedback