Add option to force allow background sync in addition to push
Change-Id: I545475f1f8b36a43712613493173c9a6638cc7f6
This commit is contained in:
parent
adfa2b36af
commit
8005f44768
@ -182,7 +182,7 @@ object UPHelper {
|
|||||||
* return custom
|
* return custom
|
||||||
*/
|
*/
|
||||||
val vectorPreferences = VectorPreferences(context)
|
val vectorPreferences = VectorPreferences(context)
|
||||||
if (vectorPreferences.forceUsCustomUpGateway()) {
|
if (vectorPreferences.forceUseCustomUpGateway()) {
|
||||||
return custom
|
return custom
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -196,6 +196,14 @@ object UPHelper {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun allowBackgroundSync(context: Context): Boolean {
|
||||||
|
if (!hasEndpoint(context)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
val vectorPreferences = VectorPreferences(context)
|
||||||
|
return vectorPreferences.forceAllowBackgroundSync()
|
||||||
|
}
|
||||||
|
|
||||||
fun distributorExists(context: Context): Boolean {
|
fun distributorExists(context: Context): Boolean {
|
||||||
val up = Registration()
|
val up = Registration()
|
||||||
return up.getDistributor(context).isNotEmpty()
|
return up.getDistributor(context).isNotEmpty()
|
||||||
|
@ -169,9 +169,11 @@ val upHandler = object: MessagingReceiverHandler {
|
|||||||
Timber.i("onNewEndpoint: skipped")
|
Timber.i("onNewEndpoint: skipped")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!UPHelper.allowBackgroundSync(context)) {
|
||||||
val mode = BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_DISABLED
|
val mode = BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_DISABLED
|
||||||
vectorPreferences.setFdroidSyncBackgroundMode(mode)
|
vectorPreferences.setFdroidSyncBackgroundMode(mode)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onRegistrationFailed(context: Context?, instance: String) {
|
override fun onRegistrationFailed(context: Context?, instance: String) {
|
||||||
Toast.makeText(context, "Push service registration failed", Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, "Push service registration failed", Toast.LENGTH_SHORT).show()
|
||||||
|
@ -262,7 +262,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 (UPHelper.hasEndpoint(context)) {
|
if (!UPHelper.allowBackgroundSync(context)) {
|
||||||
currentSession?.stopAnyBackgroundSync()
|
currentSession?.stopAnyBackgroundSync()
|
||||||
} else {
|
} else {
|
||||||
// for fdroid we should not stop, it should continue syncing
|
// for fdroid we should not stop, it should continue syncing
|
||||||
@ -367,7 +367,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 (UPHelper.hasEndpoint(context)) {
|
if (!UPHelper.allowBackgroundSync(context)) {
|
||||||
// only for push version as fdroid version is already doing it?
|
// only for push version as fdroid version is already doing it?
|
||||||
currentSession?.startAutomaticBackgroundSync(30, 0)
|
currentSession?.startAutomaticBackgroundSync(30, 0)
|
||||||
} else {
|
} else {
|
||||||
|
@ -206,6 +206,7 @@ class VectorPreferences @Inject constructor(private val context: Context) {
|
|||||||
private const val SETTINGS_OPEN_CHATS_AT_FIRST_UNREAD = "SETTINGS_OPEN_CHATS_AT_FIRST_UNREAD"
|
private const val SETTINGS_OPEN_CHATS_AT_FIRST_UNREAD = "SETTINGS_OPEN_CHATS_AT_FIRST_UNREAD"
|
||||||
const val SETTINGS_VOICE_MESSAGE = "SETTINGS_VOICE_MESSAGE"
|
const val SETTINGS_VOICE_MESSAGE = "SETTINGS_VOICE_MESSAGE"
|
||||||
const val SETTINGS_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY = "SETTINGS_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY"
|
const val SETTINGS_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY = "SETTINGS_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY"
|
||||||
|
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"
|
||||||
private const val DID_PROMOTE_NEW_RESTRICTED_JOIN_RULE = "DID_PROMOTE_NEW_RESTRICTED_JOIN_RULE"
|
private const val DID_PROMOTE_NEW_RESTRICTED_JOIN_RULE = "DID_PROMOTE_NEW_RESTRICTED_JOIN_RULE"
|
||||||
@ -1022,10 +1023,14 @@ class VectorPreferences @Inject constructor(private val context: Context) {
|
|||||||
return Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP && defaultPrefs.getBoolean(SETTINGS_VOICE_MESSAGE, true)
|
return Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP && defaultPrefs.getBoolean(SETTINGS_VOICE_MESSAGE, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun forceUsCustomUpGateway(): Boolean {
|
fun forceUseCustomUpGateway(): Boolean {
|
||||||
return defaultPrefs.getBoolean(SETTINGS_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY, false)
|
return defaultPrefs.getBoolean(SETTINGS_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun forceAllowBackgroundSync(): Boolean {
|
||||||
|
return defaultPrefs.getBoolean(SETTINGS_FORCE_ALLOW_BACKGROUND_SYNC, false)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* I likely do more fresh installs of the app than anyone else, so a shortcut to change some of the default settings to
|
* I likely do more fresh installs of the app than anyone else, so a shortcut to change some of the default settings to
|
||||||
* my preferred values can safe me some time
|
* my preferred values can safe me some time
|
||||||
|
@ -134,6 +134,14 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_FORCE_ALLOW_BACKGROUND_SYNC)?.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
|
||||||
|
if (newValue != true && UPHelper.hasEndpoint(requireContext())) {
|
||||||
|
onOptionSelected(BackgroundSyncMode.FDROID_BACKGROUND_SYNC_MODE_DISABLED)
|
||||||
|
}
|
||||||
|
Handler(Looper.getMainLooper()).postDelayed({ refreshBackgroundSyncPrefs() } , 500)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
refreshBackgroundSyncPrefs()
|
refreshBackgroundSyncPrefs()
|
||||||
|
|
||||||
handleSystemPreference()
|
handleSystemPreference()
|
||||||
@ -168,7 +176,7 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
findPreference<VectorPreferenceCategory>(VectorPreferences.SETTINGS_BACKGROUND_SYNC_PREFERENCE_KEY)?.let {
|
findPreference<VectorPreferenceCategory>(VectorPreferences.SETTINGS_BACKGROUND_SYNC_PREFERENCE_KEY)?.let {
|
||||||
it.isVisible = !UPHelper.hasEndpoint(requireContext())
|
it.isVisible = UPHelper.allowBackgroundSync(requireContext())
|
||||||
}
|
}
|
||||||
|
|
||||||
findPreference<VectorEditTextPreference>(VectorPreferences.SETTINGS_SET_SYNC_TIMEOUT_PREFERENCE_KEY)?.let {
|
findPreference<VectorEditTextPreference>(VectorPreferences.SETTINGS_SET_SYNC_TIMEOUT_PREFERENCE_KEY)?.let {
|
||||||
@ -272,7 +280,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 (!UPHelper.hasEndpoint(requireContext())) {
|
if (UPHelper.allowBackgroundSync(requireContext())) {
|
||||||
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_START_ON_BOOT_PREFERENCE_KEY)
|
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_START_ON_BOOT_PREFERENCE_KEY)
|
||||||
?.isChecked = vectorPreferences.autoStartOnBoot()
|
?.isChecked = vectorPreferences.autoStartOnBoot()
|
||||||
}
|
}
|
||||||
|
@ -137,6 +137,8 @@
|
|||||||
<string name="settings_unifiedpush_force_custom_gateway">Force custom push gateway</string>
|
<string name="settings_unifiedpush_force_custom_gateway">Force custom push gateway</string>
|
||||||
<string name="settings_unifiedpush_force_custom_gateway_summary">Only enable this if your push endpoint does not require an external gateway.</string>
|
<string name="settings_unifiedpush_force_custom_gateway_summary">Only enable this if your push endpoint does not require an external gateway.</string>
|
||||||
<string name="settings_unifiedpush_reregister">Re-register push distributor</string>
|
<string name="settings_unifiedpush_reregister">Re-register push distributor</string>
|
||||||
|
<string name="settings_force_allow_background_sync">Allow background sync in addition to push</string>
|
||||||
|
<string name="settings_force_allow_background_sync_summary">Only meaningful while debugging your push setup!</string>
|
||||||
<string name="toast_unifiedpush_no_push_distributor">No push distributor found!</string>
|
<string name="toast_unifiedpush_no_push_distributor">No push distributor found!</string>
|
||||||
<string name="toast_unifiedpush_one_push_distributor">Registered push distributor %1$s</string>
|
<string name="toast_unifiedpush_one_push_distributor">Registered push distributor %1$s</string>
|
||||||
|
|
||||||
|
@ -138,16 +138,22 @@
|
|||||||
android:key="SETTINGS_UNIFIED_PUSH_RE_REGISTER"
|
android:key="SETTINGS_UNIFIED_PUSH_RE_REGISTER"
|
||||||
android:title="@string/settings_unifiedpush_reregister" />
|
android:title="@string/settings_unifiedpush_reregister" />
|
||||||
|
|
||||||
|
<im.vector.app.core.preference.VectorPreference
|
||||||
|
android:persistent="false"
|
||||||
|
android:title="@string/settings_notifications_targets"
|
||||||
|
app:fragment="im.vector.app.features.settings.push.PushGatewaysFragment" />
|
||||||
|
|
||||||
<im.vector.app.core.preference.VectorSwitchPreference
|
<im.vector.app.core.preference.VectorSwitchPreference
|
||||||
android:key="SETTINGS_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY"
|
android:key="SETTINGS_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY"
|
||||||
android:title="@string/settings_unifiedpush_force_custom_gateway"
|
android:title="@string/settings_unifiedpush_force_custom_gateway"
|
||||||
android:summary="@string/settings_unifiedpush_force_custom_gateway_summary"
|
android:summary="@string/settings_unifiedpush_force_custom_gateway_summary"
|
||||||
android:defaultValue="false" />
|
android:defaultValue="false" />
|
||||||
|
|
||||||
<im.vector.app.core.preference.VectorPreference
|
<im.vector.app.core.preference.VectorSwitchPreference
|
||||||
android:persistent="false"
|
android:key="SETTINGS_FORCE_ALLOW_BACKGROUND_SYNC"
|
||||||
android:title="@string/settings_notifications_targets"
|
android:title="@string/settings_force_allow_background_sync"
|
||||||
app:fragment="im.vector.app.features.settings.push.PushGatewaysFragment" />
|
android:summary="@string/settings_force_allow_background_sync_summary"
|
||||||
|
android:defaultValue="false" />
|
||||||
|
|
||||||
</im.vector.app.core.preference.VectorPreferenceCategory>
|
</im.vector.app.core.preference.VectorPreferenceCategory>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user