Commit 439e1153 authored by Sylvain Berfini's avatar Sylvain Berfini :cow:
Browse files

Added media encryption & media encryption mandatory advanced settings

Showing with 158 additions and 1 deletion
......@@ -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(
......
......@@ -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<String>()
val remoteProvisioningUrl = MutableLiveData<String>()
val mediaEncryptionIndex = MutableLiveData<Int>()
val mediaEncryptionLabels = arrayListOf<String>()
private val mediaEncryptionValues = arrayListOf<MediaEncryption>()
val mediaEncryptionMandatory = MutableLiveData<Boolean>()
val expandAudioDevices = MutableLiveData<Boolean>()
val inputAudioDeviceIndex = MutableLiveData<Int>()
val inputAudioDeviceLabels = arrayListOf<String>()
......@@ -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 {
......
......@@ -100,6 +100,79 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/keep_alive_service_switch" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/settings_title_style"
android:id="@+id/media_encryption_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:text="@string/settings_advanced_media_encryption_title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/enable_fec_switch"/>
<androidx.appcompat.widget.AppCompatSpinner
style="@style/default_text_style"
android:id="@+id/media_encryption"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginEnd="16dp"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:textSize="14sp"
android:textColor="@color/gray_main2_600"
android:gravity="center_vertical"
android:overlapAnchor="false"
android:dropDownVerticalOffset="2dp"
android:spinnerMode="dropdown"
android:popupBackground="@drawable/shape_squircle_white_background"
android:background="@drawable/edit_text_background"
app:layout_constraintTop_toBottomOf="@id/media_encryption_label"
app:layout_constraintStart_toStartOf="@id/media_encryption_label"
app:layout_constraintEnd_toEndOf="parent" />
<ImageView
android:id="@+id/media_encryption_caret"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:src="@drawable/caret_down"
android:contentDescription="@null"
app:layout_constraintTop_toTopOf="@id/media_encryption"
app:layout_constraintBottom_toBottomOf="@id/media_encryption"
app:layout_constraintEnd_toEndOf="@id/media_encryption"/>
<androidx.appcompat.widget.AppCompatTextView
style="@style/settings_title_style"
android:onClick="@{() -> viewModel.toggleMediaEncryptionMandatory()}"
android:id="@+id/media_encryption_mandatory_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="10dp"
android:text="@string/settings_advanced_media_encryption_mandatory_title"
android:maxLines="2"
android:ellipsize="end"
app:layout_constraintTop_toTopOf="@id/media_encryption_mandatory_switch"
app:layout_constraintBottom_toBottomOf="@id/media_encryption_mandatory_switch"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/media_encryption_mandatory_switch"/>
<com.google.android.material.materialswitch.MaterialSwitch
style="@style/material_switch_style"
android:id="@+id/media_encryption_mandatory_switch"
android:onClick="@{() -> viewModel.toggleMediaEncryptionMandatory()}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginEnd="16dp"
android:checked="@{viewModel.mediaEncryptionMandatory}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/media_encryption" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/settings_title_style"
android:id="@+id/push_notifications_title"
......@@ -126,7 +199,7 @@
android:paddingBottom="8dp"
android:text="@string/settings_advanced_device_id"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/enable_fec_switch"/>
app:layout_constraintTop_toBottomOf="@id/media_encryption_mandatory_switch"/>
<androidx.appcompat.widget.AppCompatEditText
style="@style/default_text_style"
......
......@@ -252,6 +252,8 @@
<string name="settings_advanced_title">Paramètres avancés</string>
<string name="settings_advanced_keep_alive_service_title">Garder l\'app en vie via un Service</string>
<string name="settings_advanced_device_id">Nom du périphérique</string>
<string name="settings_advanced_media_encryption_title">Chiffrement du média</string>
<string name="settings_advanced_media_encryption_mandatory_title">Rendre le chiffrement du média obligatoire</string>
<string name="settings_advanced_remote_provisioning_url">URL de configuration distante</string>
<string name="settings_advanced_download_apply_remote_provisioning">Télécharger &amp; appliquer</string>
<string name="settings_advanced_audio_devices_title">Périphériques audio</string>
......
......@@ -289,6 +289,8 @@
<string name="settings_advanced_title">Advanced settings</string>
<string name="settings_advanced_keep_alive_service_title">Keep app alive using Service</string>
<string name="settings_advanced_device_id">Device ID</string>
<string name="settings_advanced_media_encryption_title">Media encryption</string>
<string name="settings_advanced_media_encryption_mandatory_title">Media encryption mandatory</string>
<string name="settings_advanced_remote_provisioning_url">Remote provisioning URL</string>
<string name="settings_advanced_download_apply_remote_provisioning">Download &amp; apply</string>
<string name="settings_advanced_audio_devices_title">Audio devices</string>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment