Added delayed check for removing auto start foreground service app if registration process is quicker than the start of the Service

This commit is contained in:
Sylvain Berfini 2021-04-23 14:49:04 +02:00
parent f78be7e306
commit 5ddc3f7ff0
2 changed files with 15 additions and 0 deletions

View file

@ -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 */ /* Start call related activities */
private fun onIncomingReceived() { private fun onIncomingReceived() {

View file

@ -37,6 +37,7 @@ class CoreService : CoreService() {
if (intent?.extras?.get("StartForeground") == true) { if (intent?.extras?.get("StartForeground") == true) {
Log.i("[Service] Starting as foreground due to device boot or app update") Log.i("[Service] Starting as foreground due to device boot or app update")
coreContext.notificationsManager.startForeground(this, true) coreContext.notificationsManager.startForeground(this, true)
coreContext.checkIfForegroundServiceNotificationCanBeRemovedAfterDelay(5000)
} else if (corePreferences.keepServiceAlive) { } else if (corePreferences.keepServiceAlive) {
Log.i("[Service] Starting as foreground to keep app alive in background") Log.i("[Service] Starting as foreground to keep app alive in background")
coreContext.notificationsManager.startForeground(this, false) coreContext.notificationsManager.startForeground(this, false)