From fa9bcd3475644b00b0ddafec4d14defac82f7c8c Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 20 Jan 2025 12:25:56 +0100 Subject: [PATCH] Show toast if record_audio or camera permission is missing while in call, if request permission fails open the android app settings --- .../org/linphone/contacts/ContactLoader.kt | 25 +++++------- .../java/org/linphone/ui/call/CallActivity.kt | 40 +++++++++++++++++++ .../ui/call/viewmodel/CurrentCallViewModel.kt | 2 + app/src/main/res/values-fr/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + 5 files changed, 55 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/org/linphone/contacts/ContactLoader.kt b/app/src/main/java/org/linphone/contacts/ContactLoader.kt index 07abcb678..9dc079f40 100644 --- a/app/src/main/java/org/linphone/contacts/ContactLoader.kt +++ b/app/src/main/java/org/linphone/contacts/ContactLoader.kt @@ -372,28 +372,21 @@ class ContactLoader : LoaderManager.LoaderCallbacks { // Check for newly created friends since last sync val localFriends = friendsList.friends - for (key in friends.keys) { + for ((key, newFriend) in friends.entries) { val found = localFriends.find { it.refKey == key } if (found == null) { - val newFriend = friends[key] - if (newFriend != null) { - if (newFriend.refKey == null) { - Log.w( - "$TAG Found friend [${newFriend.name}] with no refKey, using ID [$key]" - ) - newFriend.refKey = key - } - Log.i( - "$TAG Friend [${newFriend.name}] with ref key [${newFriend.refKey}] not found in currently stored list, adding it" - ) - friendsList.addLocalFriend(newFriend) - } else { - Log.e( - "$TAG Expected to find newly fetched friend with ref key [$key] but was null!" + if (newFriend.refKey == null) { + Log.w( + "$TAG Found friend [${newFriend.name}] with no refKey, using ID [$key]" ) + newFriend.refKey = key } + Log.i( + "$TAG Friend [${newFriend.name}] with ref key [${newFriend.refKey}] not found in currently stored list, adding it" + ) + friendsList.addLocalFriend(newFriend) } } Log.i("$TAG Friends synchronized") diff --git a/app/src/main/java/org/linphone/ui/call/CallActivity.kt b/app/src/main/java/org/linphone/ui/call/CallActivity.kt index 0c3a22ab0..9f939d959 100644 --- a/app/src/main/java/org/linphone/ui/call/CallActivity.kt +++ b/app/src/main/java/org/linphone/ui/call/CallActivity.kt @@ -24,12 +24,15 @@ import android.content.Intent import android.content.pm.PackageManager import android.content.res.Resources import android.graphics.Color +import android.net.Uri import android.os.Bundle import android.os.PowerManager +import android.provider.Settings import androidx.activity.SystemBarStyle import androidx.activity.enableEdgeToEdge import androidx.activity.result.contract.ActivityResultContracts import androidx.annotation.UiThread +import androidx.core.app.ActivityCompat import androidx.core.view.ViewCompat import androidx.core.view.WindowCompat import androidx.core.view.WindowInsetsCompat @@ -93,6 +96,7 @@ class CallActivity : GenericActivity() { callViewModel.toggleVideo() } else { Log.e("$TAG CAMERA permission has been denied") + goToAndroidPermissionSettings() } } @@ -104,6 +108,7 @@ class CallActivity : GenericActivity() { callViewModel.toggleMuteMicrophone() } else { Log.e("$TAG RECORD_AUDIO permission has been denied") + goToAndroidPermissionSettings() } } @@ -328,6 +333,28 @@ class CallActivity : GenericActivity() { } callsViewModel.showTopBar.postValue(showTopBar) } + + if (ActivityCompat.checkSelfPermission( + this, + Manifest.permission.RECORD_AUDIO + ) != PackageManager.PERMISSION_GRANTED + ) { + Log.e("$TAG RECORD_AUDIO permission isn't granted") + val message = R.string.call_audio_record_permission_not_granted_toast + val icon = R.drawable.warning_circle + showRedToast(getString(message), icon) + } + + if (ActivityCompat.checkSelfPermission( + this, + Manifest.permission.CAMERA + ) != PackageManager.PERMISSION_GRANTED + ) { + Log.e("$TAG CAMERA permission isn't granted") + val message = R.string.call_camera_permission_not_granted_toast + val icon = R.drawable.warning_circle + showRedToast(getString(message), icon) + } } override fun onResume() { @@ -524,4 +551,17 @@ class CallActivity : GenericActivity() { proximityWakeLock.release(PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY) } } + + private fun goToAndroidPermissionSettings() { + Log.i("$TAG Going into Android settings for our app") + val intent = Intent( + Settings.ACTION_APPLICATION_DETAILS_SETTINGS, + Uri.fromParts( + "package", + packageName, null + ) + ) + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + startActivity(intent) + } } 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 2be680c1f..a5b7bab9d 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 @@ -653,6 +653,7 @@ class CurrentCallViewModel Manifest.permission.RECORD_AUDIO ) != PackageManager.PERMISSION_GRANTED ) { + Log.w("$TAG RECORD_AUDIO permission isn't granted, requesting it") requestRecordAudioPermission.postValue(Event(true)) return } @@ -789,6 +790,7 @@ class CurrentCallViewModel Manifest.permission.CAMERA ) != PackageManager.PERMISSION_GRANTED ) { + Log.w("$TAG CAMERA permission isn't granted, requesting it") requestCameraPermission.postValue(Event(true)) return } diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 6c867da96..fe62dd8b1 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -634,6 +634,8 @@ %s appels en pause Fusionner les appels en une conférence ? Créer une conférence + Permission d\'enregistrer l\'audio déclinée ! + Permission d\'utliser la caméra déclinée ! Vérification de sécurité Pour garantir le chiffrement, nous avons besoin d’authentifier l’appareil de votre correspondant.\nVeuillez échanger vos codes : diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 95a788122..aa3292e04 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -674,6 +674,8 @@ %s paused calls Merge all calls into conference? Create conference + Audio record permission declined! + Camera permission declined! Validate the device For your safety, we need to authenticate your correspondent device.\nPlease exchange your codes: