Add back possibility to force allow bg sync for fdroid variant
You might want to be able to enable periodic background sync even when push is enabled, if you have lots of muted rooms which don't trigger notifications, in order to speed up startup time after a longer time. Change-Id: Icc6dfe359531eb334d6862374d10f746edd8585e
This commit is contained in:
parent
bd5f011c0e
commit
bf7cf8ba7a
|
@ -42,6 +42,7 @@ class FDroidGuardServiceStarter @Inject constructor(
|
|||
}
|
||||
|
||||
override fun stop() {
|
||||
Timber.i("## Sync: stopping GuardService")
|
||||
val intent = Intent(appContext, GuardAndroidService::class.java)
|
||||
appContext.stopService(intent)
|
||||
}
|
||||
|
|
|
@ -250,6 +250,10 @@ class UnifiedPushHelper @Inject constructor(
|
|||
return UnifiedPush.getDistributor(context) == context.packageName && !fcmHelper.isFirebaseAvailable()
|
||||
}
|
||||
|
||||
fun doesBackgroundSync(): Boolean {
|
||||
return isBackgroundSync() || (vectorPreferences.forceAllowBackgroundSync() && vectorPreferences.isBackgroundSyncEnabled())
|
||||
}
|
||||
|
||||
fun getPrivacyFriendlyUpEndpoint(): String? {
|
||||
val endpoint = unifiedPushStore.getEndpointOrToken()
|
||||
if (endpoint.isNullOrEmpty()) return null
|
||||
|
|
|
@ -140,10 +140,12 @@ class VectorMessagingReceiver : MessagingReceiver() {
|
|||
Timber.tag(loggerTag.value).i("onNewEndpoint: skipped")
|
||||
}
|
||||
}
|
||||
if (!vectorPreferences.forceAllowBackgroundSync()) {
|
||||
val mode = BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_DISABLED
|
||||
vectorPreferences.setFdroidSyncBackgroundMode(mode)
|
||||
guardServiceStarter.stop()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onRegistrationFailed(context: Context, instance: String) {
|
||||
Toast.makeText(context, "Push service registration failed", Toast.LENGTH_SHORT).show()
|
||||
|
|
|
@ -273,7 +273,7 @@ class WebRtcCallManager @Inject constructor(
|
|||
audioManager.setMode(CallAudioManager.Mode.DEFAULT)
|
||||
// did we start background sync? so we should stop it
|
||||
if (isInBackground) {
|
||||
if (!unifiedPushHelper.isBackgroundSync()) {
|
||||
if (!unifiedPushHelper.doesBackgroundSync()) {
|
||||
currentSession?.syncService()?.stopAnyBackgroundSync()
|
||||
} else {
|
||||
// for fdroid we should not stop, it should continue syncing
|
||||
|
@ -379,7 +379,7 @@ class WebRtcCallManager @Inject constructor(
|
|||
// and thus won't be able to received events. For example if the call is
|
||||
// accepted on an other session this device will continue ringing
|
||||
if (isInBackground) {
|
||||
if (!unifiedPushHelper.isBackgroundSync()) {
|
||||
if (!unifiedPushHelper.doesBackgroundSync()) {
|
||||
// only for push version as fdroid version is already doing it?
|
||||
currentSession?.syncService()?.startAutomaticBackgroundSync(30, 0)
|
||||
} else {
|
||||
|
|
|
@ -230,6 +230,7 @@ class VectorPreferences @Inject constructor(
|
|||
private const val SETTINGS_FLOATING_DATE = "SETTINGS_FLOATING_DATE"
|
||||
private const val SETTINGS_SPACE_BACK_NAVIGATION = "SETTINGS_SPACE_BACK_NAVIGATION"
|
||||
const val SETTINGS_FOLLOW_SYSTEM_LOCALE = "SETTINGS_FOLLOW_SYSTEM_LOCALE"
|
||||
const val SETTINGS_FORCE_ALLOW_BACKGROUND_SYNC = "SETTINGS_FORCE_ALLOW_BACKGROUND_SYNC"
|
||||
|
||||
private const val DID_ASK_TO_ENABLE_SESSION_PUSH = "DID_ASK_TO_ENABLE_SESSION_PUSH"
|
||||
|
||||
|
@ -1260,6 +1261,11 @@ class VectorPreferences @Inject constructor(
|
|||
return getFdroidSyncBackgroundMode() != BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_DISABLED
|
||||
}
|
||||
|
||||
// SC addition
|
||||
fun forceAllowBackgroundSync(): Boolean {
|
||||
return defaultPrefs.getBoolean(SETTINGS_FORCE_ALLOW_BACKGROUND_SYNC, false)
|
||||
}
|
||||
|
||||
fun setFdroidSyncBackgroundMode(mode: BackgroundSyncMode) {
|
||||
defaultPrefs
|
||||
.edit()
|
||||
|
|
|
@ -22,6 +22,8 @@ import android.content.Intent
|
|||
import android.media.RingtoneManager
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.Parcelable
|
||||
import android.widget.Toast
|
||||
import androidx.lifecycle.LiveData
|
||||
|
@ -51,6 +53,7 @@ import im.vector.app.features.settings.BackgroundSyncModeChooserDialog
|
|||
import im.vector.app.features.settings.VectorPreferences
|
||||
import im.vector.app.features.settings.VectorSettingsBaseFragment
|
||||
import im.vector.app.features.settings.VectorSettingsFragmentInteractionListener
|
||||
import im.vector.app.push.fcm.FcmHelper
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||
|
@ -64,6 +67,7 @@ import javax.inject.Inject
|
|||
// Referenced in vector_settings_preferences_root.xml
|
||||
class VectorSettingsNotificationPreferenceFragment @Inject constructor(
|
||||
private val unifiedPushHelper: UnifiedPushHelper,
|
||||
private val fcmHelper: FcmHelper,
|
||||
private val pushersManager: PushersManager,
|
||||
private val activeSessionHolder: ActiveSessionHolder,
|
||||
private val vectorPreferences: VectorPreferences,
|
||||
|
@ -113,6 +117,22 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
// SC addition
|
||||
findPreference<SwitchPreference>(VectorPreferences.SETTINGS_FORCE_ALLOW_BACKGROUND_SYNC)?.let {
|
||||
it.setTransactionalSwitchChangeListener(lifecycleScope) { isChecked ->
|
||||
if (isChecked) {
|
||||
if (!vectorPreferences.isBackgroundSyncEnabled()) {
|
||||
vectorPreferences.setFdroidSyncBackgroundMode(BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_FOR_BATTERY)
|
||||
}
|
||||
} else {
|
||||
if (!unifiedPushHelper.isBackgroundSync() && vectorPreferences.isBackgroundSyncEnabled()) {
|
||||
vectorPreferences.setFdroidSyncBackgroundMode(BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_DISABLED)
|
||||
}
|
||||
}
|
||||
Handler(Looper.getMainLooper()).postDelayed({ refreshBackgroundSyncPrefs() } , 500)
|
||||
}
|
||||
}
|
||||
|
||||
findPreference<VectorPreference>(VectorPreferences.SETTINGS_FDROID_BACKGROUND_SYNC_MODE)?.let {
|
||||
it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||
val initialMode = vectorPreferences.getFdroidSyncBackgroundMode()
|
||||
|
@ -241,9 +261,16 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
|
|||
}
|
||||
|
||||
findPreference<VectorPreferenceCategory>(VectorPreferences.SETTINGS_BACKGROUND_SYNC_PREFERENCE_KEY)?.let {
|
||||
it.isVisible = unifiedPushHelper.isBackgroundSync()
|
||||
it.isVisible = unifiedPushHelper.doesBackgroundSync()
|
||||
}
|
||||
|
||||
// SC addition
|
||||
findPreference<SwitchPreference>(VectorPreferences.SETTINGS_FORCE_ALLOW_BACKGROUND_SYNC)?.let {
|
||||
// FCM variant doesn't have background sync code...
|
||||
it.isVisible = !unifiedPushHelper.isBackgroundSync() && !fcmHelper.isFirebaseAvailable()
|
||||
}
|
||||
|
||||
|
||||
val backgroundSyncEnabled = vectorPreferences.isBackgroundSyncEnabled()
|
||||
findPreference<VectorEditTextPreference>(VectorPreferences.SETTINGS_SET_SYNC_TIMEOUT_PREFERENCE_KEY)?.let {
|
||||
it.isEnabled = backgroundSyncEnabled
|
||||
|
@ -350,7 +377,7 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
|
|||
|
||||
private fun refreshPref() {
|
||||
// This pref may have change from troubleshoot pref fragment
|
||||
if (unifiedPushHelper.isBackgroundSync()) {
|
||||
if (unifiedPushHelper.doesBackgroundSync()) {
|
||||
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_START_ON_BOOT_PREFERENCE_KEY)
|
||||
?.isChecked = vectorPreferences.autoStartOnBoot()
|
||||
}
|
||||
|
|
|
@ -57,6 +57,12 @@
|
|||
android:persistent="false"
|
||||
android:title="@string/settings_notification_method" />
|
||||
|
||||
<im.vector.app.core.preference.VectorSwitchPreference
|
||||
android:key="SETTINGS_FORCE_ALLOW_BACKGROUND_SYNC"
|
||||
android:title="@string/settings_force_allow_background_sync"
|
||||
android:summary="@string/settings_force_allow_background_sync_summary"
|
||||
android:defaultValue="false" />
|
||||
|
||||
<!-- For API < 26 -->
|
||||
<im.vector.app.core.preference.VectorPreference
|
||||
android:dialogTitle="@string/settings_notification_ringtone"
|
||||
|
|
Loading…
Reference in New Issue