Fix regarding in-call foreground service notification & other accounts notifications alert

This commit is contained in:
Sylvain Berfini 2024-09-30 10:02:05 +02:00
parent f6d4f56bbc
commit eaa498f1ad
2 changed files with 30 additions and 34 deletions

View file

@ -598,6 +598,12 @@ class NotificationsManager @MainThread constructor(private val context: Context)
private fun startInCallForegroundService(call: Call) {
Log.i("$TAG Trying to start/update foreground Service using call notification")
val service = inCallService
if (service == null) {
Log.w("$TAG Core Foreground Service hasn't started yet...")
return
}
val channelId = context.getString(R.string.notification_channel_call_id)
val channel = notificationManager.getNotificationChannel(channelId)
val importance = channel?.importance ?: NotificationManagerCompat.IMPORTANCE_NONE
@ -606,15 +612,14 @@ class NotificationsManager @MainThread constructor(private val context: Context)
return
}
val notifiable = getNotifiableForCall(
coreContext.core.currentCall ?: coreContext.core.calls.first()
)
val notifiable = getNotifiableForCall(call)
val notification = notificationManager.activeNotifications.find {
it.id == notifiable.notificationId
}
if (notification == null) {
Log.w("$TAG No existing notification found for current Call, aborting")
stopInCallCallForegroundService()
return
}
Log.i("$TAG Found notification [${notification.id}] for current Call")
@ -653,21 +658,16 @@ class NotificationsManager @MainThread constructor(private val context: Context)
}
}
val service = inCallService
if (service != null) {
Log.i(
"$TAG Service found, starting it as foreground using notification ID [${notifiable.notificationId}] with type(s) [$mask]"
)
Compatibility.startServiceForeground(
service,
notifiable.notificationId,
notification.notification,
mask
)
currentInCallServiceNotificationId = notifiable.notificationId
} else {
Log.w("$TAG Core Foreground Service hasn't started yet...")
}
Log.i(
"$TAG Service found, starting it as foreground using notification ID [${notifiable.notificationId}] with type(s) [$mask]"
)
Compatibility.startServiceForeground(
service,
notifiable.notificationId,
notification.notification,
mask
)
currentInCallServiceNotificationId = notifiable.notificationId
}
@WorkerThread

View file

@ -400,12 +400,13 @@ class MainViewModel @UiThread constructor() : ViewModel() {
@WorkerThread
private fun computeNonDefaultAccountNotificationsCount() {
removeAlert(NON_DEFAULT_ACCOUNT_NOTIFICATIONS)
var count = 0
for (account in coreContext.core.accountList) {
if (account == coreContext.core.defaultAccount) continue
count += account.unreadChatMessageCount + account.missedCallsCount
}
if (count > 0) {
val label = AppUtils.getStringWithPlural(
R.plurals.pending_notification_for_other_accounts,
@ -415,8 +416,7 @@ class MainViewModel @UiThread constructor() : ViewModel() {
addAlert(NON_DEFAULT_ACCOUNT_NOTIFICATIONS, label, forceUpdate = true)
Log.i("$TAG Found [$count] pending notifications for other account(s)")
} else {
Log.i("$TAG No pending notification found for other account(s), clearing alert")
removeAlert(NON_DEFAULT_ACCOUNT_NOTIFICATIONS)
Log.i("$TAG No pending notification found for other account(s)")
}
}
@ -523,20 +523,16 @@ class MainViewModel @UiThread constructor() : ViewModel() {
}
alertLabel.postValue(label)
if (showAlert.value == true) {
Log.i("$TAG Alert top-bar is already visible")
if (type == SINGLE_CALL) {
Log.i("$TAG Alert top-bar is currently invisible, displaying it in a second")
coreContext.postOnCoreThreadDelayed({
if (maxAlertLevel.value != NONE) {
showAlert.postValue(true)
}
}, 1000L)
} else {
if (type == SINGLE_CALL) {
Log.i("$TAG Alert top-bar is currently invisible, displaying it in a second")
coreContext.postOnCoreThreadDelayed({
if (maxAlertLevel.value != NONE) {
showAlert.postValue(true)
}
}, 1000L)
} else {
Log.i("$TAG Alert top-bar is currently invisible, display it now")
showAlert.postValue(true)
}
Log.i("$TAG Alert top-bar is currently invisible, display it now")
showAlert.postValue(true)
}
}
}