Prevent crash when removing service task if Core isn't alive

This commit is contained in:
Sylvain Berfini 2022-11-03 11:54:54 +01:00
parent b9c178cc29
commit f3ad232c1f

View file

@ -70,17 +70,19 @@ class CoreService : CoreService() {
} }
override fun onTaskRemoved(rootIntent: Intent?) { override fun onTaskRemoved(rootIntent: Intent?) {
if (coreContext.core.callsNb > 0) { if (LinphoneApplication.contextExists()) {
Log.w("[Service] Task removed but there is at least one active call, do not stop the Core!") if (coreContext.core.callsNb > 0) {
} else if (!corePreferences.keepServiceAlive) { Log.w("[Service] Task removed but there is at least one active call, do not stop the Core!")
if (coreContext.core.isInBackground) { } else if (!corePreferences.keepServiceAlive) {
Log.i("[Service] Task removed, stopping Core") if (coreContext.core.isInBackground) {
coreContext.stop() Log.i("[Service] Task removed, stopping Core")
coreContext.stop()
} else {
Log.w("[Service] Task removed but Core is not in background, skipping")
}
} else { } else {
Log.w("[Service] Task removed but Core is not in background, skipping") Log.i("[Service] Task removed but we were asked to keep the service alive, so doing nothing")
} }
} else {
Log.i("[Service] Task removed but we were asked to keep the service alive, so doing nothing")
} }
super.onTaskRemoved(rootIntent) super.onTaskRemoved(rootIntent)