Show toast if record_audio or camera permission is missing while in call, if request permission fails open the android app settings

This commit is contained in:
Sylvain Berfini 2025-01-20 12:25:56 +01:00
parent 7f49a7756c
commit fa9bcd3475
5 changed files with 55 additions and 16 deletions

View file

@ -372,28 +372,21 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
// 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")

View file

@ -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)
}
}

View file

@ -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
}

View file

@ -634,6 +634,8 @@
<string name="calls_paused_count_label">%s appels en pause</string>
<string name="calls_list_dialog_merge_into_conference_title">Fusionner les appels en une conférence ?</string>
<string name="calls_list_dialog_merge_into_conference_label">Créer une conférence</string>
<string name="call_audio_record_permission_not_granted_toast">Permission d\'enregistrer l\'audio déclinée !</string>
<string name="call_camera_permission_not_granted_toast">Permission d\'utliser la caméra déclinée !</string>
<string name="call_dialog_zrtp_validate_trust_title">Vérification de sécurité</string>
<string name="call_dialog_zrtp_validate_trust_message">Pour garantir le chiffrement, nous avons besoin dauthentifier lappareil de votre correspondant.\nVeuillez échanger vos codes :</string>

View file

@ -674,6 +674,8 @@
<string name="calls_paused_count_label">%s paused calls</string>
<string name="calls_list_dialog_merge_into_conference_title">Merge all calls into conference?</string>
<string name="calls_list_dialog_merge_into_conference_label">Create conference</string>
<string name="call_audio_record_permission_not_granted_toast">Audio record permission declined!</string>
<string name="call_camera_permission_not_granted_toast">Camera permission declined!</string>
<string name="call_dialog_zrtp_validate_trust_title">Validate the device</string>
<string name="call_dialog_zrtp_validate_trust_message">For your safety, we need to authenticate your correspondent device.\nPlease exchange your codes:</string>