From 26df085df331c72830796efe5a7f672d543abdbb Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Wed, 9 Apr 2025 10:19:56 +0200 Subject: [PATCH] Hide push notification setting in third party SIP accounts parameters, they won't work anyway + disable push for existing third party SIP accounts when migrating to 6.0.4 --- .../java/org/linphone/core/CoreContext.kt | 19 ++++++++++++++++- .../viewmodel/AccountSettingsViewModel.kt | 21 +++++++++++++------ .../res/layout/account_settings_fragment.xml | 2 ++ app/src/main/res/values-fr/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/linphone/core/CoreContext.kt b/app/src/main/java/org/linphone/core/CoreContext.kt index ca9d358a7..1f2d790ff 100644 --- a/app/src/main/java/org/linphone/core/CoreContext.kt +++ b/app/src/main/java/org/linphone/core/CoreContext.kt @@ -602,6 +602,8 @@ class CoreContext if (oldVersion < 600000) { // 6.0.0 initial release configurationMigration5To6() + } else if (oldVersion < 600004) { // 6.0.4 + disablePushNotificationsFromThirdPartySipAccounts() } if (core.logCollectionUploadServerUrl.isNullOrEmpty()) { @@ -1043,6 +1045,21 @@ class CoreContext logcatEnabled = enable } + // Migration between versions related + + @WorkerThread + private fun disablePushNotificationsFromThirdPartySipAccounts() { + for (account in core.accountList) { + val params = account.params + if (params.identityAddress?.domain != corePreferences.defaultDomain && params.pushNotificationAllowed) { + val clone = params.clone() + clone.pushNotificationAllowed = false + Log.w("$TAG Updating account [${params.identityAddress?.asStringUriOnly()}] params to disable push notifications, they won't work and may cause issues when used with UDP transport protocol") + account.params = clone + } + } + } + @WorkerThread private fun configurationMigration5To6() { val policy = core.videoActivationPolicy.clone() @@ -1069,7 +1086,7 @@ class CoreContext for (account in core.accountList) { val params = account.params - if (params.domain == corePreferences.defaultDomain && params.limeAlgo.isNullOrEmpty()) { + if (params.identityAddress?.domain == corePreferences.defaultDomain && params.limeAlgo.isNullOrEmpty()) { val clone = params.clone() clone.limeAlgo = "c25519" Log.i("$TAG Updating account [${params.identityAddress?.asStringUriOnly()}] params to use LIME algo c25519") diff --git a/app/src/main/java/org/linphone/ui/main/settings/viewmodel/AccountSettingsViewModel.kt b/app/src/main/java/org/linphone/ui/main/settings/viewmodel/AccountSettingsViewModel.kt index 4ee95049f..ce734ac7e 100644 --- a/app/src/main/java/org/linphone/ui/main/settings/viewmodel/AccountSettingsViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/settings/viewmodel/AccountSettingsViewModel.kt @@ -24,6 +24,7 @@ import androidx.lifecycle.MediatorLiveData import androidx.lifecycle.MutableLiveData import java.util.Locale import org.linphone.LinphoneApplication.Companion.coreContext +import org.linphone.LinphoneApplication.Companion.corePreferences import org.linphone.core.AVPFMode import org.linphone.core.Account import org.linphone.core.AuthInfo @@ -45,6 +46,8 @@ class AccountSettingsViewModel val expandNatPolicySettings = MutableLiveData() + val isOnDefaultDomain = MutableLiveData() + val pushNotificationsAvailable = MutableLiveData() val pushNotificationsEnabled = MutableLiveData() @@ -129,11 +132,16 @@ class AccountSettingsViewModel account = found val params = account.params - - pushNotificationsAvailable.postValue(core.isPushNotificationAvailable) - pushNotificationsEnabled.postValue( - core.isPushNotificationAvailable && params.pushNotificationAllowed - ) + val defaultDomain = params.identityAddress?.domain == corePreferences.defaultDomain + isOnDefaultDomain.postValue(defaultDomain) + if (defaultDomain) { + pushNotificationsAvailable.postValue(core.isPushNotificationAvailable) + pushNotificationsEnabled.postValue( + core.isPushNotificationAvailable && params.pushNotificationAllowed + ) + } else { + Log.w("$TAG Account isn't on default domain [${corePreferences.defaultDomain}], do not show push notification settings") + } imEncryptionMandatory.postValue(params.instantMessagingEncryptionMandatory) @@ -199,7 +207,8 @@ class AccountSettingsViewModel if (::account.isInitialized) { val newParams = account.params.clone() - newParams.pushNotificationAllowed = pushNotificationsEnabled.value == true + + newParams.pushNotificationAllowed = core.isPushNotificationAvailable && pushNotificationsEnabled.value == true newParams.instantMessagingEncryptionMandatory = imEncryptionMandatory.value == true diff --git a/app/src/main/res/layout/account_settings_fragment.xml b/app/src/main/res/layout/account_settings_fragment.xml index 4370b094d..54de76c61 100644 --- a/app/src/main/res/layout/account_settings_fragment.xml +++ b/app/src/main/res/layout/account_settings_fragment.xml @@ -82,6 +82,7 @@ android:layout_marginEnd="16dp" android:enabled="@{viewModel.pushNotificationsAvailable}" android:checked="@={viewModel.pushNotificationsEnabled}" + android:visibility="@{viewModel.isOnDefaultDomain ? View.VISIBLE : View.GONE}" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent"/> @@ -96,6 +97,7 @@ android:text="@{viewModel.pushNotificationsAvailable ? @string/account_settings_push_notification_title : @string/account_settings_push_notification_not_available_title, default=@string/account_settings_push_notification_title}" android:maxLines="2" android:ellipsize="end" + android:visibility="@{viewModel.isOnDefaultDomain ? View.VISIBLE : View.GONE}" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="@id/push_notifications_switch" app:layout_constraintStart_toStartOf="parent" diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index f58ba37ff..2ea2f5ba5 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -118,7 +118,7 @@ Vous avez déjà un compte ? Transport Certaines fonctionnalités telles que les conversations de groupe, les vidéo-conférences, etc… nécessitent un compte &appName;.\n\nCes fonctionnalités seront masquées si vous utilisez un compte SIP tiers.\n\nPour les activer dans un projet commercial, merci de nous contacter. - Je préfère créer un compte + Je préfère créer un compte &appName; J\'ai compris Notifications push indisponible, la création de compte est donc désactivée. Notification push non reçue, merci de réessayer plus tard diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e7e453a10..ba060956a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -158,7 +158,7 @@ Already have an account? Transport Some features require a &appName; account, such as group messaging, video conferences…\n\nThese features are hidden when you register with a third party SIP account.\n\nTo enable it in a commercial project, please contact us. - I prefer to create an account + I prefer to create a &appName; account I understand Push notifications not available, account creation disabled Push notification with auth token not received in 5 seconds, please try again later