Fix F-Droid build
This commit is contained in:
parent
32bc93c87d
commit
cdcaf93fc7
|
@ -18,13 +18,17 @@ package im.vector.app.fdroid
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
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.fdroid.receiver.AlarmSyncBroadcastReceiver
|
||||||
import im.vector.app.features.settings.BackgroundSyncMode
|
import im.vector.app.features.settings.BackgroundSyncMode
|
||||||
import im.vector.app.features.settings.VectorPreferences
|
import im.vector.app.features.settings.VectorPreferences
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
object BackgroundSyncStarter {
|
object BackgroundSyncStarter {
|
||||||
fun start(context: Context, vectorPreferences: VectorPreferences, activeSessionHolder: ActiveSessionHolder) {
|
fun start(context: Context,
|
||||||
|
vectorPreferences: VectorPreferences,
|
||||||
|
activeSessionHolder: ActiveSessionHolder,
|
||||||
|
clock: Clock) {
|
||||||
if (vectorPreferences.areNotificationEnabledForDevice()) {
|
if (vectorPreferences.areNotificationEnabledForDevice()) {
|
||||||
val activeSession = activeSessionHolder.getSafeActiveSession() ?: return
|
val activeSession = activeSessionHolder.getSafeActiveSession() ?: return
|
||||||
when (vectorPreferences.getFdroidSyncBackgroundMode()) {
|
when (vectorPreferences.getFdroidSyncBackgroundMode()) {
|
||||||
|
@ -38,7 +42,12 @@ object BackgroundSyncStarter {
|
||||||
}
|
}
|
||||||
BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_FOR_REALTIME -> {
|
BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_FOR_REALTIME -> {
|
||||||
// We need to use alarm in this mode
|
// 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")
|
Timber.i("## Sync: Alarm scheduled to start syncing")
|
||||||
}
|
}
|
||||||
BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_DISABLED -> {
|
BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_DISABLED -> {
|
||||||
|
|
|
@ -27,6 +27,7 @@ import androidx.core.content.getSystemService
|
||||||
import im.vector.app.core.extensions.singletonEntryPoint
|
import im.vector.app.core.extensions.singletonEntryPoint
|
||||||
import im.vector.app.core.platform.PendingIntentCompat
|
import im.vector.app.core.platform.PendingIntentCompat
|
||||||
import im.vector.app.core.services.VectorSyncService
|
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 org.matrix.android.sdk.api.session.sync.job.SyncService
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
|
@ -34,10 +35,13 @@ class AlarmSyncBroadcastReceiver : BroadcastReceiver() {
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
Timber.d("## Sync: AlarmSyncBroadcastReceiver received intent")
|
Timber.d("## Sync: AlarmSyncBroadcastReceiver received intent")
|
||||||
val vectorPreferences = context.singletonEntryPoint()
|
val singletonEntryPoint = context.singletonEntryPoint()
|
||||||
.takeIf { it.activeSessionHolder().getSafeActiveSession() != null }
|
if (singletonEntryPoint.activeSessionHolder().getSafeActiveSession() == null) {
|
||||||
?.vectorPreferences()
|
Timber.v("No active session, so don't launch sync service.")
|
||||||
?: return Unit.also { 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
|
val sessionId = intent.getStringExtra(SyncService.EXTRA_SESSION_ID) ?: return
|
||||||
VectorSyncService.newPeriodicIntent(
|
VectorSyncService.newPeriodicIntent(
|
||||||
|
@ -52,7 +56,7 @@ class AlarmSyncBroadcastReceiver : BroadcastReceiver() {
|
||||||
ContextCompat.startForegroundService(context, it)
|
ContextCompat.startForegroundService(context, it)
|
||||||
} catch (ex: Throwable) {
|
} catch (ex: Throwable) {
|
||||||
Timber.i("## Sync: Failed to start service, Alarm scheduled to restart service")
|
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)
|
Timber.e(ex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +65,7 @@ class AlarmSyncBroadcastReceiver : BroadcastReceiver() {
|
||||||
companion object {
|
companion object {
|
||||||
private const val REQUEST_CODE = 0
|
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
|
// Reschedule
|
||||||
Timber.v("## Sync: Scheduling alarm for background sync in $delayInSeconds seconds")
|
Timber.v("## Sync: Scheduling alarm for background sync in $delayInSeconds seconds")
|
||||||
val intent = Intent(context, AlarmSyncBroadcastReceiver::class.java).apply {
|
val intent = Intent(context, AlarmSyncBroadcastReceiver::class.java).apply {
|
||||||
|
|
|
@ -32,7 +32,8 @@ class OnApplicationUpgradeOrRebootReceiver : BroadcastReceiver() {
|
||||||
BackgroundSyncStarter.start(
|
BackgroundSyncStarter.start(
|
||||||
context,
|
context,
|
||||||
singletonEntryPoint.vectorPreferences(),
|
singletonEntryPoint.vectorPreferences(),
|
||||||
singletonEntryPoint.activeSessionHolder()
|
singletonEntryPoint.activeSessionHolder(),
|
||||||
|
singletonEntryPoint.clock()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
import im.vector.app.core.pushers.PushersManager
|
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.BackgroundSyncStarter
|
||||||
import im.vector.app.fdroid.receiver.AlarmSyncBroadcastReceiver
|
import im.vector.app.fdroid.receiver.AlarmSyncBroadcastReceiver
|
||||||
import im.vector.app.features.settings.VectorPreferences
|
import im.vector.app.features.settings.VectorPreferences
|
||||||
|
@ -66,7 +67,10 @@ object FcmHelper {
|
||||||
AlarmSyncBroadcastReceiver.cancelAlarm(context)
|
AlarmSyncBroadcastReceiver.cancelAlarm(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onEnterBackground(context: Context, vectorPreferences: VectorPreferences, activeSessionHolder: ActiveSessionHolder) {
|
fun onEnterBackground(context: Context,
|
||||||
BackgroundSyncStarter.start(context, vectorPreferences, activeSessionHolder)
|
vectorPreferences: VectorPreferences,
|
||||||
|
activeSessionHolder: ActiveSessionHolder,
|
||||||
|
clock: Clock) {
|
||||||
|
BackgroundSyncStarter.start(context, vectorPreferences, activeSessionHolder, clock)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ import im.vector.app.R
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
import im.vector.app.core.di.DefaultSharedPreferences
|
import im.vector.app.core.di.DefaultSharedPreferences
|
||||||
import im.vector.app.core.pushers.PushersManager
|
import im.vector.app.core.pushers.PushersManager
|
||||||
|
import im.vector.app.core.time.Clock
|
||||||
import im.vector.app.features.settings.VectorPreferences
|
import im.vector.app.features.settings.VectorPreferences
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
|
@ -107,7 +108,10 @@ object FcmHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UNUSED_PARAMETER")
|
@Suppress("UNUSED_PARAMETER")
|
||||||
fun onEnterBackground(context: Context, vectorPreferences: VectorPreferences, activeSessionHolder: ActiveSessionHolder) {
|
fun onEnterBackground(context: Context,
|
||||||
|
vectorPreferences: VectorPreferences,
|
||||||
|
activeSessionHolder: ActiveSessionHolder,
|
||||||
|
clock: Clock) {
|
||||||
// No op
|
// No op
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ import dagger.hilt.android.HiltAndroidApp
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
import im.vector.app.core.extensions.configureAndStart
|
import im.vector.app.core.extensions.configureAndStart
|
||||||
import im.vector.app.core.extensions.startSyncing
|
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.analytics.VectorAnalytics
|
||||||
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
||||||
import im.vector.app.features.configuration.VectorConfiguration
|
import im.vector.app.features.configuration.VectorConfiguration
|
||||||
|
@ -85,6 +86,7 @@ class VectorApplication :
|
||||||
@Inject lateinit var emojiCompatWrapper: EmojiCompatWrapper
|
@Inject lateinit var emojiCompatWrapper: EmojiCompatWrapper
|
||||||
@Inject lateinit var vectorUncaughtExceptionHandler: VectorUncaughtExceptionHandler
|
@Inject lateinit var vectorUncaughtExceptionHandler: VectorUncaughtExceptionHandler
|
||||||
@Inject lateinit var activeSessionHolder: ActiveSessionHolder
|
@Inject lateinit var activeSessionHolder: ActiveSessionHolder
|
||||||
|
@Inject lateinit var clock: Clock
|
||||||
@Inject lateinit var notificationDrawerManager: NotificationDrawerManager
|
@Inject lateinit var notificationDrawerManager: NotificationDrawerManager
|
||||||
@Inject lateinit var vectorPreferences: VectorPreferences
|
@Inject lateinit var vectorPreferences: VectorPreferences
|
||||||
@Inject lateinit var versionProvider: VersionProvider
|
@Inject lateinit var versionProvider: VersionProvider
|
||||||
|
@ -180,7 +182,7 @@ class VectorApplication :
|
||||||
|
|
||||||
override fun onPause(owner: LifecycleOwner) {
|
override fun onPause(owner: LifecycleOwner) {
|
||||||
Timber.i("App entered background")
|
Timber.i("App entered background")
|
||||||
FcmHelper.onEnterBackground(appContext, vectorPreferences, activeSessionHolder)
|
FcmHelper.onEnterBackground(appContext, vectorPreferences, activeSessionHolder, clock)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
ProcessLifecycleOwner.get().lifecycle.addObserver(appStateHandler)
|
ProcessLifecycleOwner.get().lifecycle.addObserver(appStateHandler)
|
||||||
|
|
|
@ -21,6 +21,7 @@ import dagger.hilt.InstallIn
|
||||||
import dagger.hilt.components.SingletonComponent
|
import dagger.hilt.components.SingletonComponent
|
||||||
import im.vector.app.core.dialogs.UnrecognizedCertificateDialog
|
import im.vector.app.core.dialogs.UnrecognizedCertificateDialog
|
||||||
import im.vector.app.core.error.ErrorFormatter
|
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.analytics.AnalyticsTracker
|
||||||
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
||||||
import im.vector.app.features.home.AvatarRenderer
|
import im.vector.app.features.home.AvatarRenderer
|
||||||
|
@ -46,6 +47,8 @@ interface SingletonEntryPoint {
|
||||||
|
|
||||||
fun navigator(): Navigator
|
fun navigator(): Navigator
|
||||||
|
|
||||||
|
fun clock(): Clock
|
||||||
|
|
||||||
fun errorFormatter(): ErrorFormatter
|
fun errorFormatter(): ErrorFormatter
|
||||||
|
|
||||||
fun bugReporter(): BugReporter
|
fun bugReporter(): BugReporter
|
||||||
|
|
Loading…
Reference in New Issue