Fixed issue with call notifications & channels

This commit is contained in:
Sylvain Berfini 2023-09-11 14:20:01 +02:00
parent 18254fd385
commit e4551713dc
2 changed files with 29 additions and 9 deletions

View file

@ -106,6 +106,7 @@ class NotificationsManager @MainThread constructor(private val context: Context)
init {
createServiceChannel()
createIncomingCallNotificationChannel()
createActiveCallNotificationChannel()
for (notification in notificationManager.activeNotifications) {
if (notification.tag.isNullOrEmpty()) {
@ -181,11 +182,11 @@ class NotificationsManager @MainThread constructor(private val context: Context)
@WorkerThread
private fun startCallForeground() {
val channelId = context.getString(R.string.notification_channel_service_id)
val channelId = context.getString(R.string.notification_channel_call_id)
val channel = notificationManager.getNotificationChannel(channelId)
val importance = channel?.importance ?: NotificationManagerCompat.IMPORTANCE_NONE
if (importance == NotificationManagerCompat.IMPORTANCE_NONE) {
Log.e("$TAG Service channel has been disabled, can't start foreground service!")
Log.e("$TAG Calls channel has been disabled, can't start foreground service!")
return
}
@ -328,10 +329,13 @@ class NotificationsManager @MainThread constructor(private val context: Context)
)
}
val channel = if (isIncoming) {
context.getString(R.string.notification_channel_incoming_call_id)
} else {
context.getString(R.string.notification_channel_service_id)
val channel = when (call.state) {
Call.State.IncomingReceived, Call.State.IncomingEarlyMedia -> {
context.getString(R.string.notification_channel_incoming_call_id)
}
else -> {
context.getString(R.string.notification_channel_call_id)
}
}
val builder = NotificationCompat.Builder(
@ -349,7 +353,7 @@ class NotificationsManager @MainThread constructor(private val context: Context)
setStyle(style)
} catch (iae: IllegalArgumentException) {
Log.e(
"[Api31 Compatibility] Can't use notification call style: $iae, using API 26 notification instead"
"$TAG Can't use notification call style: $iae, using API 26 notification instead"
)
}
setSmallIcon(smallIcon)
@ -432,13 +436,27 @@ class NotificationsManager @MainThread constructor(private val context: Context)
val channel = NotificationChannel(id, name, NotificationManager.IMPORTANCE_HIGH)
channel.description = name
channel.lightColor = context.getColor(R.color.primary_color)
channel.lockscreenVisibility
channel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
channel.enableVibration(true)
channel.enableLights(true)
channel.setShowBadge(false)
notificationManager.createNotificationChannel(channel)
}
@MainThread
private fun createActiveCallNotificationChannel() {
val id = context.getString(R.string.notification_channel_call_id)
val name = context.getString(R.string.notification_channel_call_name)
val channel = NotificationChannel(id, name, NotificationManager.IMPORTANCE_DEFAULT)
channel.description = name
channel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
channel.enableVibration(false)
channel.enableLights(false)
channel.setShowBadge(false)
notificationManager.createNotificationChannel(channel)
}
@MainThread
private fun createServiceChannel() {
val id = context.getString(R.string.notification_channel_service_id)

View file

@ -10,7 +10,8 @@
<string name="vertical_separator" translatable="false">|</string>
<string name="assistant_web_platform_link" translatable="false">subscribe.linphone.org</string>
<string name="assistant_linphone_contact_us_link" translatable="false">linphone.org/contact</string>
<string name="notification_channel_incoming_call_id" translatable="false">linphone_notification_call_id</string>
<string name="notification_channel_call_id" translatable="false">linphone_notification_call_id</string>
<string name="notification_channel_incoming_call_id" translatable="false">linphone_notification_incoming_call_id</string>
<string name="notification_channel_service_id" translatable="false">linphone_notification_service_id</string>
<string name="sip_address">SIP address</string>
@ -23,6 +24,7 @@
<string name="or">or</string>
<string name="next">next</string>
<string name="notification_channel_call_name">&appName; active calls notifications</string>
<string name="notification_channel_incoming_call_name">&appName; incoming calls notifications</string>
<string name="notification_channel_service_name">&appName; service notification</string>