Browse Source

Fix crash when getting the system ringtone for ringing calls (#3131)

pull/3133/head
Jorge Martin Espinosa 3 months ago committed by GitHub
parent
commit
05df1f2065
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      features/call/impl/src/main/kotlin/io/element/android/features/call/impl/notifications/RingingCallNotificationCreator.kt
  2. 9
      libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/channels/NotificationChannels.kt

9
features/call/impl/src/main/kotlin/io/element/android/features/call/impl/notifications/RingingCallNotificationCreator.kt

@ -116,7 +116,8 @@ class RingingCallNotificationCreator @Inject constructor(
false false
) )
val ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE) // TODO use a fallback ringtone if the default ringtone is not available
val ringtoneUri = runCatching { RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE) }.getOrNull()
return NotificationCompat.Builder(context, notificationChannelId) return NotificationCompat.Builder(context, notificationChannelId)
.setSmallIcon(CommonDrawables.ic_notification_small) .setSmallIcon(CommonDrawables.ic_notification_small)
.setPriority(NotificationCompat.PRIORITY_MAX) .setPriority(NotificationCompat.PRIORITY_MAX)
@ -127,7 +128,11 @@ class RingingCallNotificationCreator @Inject constructor(
.setWhen(timestamp) .setWhen(timestamp)
.setOngoing(true) .setOngoing(true)
.setShowWhen(false) .setShowWhen(false)
.setSound(ringtoneUri, AudioManager.STREAM_RING) .apply {
if (ringtoneUri != null) {
setSound(ringtoneUri, AudioManager.STREAM_RING)
}
}
.setTimeoutAfter(ElementCallConfig.RINGING_CALL_DURATION_SECONDS.seconds.inWholeMilliseconds) .setTimeoutAfter(ElementCallConfig.RINGING_CALL_DURATION_SECONDS.seconds.inWholeMilliseconds)
.setContentIntent(answerIntent) .setContentIntent(answerIntent)
.setDeleteIntent(declineIntent) .setDeleteIntent(declineIntent)

9
libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/channels/NotificationChannels.kt

@ -162,7 +162,8 @@ class DefaultNotificationChannels @Inject constructor(
) )
// Register a channel for incoming call notifications which will ring the device when received // Register a channel for incoming call notifications which will ring the device when received
val ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE) // TODO use a fallback ringtone if the default ringtone is not available
val ringtoneUri = runCatching { RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE) }.getOrNull()
notificationManager.createNotificationChannel( notificationManager.createNotificationChannel(
NotificationChannelCompat.Builder( NotificationChannelCompat.Builder(
RINGING_CALL_NOTIFICATION_CHANNEL_ID, RINGING_CALL_NOTIFICATION_CHANNEL_ID,
@ -170,7 +171,9 @@ class DefaultNotificationChannels @Inject constructor(
) )
.setName(stringProvider.getString(R.string.notification_channel_ringing_calls).ifEmpty { "Ringing calls" }) .setName(stringProvider.getString(R.string.notification_channel_ringing_calls).ifEmpty { "Ringing calls" })
.setVibrationEnabled(true) .setVibrationEnabled(true)
.setSound( .apply {
if (ringtoneUri != null) {
setSound(
ringtoneUri, ringtoneUri,
AudioAttributes.Builder() AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
@ -178,6 +181,8 @@ class DefaultNotificationChannels @Inject constructor(
.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE) .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
.build() .build()
) )
}
}
.setDescription(stringProvider.getString(R.string.notification_channel_ringing_calls)) .setDescription(stringProvider.getString(R.string.notification_channel_ringing_calls))
.setLightsEnabled(true) .setLightsEnabled(true)
.setLightColor(accentColor) .setLightColor(accentColor)

Loading…
Cancel
Save