diff --git a/app/src/main/java/org/linphone/core/CoreContext.kt b/app/src/main/java/org/linphone/core/CoreContext.kt index 7b47fad80..ad4ef3abc 100644 --- a/app/src/main/java/org/linphone/core/CoreContext.kt +++ b/app/src/main/java/org/linphone/core/CoreContext.kt @@ -612,6 +612,20 @@ class CoreContext(val context: Context, coreConfig: Config) { } } + fun checkIfForegroundServiceNotificationCanBeRemovedAfterDelay(delayInMs: Long) { + coroutineScope.launch { + withContext(Dispatchers.Default) { + delay(delayInMs) + withContext(Dispatchers.Main) { + if (core.defaultAccount != null && core.defaultAccount?.state == RegistrationState.Ok) { + Log.i("[Context] Default account is registered, cancel foreground service notification if possible") + notificationsManager.stopForegroundNotificationIfPossible() + } + } + } + } + } + /* Start call related activities */ private fun onIncomingReceived() { diff --git a/app/src/main/java/org/linphone/core/CoreService.kt b/app/src/main/java/org/linphone/core/CoreService.kt index 05e2c3e12..76a01ef52 100644 --- a/app/src/main/java/org/linphone/core/CoreService.kt +++ b/app/src/main/java/org/linphone/core/CoreService.kt @@ -37,6 +37,7 @@ class CoreService : CoreService() { if (intent?.extras?.get("StartForeground") == true) { Log.i("[Service] Starting as foreground due to device boot or app update") coreContext.notificationsManager.startForeground(this, true) + coreContext.checkIfForegroundServiceNotificationCanBeRemovedAfterDelay(5000) } else if (corePreferences.keepServiceAlive) { Log.i("[Service] Starting as foreground to keep app alive in background") coreContext.notificationsManager.startForeground(this, false)