diff --git a/vector/src/fdroid/java/im/vector/app/fdroid/receiver/AlarmSyncBroadcastReceiver.kt b/vector/src/fdroid/java/im/vector/app/fdroid/receiver/AlarmSyncBroadcastReceiver.kt index 674e7dfef5..1b5c71d952 100644 --- a/vector/src/fdroid/java/im/vector/app/fdroid/receiver/AlarmSyncBroadcastReceiver.kt +++ b/vector/src/fdroid/java/im/vector/app/fdroid/receiver/AlarmSyncBroadcastReceiver.kt @@ -26,28 +26,20 @@ import androidx.core.content.ContextCompat import androidx.core.content.getSystemService import im.vector.app.core.di.HasVectorInjector import im.vector.app.core.services.VectorSyncService -import im.vector.app.features.settings.VectorPreferences import org.matrix.android.sdk.internal.session.sync.job.SyncService import timber.log.Timber class AlarmSyncBroadcastReceiver : BroadcastReceiver() { - lateinit var vectorPreferences: VectorPreferences - override fun onReceive(context: Context, intent: Intent) { - val appContext = context.applicationContext - if (appContext is HasVectorInjector) { - val activeSession = appContext.injector().activeSessionHolder().getSafeActiveSession() - if (activeSession == null) { - Timber.v("No active session don't launch sync service.") - return - } - vectorPreferences = appContext.injector().vectorPreferences() - } + Timber.d("## Sync: AlarmSyncBroadcastReceiver received intent") + val vectorPreferences = (context.applicationContext as? HasVectorInjector) + ?.injector() + ?.takeIf { it.activeSessionHolder().getSafeActiveSession() != null } + ?.vectorPreferences() + ?: return Unit.also { Timber.v("No active session, so don't launch sync service.") } val sessionId = intent.getStringExtra(SyncService.EXTRA_SESSION_ID) ?: return - // This method is called when the BroadcastReceiver is receiving an Intent broadcast. - Timber.d("RestartBroadcastReceiver received intent") VectorSyncService.newPeriodicIntent(context, sessionId, vectorPreferences.backgroundSyncTimeOut(), vectorPreferences.backgroundSyncDelay()).let { try { ContextCompat.startForegroundService(context, it)