NSClient: resolve ConcurrentModificationException

This commit is contained in:
Milos Kozak 2022-06-22 10:26:00 +02:00
parent 5b383d5201
commit ca5fd58ec6
4 changed files with 9 additions and 9 deletions

View file

@ -28,6 +28,7 @@ import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.JsonHelper import info.nightscout.androidaps.utils.JsonHelper
import info.nightscout.androidaps.utils.JsonHelper.safeGetLong import info.nightscout.androidaps.utils.JsonHelper.safeGetLong
import info.nightscout.androidaps.interfaces.BuildHelper import info.nightscout.androidaps.interfaces.BuildHelper
import info.nightscout.androidaps.utils.XDripBroadcast
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
@ -49,6 +50,7 @@ class NSClientAddUpdateWorker(
@Inject lateinit var rxBus: RxBus @Inject lateinit var rxBus: RxBus
@Inject lateinit var uel: UserEntryLogger @Inject lateinit var uel: UserEntryLogger
@Inject lateinit var virtualPumpPlugin: VirtualPumpPlugin @Inject lateinit var virtualPumpPlugin: VirtualPumpPlugin
@Inject lateinit var xDripBroadcast: XDripBroadcast
override fun doWork(): Result { override fun doWork(): Result {
val treatments = dataWorker.pickupJSONArray(inputData.getLong(DataWorker.STORE_KEY, -1)) val treatments = dataWorker.pickupJSONArray(inputData.getLong(DataWorker.STORE_KEY, -1))
@ -508,6 +510,7 @@ class NSClientAddUpdateWorker(
} }
} }
nsClientPlugin.updateLatestDateReceivedIfNewer(latestDateInReceivedData) nsClientPlugin.updateLatestDateReceivedIfNewer(latestDateInReceivedData)
xDripBroadcast.sendTreatments(treatments)
return ret return ret
} }

View file

@ -14,6 +14,7 @@ import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.events.EventAppExit import info.nightscout.androidaps.events.EventAppExit
import info.nightscout.androidaps.events.EventConfigBuilderChange import info.nightscout.androidaps.events.EventConfigBuilderChange
import info.nightscout.androidaps.events.EventPreferenceChange import info.nightscout.androidaps.events.EventPreferenceChange
import info.nightscout.androidaps.interfaces.BuildHelper
import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.Config
import info.nightscout.androidaps.interfaces.DataSyncSelector import info.nightscout.androidaps.interfaces.DataSyncSelector
import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.interfaces.ResourceHelper
@ -47,8 +48,6 @@ import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.JsonHelper.safeGetString import info.nightscout.androidaps.utils.JsonHelper.safeGetString
import info.nightscout.androidaps.utils.JsonHelper.safeGetStringAllowNull import info.nightscout.androidaps.utils.JsonHelper.safeGetStringAllowNull
import info.nightscout.androidaps.utils.T.Companion.mins import info.nightscout.androidaps.utils.T.Companion.mins
import info.nightscout.androidaps.utils.XDripBroadcast
import info.nightscout.androidaps.interfaces.BuildHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag import info.nightscout.shared.logging.LTag
@ -83,7 +82,6 @@ class NSClientService : DaggerService() {
@Inject lateinit var dataWorker: DataWorker @Inject lateinit var dataWorker: DataWorker
@Inject lateinit var dataSyncSelector: DataSyncSelector @Inject lateinit var dataSyncSelector: DataSyncSelector
@Inject lateinit var repository: AppRepository @Inject lateinit var repository: AppRepository
@Inject lateinit var xDripBroadcast: XDripBroadcast
companion object { companion object {
@ -473,7 +471,6 @@ class NSClientService : DaggerService() {
.setInputData(dataWorker.storeInputData(profileStoreJson)) .setInputData(dataWorker.storeInputData(profileStoreJson))
.build() .build()
) )
xDripBroadcast.sendProfile(profileStoreJson)
} }
} }
if (data.has("treatments")) { if (data.has("treatments")) {
@ -492,7 +489,6 @@ class NSClientService : DaggerService() {
.setInputData(dataWorker.storeInputData(addedOrUpdatedTreatments)) .setInputData(dataWorker.storeInputData(addedOrUpdatedTreatments))
.build() .build()
) )
xDripBroadcast.sendTreatments(addedOrUpdatedTreatments)
} }
} }
if (data.has("devicestatus")) { if (data.has("devicestatus")) {
@ -536,7 +532,6 @@ class NSClientService : DaggerService() {
.setInputData(dataWorker.storeInputData(sgvs)) .setInputData(dataWorker.storeInputData(sgvs))
.build() .build()
) )
xDripBroadcast.sendSgvs(sgvs)
} }
} }
rxBus.send(EventNSClientNewLog("LAST", dateUtil.dateAndTimeString(latestDateInReceivedData))) rxBus.send(EventNSClientNewLog("LAST", dateUtil.dateAndTimeString(latestDateInReceivedData)))

