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() {
|
override fun stop() {
|
||||||
|
Timber.i("## Sync: stopping GuardService")
|
||||||
val intent = Intent(appContext, GuardAndroidService::class.java)
|
val intent = Intent(appContext, GuardAndroidService::class.java)
|
||||||
appContext.stopService(intent)
|
appContext.stopService(intent)
|
||||||
}
|
}
|
||||||
|
|
|
@ -250,6 +250,10 @@ class UnifiedPushHelper @Inject constructor(
|
||||||
return UnifiedPush.getDistributor(context) == context.packageName && !fcmHelper.isFirebaseAvailable()
|
return UnifiedPush.getDistributor(context) == context.packageName && !fcmHelper.isFirebaseAvailable()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun doesBackgroundSync(): Boolean {
|
||||||
|
return isBackgroundSync() || (vectorPreferences.forceAllowBackgroundSync() && vectorPreferences.isBackgroundSyncEnabled())
|
||||||
|
}
|
||||||
|
|
||||||
fun getPrivacyFriendlyUpEndpoint(): String? {
|
fun getPrivacyFriendlyUpEndpoint(): String? {
|
||||||
val endpoint = unifiedPushStore.getEndpointOrToken()
|
val endpoint = unifiedPushStore.getEndpointOrToken()
|
||||||
if (endpoint.isNullOrEmpty()) return null
|
if (endpoint.isNullOrEmpty()) return null
|
||||||
|
|
|
@ -140,9 +140,11 @@ class VectorMessagingReceiver : MessagingReceiver() {
|
||||||
Timber.tag(loggerTag.value).i("onNewEndpoint: skipped")
|
Timber.tag(loggerTag.value).i("onNewEndpoint: skipped")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val mode = BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_DISABLED
|
if (!vectorPreferences.forceAllowBackgroundSync()) {
|
||||||
vectorPreferences.setFdroidSyncBackgroundMode(mode)
|
val mode = BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_DISABLED
|
||||||
guardServiceStarter.stop()
|
vectorPreferences.setFdroidSyncBackgroundMode(mode)
|
||||||
|
guardServiceStarter.stop()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onRegistrationFailed(context: Context, instance: String) {
|
override fun onRegistrationFailed(context: Context, instance: String) {
|
||||||
|
|
|
@ -273,7 +273,7 @@ class WebRtcCallManager @Inject constructor(
|
||||||
audioManager.setMode(CallAudioManager.Mode.DEFAULT)
|
audioManager.setMode(CallAudioManager.Mode.DEFAULT)
|
||||||
// did we start background sync? so we should stop it
|
// did we start background sync? so we should stop it
|
||||||
if (isInBackground) {
|
if (isInBackground) {
|
||||||
if (!unifiedPushHelper.isBackgroundSync()) {
|
if (!unifiedPushHelper.doesBackgroundSync()) {
|
||||||
currentSession?.syncService()?.stopAnyBackgroundSync()
|
currentSession?.syncService()?.stopAnyBackgroundSync()
|
||||||
} else {
|
} else {
|
||||||
// for fdroid we should not stop, it should continue syncing
|
// 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
|
// 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
|
// accepted on an other session this device will continue ringing
|
||||||
if (isInBackground) {
|
if (isInBackground) {
|
||||||
if (!unifiedPushHelper.isBackgroundSync()) {
|
if (!unifiedPushHelper.doesBackgroundSync()) {
|
||||||
// only for push version as fdroid version is already doing it?
|
// only for push version as fdroid version is already doing it?
|
||||||
currentSession?.syncService()?.startAutomaticBackgroundSync(30, 0)
|
currentSession?.syncService()?.startAutomaticBackgroundSync(30, 0)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -230,6 +230,7 @@ class VectorPreferences @Inject constructor(
|
||||||
private const val SETTINGS_FLOATING_DATE = "SETTINGS_FLOATING_DATE"
|
private const val SETTINGS_FLOATING_DATE = "SETTINGS_FLOATING_DATE"
|
||||||
private const val SETTINGS_SPACE_BACK_NAVIGATION = "SETTINGS_SPACE_BACK_NAVIGATION"
|
private const val SETTINGS_SPACE_BACK_NAVIGATION = "SETTINGS_SPACE_BACK_NAVIGATION"
|
||||||
const val SETTINGS_FOLLOW_SYSTEM_LOCALE = "SETTINGS_FOLLOW_SYSTEM_LOCALE"
|
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"
|
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
|
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) {
|
fun setFdroidSyncBackgroundMode(mode: BackgroundSyncMode) {
|
||||||
defaultPrefs
|
defaultPrefs
|
||||||
.edit()
|
.edit()
|
||||||
|
|
|
@ -22,6 +22,8 @@ import android.content.Intent
|
||||||
import android.media.RingtoneManager
|
import android.media.RingtoneManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.lifecycle.LiveData
|
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.VectorPreferences
|
||||||
import im.vector.app.features.settings.VectorSettingsBaseFragment
|
import im.vector.app.features.settings.VectorSettingsBaseFragment
|
||||||
import im.vector.app.features.settings.VectorSettingsFragmentInteractionListener
|
import im.vector.app.features.settings.VectorSettingsFragmentInteractionListener
|
||||||
|
import im.vector.app.push.fcm.FcmHelper
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.matrix.android.sdk.api.extensions.tryOrNull
|
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||||
|
@ -64,6 +67,7 @@ import javax.inject.Inject
|
||||||
// Referenced in vector_settings_preferences_root.xml
|
// Referenced in vector_settings_preferences_root.xml
|
||||||
class VectorSettingsNotificationPreferenceFragment @Inject constructor(
|
class VectorSettingsNotificationPreferenceFragment @Inject constructor(
|
||||||
private val unifiedPushHelper: UnifiedPushHelper,
|
private val unifiedPushHelper: UnifiedPushHelper,
|
||||||
|
private val fcmHelper: FcmHelper,
|
||||||
private val pushersManager: PushersManager,
|
private val pushersManager: PushersManager,
|
||||||
private val activeSessionHolder: ActiveSessionHolder,
|
private val activeSessionHolder: ActiveSessionHolder,
|
||||||
private val vectorPreferences: VectorPreferences,
|
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 {
|
findPreference<VectorPreference>(VectorPreferences.SETTINGS_FDROID_BACKGROUND_SYNC_MODE)?.let {
|
||||||
it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||||
val initialMode = vectorPreferences.getFdroidSyncBackgroundMode()
|
val initialMode = vectorPreferences.getFdroidSyncBackgroundMode()
|
||||||
|
@ -241,9 +261,16 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
findPreference<VectorPreferenceCategory>(VectorPreferences.SETTINGS_BACKGROUND_SYNC_PREFERENCE_KEY)?.let {
|
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()
|
val backgroundSyncEnabled = vectorPreferences.isBackgroundSyncEnabled()
|
||||||
findPreference<VectorEditTextPreference>(VectorPreferences.SETTINGS_SET_SYNC_TIMEOUT_PREFERENCE_KEY)?.let {
|
findPreference<VectorEditTextPreference>(VectorPreferences.SETTINGS_SET_SYNC_TIMEOUT_PREFERENCE_KEY)?.let {
|
||||||
it.isEnabled = backgroundSyncEnabled
|
it.isEnabled = backgroundSyncEnabled
|
||||||
|
@ -350,7 +377,7 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
|
||||||
|
|
||||||
private fun refreshPref() {
|
private fun refreshPref() {
|
||||||
// This pref may have change from troubleshoot pref fragment
|
// This pref may have change from troubleshoot pref fragment
|
||||||
if (unifiedPushHelper.isBackgroundSync()) {
|
if (unifiedPushHelper.doesBackgroundSync()) {
|
||||||
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_START_ON_BOOT_PREFERENCE_KEY)
|
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_START_ON_BOOT_PREFERENCE_KEY)
|
||||||
?.isChecked = vectorPreferences.autoStartOnBoot()
|
?.isChecked = vectorPreferences.autoStartOnBoot()
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,12 @@
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:title="@string/settings_notification_method" />
|
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 -->
|
<!-- For API < 26 -->
|
||||||
<im.vector.app.core.preference.VectorPreference
|
<im.vector.app.core.preference.VectorPreference
|
||||||
android:dialogTitle="@string/settings_notification_ringtone"
|
android:dialogTitle="@string/settings_notification_ringtone"
|
||||||
|
|
Loading…
Reference in New Issue