diff --git a/service/src/main/kotlin/org/microg/nlp/service/AbstractBackendHelper.kt b/service/src/main/kotlin/org/microg/nlp/service/AbstractBackendHelper.kt index e8828b2..ff3ab9a 100644 --- a/service/src/main/kotlin/org/microg/nlp/service/AbstractBackendHelper.kt +++ b/service/src/main/kotlin/org/microg/nlp/service/AbstractBackendHelper.kt @@ -54,6 +54,12 @@ abstract class AbstractBackendHelper(private val TAG: String, private val contex Log.w(TAG, e) } } + unbindNow() + } + } + + fun unbindNow() { + if (bound) { try { Log.d(TAG, "Unbinding from: $serviceIntent") context.unbindService(this) diff --git a/service/src/main/kotlin/org/microg/nlp/service/GeocodeFuser.kt b/service/src/main/kotlin/org/microg/nlp/service/GeocodeFuser.kt index 32d73cb..dc9ba77 100644 --- a/service/src/main/kotlin/org/microg/nlp/service/GeocodeFuser.kt +++ b/service/src/main/kotlin/org/microg/nlp/service/GeocodeFuser.kt @@ -52,8 +52,14 @@ class GeocodeFuser(private val context: Context, private val lifecycle: Lifecycl } } - suspend fun destroy() { - unbind() + private fun unbindNow() { + for (backendHelper in backendHelpers) { + backendHelper.unbindNow() + } + } + + fun destroy() { + unbindNow() backendHelpers.clear() } diff --git a/service/src/main/kotlin/org/microg/nlp/service/GeocodeService.kt b/service/src/main/kotlin/org/microg/nlp/service/GeocodeService.kt index e49324b..9ee3f8e 100644 --- a/service/src/main/kotlin/org/microg/nlp/service/GeocodeService.kt +++ b/service/src/main/kotlin/org/microg/nlp/service/GeocodeService.kt @@ -41,9 +41,7 @@ class GeocodeService : LifecycleService() { } override fun onDestroy() { - lifecycleScope.launch { - service.destroy() - } + service.destroy() super.onDestroy() Log.d(TAG, "Destroyed") } @@ -187,7 +185,7 @@ class GeocodeServiceImpl(private val context: Context, private val lifecycle: Li fuser.dump(writer) } - suspend fun destroy() { + fun destroy() { fuser.destroy() } diff --git a/service/src/main/kotlin/org/microg/nlp/service/LocationFuser.kt b/service/src/main/kotlin/org/microg/nlp/service/LocationFuser.kt index 6717518..8cefc67 100644 --- a/service/src/main/kotlin/org/microg/nlp/service/LocationFuser.kt +++ b/service/src/main/kotlin/org/microg/nlp/service/LocationFuser.kt @@ -57,6 +57,12 @@ class LocationFuser(private val context: Context, private val lifecycle: Lifecyc } } + private fun unbindNow() { + for (handler in backendHelpers) { + handler.unbindNow() + } + } + fun bind() { fusing = false for (handler in backendHelpers) { @@ -64,8 +70,8 @@ class LocationFuser(private val context: Context, private val lifecycle: Lifecyc } } - suspend fun destroy() { - unbind() + fun destroy() { + unbindNow() backendHelpers.clear() } diff --git a/service/src/main/kotlin/org/microg/nlp/service/LocationService.kt b/service/src/main/kotlin/org/microg/nlp/service/LocationService.kt index 5676083..630171a 100644 --- a/service/src/main/kotlin/org/microg/nlp/service/LocationService.kt +++ b/service/src/main/kotlin/org/microg/nlp/service/LocationService.kt @@ -46,9 +46,7 @@ class LocationService : LifecycleService() { } override fun onDestroy() { - lifecycleScope.launch { - service.destroy() - } + service.destroy() super.onDestroy() Log.d(TAG, "Destroyed") } @@ -340,7 +338,7 @@ class LocationServiceImpl(private val context: Context, private val lifecycle: L fuser.dump(writer) } - suspend fun destroy() { + fun destroy() { fuser.destroy() }