77
88package io.element.android.libraries.push.impl.notifications.channels
99
10+ import android.content.ContentResolver
11+ import android.content.Context
1012import android.media.AudioAttributes
13+ import android.media.AudioAttributes.USAGE_NOTIFICATION
1114import android.media.AudioManager
15+ import android.net.Uri
1216import android.os.Build
1317import android.provider.Settings
1418import androidx.annotation.ChecksSdkIntAtLeast
@@ -19,14 +23,15 @@ import dev.zacsweers.metro.ContributesBinding
1923import dev.zacsweers.metro.Inject
2024import dev.zacsweers.metro.SingleIn
2125import io.element.android.appconfig.NotificationConfig
26+ import io.element.android.libraries.di.annotations.ApplicationContext
2227import io.element.android.libraries.push.impl.R
2328import io.element.android.services.toolbox.api.strings.StringProvider
2429
2530/* ==========================================================================================
2631 * IDs for channels
2732 * ========================================================================================== */
2833internal const val SILENT_NOTIFICATION_CHANNEL_ID = " DEFAULT_SILENT_NOTIFICATION_CHANNEL_ID_V2"
29- internal const val NOISY_NOTIFICATION_CHANNEL_ID = " DEFAULT_NOISY_NOTIFICATION_CHANNEL_ID "
34+ internal const val NOISY_NOTIFICATION_CHANNEL_ID = " DEFAULT_NOISY_NOTIFICATION_CHANNEL_ID_V2 "
3035internal const val CALL_NOTIFICATION_CHANNEL_ID = " CALL_NOTIFICATION_CHANNEL_ID_V3"
3136internal const val RINGING_CALL_NOTIFICATION_CHANNEL_ID = " RINGING_CALL_NOTIFICATION_CHANNEL_ID"
3237
@@ -61,6 +66,8 @@ private fun supportNotificationChannels() = Build.VERSION.SDK_INT >= Build.VERSI
6166class DefaultNotificationChannels (
6267 private val notificationManager : NotificationManagerCompat ,
6368 private val stringProvider : StringProvider ,
69+ @ApplicationContext
70+ private val context : Context ,
6471) : NotificationChannels {
6572 init {
6673 createNotificationChannels()
@@ -94,6 +101,7 @@ class DefaultNotificationChannels(
94101 // Migration - Remove deprecated channels
95102 for (channelId in listOf (
96103 " DEFAULT_SILENT_NOTIFICATION_CHANNEL_ID" ,
104+ " DEFAULT_NOISY_NOTIFICATION_CHANNEL_ID" ,
97105 " CALL_NOTIFICATION_CHANNEL_ID" ,
98106 " CALL_NOTIFICATION_CHANNEL_ID_V2" ,
99107 " LISTEN_FOR_EVENTS_NOTIFICATION_CHANNEL_ID" ,
@@ -112,6 +120,17 @@ class DefaultNotificationChannels(
112120 NOISY_NOTIFICATION_CHANNEL_ID ,
113121 NotificationManagerCompat .IMPORTANCE_DEFAULT
114122 )
123+ .setSound(
124+ Uri .Builder ()
125+ .scheme(ContentResolver .SCHEME_ANDROID_RESOURCE )
126+ // Strangely wwe have to provide a "//" before the package name
127+ .path(" //" + context.packageName + " /" + R .raw.message)
128+ .build(),
129+ AudioAttributes .Builder ()
130+ .setContentType(AudioAttributes .CONTENT_TYPE_SONIFICATION )
131+ .setUsage(USAGE_NOTIFICATION )
132+ .build(),
133+ )
115134 .setName(stringProvider.getString(R .string.notification_channel_noisy).ifEmpty { " Noisy notifications" })
116135 .setDescription(stringProvider.getString(R .string.notification_channel_noisy))
117136 .setVibrationEnabled(true )
0 commit comments