From 6a76513f1e8c1ee47ac9a05831b413892dd36b11 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 23 Aug 2021 13:52:48 +0200 Subject: [PATCH] Fixed background mode advanced setting switch not starting the service & notification --- app/src/main/java/org/linphone/core/CoreService.kt | 8 ++++---- .../org/linphone/notifications/NotificationsManager.kt | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/linphone/core/CoreService.kt b/app/src/main/java/org/linphone/core/CoreService.kt index 76a01ef52..1eeac37da 100644 --- a/app/src/main/java/org/linphone/core/CoreService.kt +++ b/app/src/main/java/org/linphone/core/CoreService.kt @@ -34,13 +34,13 @@ class CoreService : CoreService() { } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { - if (intent?.extras?.get("StartForeground") == true) { + if (corePreferences.keepServiceAlive) { + Log.i("[Service] Starting as foreground to keep app alive in background") + coreContext.notificationsManager.startForeground(this, false) + } else 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) } return super.onStartCommand(intent, flags, startId) } diff --git a/app/src/main/java/org/linphone/notifications/NotificationsManager.kt b/app/src/main/java/org/linphone/notifications/NotificationsManager.kt index 2e73f882e..6f78bc176 100644 --- a/app/src/main/java/org/linphone/notifications/NotificationsManager.kt +++ b/app/src/main/java/org/linphone/notifications/NotificationsManager.kt @@ -252,7 +252,10 @@ class NotificationsManager(private val context: Context) { if (coreService != null) { startForeground(coreService, useAutoStartDescription = false) } else { - Log.e("[Notifications Manager] Can't start service as foreground, no service!") + Log.w("[Notifications Manager] Can't start service as foreground without a service, starting it now") + val intent = Intent() + intent.setClass(coreContext.context, CoreService::class.java) + coreContext.context.startService(intent) } }