Added media encryption statistics when long clicking media encryption icon on top of active call

This commit is contained in:
Sylvain Berfini 2024-01-19 15:03:21 +01:00
parent d232fa0d14
commit b185de70ca
10 changed files with 398 additions and 8 deletions

View file

@ -35,11 +35,13 @@ import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import androidx.window.layout.FoldingFeature
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.R
import org.linphone.core.tools.Log
import org.linphone.databinding.CallActiveFragmentBinding
import org.linphone.ui.call.CallActivity
import org.linphone.ui.call.model.CallMediaEncryptionModel
import org.linphone.ui.call.model.ZrtpSasConfirmationDialogModel
import org.linphone.ui.call.viewmodel.CallsViewModel
import org.linphone.ui.call.viewmodel.CurrentCallViewModel
@ -63,6 +65,8 @@ class ActiveCallFragment : GenericCallFragment() {
private var zrtpSasDialog: Dialog? = null
private var bottomSheetDialog: BottomSheetDialogFragment? = null
// For moving video preview purposes
private var previewX: Float = 0f
@ -152,6 +156,10 @@ class ActiveCallFragment : GenericCallFragment() {
findNavController().navigate(action)
}
binding.setCallStatisticsClickListener {
showCallStatistics()
}
sharedViewModel = requireActivity().run {
ViewModelProvider(this)[SharedCallViewModel::class.java]
}
@ -272,6 +280,12 @@ class ActiveCallFragment : GenericCallFragment() {
}
}
}
callViewModel.showMediaEncryptionStatisticsEvent.observe(viewLifecycleOwner) {
it.consume { model ->
showMediaEncryptionStatistics(model)
}
}
}
@SuppressLint("ClickableViewAccessibility")
@ -295,6 +309,9 @@ class ActiveCallFragment : GenericCallFragment() {
zrtpSasDialog?.dismiss()
zrtpSasDialog = null
bottomSheetDialog?.dismiss()
bottomSheetDialog = null
binding.localPreviewVideoSurface.setOnTouchListener(null)
}
@ -317,4 +334,17 @@ class ActiveCallFragment : GenericCallFragment() {
set.applyTo(constraintLayout)
}
private fun showCallStatistics() {
// TODO
}
private fun showMediaEncryptionStatistics(model: CallMediaEncryptionModel) {
val modalBottomSheet = MediaEncryptionStatisticsDialogFragment(model)
modalBottomSheet.show(
requireActivity().supportFragmentManager,
MediaEncryptionStatisticsDialogFragment.TAG
)
bottomSheetDialog = modalBottomSheet
}
}

View file

