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.safeGetLong
import info.nightscout.androidaps.interfaces.BuildHelper
import info.nightscout.androidaps.utils.XDripBroadcast
import info.nightscout.shared.sharedPreferences.SP
import java.util.concurrent.TimeUnit
import javax.inject.Inject
@ -49,6 +50,7 @@ class NSClientAddUpdateWorker(
@Inject lateinit var rxBus: RxBus
@Inject lateinit var uel: UserEntryLogger
@Inject lateinit var virtualPumpPlugin: VirtualPumpPlugin
@Inject lateinit var xDripBroadcast: XDripBroadcast
override fun doWork(): Result {
val treatments = dataWorker.pickupJSONArray(inputData.getLong(DataWorker.STORE_KEY, -1))
@ -508,6 +510,7 @@ class NSClientAddUpdateWorker(
}
}
nsClientPlugin.updateLatestDateReceivedIfNewer(latestDateInReceivedData)
xDripBroadcast.sendTreatments(treatments)
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.EventConfigBuilderChange
import info.nightscout.androidaps.events.EventPreferenceChange
import info.nightscout.androidaps.interfaces.BuildHelper
import info.nightscout.androidaps.interfaces.Config
import info.nightscout.androidaps.interfaces.DataSyncSelector
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.safeGetStringAllowNull
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.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
@ -83,7 +82,6 @@ class NSClientService : DaggerService() {
@Inject lateinit var dataWorker: DataWorker
@Inject lateinit var dataSyncSelector: DataSyncSelector
@Inject lateinit var repository: AppRepository
@Inject lateinit var xDripBroadcast: XDripBroadcast
companion object {
@ -473,7 +471,6 @@ class NSClientService : DaggerService() {
.setInputData(dataWorker.storeInputData(profileStoreJson))
.build()
)
xDripBroadcast.sendProfile(profileStoreJson)
}
}
if (data.has("treatments")) {
@ -492,7 +489,6 @@ class NSClientService : DaggerService() {
.setInputData(dataWorker.storeInputData(addedOrUpdatedTreatments))
.build()
)
xDripBroadcast.sendTreatments(addedOrUpdatedTreatments)
}
}
if (data.has("devicestatus")) {
@ -536,7 +532,6 @@ class NSClientService : DaggerService() {
.setInputData(dataWorker.storeInputData(sgvs))
.build()
)
xDripBroadcast.sendSgvs(sgvs)
}
}
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 config: Config
@Inject lateinit var localProfilePlugin: LocalProfilePlugin
@Inject lateinit var xDripBroadcast: XDripBroadcast
init {
(context.applicationContext as HasAndroidInjector).androidInjector().inject(this)
@ -469,6 +470,7 @@ class LocalProfilePlugin @Inject constructor(
override fun doWork(): Result {
val profileJson = dataWorker.pickupJSONObject(inputData.getLong(DataWorker.STORE_KEY, -1))
?: 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) {
val store = ProfileStore(injector, profileJson, dateUtil)
val createdAt = store.getStartDate()

View file

@ -115,11 +115,11 @@ class NSClientSourcePlugin @Inject constructor(
@Suppress("SpellCheckingInspection")
override fun doWork(): Result {
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))
?: 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 {
var latestDateInReceivedData: Long = 0