Close #7227: Re-enable storage maintenance call.

Re-enable storage maintenance call by introducing WorkManager worker on A-C side and consuming it from Fenix.
The work request is periodic and the repeat interval is 24h. It requires the device to be idle and not to have
low battery. This feature is available only for Nightly for now.
pull/543/head
kycn 2 years ago committed by mergify[bot]
parent 408d15af9b
commit dda6719c32

@ -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
}

@ -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
}

@ -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

@ -38,7 +38,6 @@
<string name="pref_key_addons" translatable="false">pref_key_addons</string>
<string name="pref_key_override_amo_user" translatable="false">pref_key_override_amo_user</string>
<string name="pref_key_override_amo_collection" translatable="false">pref_key_override_amo_collection</string>
<string name="pref_key_last_maintenance" translatable="false">pref_key_last_maintenance</string>
<string name="pref_key_help" translatable="false">pref_key_help</string>
<string name="pref_key_rate" translatable="false">pref_key_rate</string>
<string name="pref_key_about" translatable="false">pref_key_about</string>

Loading…
Cancel
Save