try to prevent CuncurrentModificationException
This commit is contained in:
parent
e59c77650a
commit
79795c41b4
|
@ -1,6 +1,5 @@
|
||||||
package info.nightscout.androidaps.plugins.configBuilder
|
package info.nightscout.androidaps.plugins.configBuilder
|
||||||
|
|
||||||
import androidx.collection.LongSparseArray
|
|
||||||
import info.nightscout.androidaps.Constants
|
import info.nightscout.androidaps.Constants
|
||||||
import info.nightscout.androidaps.core.R
|
import info.nightscout.androidaps.core.R
|
||||||
import info.nightscout.androidaps.data.ProfileSealed
|
import info.nightscout.androidaps.data.ProfileSealed
|
||||||
|
@ -11,19 +10,19 @@ import info.nightscout.androidaps.database.transactions.InsertOrUpdateProfileSwi
|
||||||
import info.nightscout.androidaps.events.EventEffectiveProfileSwitchChanged
|
import info.nightscout.androidaps.events.EventEffectiveProfileSwitchChanged
|
||||||
import info.nightscout.androidaps.extensions.fromConstant
|
import info.nightscout.androidaps.extensions.fromConstant
|
||||||
import info.nightscout.androidaps.interfaces.*
|
import info.nightscout.androidaps.interfaces.*
|
||||||
import info.nightscout.shared.logging.AAPSLogger
|
|
||||||
import info.nightscout.shared.logging.LTag
|
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.data.DeviceStatusData
|
import info.nightscout.androidaps.plugins.general.nsclient.data.DeviceStatusData
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
import info.nightscout.androidaps.utils.HardLimits
|
import info.nightscout.androidaps.utils.HardLimits
|
||||||
import info.nightscout.androidaps.utils.T
|
import info.nightscout.androidaps.utils.T
|
||||||
import info.nightscout.androidaps.interfaces.ResourceHelper
|
|
||||||
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.LTag
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
import info.nightscout.shared.sharedPreferences.SP
|
||||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||||
import io.reactivex.rxjava3.kotlin.plusAssign
|
import io.reactivex.rxjava3.kotlin.plusAssign
|
||||||
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@ -43,7 +42,7 @@ class ProfileFunctionImplementation @Inject constructor(
|
||||||
private val deviceStatusData: DeviceStatusData
|
private val deviceStatusData: DeviceStatusData
|
||||||
) : ProfileFunction {
|
) : ProfileFunction {
|
||||||
|
|
||||||
val cache = HashMap<Long,Profile?>()
|
var cache = ConcurrentHashMap<Long, Profile?>()
|
||||||
|
|
||||||
private val disposable = CompositeDisposable()
|
private val disposable = CompositeDisposable()
|
||||||
|
|
||||||
|
@ -53,16 +52,7 @@ class ProfileFunctionImplementation @Inject constructor(
|
||||||
.observeOn(aapsSchedulers.io)
|
.observeOn(aapsSchedulers.io)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
{
|
{
|
||||||
synchronized(cache) {
|
synchronized(cache) { cache.keys.removeIf { key -> key > it.startDate } }
|
||||||
for (key in cache.keys) {
|
|
||||||
if (key > it.startDate) {
|
|
||||||
aapsLogger.debug(LTag.AUTOSENS, "Removing from profileCache: " + dateUtil.dateAndTimeAndSecondsString(key))
|
|
||||||
cache.remove(key)
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, fabricPrivacy::logException
|
}, fabricPrivacy::logException
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -134,7 +124,7 @@ class ProfileFunctionImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized(cache) {
|
synchronized(cache) {
|
||||||
cache.put(rounded, null)
|
cache.remove(rounded)
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue