From 7cff514c3ac2f2f8ed28a3d724f3e1b51b0ae502 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Fri, 17 May 2024 16:32:15 +0200 Subject: [PATCH] Hidden change mode area & child fragment in account profile, moved IM encryption mandatory to account settings --- .../viewmodel/AccountProfileViewModel.kt | 12 ---- .../viewmodel/AccountSettingsViewModel.kt | 26 +++++++-- .../shape_edit_text_disabled_background.xml | 4 +- .../res/layout/account_profile_fragment.xml | 57 +------------------ .../res/layout/account_settings_fragment.xml | 36 +++++++++++- app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 7 files changed, 59 insertions(+), 78 deletions(-) diff --git a/app/src/main/java/org/linphone/ui/main/settings/viewmodel/AccountProfileViewModel.kt b/app/src/main/java/org/linphone/ui/main/settings/viewmodel/AccountProfileViewModel.kt index 719605c1f..721b52f0e 100644 --- a/app/src/main/java/org/linphone/ui/main/settings/viewmodel/AccountProfileViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/settings/viewmodel/AccountProfileViewModel.kt @@ -54,8 +54,6 @@ class AccountProfileViewModel @UiThread constructor() : GenericViewModel() { val registerEnabled = MutableLiveData() - val showModeSelection = MutableLiveData() - val isCurrentlySelectedModeSecure = MutableLiveData() val devices = MutableLiveData>() @@ -117,16 +115,6 @@ class AccountProfileViewModel @UiThread constructor() : GenericViewModel() { sipAddress.postValue(account.params.identityAddress?.asStringUriOnly()) displayName.postValue(account.params.identityAddress?.displayName) - val limeServerUrl = account.params.limeServerUrl - val conferenceFactoryUri = account.params.conferenceFactoryUri - val showMode = limeServerUrl.orEmpty().isNotEmpty() && conferenceFactoryUri.orEmpty().isNotEmpty() - if (!showMode) { - Log.i( - "$TAG Either LIME server URL or conference factory URI isn't set, hiding end-to-end encrypted/interop mode selection" - ) - } - showModeSelection.postValue(showMode) - val devicesList = arrayListOf() // TODO FIXME: use real devices list from API, not implemented yet devices.postValue(devicesList) 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 ed1c0faba..4e2638e1e 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 @@ -20,6 +20,7 @@ package org.linphone.ui.main.settings.viewmodel import androidx.annotation.UiThread +import androidx.lifecycle.MediatorLiveData import androidx.lifecycle.MutableLiveData import java.util.Locale import org.linphone.LinphoneApplication.Companion.coreContext @@ -29,7 +30,6 @@ import org.linphone.core.NatPolicy import org.linphone.core.TransportType import org.linphone.core.tools.Log import org.linphone.ui.GenericViewModel -import org.linphone.ui.main.model.isEndToEndEncryptionMandatory import org.linphone.utils.Event class AccountSettingsViewModel @UiThread constructor() : GenericViewModel() { @@ -37,12 +37,14 @@ class AccountSettingsViewModel @UiThread constructor() : GenericViewModel() { private const val TAG = "[Account Settings ViewModel]" } - val isAccountInSecureMode = MutableLiveData() - val pushNotificationsAvailable = MutableLiveData() val pushNotificationsEnabled = MutableLiveData() + val imEncryptionMandatoryAvailable = MediatorLiveData() + + val imEncryptionMandatory = MutableLiveData() + val availableTransports = arrayListOf() val selectedTransport = MutableLiveData() @@ -78,6 +80,13 @@ class AccountSettingsViewModel @UiThread constructor() : GenericViewModel() { availableTransports.add(TransportType.Udp.name.uppercase(Locale.getDefault())) availableTransports.add(TransportType.Tcp.name.uppercase(Locale.getDefault())) availableTransports.add(TransportType.Tls.name.uppercase(Locale.getDefault())) + + imEncryptionMandatoryAvailable.addSource(limeServerUrl) { + imEncryptionMandatoryAvailable.value = isImEncrptionMandatoryAvailable() + } + imEncryptionMandatoryAvailable.addSource(conferenceFactoryUri) { + imEncryptionMandatoryAvailable.value = isImEncrptionMandatoryAvailable() + } } @UiThread @@ -90,8 +99,6 @@ class AccountSettingsViewModel @UiThread constructor() : GenericViewModel() { Log.i("$TAG Found matching account [$found]") account = found - isAccountInSecureMode.postValue(account.isEndToEndEncryptionMandatory()) - val params = account.params pushNotificationsAvailable.postValue(core.isPushNotificationAvailable) @@ -99,6 +106,8 @@ class AccountSettingsViewModel @UiThread constructor() : GenericViewModel() { core.isPushNotificationAvailable && params.pushNotificationAllowed ) + imEncryptionMandatory.postValue(params.instantMessagingEncryptionMandatory) + val transportType = params.serverAddress?.transport ?: TransportType.Tls selectedTransport.postValue(transportType) @@ -142,6 +151,8 @@ class AccountSettingsViewModel @UiThread constructor() : GenericViewModel() { val newParams = account.params.clone() newParams.pushNotificationAllowed = pushNotificationsEnabled.value == true + newParams.instantMessagingEncryptionMandatory = imEncryptionMandatory.value == true + val server = sipProxyServer.value.orEmpty() if (server.isNotEmpty()) { val serverAddress = core.interpretUrl(server, false) @@ -187,4 +198,9 @@ class AccountSettingsViewModel @UiThread constructor() : GenericViewModel() { } } } + + @UiThread + fun isImEncrptionMandatoryAvailable(): Boolean { + return limeServerUrl.value.orEmpty().isNotEmpty() && conferenceFactoryUri.value.orEmpty().isNotEmpty() + } } diff --git a/app/src/main/res/drawable/shape_edit_text_disabled_background.xml b/app/src/main/res/drawable/shape_edit_text_disabled_background.xml index b5eeed4fd..a73c9815f 100644 --- a/app/src/main/res/drawable/shape_edit_text_disabled_background.xml +++ b/app/src/main/res/drawable/shape_edit_text_disabled_background.xml @@ -1,6 +1,6 @@ - - + + \ No newline at end of file diff --git a/app/src/main/res/layout/account_profile_fragment.xml b/app/src/main/res/layout/account_profile_fragment.xml index b05737de6..c15339f08 100644 --- a/app/src/main/res/layout/account_profile_fragment.xml +++ b/app/src/main/res/layout/account_profile_fragment.xml @@ -86,12 +86,6 @@ app:constraint_referenced_ids="details_background, sip_address, sip_address_label, display_name, display_name_label, prefix, prefix_caret, prefix_label, prefix_label_tooltip" android:visibility="@{viewModel.expandDetails ? View.VISIBLE : View.GONE}" /> - - - - - - - - + app:layout_constraintTop_toBottomOf="@id/connection_background"/> + + + + @@ -303,7 +331,7 @@ android:layout_marginTop="20dp" android:layout_marginEnd="16dp" android:checked="@={viewModel.cpimInBasicChatRooms}" - android:visibility="@{viewModel.isAccountInSecureMode ? View.GONE : View.VISIBLE}" + android:visibility="@{viewModel.imEncryptionMandatory ? View.GONE : View.VISIBLE}" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/bundle_mode_switch" /> @@ -317,7 +345,7 @@ android:text="@string/account_settings_cpim_in_basic_conversations_title" android:maxLines="2" android:ellipsize="end" - android:visibility="@{viewModel.isAccountInSecureMode ? View.GONE : View.VISIBLE}" + android:visibility="@{viewModel.imEncryptionMandatory ? View.GONE : View.VISIBLE}" app:layout_constraintTop_toTopOf="@id/cpim_basic_chat_room_switch" app:layout_constraintBottom_toBottomOf="@id/cpim_basic_chat_room_switch" app:layout_constraintStart_toStartOf="parent" @@ -380,6 +408,7 @@ android:background="@drawable/edit_text_background" android:paddingStart="20dp" android:paddingEnd="20dp" + android:enabled="@{!viewModel.imEncryptionMandatory}" android:text="@={viewModel.conferenceFactoryUri}" android:inputType="text|textUri" app:layout_constraintStart_toStartOf="parent" @@ -443,6 +472,7 @@ android:background="@drawable/edit_text_background" android:paddingStart="20dp" android:paddingEnd="20dp" + android:enabled="@{!viewModel.imEncryptionMandatory}" android:text="@={viewModel.limeServerUrl}" android:inputType="text|textUri" 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 b4da16603..44afe725f 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -312,6 +312,7 @@ Paramètres de compte Autoriser les notifications poussées Les notifications poussées ne sont pas disponibles ! + Chiffrement obligatoire des conversations URL du serveur mandataire Serveur mandataire sortant URL du serveur STUN diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 642f84f0d..de5b099c2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -347,6 +347,7 @@ Account settings Allow push notifications Push notifications aren\'t available! + IM encryption mandatory SIP proxy server URL Outbound proxy STUN server URL