@ -0,0 +1,73 @@
/*
* Copyright (c) 2010-2023 Belledonne Communications SARL.
*
* This file is part of linphone-android
* (see https://www.linphone.org).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.linphone.ui.call.fragment
import android.app.Dialog
import android.content.DialogInterface
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.UiThread
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import org.linphone.databinding.CallMediaEncryptionStatsMenuBinding
import org.linphone.ui.call.model.CallMediaEncryptionModel
@UiThread
class MediaEncryptionStatisticsDialogFragment(
private val model: CallMediaEncryptionModel,
private val onDismiss: (() -> Unit)? = null
) : BottomSheetDialogFragment() {
companion object {
const val TAG = "MediaEncryptionStatisticsDialogFragment"
}
override fun onCancel(dialog: DialogInterface) {
onDismiss?.invoke()
super.onCancel(dialog)
}
override fun onDismiss(dialog: DialogInterface) {
onDismiss?.invoke()
super.onDismiss(dialog)
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
// Makes sure all menu entries are visible,
// required for landscape mode (otherwise only first item is visible)
dialog.behavior.state = BottomSheetBehavior.STATE_EXPANDED
return dialog
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val view = CallMediaEncryptionStatsMenuBinding.inflate(layoutInflater)
view.model = model
return view.root
}
}

View file

@ -0,0 +1,107 @@
/*
* Copyright (c) 2010-2023 Belledonne Communications SARL.
*
* This file is part of linphone-android
* (see https://www.linphone.org).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.linphone.ui.call.model
import androidx.annotation.WorkerThread
import androidx.lifecycle.MutableLiveData
import org.linphone.R
import org.linphone.core.Call
import org.linphone.core.MediaEncryption
import org.linphone.core.StreamType
import org.linphone.utils.AppUtils
class CallMediaEncryptionModel @WorkerThread constructor(call: Call) {
val mediaEncryption = MutableLiveData<String>()
val isMediaEncryptionZrtp = MutableLiveData<Boolean>()
val zrtpCipher = MutableLiveData<String>()
val zrtpKeyAgreement = MutableLiveData<String>()
val zrtpHash = MutableLiveData<String>()
val zrtpAuthTag = MutableLiveData<String>()
val zrtpAuthSas = MutableLiveData<String>()
init {
isMediaEncryptionZrtp.postValue(false)
val stats = call.getStats(StreamType.Audio)
if (stats != null) {
// ZRTP stats are only available when authentication token isn't null !
if (call.currentParams.mediaEncryption == MediaEncryption.ZRTP && call.authenticationToken != null) {
isMediaEncryptionZrtp.postValue(true)
if (stats.isZrtpKeyAgreementAlgoPostQuantum) {
mediaEncryption.postValue(
AppUtils.getFormattedString(
R.string.call_stats_media_encryption,
AppUtils.getString(
R.string.call_stats_media_encryption_zrtp_post_quantum
)
)
)
} else {
mediaEncryption.postValue(
AppUtils.getFormattedString(
R.string.call_stats_media_encryption,
call.currentParams.mediaEncryption.name
)
)
}
zrtpCipher.postValue(
AppUtils.getFormattedString(
R.string.call_stats_zrtp_cipher_algo,
stats.zrtpCipherAlgo
)
)
zrtpKeyAgreement.postValue(
AppUtils.getFormattedString(
R.string.call_stats_zrtp_key_agreement_algo,
stats.zrtpKeyAgreementAlgo
)
)
zrtpHash.postValue(
AppUtils.getFormattedString(
R.string.call_stats_zrtp_hash_algo,
stats.zrtpHashAlgo
)
)
zrtpAuthTag.postValue(
AppUtils.getFormattedString(
R.string.call_stats_zrtp_auth_tag_algo,
stats.zrtpAuthTagAlgo
)
)
zrtpAuthSas.postValue(
AppUtils.getFormattedString(
R.string.call_stats_zrtp_sas_algo,
stats.zrtpSasAlgo
)
)
} else {
mediaEncryption.postValue(
AppUtils.getFormattedString(
R.string.call_stats_media_encryption,
call.currentParams.mediaEncryption.name
)
)
}
}
}
}

View file

@ -41,6 +41,7 @@ import org.linphone.core.MediaDirection
import org.linphone.core.MediaEncryption
import org.linphone.core.tools.Log
import org.linphone.ui.call.model.AudioDeviceModel
import org.linphone.ui.call.model.CallMediaEncryptionModel
import org.linphone.ui.call.model.ConferenceModel
import org.linphone.ui.main.contacts.model.ContactAvatarModel
import org.linphone.ui.main.history.model.NumpadModel
@ -135,6 +136,10 @@ class CurrentCallViewModel @UiThread constructor() : ViewModel() {
MutableLiveData<Event<Pair<String, String>>>()
}
val showMediaEncryptionStatisticsEvent: MutableLiveData<Event<CallMediaEncryptionModel>> by lazy {
MutableLiveData<Event<CallMediaEncryptionModel>>()
}
// Conference
val conferenceModel = ConferenceModel()
@ -652,6 +657,16 @@ class CurrentCallViewModel @UiThread constructor() : ViewModel() {
}
}
@UiThread
fun showMediaEncryptionStatisticsIfPossible(): Boolean {
coreContext.postOnCoreThread {
val model = CallMediaEncryptionModel(currentCall)
showMediaEncryptionStatisticsEvent.postValue(Event(model))
}
return true
}
@WorkerThread
private fun showZrtpSasDialog(authToken: String) {
val upperCaseAuthToken = authToken.uppercase(Locale.getDefault())

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="256"
android:viewportHeight="256">
<path
android:pathData="M224,200h-8V40a8,8 0,0 0,-8 -8H152a8,8 0,0 0,-8 8V80H96a8,8 0,0 0,-8 8v40H48a8,8 0,0 0,-8 8v64H32a8,8 0,0 0,0 16H224a8,8 0,0 0,0 -16ZM160,48h40V200H160ZM104,96h40V200H104ZM56,144H88v56H56Z"
android:fillColor="#4e6074"/>
</vector>

View file

@ -12,7 +12,7 @@
name="callsListClickListener"
type="View.OnClickListener" />
<variable
name="chatClickListener"
name="callStatisticsClickListener"
type="View.OnClickListener" />
<variable
name="viewModel"
@ -120,16 +120,31 @@
<ImageView
android:id="@+id/chat"
android:onClick="@{chatClickListener}"
android:layout_width="0dp"
android:layout_height="@dimen/call_button_size"
android:layout_marginTop="@dimen/call_extra_button_top_margin"
android:background="@drawable/shape_round_in_call_disabled_button_background"
android:padding="@dimen/call_button_icon_padding"
android:src="@drawable/chat_teardrop_text"
android:visibility="gone"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="@id/chat_label"
app:layout_constraintStart_toStartOf="@id/chat_label"
app:layout_constraintTop_toBottomOf="@id/main_actions"
app:tint="@color/gray_500" />
<ImageView
android:id="@+id/stats"
android:onClick="@{callStatisticsClickListener}"
android:layout_width="0dp"
android:layout_height="@dimen/call_button_size"
android:layout_marginTop="@dimen/call_extra_button_top_margin"
android:background="@drawable/in_call_button_background_red"
android:padding="@dimen/call_button_icon_padding"
android:src="@drawable/chat_teardrop_text"
android:src="@drawable/chart_bar"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="@id/chat_label"
app:layout_constraintStart_toStartOf="@id/chat_label"
app:layout_constraintEnd_toEndOf="@id/stats_label"
app:layout_constraintStart_toStartOf="@id/stats_label"
app:layout_constraintTop_toBottomOf="@id/main_actions"
app:tint="@color/in_call_button_tint_color" />
@ -212,7 +227,7 @@
android:layout_height="wrap_content"
android:paddingBottom="15dp"
android:text="@string/call_action_show_dialer"
app:layout_constraintEnd_toStartOf="@id/chat_label"
app:layout_constraintEnd_toStartOf="@id/stats_label"
app:layout_constraintStart_toEndOf="@id/calls_list_label"
app:layout_constraintTop_toBottomOf="@id/numpad" />
@ -223,10 +238,23 @@
android:layout_height="wrap_content"
android:paddingBottom="15dp"
android:text="@string/call_action_show_messages"
android:visibility="gone"
app:layout_constraintEnd_toStartOf="@id/pause_call_label"
app:layout_constraintStart_toEndOf="@id/numpad_label"
app:layout_constraintTop_toBottomOf="@id/chat" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/stats_label"
android:onClick="@{callStatisticsClickListener}"
style="@style/in_call_extra_action_label_style"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingBottom="15dp"
android:text="@string/call_action_show_statistics"
app:layout_constraintEnd_toStartOf="@id/pause_call_label"
app:layout_constraintStart_toEndOf="@id/numpad_label"
app:layout_constraintTop_toBottomOf="@id/stats" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/in_call_extra_action_label_style"
android:id="@+id/pause_call_label"
@ -237,7 +265,7 @@
android:paddingBottom="15dp"
android:text="@{viewModel.isPaused ? @string/call_action_resume_call : @string/call_action_pause_call, default=@string/call_action_pause_call}"
app:layout_constraintEnd_toStartOf="@id/record_call_label"
app:layout_constraintStart_toEndOf="@id/chat_label"
app:layout_constraintStart_toEndOf="@id/stats_label"
app:layout_constraintTop_toBottomOf="@id/pause_call" />
<androidx.appcompat.widget.AppCompatTextView

View file

@ -11,6 +11,9 @@
<variable
name="callsListClickListener"
type="View.OnClickListener" />
<variable
name="callStatisticsClickListener"
type="View.OnClickListener" />
<variable
name="viewModel"
type="org.linphone.ui.call.viewmodel.CurrentCallViewModel" />
@ -123,12 +126,28 @@
android:padding="@dimen/call_button_icon_padding"
android:src="@drawable/chat_teardrop_text"
android:background="@drawable/shape_round_in_call_disabled_button_background"
android:visibility="gone"
app:tint="?attr/color_grey_500"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintTop_toBottomOf="@id/transfer_label"
app:layout_constraintStart_toStartOf="@id/transfer"
app:layout_constraintEnd_toEndOf="@id/transfer"/>
<ImageView
android:id="@+id/stats"
android:onClick="@{callStatisticsClickListener}"
android:layout_width="0dp"
android:layout_height="@dimen/call_button_size"
android:layout_marginTop="@dimen/call_extra_button_top_margin"
android:padding="@dimen/call_button_icon_padding"
android:src="@drawable/chart_bar"
android:background="@drawable/in_call_button_background_red"
app:tint="@color/in_call_button_tint_color"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintTop_toBottomOf="@id/transfer_label"
app:layout_constraintStart_toStartOf="@id/transfer"
app:layout_constraintEnd_toEndOf="@id/transfer"/>
<ImageView
android:id="@+id/pause_call"
android:onClick="@{() -> viewModel.togglePause()}"
@ -215,10 +234,22 @@
android:layout_height="wrap_content"
android:paddingBottom="15dp"
android:text="@string/call_action_show_messages"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@id/chat"
app:layout_constraintStart_toStartOf="@id/transfer_label"
app:layout_constraintEnd_toEndOf="@id/transfer_label" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/in_call_extra_action_label_style"
android:id="@+id/stats_label"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingBottom="15dp"
android:text="@string/call_action_show_statistics"
app:layout_constraintTop_toBottomOf="@id/stats"
app:layout_constraintStart_toStartOf="@id/transfer_label"
app:layout_constraintEnd_toEndOf="@id/transfer_label" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/in_call_extra_action_label_style"
android:id="@+id/pause_call_label"

View file

@ -12,6 +12,9 @@
<variable
name="callsListClickListener"
type="View.OnClickListener" />
<variable
name="callStatisticsClickListener"
type="View.OnClickListener" />
<variable
name="viewModel"
type="org.linphone.ui.call.viewmodel.CurrentCallViewModel" />
@ -195,6 +198,7 @@
<ImageView
android:id="@+id/media_encryption"
android:onClick="@{() -> viewModel.showZrtpSasDialogIfPossible()}"
android:onLongClick="@{() -> viewModel.showMediaEncryptionStatisticsIfPossible()}"
android:layout_width="@dimen/call_top_bar_info_height"
android:layout_height="@dimen/call_top_bar_info_height"
android:padding="10dp"
@ -253,7 +257,8 @@
bind:viewModel="@{viewModel}"
bind:callsViewModel="@{callsViewModel}"
bind:newCallClickListener="@{newCallClickListener}"
bind:callsListClickListener="@{callsListClickListener}"/>
bind:callsListClickListener="@{callsListClickListener}"
bind:callStatisticsClickListener="@{callStatisticsClickListener}"/>
<include
android:id="@+id/call_numpad"

View file

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<import type="android.view.View" />
<variable
name="model"
type="org.linphone.ui.call.model.CallMediaEncryptionModel" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatTextView
style="@style/context_menu_action_label_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="@{model.mediaEncryption}"
android:textColor="@color/black"
android:gravity="center_vertical" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/context_menu_action_label_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="@{model.zrtpCipher}"
android:textColor="@color/black"
android:gravity="center_vertical"
android:visibility="@{model.isMediaEncryptionZrtp ? View.VISIBLE : View.GONE}"/>
<androidx.appcompat.widget.AppCompatTextView
style="@style/context_menu_action_label_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="@{model.zrtpKeyAgreement}"
android:textColor="@color/black"
android:gravity="center_vertical"
android:visibility="@{model.isMediaEncryptionZrtp ? View.VISIBLE : View.GONE}" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/context_menu_action_label_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="@{model.zrtpHash}"
android:textColor="@color/black"
android:gravity="center_vertical"
android:visibility="@{model.isMediaEncryptionZrtp ? View.VISIBLE : View.GONE}" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/context_menu_action_label_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="@{model.zrtpAuthTag}"
android:textColor="@color/black"
android:gravity="center_vertical"
android:visibility="@{model.isMediaEncryptionZrtp ? View.VISIBLE : View.GONE}" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/context_menu_action_label_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="@{model.zrtpAuthSas}"
android:textColor="@color/black"
android:gravity="center_vertical"
android:visibility="@{model.isMediaEncryptionZrtp ? View.VISIBLE : View.GONE}" />
</LinearLayout>
</layout>

View file

@ -498,6 +498,7 @@
<string name="call_action_go_to_calls_list">Calls list</string>
<string name="call_action_show_dialer">Dialer</string>
<string name="call_action_show_messages">Messages</string>
<string name="call_action_show_statistics">Statistics</string>
<string name="call_action_pause_call">Pause</string>
<string name="call_action_resume_call">Resume</string>
<string name="call_action_record_call">Record</string>
@ -524,6 +525,14 @@
<string name="call_audio_device_type_headset">Headset</string>
<string name="call_audio_device_type_headphones">Headphones</string>
<string name="call_stats_media_encryption">Media encryption: %s</string>
<string name="call_stats_media_encryption_zrtp_post_quantum">Post Quantum ZRTP</string>
<string name="call_stats_zrtp_cipher_algo">Cipher algorithm: %s</string>
<string name="call_stats_zrtp_key_agreement_algo">Key agreement algorithm: %s</string>
<string name="call_stats_zrtp_hash_algo">Hash algorithm: %s</string>
<string name="call_stats_zrtp_auth_tag_algo">Authentication algorithm: %s</string>
<string name="call_stats_zrtp_sas_algo">SAS algorithm: %s</string>
<string name="conference_share_link_title">Share invitation</string>
<string name="conference_call_empty">Waiting for other participants…</string>
<string name="conference_action_screen_sharing">Screen share</string>