Fix F-Droid build

This commit is contained in:
Benoit Marty 2022-05-03 12:34:34 +02:00 committed by Benoit Marty
parent 32bc93c87d
commit cdcaf93fc7
7 changed files with 40 additions and 13 deletions

View file

@ -18,13 +18,17 @@ package im.vector.app.fdroid
import android.content.Context
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.time.Clock
import im.vector.app.fdroid.receiver.AlarmSyncBroadcastReceiver
import im.vector.app.features.settings.BackgroundSyncMode
import im.vector.app.features.settings.VectorPreferences
import timber.log.Timber
object BackgroundSyncStarter {
fun start(context: Context, vectorPreferences: VectorPreferences, activeSessionHolder: ActiveSessionHolder) {
fun start(context: Context,
vectorPreferences: VectorPreferences,
activeSessionHolder: ActiveSessionHolder,
clock: Clock) {
if (vectorPreferences.areNotificationEnabledForDevice()) {
val activeSession = activeSessionHolder.getSafeActiveSession() ?: return
when (vectorPreferences.getFdroidSyncBackgroundMode()) {
@ -38,7 +42,12 @@ object BackgroundSyncStarter {
}
BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_FOR_REALTIME -> {
// We need to use alarm in this mode
AlarmSyncBroadcastReceiver.scheduleAlarm(context, activeSession.sessionId, vectorPreferences.backgroundSyncDelay())
AlarmSyncBroadcastReceiver.scheduleAlarm(
context,
activeSession.sessionId,
vectorPreferences.backgroundSyncDelay(),
clock
)
Timber.i("## Sync: Alarm scheduled to start syncing")
}
BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_DISABLED -> {

View file

@ -27,6 +27,7 @@ import androidx.core.content.getSystemService
import im.vector.app.core.extensions.singletonEntryPoint
import im.vector.app.core.platform.PendingIntentCompat
import im.vector.app.core.services.VectorSyncService
import im.vector.app.core.time.Clock
import org.matrix.android.sdk.api.session.sync.job.SyncService
import timber.log.Timber
@ -34,10 +35,13 @@ class AlarmSyncBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
Timber.d("## Sync: AlarmSyncBroadcastReceiver received intent")
val vectorPreferences = context.singletonEntryPoint()
.takeIf { it.activeSessionHolder().getSafeActiveSession() != null }
?.vectorPreferences()
?: return Unit.also { Timber.v("No active session, so don't launch sync service.") }
val singletonEntryPoint = context.singletonEntryPoint()
if (singletonEntryPoint.activeSessionHolder().getSafeActiveSession() == null) {
Timber.v("No active session, so don't launch sync service.")
return
}
val vectorPreferences = singletonEntryPoint.vectorPreferences()
val clock = singletonEntryPoint.clock()
val sessionId = intent.getStringExtra(SyncService.EXTRA_SESSION_ID) ?: return
VectorSyncService.newPeriodicIntent(
@ -52,7 +56,7 @@ class AlarmSyncBroadcastReceiver : BroadcastReceiver() {
ContextCompat.startForegroundService(context, it)
} catch (ex: Throwable) {
Timber.i("## Sync: Failed to start service, Alarm scheduled to restart service")
scheduleAlarm(context, sessionId, vectorPreferences.backgroundSyncDelay())
scheduleAlarm(context, sessionId, vectorPreferences.backgroundSyncDelay(), clock)
Timber.e(ex)
}
}
@ -61,7 +65,7 @@ class AlarmSyncBroadcastReceiver : BroadcastReceiver() {
companion object {
private const val REQUEST_CODE = 0
fun scheduleAlarm(context: Context, sessionId: String, delayInSeconds: Int) {
fun scheduleAlarm(context: Context, sessionId: String, delayInSeconds: Int, clock: Clock) {
// Reschedule
Timber.v("## Sync: Scheduling alarm for background sync in $delayInSeconds seconds")
val intent = Intent(context, AlarmSyncBroadcastReceiver::class.java).apply {

View file

@ -32,7 +32,8 @@ class OnApplicationUpgradeOrRebootReceiver : BroadcastReceiver() {
BackgroundSyncStarter.start(
context,
singletonEntryPoint.vectorPreferences(),
singletonEntryPoint.activeSessionHolder()
singletonEntryPoint.activeSessionHolder(),
singletonEntryPoint.clock()
)
}
}

View file

@ -21,6 +21,7 @@ import android.app.Activity
import android.content.Context
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.pushers.PushersManager
import im.vector.app.core.time.Clock
import im.vector.app.fdroid.BackgroundSyncStarter
import im.vector.app.fdroid.receiver.AlarmSyncBroadcastReceiver
import im.vector.app.features.settings.VectorPreferences
@ -66,7 +67,10 @@ object FcmHelper {
AlarmSyncBroadcastReceiver.cancelAlarm(context)
}
fun onEnterBackground(context: Context, vectorPreferences: VectorPreferences, activeSessionHolder: ActiveSessionHolder) {
BackgroundSyncStarter.start(context, vectorPreferences, activeSessionHolder)
fun onEnterBackground(context: Context,
vectorPreferences: VectorPreferences,
activeSessionHolder: ActiveSessionHolder,
clock: Clock) {
BackgroundSyncStarter.start(context, vectorPreferences, activeSessionHolder, clock)
}
}

View file

@ -26,6 +26,7 @@ import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.di.DefaultSharedPreferences
import im.vector.app.core.pushers.PushersManager
import im.vector.app.core.time.Clock
import im.vector.app.features.settings.VectorPreferences
import timber.log.Timber
@ -107,7 +108,10 @@ object FcmHelper {
}
@Suppress("UNUSED_PARAMETER")
fun onEnterBackground(context: Context, vectorPreferences: VectorPreferences, activeSessionHolder: ActiveSessionHolder) {
fun onEnterBackground(context: Context,
vectorPreferences: VectorPreferences,
activeSessionHolder: ActiveSessionHolder,
clock: Clock) {
// No op
}
}

View file

@ -43,6 +43,7 @@ import dagger.hilt.android.HiltAndroidApp
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.extensions.configureAndStart
import im.vector.app.core.extensions.startSyncing
import im.vector.app.core.time.Clock
import im.vector.app.features.analytics.VectorAnalytics
import im.vector.app.features.call.webrtc.WebRtcCallManager
import im.vector.app.features.configuration.VectorConfiguration
@ -85,6 +86,7 @@ class VectorApplication :
@Inject lateinit var emojiCompatWrapper: EmojiCompatWrapper
@Inject lateinit var vectorUncaughtExceptionHandler: VectorUncaughtExceptionHandler
@Inject lateinit var activeSessionHolder: ActiveSessionHolder
@Inject lateinit var clock: Clock
@Inject lateinit var notificationDrawerManager: NotificationDrawerManager
@Inject lateinit var vectorPreferences: VectorPreferences
@Inject lateinit var versionProvider: VersionProvider
@ -180,7 +182,7 @@ class VectorApplication :
override fun onPause(owner: LifecycleOwner) {
Timber.i("App entered background")
FcmHelper.onEnterBackground(appContext, vectorPreferences, activeSessionHolder)
FcmHelper.onEnterBackground(appContext, vectorPreferences, activeSessionHolder, clock)
}
})
ProcessLifecycleOwner.get().lifecycle.addObserver(appStateHandler)

View file

@ -21,6 +21,7 @@ import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import im.vector.app.core.dialogs.UnrecognizedCertificateDialog
import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.time.Clock
import im.vector.app.features.analytics.AnalyticsTracker
import im.vector.app.features.call.webrtc.WebRtcCallManager
import im.vector.app.features.home.AvatarRenderer
@ -46,6 +47,8 @@ interface SingletonEntryPoint {
fun navigator(): Navigator
fun clock(): Clock
fun errorFormatter(): ErrorFormatter
fun bugReporter(): BugReporter