diff --git a/app/src/main/java/org/linphone/ui/main/settings/fragment/SettingsAdvancedFragment.kt b/app/src/main/java/org/linphone/ui/main/settings/fragment/SettingsAdvancedFragment.kt index 146828fca..1f1458179 100644 --- a/app/src/main/java/org/linphone/ui/main/settings/fragment/SettingsAdvancedFragment.kt +++ b/app/src/main/java/org/linphone/ui/main/settings/fragment/SettingsAdvancedFragment.kt @@ -42,6 +42,15 @@ class SettingsAdvancedFragment : GenericMainFragment() { private lateinit var viewModel: SettingsViewModel + private val mediaEncryptionDropdownListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { + viewModel.setMediaEncryption(position) + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + } + } + private val inputAudioDeviceDropdownListener = object : AdapterView.OnItemSelectedListener { override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { viewModel.setInputAudioDevice(position) @@ -83,6 +92,10 @@ class SettingsAdvancedFragment : GenericMainFragment() { goBack() } + viewModel.mediaEncryptionIndex.observe(viewLifecycleOwner) { + setupMediaEncryptionPicker() + } + viewModel.inputAudioDeviceIndex.observe(viewLifecycleOwner) { setupInputAudioDevicePicker() } @@ -101,6 +114,19 @@ class SettingsAdvancedFragment : GenericMainFragment() { super.onPause() } + private fun setupMediaEncryptionPicker() { + val index = viewModel.mediaEncryptionIndex.value ?: 0 + val adapter = ArrayAdapter( + requireContext(), + R.layout.drop_down_item, + viewModel.mediaEncryptionLabels + ) + adapter.setDropDownViewResource(R.layout.generic_dropdown_cell) + binding.mediaEncryption.adapter = adapter + binding.mediaEncryption.onItemSelectedListener = mediaEncryptionDropdownListener + binding.mediaEncryption.setSelection(index) + } + private fun setupInputAudioDevicePicker() { val index = viewModel.inputAudioDeviceIndex.value ?: 0 val adapter = ArrayAdapter( diff --git a/app/src/main/java/org/linphone/ui/main/settings/viewmodel/SettingsViewModel.kt b/app/src/main/java/org/linphone/ui/main/settings/viewmodel/SettingsViewModel.kt index c14e24be9..420948859 100644 --- a/app/src/main/java/org/linphone/ui/main/settings/viewmodel/SettingsViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/settings/viewmodel/SettingsViewModel.kt @@ -33,6 +33,7 @@ import org.linphone.core.CoreListenerStub import org.linphone.core.EcCalibratorStatus import org.linphone.core.Factory import org.linphone.core.FriendList +import org.linphone.core.MediaEncryption import org.linphone.core.Tunnel import org.linphone.core.VFS import org.linphone.core.tools.Log @@ -179,6 +180,11 @@ class SettingsViewModel @UiThread constructor() : GenericViewModel() { val deviceName = MutableLiveData() val remoteProvisioningUrl = MutableLiveData() + val mediaEncryptionIndex = MutableLiveData() + val mediaEncryptionLabels = arrayListOf() + private val mediaEncryptionValues = arrayListOf() + val mediaEncryptionMandatory = MutableLiveData() + val expandAudioDevices = MutableLiveData() val inputAudioDeviceIndex = MutableLiveData() val inputAudioDeviceLabels = arrayListOf() @@ -291,6 +297,7 @@ class SettingsViewModel @UiThread constructor() : GenericViewModel() { deviceName.postValue(corePreferences.deviceName) remoteProvisioningUrl.postValue(core.provisioningUri) + setupMediaEncryption() setupAudioDevices() setupCodecs() } @@ -622,6 +629,53 @@ class SettingsViewModel @UiThread constructor() : GenericViewModel() { } } + @WorkerThread + private fun setupMediaEncryption() { + val core = coreContext.core + + mediaEncryptionLabels.clear() + mediaEncryptionValues.clear() + + var index = 0 + val defaultMediaEncryption = core.mediaEncryption + Log.i("$TAG Current media encryption is [$defaultMediaEncryption]") + for (encryption in MediaEncryption.entries) { + if (core.isMediaEncryptionSupported(encryption)) { + mediaEncryptionLabels.add(encryption.toString()) + mediaEncryptionValues.add(encryption) + if (encryption == defaultMediaEncryption) { + mediaEncryptionIndex.postValue(index) + } + index += 1 + } + } + + mediaEncryptionMandatory.postValue(core.isMediaEncryptionMandatory) + } + + @UiThread + fun setMediaEncryption(index: Int) { + coreContext.postOnCoreThread { core -> + val mediaEncryption = mediaEncryptionValues[index] + core.mediaEncryption = mediaEncryption + + if (mediaEncryption == MediaEncryption.None) { + core.isMediaEncryptionMandatory = false + mediaEncryptionMandatory.postValue(false) + } + } + } + + @UiThread + fun toggleMediaEncryptionMandatory() { + val newValue = mediaEncryptionMandatory.value == false + + coreContext.postOnCoreThread { core -> + core.isMediaEncryptionMandatory = newValue + mediaEncryptionMandatory.postValue(newValue) + } + } + @UiThread fun updateDeviceName() { coreContext.postOnCoreThread { diff --git a/app/src/main/res/layout/settings_advanced_fragment.xml b/app/src/main/res/layout/settings_advanced_fragment.xml index e5faad970..ea6229d69 100644 --- a/app/src/main/res/layout/settings_advanced_fragment.xml +++ b/app/src/main/res/layout/settings_advanced_fragment.xml @@ -100,6 +100,79 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/keep_alive_service_switch" /> + + + + + + + + + + + + app:layout_constraintTop_toBottomOf="@id/media_encryption_mandatory_switch"/> Paramètres avancés Garder l\'app en vie via un Service Nom du périphérique + Chiffrement du média + Rendre le chiffrement du média obligatoire URL de configuration distante Télécharger & appliquer Périphériques audio diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 610d246cc..8c8a9dbe0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -289,6 +289,8 @@ Advanced settings Keep app alive using Service Device ID + Media encryption + Media encryption mandatory Remote provisioning URL Download & apply Audio devices