1
0
mirror of https://github.com/vector-im/riotX-android synced 2025-10-06 00:02:48 +02:00

Restart fdroid sync on application boot

This commit is contained in:
Valere
2020-09-09 10:33:34 +02:00
committed by Benoit Marty
parent 971b425e17
commit 43c24e55ab

View File

@@ -21,6 +21,8 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import im.vector.app.core.di.HasVectorInjector
import im.vector.app.core.extensions.vectorComponent
import im.vector.app.features.settings.BackgroundSyncMode
import timber.log.Timber
class OnApplicationUpgradeOrRebootReceiver : BroadcastReceiver() {
@@ -30,8 +32,23 @@ class OnApplicationUpgradeOrRebootReceiver : BroadcastReceiver() {
val appContext = context.applicationContext
if (appContext is HasVectorInjector) {
val activeSession = appContext.injector().activeSessionHolder().getSafeActiveSession()
val preferences = appContext.vectorComponent().vectorPreferences()
if (activeSession != null) {
AlarmSyncBroadcastReceiver.scheduleAlarm(context, activeSession.sessionId, 10)
when (preferences.getFdroidSyncBackgroundMode()) {
BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_FOR_BATTERY -> {
Timber.i("## Sync: OnBoot Work scheduled to periodically sync")
activeSession.startAutomaticBackgroundSync(
preferences.backgroundSyncTimeOut().toLong(),
preferences.backgroundSyncDelay().toLong()
)
}
BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_FOR_REALTIME -> {
AlarmSyncBroadcastReceiver.scheduleAlarm(context, activeSession.sessionId, preferences.backgroundSyncDelay())
}
BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_DISABLED -> {
// nop
}
}
}
}
}