From ce3c37ad158ecea03426119974c176836bef6304 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Tue, 25 Jun 2024 11:25:01 +0200 Subject: [PATCH] Hide zrtp dialog alert try again button after second failed attempt + added landscape layout + fixed security level update on avatar --- .../ui/call/fragment/ActiveCallFragment.kt | 7 +- .../ui/call/model/ZrtpAlertDialogModel.kt | 2 +- .../ui/call/viewmodel/CurrentCallViewModel.kt | 41 +++-- .../dialog_zrtp_security_alert.xml | 140 ++++++++++++++++++ .../res/layout/dialog_zrtp_security_alert.xml | 1 + 5 files changed, 172 insertions(+), 19 deletions(-) create mode 100644 app/src/main/res/layout-land/dialog_zrtp_security_alert.xml diff --git a/app/src/main/java/org/linphone/ui/call/fragment/ActiveCallFragment.kt b/app/src/main/java/org/linphone/ui/call/fragment/ActiveCallFragment.kt index ab4d9e3a7..721caf2ed 100644 --- a/app/src/main/java/org/linphone/ui/call/fragment/ActiveCallFragment.kt +++ b/app/src/main/java/org/linphone/ui/call/fragment/ActiveCallFragment.kt @@ -239,7 +239,8 @@ class ActiveCallFragment : GenericCallFragment() { doNotTint = true ) } else { - showZrtpAlertDialog() + // Only allow "trying again" once + showZrtpAlertDialog(callViewModel.zrtpSasValidationAttempts == 1) } } } @@ -444,8 +445,8 @@ class ActiveCallFragment : GenericCallFragment() { zrtpSasDialog = dialog } - private fun showZrtpAlertDialog() { - val model = ZrtpAlertDialogModel() + private fun showZrtpAlertDialog(allowTryAgain: Boolean = true) { + val model = ZrtpAlertDialogModel(allowTryAgain) val dialog = DialogUtils.getZrtpAlertDialog(requireActivity(), model) model.tryAgainEvent.observe(viewLifecycleOwner) { event -> diff --git a/app/src/main/java/org/linphone/ui/call/model/ZrtpAlertDialogModel.kt b/app/src/main/java/org/linphone/ui/call/model/ZrtpAlertDialogModel.kt index a7005c352..9a90ca36a 100644 --- a/app/src/main/java/org/linphone/ui/call/model/ZrtpAlertDialogModel.kt +++ b/app/src/main/java/org/linphone/ui/call/model/ZrtpAlertDialogModel.kt @@ -24,7 +24,7 @@ import androidx.lifecycle.MutableLiveData import org.linphone.ui.GenericViewModel import org.linphone.utils.Event -class ZrtpAlertDialogModel @UiThread constructor() : GenericViewModel() { +class ZrtpAlertDialogModel @UiThread constructor(val allowTryAgain: Boolean) : GenericViewModel() { companion object { private const val TAG = "[ZRTP Alert Dialog]" } diff --git a/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt b/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt index 7f91fec70..15366ee18 100644 --- a/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt +++ b/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt @@ -177,6 +177,8 @@ class CurrentCallViewModel @UiThread constructor() : GenericViewModel() { MutableLiveData>() } + var zrtpSasValidationAttempts = 0 + // Chat val operationInProgress = MutableLiveData() @@ -243,11 +245,14 @@ class CurrentCallViewModel @UiThread constructor() : GenericViewModel() { Log.w( "$TAG Notified that authentication token is [${if (verified) "verified" else "not verified!"}]" ) + zrtpSasValidationAttempts += 1 isZrtpSasValidationRequired.postValue(!verified) zrtpAuthTokenVerifiedEvent.postValue(Event(verified)) if (verified) { isMediaEncrypted.postValue(true) } + + updateAvatarModelSecurityLevel(verified) } override fun onRemoteRecording(call: Call, recording: Boolean) { @@ -991,21 +996,7 @@ class CurrentCallViewModel @UiThread constructor() : GenericViewModel() { "$TAG Current call media encryption is ZRTP, auth token is [${if (isDeviceTrusted) "trusted" else "not trusted yet"}], cache mismatch is [$cacheMismatch]" ) - val securityLevel = if (isDeviceTrusted) SecurityLevel.EndToEndEncryptedAndVerified else SecurityLevel.EndToEndEncrypted - val avatarModel = contact.value - if (avatarModel != null && currentCall.conference == null) { // Don't do it for conferences - avatarModel.trust.postValue(securityLevel) - contact.postValue(avatarModel!!) - - // Also update avatar contact model if any for the rest of the app - val address = currentCall.remoteAddress - val storedModel = coreContext.contactsManager.getContactAvatarModelForAddress( - address - ) - storedModel.updateSecurityLevel(address) - } else { - Log.e("$TAG No avatar model found!") - } + updateAvatarModelSecurityLevel(isDeviceTrusted && !cacheMismatch) isMediaEncrypted.postValue(true) isZrtp.postValue(true) @@ -1053,6 +1044,7 @@ class CurrentCallViewModel @UiThread constructor() : GenericViewModel() { isMediaEncrypted.postValue(false) terminatedByUsed = false + zrtpSasValidationAttempts = 0 currentCall = call callStatsModel.update(call, call.audioStats) callMediaEncryptionModel.update(call) @@ -1231,4 +1223,23 @@ class CurrentCallViewModel @UiThread constructor() : GenericViewModel() { } } } + + @WorkerThread + private fun updateAvatarModelSecurityLevel(trusted: Boolean) { + val securityLevel = if (trusted) SecurityLevel.EndToEndEncryptedAndVerified else SecurityLevel.EndToEndEncrypted + val avatarModel = contact.value + if (avatarModel != null && currentCall.conference == null) { // Don't do it for conferences + avatarModel.trust.postValue(securityLevel) + contact.postValue(avatarModel!!) + } else { + Log.e("$TAG No avatar model found!") + } + + // Also update avatar contact model if any for the rest of the app + val address = currentCall.remoteAddress + val storedModel = coreContext.contactsManager.getContactAvatarModelForAddress( + address + ) + storedModel.updateSecurityLevel(address) + } } diff --git a/app/src/main/res/layout-land/dialog_zrtp_security_alert.xml b/app/src/main/res/layout-land/dialog_zrtp_security_alert.xml new file mode 100644 index 000000000..724004e94 --- /dev/null +++ b/app/src/main/res/layout-land/dialog_zrtp_security_alert.xml @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_zrtp_security_alert.xml b/app/src/main/res/layout/dialog_zrtp_security_alert.xml index f8b87e820..313340c22 100644 --- a/app/src/main/res/layout/dialog_zrtp_security_alert.xml +++ b/app/src/main/res/layout/dialog_zrtp_security_alert.xml @@ -95,6 +95,7 @@ android:textColor="?attr/color_danger_500" android:maxLines="1" android:ellipsize="end" + android:visibility="@{viewModel.allowTryAgain ? View.VISIBLE : View.GONE, default=gone}" app:layout_constraintWidth_max="@dimen/button_max_width" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"