From 70db7354768ed2f24cae0f0d8919ed9024bfb2cd Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 27 Oct 2023 23:26:03 +0200 Subject: [PATCH] NSCv3: catch stop service crash --- .../app/aaps/plugins/sync/nsclientV3/NSClientV3Plugin.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/nsclientV3/NSClientV3Plugin.kt b/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/nsclientV3/NSClientV3Plugin.kt index a8ad36955d..21555b15bb 100644 --- a/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/nsclientV3/NSClientV3Plugin.kt +++ b/plugins/sync/src/main/kotlin/app/aaps/plugins/sync/nsclientV3/NSClientV3Plugin.kt @@ -194,7 +194,7 @@ class NSClientV3Plugin @Inject constructor( disposable += rxBus .toObservable(EventAppExit::class.java) .observeOn(aapsSchedulers.io) - .subscribe({ if (nsClientV3Service != null) context.unbindService(serviceConnection) }, fabricPrivacy::logException) + .subscribe({ stopService() }, fabricPrivacy::logException) disposable += rxBus .toObservable(EventConnectivityOptionChanged::class.java) .observeOn(aapsSchedulers.io) @@ -359,7 +359,11 @@ class NSClientV3Plugin @Inject constructor( } private fun stopService() { - if (nsClientV3Service != null) context.unbindService(serviceConnection) + try { + if (nsClientV3Service != null) context.unbindService(serviceConnection) + } catch (e: Exception) { + nsClientV3Service = null + } } override fun resend(reason: String) {