diff --git a/vector/src/main/java/im/vector/app/core/pushers/UPHelper.kt b/vector/src/main/java/im/vector/app/core/pushers/UPHelper.kt index 9928fc548d..218bb77f33 100644 --- a/vector/src/main/java/im/vector/app/core/pushers/UPHelper.kt +++ b/vector/src/main/java/im/vector/app/core/pushers/UPHelper.kt @@ -22,6 +22,7 @@ import androidx.core.content.edit import com.google.android.material.dialog.MaterialAlertDialogBuilder import im.vector.app.R import im.vector.app.core.di.DefaultSharedPreferences +import im.vector.app.features.settings.VectorPreferences import im.vector.app.push.fcm.FcmHelper import org.unifiedpush.android.connector.Registration import timber.log.Timber @@ -158,6 +159,10 @@ object UPHelper { * if GET custom returns """{"unifiedpush":{"gateway":"matrix"}}""" * return custom */ + val vectorPreferences = VectorPreferences(context) + if (vectorPreferences.forceUsCustomUpGateway()) { + return custom + } } return default } diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt index d3487a4100..b6ab287037 100755 --- a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt @@ -205,6 +205,7 @@ class VectorPreferences @Inject constructor(private val context: Context) { private const val SETTINGS_USER_COLOR_MODE_PUBLIC_ROOM = "SETTINGS_USER_COLOR_MODE_PUBLIC_ROOM" 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_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY = "SETTINGS_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY" 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" @@ -1021,6 +1022,10 @@ class VectorPreferences @Inject constructor(private val context: Context) { return Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP && defaultPrefs.getBoolean(SETTINGS_VOICE_MESSAGE, true) } + fun forceUsCustomUpGateway(): Boolean { + return defaultPrefs.getBoolean(SETTINGS_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY, false) + } + /** * 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 @@ -1041,6 +1046,7 @@ class VectorPreferences @Inject constructor(private val context: Context) { .putBoolean(SETTINGS_LABS_ENABLE_SWIPE_TO_REPLY, false) .putBoolean(SETTINGS_VOICE_MESSAGE, false) .putBoolean(SETTINGS_USE_RAGE_SHAKE_KEY, true) + .putBoolean(SETTINGS_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY, true) .apply() } diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsLabsFragment.kt b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsLabsFragment.kt index c691170dc1..c6c2179a9a 100644 --- a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsLabsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsLabsFragment.kt @@ -17,9 +17,12 @@ package im.vector.app.features.settings import android.os.Build +import android.os.Handler +import android.os.Looper import androidx.preference.Preference import im.vector.app.R import im.vector.app.core.preference.VectorSwitchPreference +import im.vector.app.core.pushers.UPHelper import im.vector.app.features.themes.ThemeUtils import im.vector.app.features.MainActivity import im.vector.app.features.MainActivityArgs @@ -58,5 +61,10 @@ class VectorSettingsLabsFragment @Inject constructor( findPreference(VectorPreferences.SETTINGS_ALLOW_URL_PREVIEW_IN_ENCRYPTED_ROOM_KEY)?.isEnabled = vectorPreferences.showUrlPreviews() findPreference(VectorPreferences.SETTINGS_VOICE_MESSAGE)?.isEnabled = Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP + + findPreference(VectorPreferences.SETTINGS_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY)?.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, _ -> + Handler(Looper.getMainLooper()).postDelayed({ context?.let { UPHelper.registerUnifiedPush(it)} } , 1000) + true + } } } diff --git a/vector/src/main/res/values/strings_sc.xml b/vector/src/main/res/values/strings_sc.xml index 408f04823f..de429f0e13 100644 --- a/vector/src/main/res/values/strings_sc.xml +++ b/vector/src/main/res/values/strings_sc.xml @@ -132,4 +132,8 @@ Mess up settings If you continue, this will mess with your app settings! + UnifiedPush + Force custom push gateway + Only enable this if your push endpoint does not require an external gateway. + diff --git a/vector/src/main/res/xml/vector_settings_labs.xml b/vector/src/main/res/xml/vector_settings_labs.xml index 99525f7f93..654c1dbab6 100644 --- a/vector/src/main/res/xml/vector_settings_labs.xml +++ b/vector/src/main/res/xml/vector_settings_labs.xml @@ -82,5 +82,15 @@ android:summary="@string/labs_use_restricted_join_rule_desc"/> + + + + +