diff --git a/app/src/main/java/org/linphone/notifications/NotificationsManager.kt b/app/src/main/java/org/linphone/notifications/NotificationsManager.kt index 3190bc22d..5fe0f8695 100644 --- a/app/src/main/java/org/linphone/notifications/NotificationsManager.kt +++ b/app/src/main/java/org/linphone/notifications/NotificationsManager.kt @@ -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 diff --git a/app/src/main/java/org/linphone/ui/main/viewmodel/MainViewModel.kt b/app/src/main/java/org/linphone/ui/main/viewmodel/MainViewModel.kt index d47104b8f..44da148ef 100644 --- a/app/src/main/java/org/linphone/ui/main/viewmodel/MainViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/viewmodel/MainViewModel.kt @@ -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) } } }