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 51e56e5c0..d3e95faab 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 @@ -36,6 +36,7 @@ import org.linphone.core.AlertListenerStub import org.linphone.core.AudioDevice import org.linphone.core.Call import org.linphone.core.CallListenerStub +import org.linphone.core.ChatRoom.SecurityLevel import org.linphone.core.Core import org.linphone.core.CoreListenerStub import org.linphone.core.MediaDirection @@ -556,19 +557,20 @@ class CurrentCallViewModel @UiThread constructor() : ViewModel() { when (currentCall.currentParams.mediaEncryption) { MediaEncryption.ZRTP -> { val authToken = currentCall.authenticationToken - val deviceIsTrusted = currentCall.authenticationTokenVerified && authToken != null + val isDeviceTrusted = currentCall.authenticationTokenVerified && authToken != null Log.i( - "$TAG Current call media encryption is ZRTP, auth token is ${if (deviceIsTrusted) "trusted" else "not trusted yet"}" + "$TAG Current call media encryption is ZRTP, auth token is ${if (isDeviceTrusted) "trusted" else "not trusted yet"}" ) - isRemoteDeviceTrusted.postValue(deviceIsTrusted) - contact.value?.showTrust?.postValue(deviceIsTrusted) + isRemoteDeviceTrusted.postValue(isDeviceTrusted) + val securityLevel = if (isDeviceTrusted) SecurityLevel.Encrypted else SecurityLevel.Safe + contact.value?.trust?.postValue(securityLevel) - if (!deviceIsTrusted && authToken.orEmpty().isNotEmpty()) { + if (!isDeviceTrusted && authToken.orEmpty().isNotEmpty()) { Log.i("$TAG Showing ZRTP SAS confirmation dialog") showZrtpSasDialog(authToken!!.uppercase(Locale.getDefault())) } - return deviceIsTrusted + return isDeviceTrusted } MediaEncryption.SRTP, MediaEncryption.DTLS -> { } @@ -614,18 +616,19 @@ class CurrentCallViewModel @UiThread constructor() : ViewModel() { displayedAddress.postValue(address.asStringUriOnly()) val isDeviceTrusted = updateEncryption() + val securityLevel = if (isDeviceTrusted) SecurityLevel.Encrypted else SecurityLevel.Safe val friend = coreContext.contactsManager.findContactByAddress(address) if (friend != null) { displayedName.postValue(friend.name) val model = ContactAvatarModel(friend) - model.showTrust.postValue(isDeviceTrusted) + model.trust.postValue(securityLevel) contact.postValue(model) } else { val fakeFriend = coreContext.core.createFriend() fakeFriend.name = LinphoneUtils.getDisplayName(address) fakeFriend.addAddress(address) val model = ContactAvatarModel(fakeFriend) - model.showTrust.postValue(isDeviceTrusted) + model.trust.postValue(securityLevel) contact.postValue(model) displayedName.postValue(fakeFriend.name) } diff --git a/app/src/main/java/org/linphone/ui/main/contacts/model/ContactAvatarModel.kt b/app/src/main/java/org/linphone/ui/main/contacts/model/ContactAvatarModel.kt index 0b93c78bd..51cf018ee 100644 --- a/app/src/main/java/org/linphone/ui/main/contacts/model/ContactAvatarModel.kt +++ b/app/src/main/java/org/linphone/ui/main/contacts/model/ContactAvatarModel.kt @@ -25,6 +25,7 @@ import android.provider.ContactsContract import androidx.annotation.WorkerThread import androidx.lifecycle.MutableLiveData import org.linphone.R +import org.linphone.core.ChatRoom.SecurityLevel import org.linphone.core.ConsolidatedPresence import org.linphone.core.Friend import org.linphone.core.FriendListenerStub @@ -55,7 +56,7 @@ class ContactAvatarModel @WorkerThread constructor(val friend: Friend) { val firstContactStartingByThatLetter = MutableLiveData() - val showTrust = MutableLiveData() + val trust = MutableLiveData() private val friendListener = object : FriendListenerStub() { @WorkerThread @@ -70,6 +71,8 @@ class ContactAvatarModel @WorkerThread constructor(val friend: Friend) { init { friend.addListener(friendListener) + trust.postValue(SecurityLevel.Safe) // TODO FIXME: use API + name.postValue(friend.name) computePresence() avatar.postValue(getAvatarUri()) diff --git a/app/src/main/java/org/linphone/utils/DataBindingUtils.kt b/app/src/main/java/org/linphone/utils/DataBindingUtils.kt index 66e164dcc..ae8f858bc 100644 --- a/app/src/main/java/org/linphone/utils/DataBindingUtils.kt +++ b/app/src/main/java/org/linphone/utils/DataBindingUtils.kt @@ -53,6 +53,7 @@ import io.getstream.avatarview.AvatarView import io.getstream.avatarview.coil.loadImage import org.linphone.BR import org.linphone.R +import org.linphone.core.ChatRoom import org.linphone.core.ConsolidatedPresence import org.linphone.core.tools.Log import org.linphone.ui.main.contacts.model.ContactAvatarModel @@ -306,13 +307,22 @@ fun AvatarView.loadContactAvatar(contact: ContactAvatarModel?) { avatarInitials = initials } - if (contact.showTrust.value == true) { - avatarBorderColor = - resources.getColor(R.color.blue_info_500, context.theme) - avatarBorderWidth = - AppUtils.getDimension(R.dimen.avatar_trust_border_width).toInt() - } else { - avatarBorderWidth = AppUtils.getDimension(R.dimen.zero).toInt() + when (contact.trust.value) { + ChatRoom.SecurityLevel.Unsafe -> { + avatarBorderColor = + resources.getColor(R.color.red_danger_500, context.theme) + avatarBorderWidth = + AppUtils.getDimension(R.dimen.avatar_trust_border_width).toInt() + } + ChatRoom.SecurityLevel.Encrypted -> { + avatarBorderColor = + resources.getColor(R.color.blue_info_500, context.theme) + avatarBorderWidth = + AppUtils.getDimension(R.dimen.avatar_trust_border_width).toInt() + } + else -> { + avatarBorderWidth = AppUtils.getDimension(R.dimen.zero).toInt() + } } }, onSuccess = { _, _ -> diff --git a/app/src/main/res/drawable/not_trusted.xml b/app/src/main/res/drawable/not_trusted.xml new file mode 100644 index 000000000..456af5f53 --- /dev/null +++ b/app/src/main/res/drawable/not_trusted.xml @@ -0,0 +1,23 @@ + + + + + + + + + diff --git a/app/src/main/res/layout/call_active_fragment.xml b/app/src/main/res/layout/call_active_fragment.xml index c37a73d13..f000cea8c 100644 --- a/app/src/main/res/layout/call_active_fragment.xml +++ b/app/src/main/res/layout/call_active_fragment.xml @@ -5,6 +5,7 @@ + @@ -90,8 +91,8 @@ android:id="@+id/trust_badge" android:layout_width="@dimen/avatar_presence_badge_in_call_size" android:layout_height="@dimen/avatar_presence_badge_in_call_size" - android:src="@drawable/trusted" - android:visibility="@{viewModel.contact.showTrust ? View.VISIBLE : View.GONE}" + android:src="@{viewModel.contact.trust == SecurityLevel.Encrypted ? @drawable/trusted : @drawable/not_trusted, default=@drawable/trusted}" + android:visibility="@{viewModel.contact.trust == SecurityLevel.Encrypted || viewModel.contact.trust == SecurityLevel.Unsafe ? View.VISIBLE : View.GONE}" app:layout_constraintStart_toStartOf="@id/avatar" app:layout_constraintBottom_toBottomOf="@id/avatar"/> diff --git a/app/src/main/res/layout/contact_favourite_list_cell.xml b/app/src/main/res/layout/contact_favourite_list_cell.xml index 436b20877..2061436e4 100644 --- a/app/src/main/res/layout/contact_favourite_list_cell.xml +++ b/app/src/main/res/layout/contact_favourite_list_cell.xml @@ -6,6 +6,7 @@ + @@ -55,6 +56,15 @@ app:layout_constraintEnd_toEndOf="@id/avatar" app:layout_constraintBottom_toBottomOf="@id/avatar"/> + + + @@ -125,6 +126,15 @@ app:layout_constraintEnd_toEndOf="@id/avatar" app:layout_constraintBottom_toBottomOf="@id/avatar"/> + + + @@ -84,6 +85,15 @@ app:layout_constraintEnd_toEndOf="@id/avatar" app:layout_constraintBottom_toBottomOf="@id/avatar"/> + + + @@ -99,6 +100,15 @@ app:layout_constraintEnd_toEndOf="@id/avatar" app:layout_constraintBottom_toBottomOf="@id/avatar"/> + + + @@ -61,6 +62,15 @@ app:layout_constraintEnd_toEndOf="@id/avatar" app:layout_constraintBottom_toBottomOf="@id/avatar"/> + +