NSCv3: resolve starting service
This commit is contained in:
parent
0c36f3f567
commit
2b89a78102
2 changed files with 8 additions and 12 deletions
|
@ -204,7 +204,7 @@ class NSClientV3Plugin @Inject constructor(
|
|||
if (ev.connected) {
|
||||
when {
|
||||
isAllowed && nsClientV3Service?.storageSocket == null -> setClient("CONNECTIVITY") // socket must be created
|
||||
!isAllowed && nsClientV3Service?.storageSocket != null -> shutdownWebsockets()
|
||||
!isAllowed && nsClientV3Service?.storageSocket != null -> stopService()
|
||||
}
|
||||
if (isAllowed) executeLoop("CONNECTIVITY", forceNew = false)
|
||||
}
|
||||
|
@ -221,7 +221,7 @@ class NSClientV3Plugin @Inject constructor(
|
|||
ev.isChanged(rh.gs(app.aaps.core.utils.R.string.key_ns_alarms)) ||
|
||||
ev.isChanged(rh.gs(app.aaps.core.utils.R.string.key_ns_announcements))
|
||||
) {
|
||||
shutdownWebsockets()
|
||||
stopService()
|
||||
setClient("SETTING CHANGE")
|
||||
}
|
||||
if (ev.isChanged(rh.gs(app.aaps.core.utils.R.string.key_local_profile_last_change)))
|
||||
|
@ -310,7 +310,7 @@ class NSClientV3Plugin @Inject constructor(
|
|||
override fun onStop() {
|
||||
handler.removeCallbacksAndMessages(null)
|
||||
disposable.clear()
|
||||
shutdownWebsockets()
|
||||
stopService()
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
|
@ -348,24 +348,18 @@ class NSClientV3Plugin @Inject constructor(
|
|||
logger = { msg -> aapsLogger.debug(LTag.HTTP, msg) }
|
||||
)
|
||||
SystemClock.sleep(2000)
|
||||
initializeWebSockets(reason)
|
||||
startService(reason)
|
||||
rxBus.send(EventSWSyncStatus(status))
|
||||
}
|
||||
|
||||
private fun initializeWebSockets(reason: String) {
|
||||
private fun startService(reason: String) {
|
||||
if (sp.getBoolean(app.aaps.core.utils.R.string.key_ns_use_ws, true)) {
|
||||
context.bindService(Intent(context, NSClientV3Service::class.java), serviceConnection, Context.BIND_AUTO_CREATE)
|
||||
while (nsClientV3Service == null) {
|
||||
aapsLogger.debug(LTag.NSCLIENT, "Waiting for service start")
|
||||
SystemClock.sleep(100)
|
||||
}
|
||||
nsClientV3Service?.initializeWebSockets(reason)
|
||||
}
|
||||
}
|
||||
|
||||
private fun shutdownWebsockets() {
|
||||
private fun stopService() {
|
||||
if (nsClientV3Service != null) context.unbindService(serviceConnection)
|
||||
nsClientV3Service?.shutdownWebsockets()
|
||||
}
|
||||
|
||||
override fun resend(reason: String) {
|
||||
|
|
|
@ -70,10 +70,12 @@ class NSClientV3Service : DaggerService() {
|
|||
super.onCreate()
|
||||
wakeLock = (getSystemService(Context.POWER_SERVICE) as PowerManager).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidAPS:NSClientService")
|
||||
wakeLock?.acquire()
|
||||
initializeWebSockets("onCreate")
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
shutdownWebsockets()
|
||||
disposable.clear()
|
||||
if (wakeLock?.isHeld == true) wakeLock?.release()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue