@ -16,8 +16,6 @@
@@ -16,8 +16,6 @@
package io.element.android.libraries.push.impl.notifications.channels
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.media.AudioAttributes
import android.media.AudioManager
@ -26,8 +24,8 @@ import android.os.Build
@@ -26,8 +24,8 @@ import android.os.Build
import androidx.annotation.ChecksSdkIntAtLeast
import androidx.core.app.NotificationChannelCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import com.squareup.anvil.annotations.ContributesBinding
import io.element.android.appconfig.NotificationConfig
import io.element.android.libraries.di.AppScope
import io.element.android.libraries.di.ApplicationContext
import io.element.android.libraries.di.SingleIn
@ -38,14 +36,9 @@ import javax.inject.Inject
@@ -38,14 +36,9 @@ import javax.inject.Inject
/ * === === === === === === === === === === === === === === === === === === === === === === === === === === === === === ===
* IDs for channels
* === === === === === === === === === === === === === === === === === === === === === === === === === === === === === === * /
private const val LISTENING _FOR _EVENTS _NOTIFICATION _CHANNEL _ID = " LISTEN_FOR_EVENTS_NOTIFICATION_CHANNEL_ID "
internal const val SILENT _NOTIFICATION _CHANNEL _ID = " DEFAULT_SILENT_NOTIFICATION_CHANNEL_ID_V2 "
internal const val NOISY _NOTIFICATION _CHANNEL _ID = " DEFAULT_NOISY_NOTIFICATION_CHANNEL_ID "
// Legacy channel
private const val CALL _NOTIFICATION _CHANNEL _ID _V2 = " CALL_NOTIFICATION_CHANNEL_ID_V2 "
internal const val CALL _NOTIFICATION _CHANNEL _ID _V3 = " CALL_NOTIFICATION_CHANNEL_ID_V3 "
internal const val CALL _NOTIFICATION _CHANNEL _ID = " CALL_NOTIFICATION_CHANNEL_ID_V3 "
internal const val RINGING _CALL _NOTIFICATION _CHANNEL _ID = " RINGING_CALL_NOTIFICATION_CHANNEL_ID "
/ * *
@ -96,7 +89,7 @@ class DefaultNotificationChannels @Inject constructor(
@@ -96,7 +89,7 @@ class DefaultNotificationChannels @Inject constructor(
return
}
val accentColor = ContextCompat . getColor ( context , R . color . notification _accent _color )
val accentColor = NotificationConfig . NOTIFICATION _ACCENT _COLOR
// Migration - the noisy channel was deleted and recreated when sound preference was changed (id was DEFAULT_NOISY_NOTIFICATION_CHANNEL_ID_BASE
// + currentTimeMillis).
@ -110,76 +103,62 @@ class DefaultNotificationChannels @Inject constructor(
@@ -110,76 +103,62 @@ class DefaultNotificationChannels @Inject constructor(
}
}
// Migration - Remove deprecated channels
for ( channelId in listOf ( " DEFAULT_SILENT_NOTIFICATION_CHANNEL_ID " , " CALL_NOTIFICATION_CHANNEL_ID " ) ) {
for ( channelId in listOf (
" DEFAULT_SILENT_NOTIFICATION_CHANNEL_ID " ,
" CALL_NOTIFICATION_CHANNEL_ID " ,
" CALL_NOTIFICATION_CHANNEL_ID_V2 " ,
" LISTEN_FOR_EVENTS_NOTIFICATION_CHANNEL_ID " ,
) ) {
notificationManager . getNotificationChannel ( channelId ) ?. let {
notificationManager . deleteNotificationChannel ( channelId )
}
}
// Migration - Create new call channel
notificationManager . deleteNotificationChannel ( CALL _NOTIFICATION _CHANNEL _ID _V2 )
/ * *
* Default notification importance : shows everywhere , makes noise , but does not visually
* intrude .
* /
notificationManager . createNotificationChannel (
NotificationChannel (
NotificationChannelCompat . Builder (
NOISY _NOTIFICATION _CHANNEL _ID ,
stringProvider . getString ( R . string . notification _channel _noisy ) . ifEmpty { " Noisy notifications " } ,
NotificationManager . IMPORTANCE _DEFAULT
NotificationManagerCompat . IMPORTANCE _DEFAULT
)
. appl y {
description = stringProvider . getString ( R . string . notification _channel _noisy )
enableVibration ( true )
enableLights ( true )
lightColor = accentColor
}
. setN ame ( stringProvider . getString ( R . string . notification _channel _noisy ) . ifEmpt y { " Noisy notifications " } )
. setDescription ( stringProvider . getString ( R . string . notification _channel _noisy ) )
. setVibrationEnabled ( true )
. setLightsEnabled ( true )
. setLightColor ( accentColor )
. build ( )
)
/ * *
* Low notification importance : shows everywhere , but is not intrusive .
* /
notificationManager . createNotificationChannel (
NotificationChannel (
NotificationChannelCompat . Builder (
SILENT _NOTIFICATION _CHANNEL _ID ,
stringProvider . getString ( R . string . notification _channel _silent ) . ifEmpty { " Silent notifications " } ,
NotificationManager . IMPORTANCE _LOW
NotificationManagerCompat . IMPORTANCE _LOW
)
. apply {
description = stringProvider . getString ( R . string . notification _channel _silent )
setSound ( null , null )
enableLights ( true )
lightColor = accentColor
}
)
notificationManager . createNotificationChannel (
NotificationChannel (
LISTENING _FOR _EVENTS _NOTIFICATION _CHANNEL _ID ,
stringProvider . getString ( R . string . notification _channel _listening _for _events ) . ifEmpty { " Listening for events " } ,
NotificationManager . IMPORTANCE _MIN
)
. apply {
description = stringProvider . getString ( R . string . notification _channel _listening _for _events )
setSound ( null , null )
setShowBadge ( false )
}
. setName ( stringProvider . getString ( R . string . notification _channel _silent ) . ifEmpty { " Silent notifications " } )
. setDescription ( stringProvider . getString ( R . string . notification _channel _silent ) )
. setSound ( null , null )
. setLightsEnabled ( true )
. setLightColor ( accentColor )
. build ( )
)
// Register a channel for incoming and in progress call notifications with no ringing
notificationManager . createNotificationChannel (
NotificationChannel (
CALL _NOTIFICATION _CHANNEL _ID _V3 ,
stringProvider . getString ( R . string . notification _channel _call ) . ifEmpty { " Call " } ,
NotificationManager . IMPORTANCE _HIGH
NotificationChannelCompat . Builder (
CALL _NOTIFICATION _CHANNEL _ID ,
NotificationManagerCompat . IMPORTANCE _HIGH
)
. appl y {
description = stringProvider . getString ( R . string . notification _channel _call )
enableVibration ( true )
enableLights ( true )
lightColor = accentColor
}
. setName ( stringProvider . getString ( R . string . notification _channel _call ) . ifEmpty { " Call " } )
. setDescription ( stringProvider . getString ( R . string . notification _channel _call ) )
. setVibrationEnabled ( true )
. setLightsEnabled ( true )
. setLightColor ( accentColor )
. build ( )
)
// Register a channel for incoming call notifications which will ring the device when received
@ -207,7 +186,7 @@ class DefaultNotificationChannels @Inject constructor(
@@ -207,7 +186,7 @@ class DefaultNotificationChannels @Inject constructor(
}
override fun getChannelForIncomingCall ( ring : Boolean ) : String {
return if ( ring ) RINGING _CALL _NOTIFICATION _CHANNEL _ID else CALL _NOTIFICATION _CHANNEL _ID _V3
return if ( ring ) RINGING _CALL _NOTIFICATION _CHANNEL _ID else CALL _NOTIFICATION _CHANNEL _ID
}
override fun getChannelIdForMessage ( noisy : Boolean ) : String {