Null ringtone Uri must be allowed

App would crash on pre-Oreo devices with "No sound" setting

Signed-off-by: Dariusz Olszewski <starypatyk@users.noreply.github.com>
This commit is contained in:
Dariusz Olszewski 2021-12-27 17:30:29 +01:00 committed by Marcel Hibbe
parent d99295118b
commit c99da0282d
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B

View File

@ -65,7 +65,7 @@ object NotificationUtils {
channelId: String, channelId: String,
channelName: String, channelName: String,
channelDescription: String, channelDescription: String,
sound: Uri, sound: Uri?,
audioAttributes: AudioAttributes audioAttributes: AudioAttributes
) { ) {
@ -281,7 +281,7 @@ object NotificationUtils {
ringtonePreferencesString: String?, ringtonePreferencesString: String?,
defaultRingtoneUri: String, defaultRingtoneUri: String,
channelId: String channelId: String
): Uri { ): Uri? {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = getNotificationChannel(context, channelId) val channel = getNotificationChannel(context, channelId)
if (channel != null) { if (channel != null) {
@ -296,7 +296,7 @@ object NotificationUtils {
try { try {
val ringtoneSettings = val ringtoneSettings =
LoganSquare.parse(ringtonePreferencesString, RingtoneSettings::class.java) LoganSquare.parse(ringtonePreferencesString, RingtoneSettings::class.java)
return ringtoneSettings.ringtoneUri!! return ringtoneSettings.ringtoneUri
} catch (exception: IOException) { } catch (exception: IOException) {
return Uri.parse(defaultRingtoneUri) return Uri.parse(defaultRingtoneUri)
} }
@ -306,7 +306,7 @@ object NotificationUtils {
fun getCallRingtoneUri( fun getCallRingtoneUri(
context: Context, context: Context,
appPreferences: AppPreferences appPreferences: AppPreferences
): Uri { ): Uri? {
return getRingtoneUri( return getRingtoneUri(
context, context,
appPreferences.callRingtoneUri, DEFAULT_CALL_RINGTONE_URI, NOTIFICATION_CHANNEL_CALLS_V4 appPreferences.callRingtoneUri, DEFAULT_CALL_RINGTONE_URI, NOTIFICATION_CHANNEL_CALLS_V4
@ -316,7 +316,7 @@ object NotificationUtils {
fun getMessageRingtoneUri( fun getMessageRingtoneUri(
context: Context, context: Context,
appPreferences: AppPreferences appPreferences: AppPreferences
): Uri { ): Uri? {
return getRingtoneUri( return getRingtoneUri(
context, context,
appPreferences.messageRingtoneUri, DEFAULT_MESSAGE_RINGTONE_URI, NOTIFICATION_CHANNEL_MESSAGES_V4 appPreferences.messageRingtoneUri, DEFAULT_MESSAGE_RINGTONE_URI, NOTIFICATION_CHANNEL_MESSAGES_V4