Add a BuildConfig to allow external unifiedpush distrib

Change-Id: I5435c02dab05f84dd5dd99507afd1075f357e76d
This commit is contained in:
S1m 2021-11-15 20:21:01 +01:00 committed by SpiritCroc
parent c03c6867f7
commit c4fd115209
3 changed files with 21 additions and 8 deletions

View File

@ -274,6 +274,7 @@ android {
resValue "bool", "isGplay", "true"
buildConfigField "boolean", "ALLOW_FCM_USE", "true"
buildConfigField "boolean", "ALLOW_EXTERNAL_UNIFIEDPUSH_DISTRIB", "true"
buildConfigField "String", "SHORT_FLAVOR_DESCRIPTION", "\"G\""
buildConfigField "String", "FLAVOR_DESCRIPTION", "\"GooglePlay\""
}
@ -285,6 +286,7 @@ android {
resValue "bool", "isGplay", "false"
buildConfigField "boolean", "ALLOW_FCM_USE", "false"
buildConfigField "boolean", "ALLOW_EXTERNAL_UNIFIEDPUSH_DISTRIB", "true"
buildConfigField "String", "SHORT_FLAVOR_DESCRIPTION", "\"F\""
buildConfigField "String", "FLAVOR_DESCRIPTION", "\"FDroid\""
}

View File

@ -21,6 +21,7 @@ import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.core.content.edit
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import im.vector.app.BuildConfig
import im.vector.app.R
import im.vector.app.core.di.DefaultSharedPreferences
import im.vector.app.features.settings.VectorPreferences
@ -86,6 +87,11 @@ object UPHelper {
fun registerUnifiedPush(context: Context, forceShowSelection: Boolean = false, onDoneRunnable: Runnable? = null) {
val up = Registration()
if (!BuildConfig.ALLOW_EXTERNAL_UNIFIEDPUSH_DISTRIB) {
up.saveDistributor(context, context.packageName)
up.registerApp(context)
return
}
if (forceShowSelection) {
// Un-register first
up.unregisterApp(context)

View File

@ -31,6 +31,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.map
import androidx.preference.Preference
import androidx.preference.SwitchPreference
import im.vector.app.BuildConfig
import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.extensions.registerStartForActivityResult
@ -141,17 +142,21 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
}
findPreference<VectorPreference>(SETTINGS_UNIFIED_PUSH_RE_REGISTER)?.let {
it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
lifecycleScope.launch {
updateEnabledForDevice(false)
UPHelper.registerUnifiedPush(requireContext(), forceShowSelection = true) {
lifecycleScope.launch {
updateEnabledForDevice(true)
if (BuildConfig.ALLOW_EXTERNAL_UNIFIEDPUSH_DISTRIB) {
it.onPreferenceClickListener = Preference.OnPreferenceClickListener {
lifecycleScope.launch {
updateEnabledForDevice(false)
UPHelper.registerUnifiedPush(requireContext(), forceShowSelection = true) {
lifecycleScope.launch {
updateEnabledForDevice(true)
}
Handler(Looper.getMainLooper()).postDelayed({ refreshBackgroundSyncPrefs() }, 500)
}
Handler(Looper.getMainLooper()).postDelayed({ refreshBackgroundSyncPrefs() }, 500)
}
true
}
true
} else {
it.isVisible = false
}
}