View file

@ -461,6 +461,7 @@ class LocalProfilePlugin @Inject constructor(
@Inject lateinit var sp: SP @Inject lateinit var sp: SP
@Inject lateinit var config: Config @Inject lateinit var config: Config
@Inject lateinit var localProfilePlugin: LocalProfilePlugin @Inject lateinit var localProfilePlugin: LocalProfilePlugin
@Inject lateinit var xDripBroadcast: XDripBroadcast
init { init {
(context.applicationContext as HasAndroidInjector).androidInjector().inject(this) (context.applicationContext as HasAndroidInjector).androidInjector().inject(this)
@ -469,6 +470,7 @@ class LocalProfilePlugin @Inject constructor(
override fun doWork(): Result { override fun doWork(): Result {
val profileJson = dataWorker.pickupJSONObject(inputData.getLong(DataWorker.STORE_KEY, -1)) val profileJson = dataWorker.pickupJSONObject(inputData.getLong(DataWorker.STORE_KEY, -1))
?: return Result.failure(workDataOf("Error" to "missing input data")) ?: return Result.failure(workDataOf("Error" to "missing input data"))
xDripBroadcast.sendProfile(profileJson)
if (sp.getBoolean(R.string.key_ns_receive_profile_store, true) || config.NSCLIENT) { if (sp.getBoolean(R.string.key_ns_receive_profile_store, true) || config.NSCLIENT) {
val store = ProfileStore(injector, profileJson, dateUtil) val store = ProfileStore(injector, profileJson, dateUtil)
val createdAt = store.getStartDate() val createdAt = store.getStartDate()

View file

@ -115,11 +115,11 @@ class NSClientSourcePlugin @Inject constructor(
@Suppress("SpellCheckingInspection") @Suppress("SpellCheckingInspection")
override fun doWork(): Result { override fun doWork(): Result {
var ret = Result.success() var ret = Result.success()
if (!nsClientSourcePlugin.isEnabled() && !sp.getBoolean(R.string.key_ns_receive_cgm, false)) return Result.success(workDataOf("Result" to "Sync not enabled"))
val sgvs = dataWorker.pickupJSONArray(inputData.getLong(DataWorker.STORE_KEY, -1)) val sgvs = dataWorker.pickupJSONArray(inputData.getLong(DataWorker.STORE_KEY, -1))
?: return Result.failure(workDataOf("Error" to "missing input data")) ?: return Result.failure(workDataOf("Error" to "missing input data"))
xDripBroadcast.sendSgvs(sgvs)
if (!nsClientSourcePlugin.isEnabled() && !sp.getBoolean(R.string.key_ns_receive_cgm, false))
return Result.success(workDataOf("Result" to "Sync not enabled"))
try { try {
var latestDateInReceivedData: Long = 0 var latestDateInReceivedData: Long = 0