diff --git a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt index 06acac6c20..d4a12f1aa8 100644 --- a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt +++ b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt @@ -121,4 +121,9 @@ object FeatureFlags { * Enables the save to PDF feature. */ const val saveToPDF = true + + /** + * Enables storage maintenance feature + * */ + val storageMaintenanceFeature = Config.channel.isNightlyOrDebug } diff --git a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt index 192f4b8107..38353ba59b 100644 --- a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt +++ b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt @@ -28,6 +28,7 @@ import mozilla.appservices.Megazord import mozilla.components.browser.state.action.SystemAction import mozilla.components.browser.state.selector.selectedTab import mozilla.components.browser.state.store.BrowserStore +import mozilla.components.browser.storage.sync.GlobalPlacesDependencyProvider import mozilla.components.concept.base.crash.Breadcrumb import mozilla.components.concept.engine.webextension.WebExtension import mozilla.components.concept.engine.webextension.isUnsupported @@ -210,6 +211,14 @@ open class FenixApplication : LocaleAwareApplication(), Provider { components.core.engine.warmUp() } initializeWebExtensionSupport() + if (FeatureFlags.storageMaintenanceFeature) { + // Make sure to call this function before registering a storage worker + // (e.g. components.core.historyStorage.registerStorageMaintenanceWorker()) + // as the storage maintenance worker needs a places storage globally when + // it is needed while the app is not running and WorkManager wakes up the app + // for the periodic task. + GlobalPlacesDependencyProvider.initialize(components.core.historyStorage) + } restoreBrowserState() restoreDownloads() @@ -229,12 +238,6 @@ open class FenixApplication : LocaleAwareApplication(), Provider { registerActivityLifecycleCallbacks(visibilityLifecycleCallback) registerActivityLifecycleCallbacks(MarkersActivityLifecycleCallbacks(components.core.engine)) - // Storage maintenance disabled, for now, as it was interfering with background migrations. - // See https://github.com/mozilla-mobile/fenix/issues/7227 for context. - // if ((System.currentTimeMillis() - settings().lastPlacesStorageMaintenance) > ONE_DAY_MILLIS) { - // runStorageMaintenance() - // } - components.appStartReasonProvider.registerInAppOnCreate(this) components.startupActivityLog.registerInAppOnCreate(this) initVisualCompletenessQueueAndQueueTasks() @@ -343,6 +346,18 @@ open class FenixApplication : LocaleAwareApplication(), Provider { } } + fun queueStorageMaintenance() { + if (FeatureFlags.storageMaintenanceFeature) { + queue.runIfReadyOrQueue { + // Make sure GlobalPlacesDependencyProvider.initialize(components.core.historyStorage) + // is called before this call. When app is not running and WorkManager wakes up + // the app for the periodic task, it will require a globally provided places storage + // to run the maintenance on. + components.core.historyStorage.registerStorageMaintenanceWorker() + } + } + } + initQueue() // We init these items in the visual completeness queue to avoid them initing in the critical @@ -351,6 +366,7 @@ open class FenixApplication : LocaleAwareApplication(), Provider { queueMetrics() queueReviewPrompt() queueRestoreLocale() + queueStorageMaintenance() } private fun startMetricsIfEnabled() { @@ -363,20 +379,6 @@ open class FenixApplication : LocaleAwareApplication(), Provider { } } - // See https://github.com/mozilla-mobile/fenix/issues/7227 for context. - // To re-enable this, we need to do so in a way that won't interfere with any startup operations - // which acquire reserved+ sqlite lock. Currently, Fennec migrations need to write to storage - // on startup, and since they run in a background service we can't simply order these operations. - // @OptIn(DelicateCoroutinesApi::class) // GlobalScope usage - // 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() - // } - // settings().lastPlacesStorageMaintenance = System.currentTimeMillis() - // } - protected open fun setupLeakCanary() { // no-op, LeakCanary is disabled by default } 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 14b0b4023d..597efc641b 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -1035,11 +1035,6 @@ class Settings(private val appContext: Context) : PreferencesHolder { 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 ca7b8a329f..c01bd3dfc5 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -38,7 +38,6 @@ pref_key_addons pref_key_override_amo_user pref_key_override_amo_collection - pref_key_last_maintenance pref_key_help pref_key_rate pref_key_about