Added setting for legacy push format + moved some configuration for CoreContext to CorePreferences

This commit is contained in:
Sylvain Berfini 2020-10-15 14:30:20 +02:00
parent 38d24fd113
commit d7f31b79cb
6 changed files with 48 additions and 14 deletions

View file

@ -46,6 +46,13 @@ class NetworkSettingsViewModel : GenericSettingsViewModel() {
val pushNotifications = MutableLiveData<Boolean>()
val pushNotificationsAvailable = MutableLiveData<Boolean>()
val legacyPushNotificationFormatListener = object : SettingListenerStub() {
override fun onBoolValueChanged(newValue: Boolean) {
prefs.useLegacyPushNotificationFormat = newValue
}
}
val legacyPushNotificationFormat = MutableLiveData<Boolean>()
val randomPortsListener = object : SettingListenerStub() {
override fun onBoolValueChanged(newValue: Boolean) {
val port = if (newValue) -1 else 5060
@ -71,6 +78,7 @@ class NetworkSettingsViewModel : GenericSettingsViewModel() {
allowIpv6.value = core.ipv6Enabled()
pushNotifications.value = core.isPushNotificationEnabled
pushNotificationsAvailable.value = core.isPushNotificationAvailable
legacyPushNotificationFormat.value = prefs.useLegacyPushNotificationFormat
randomPorts.value = getSipPort() == -1
sipPort.value = getSipPort()
}

View file

@ -220,11 +220,12 @@ class CoreContext(val context: Context, coreConfig: Config) {
notificationsManager.onCoreReady()
core.addListener(listener)
if (isPush) {
Log.i("[Context] Push received, assume in background")
core.enterBackground()
}
core.config.setBool("net", "use_legacy_push_notification_params", true)
core.start()
configureCore()
@ -252,8 +253,8 @@ class CoreContext(val context: Context, coreConfig: Config) {
private fun configureCore() {
Log.i("[Context] Configuring Core")
core.zrtpSecretsFile = context.filesDir.absolutePath + "/zrtp_secrets"
core.callLogsDatabasePath = context.filesDir.absolutePath + "/linphone-log-history.db"
core.zrtpSecretsFile = corePreferences.zrtpSecretsPath
core.callLogsDatabasePath = corePreferences.callHistoryDatabasePath
initUserCertificates()
@ -297,7 +298,7 @@ class CoreContext(val context: Context, coreConfig: Config) {
}
private fun initUserCertificates() {
val userCertsPath = context.filesDir.absolutePath + "/user-certs"
val userCertsPath = corePreferences.userCertificatesPath
val f = File(userCertsPath)
if (!f.exists()) {
if (!f.mkdir()) {

View file

@ -241,6 +241,12 @@ class CorePreferences constructor(private val context: Context) {
config.setInt("app", "version_check_url_last_timestamp", value)
}
var useLegacyPushNotificationFormat: Boolean
get() = config.getBool("net", "use_legacy_push_notification_params", false)
set(value) {
config.setBool("net", "use_legacy_push_notification_params", value)
}
/* Read only application settings, some were previously in non_localizable_custom */
val defaultDomain: String
@ -398,6 +404,15 @@ class CorePreferences constructor(private val context: Context) {
val ringtonePath: String
get() = context.filesDir.absolutePath + "/share/sounds/linphone/rings/notes_of_the_optimistic.mkv"
val userCertificatesPath: String
get() = context.filesDir.absolutePath + "/user-certs"
val zrtpSecretsPath: String
get() = context.filesDir.absolutePath + "/zrtp_secrets"
val callHistoryDatabasePath: String
get() = context.filesDir.absolutePath + "/linphone-log-history.db"
fun copyAssetsFromPackage() {
copy("linphonerc_default", configPath)
copy("linphonerc_factory", factoryConfigPath, true)

View file

@ -68,29 +68,37 @@
<include
layout="@layout/settings_widget_switch"
linphone:title="@{@string/network_settings_wifi_only_title}"
linphone:subtitle="@{@string/advanced_settings_wifi_only_summary}"
linphone:subtitle="@{@string/network_settings_wifi_only_summary}"
linphone:listener="@{viewModel.wifiOnlyListener}"
linphone:checked="@={viewModel.wifiOnly}"/>
<include
layout="@layout/settings_widget_switch"
linphone:title="@{@string/network_settings_allow_ipv6_title}"
linphone:subtitle="@{@string/advanced_settings_allow_ipv6_summary}"
linphone:subtitle="@{@string/network_settings_allow_ipv6_summary}"
linphone:listener="@{viewModel.allowIpv6Listener}"
linphone:checked="@={viewModel.allowIpv6}"/>
<include
layout="@layout/settings_widget_switch"
linphone:title="@{@string/network_settings_push_notifications_title}"
linphone:subtitle="@{@string/advanced_settings_push_notifications_summary}"
linphone:subtitle="@{@string/network_settings_push_notifications_summary}"
linphone:listener="@{viewModel.pushNotificationsListener}"
linphone:checked="@={viewModel.pushNotifications}"
linphone:enabled="@{viewModel.pushNotificationsAvailable}"/>
<include
layout="@layout/settings_widget_switch"
linphone:title="@{@string/network_settings_legacy_push_notification_format_title}"
linphone:subtitle="@{@string/network_settings_legacy_push_notification_format_summary}"
linphone:listener="@{viewModel.legacyPushNotificationFormatListener}"
linphone:checked="@={viewModel.legacyPushNotificationFormat}"
linphone:enabled="@{viewModel.pushNotificationsAvailable}"/>
<include
layout="@layout/settings_widget_switch"
linphone:title="@{@string/network_settings_random_ports_title}"
linphone:subtitle="@{@string/advanced_settings_random_ports_summary}"
linphone:subtitle="@{@string/network_settings_random_ports_summary}"
linphone:listener="@{viewModel.randomPortsListener}"
linphone:checked="@={viewModel.randomPorts}"/>

View file

@ -425,13 +425,15 @@
<!-- Network settings -->
<string name="network_settings_wifi_only_title">Use WiFi only</string>
<string name="advanced_settings_wifi_only_summary"></string>
<string name="network_settings_wifi_only_summary"></string>
<string name="network_settings_allow_ipv6_title">Allow IPv6</string>
<string name="advanced_settings_allow_ipv6_summary"></string>
<string name="network_settings_allow_ipv6_summary"></string>
<string name="network_settings_push_notifications_title">Enable push notifications</string>
<string name="advanced_settings_push_notifications_summary"></string>
<string name="network_settings_push_notifications_summary"></string>
<string name="network_settings_legacy_push_notification_format_title">Use legacy push notification params</string>
<string name="network_settings_legacy_push_notification_format_summary">Required when using Flexisip &lt; 2.0</string>
<string name="network_settings_random_ports_title">Use random ports</string>
<string name="advanced_settings_random_ports_summary"></string>
<string name="network_settings_random_ports_summary"></string>
<string name="network_settings_sip_port_title">SIP port to use</string>
<string name="network_settings_sip_port_summary"></string>