Fix crash when getting the system ringtone for ringing calls (#3131)
This commit is contained in:
parent
e9e7d4d0c4
commit
e4e7cdfa17
2 changed files with 21 additions and 11 deletions
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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,14 +171,18 @@ 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 {
|
||||||
ringtoneUri,
|
if (ringtoneUri != null) {
|
||||||
AudioAttributes.Builder()
|
setSound(
|
||||||
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
ringtoneUri,
|
||||||
.setLegacyStreamType(AudioManager.STREAM_RING)
|
AudioAttributes.Builder()
|
||||||
.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
|
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
||||||
.build()
|
.setLegacyStreamType(AudioManager.STREAM_RING)
|
||||||
)
|
.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
|
||||||
|
.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…
Add table
Add a link
Reference in a new issue