Merge remote-tracking branch 'ns/dev' into newdb

This commit is contained in:
Milos Kozak 2021-02-09 18:12:10 +01:00
commit 9cade8f422
6 changed files with 37 additions and 33 deletions

View file

@ -13,6 +13,7 @@ import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.receivers.BundleStore;
import info.nightscout.androidaps.receivers.DataReceiver;
// cannot be inner class because of needed injection
public class NSClientWorker extends Worker {
@ -30,9 +31,9 @@ public class NSClientWorker extends Worker {
@NotNull
@Override
public Result doWork() {
Bundle bundle = bundleStore.pickup(getInputData().getLong("storeKey", -1));
if (bundle == null) Result.failure();
String action = getInputData().getString("action");
Bundle bundle = bundleStore.pickup(getInputData().getLong(DataReceiver.STORE_KEY, -1));
if (bundle == null) return Result.failure();
String action = getInputData().getString(DataReceiver.ACTION_KEY);
nsClientPlugin.handleNewDataFromNSClient(action, bundle);
return Result.success();
}

View file

@ -36,6 +36,7 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorP
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.receivers.BundleStore
import info.nightscout.androidaps.receivers.DataReceiver
import info.nightscout.androidaps.utils.*
import io.reactivex.rxkotlin.plusAssign
import info.nightscout.androidaps.utils.resources.ResourceHelper
@ -172,7 +173,7 @@ class SmsCommunicatorPlugin @Inject constructor(
}
override fun doWork(): Result {
val bundle = bundleStore.pickup(inputData.getLong("storeKey", -1))
val bundle = bundleStore.pickup(inputData.getLong(DataReceiver.STORE_KEY, -1))
?: return Result.failure()
val format = bundle.getString("format") ?: return Result.failure()
val pdus = bundle["pdus"] as Array<*>

View file

@ -21,6 +21,7 @@ import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
import info.nightscout.androidaps.receivers.BundleStore
import info.nightscout.androidaps.receivers.DataReceiver
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.XDripBroadcast
@ -92,7 +93,7 @@ class DexcomPlugin @Inject constructor(
override fun doWork(): Result {
if (!dexcomPlugin.isEnabled(PluginType.BGSOURCE)) return Result.failure()
val bundle = bundleStore.pickup(inputData.getLong("storeKey", -1))
val bundle = bundleStore.pickup(inputData.getLong(DataReceiver.STORE_KEY, -1))
?: return Result.failure()
try {
val sourceSensor = when (bundle.getString("sensorType") ?: "") {

View file

@ -19,6 +19,7 @@ import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
import info.nightscout.androidaps.receivers.BundleStore
import info.nightscout.androidaps.receivers.DataReceiver
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.XDripBroadcast
import info.nightscout.androidaps.utils.resources.ResourceHelper
@ -78,7 +79,7 @@ class EversensePlugin @Inject constructor(
override fun doWork(): Result {
if (!eversensePlugin.isEnabled(PluginType.BGSOURCE)) return Result.failure()
val bundle = bundleStore.pickup(inputData.getLong("storeKey", -1))
val bundle = bundleStore.pickup(inputData.getLong(DataReceiver.STORE_KEY, -1))
?: return Result.failure()
if (bundle.containsKey("currentCalibrationPhase")) aapsLogger.debug(LTag.BGSOURCE, "currentCalibrationPhase: " + bundle.getString("currentCalibrationPhase"))
if (bundle.containsKey("placementModeInProgress")) aapsLogger.debug(LTag.BGSOURCE, "placementModeInProgress: " + bundle.getBoolean("placementModeInProgress"))

View file

@ -14,6 +14,8 @@ import info.nightscout.androidaps.interfaces.PluginDescription
import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.receivers.BundleStore
import info.nightscout.androidaps.receivers.DataReceiver
import info.nightscout.androidaps.services.Intents
import info.nightscout.androidaps.utils.resources.ResourceHelper
import io.reactivex.disposables.CompositeDisposable
@ -67,6 +69,7 @@ class XdripPlugin @Inject constructor(
@Inject lateinit var xdripPlugin: XdripPlugin
@Inject lateinit var repository: AppRepository
@Inject lateinit var bundleStore: BundleStore
init {
(context.applicationContext as HasAndroidInjector).androidInjector().inject(this)
@ -74,15 +77,18 @@ class XdripPlugin @Inject constructor(
override fun doWork(): Result {
if (!xdripPlugin.isEnabled(PluginType.BGSOURCE)) return Result.failure()
xdripPlugin.aapsLogger.debug(LTag.BGSOURCE, "Received xDrip data: $inputData")
val bundle = bundleStore.pickup(inputData.getLong(DataReceiver.STORE_KEY, -1))
?: return Result.failure()
xdripPlugin.aapsLogger.debug(LTag.BGSOURCE, "Received xDrip data: $bundle")
val glucoseValues = mutableListOf<CgmSourceTransaction.TransactionGlucoseValue>()
glucoseValues += CgmSourceTransaction.TransactionGlucoseValue(
timestamp = inputData.getLong(Intents.EXTRA_TIMESTAMP, 0),
value = inputData.getDouble(Intents.EXTRA_BG_ESTIMATE, 0.0),
raw = inputData.getDouble(Intents.EXTRA_RAW, 0.0),
timestamp = bundle.getLong(Intents.EXTRA_TIMESTAMP, 0),
value = bundle.getDouble(Intents.EXTRA_BG_ESTIMATE, 0.0),
raw = bundle.getDouble(Intents.EXTRA_RAW, 0.0),
noise = null,
trendArrow = GlucoseValue.TrendArrow.fromString(inputData.getString(Intents.EXTRA_BG_SLOPE_NAME)),
sourceSensor = GlucoseValue.SourceSensor.fromString(inputData.getString(Intents.XDRIP_DATA_SOURCE_DESCRIPTION)
trendArrow = GlucoseValue.TrendArrow.fromString(bundle.getString(Intents.EXTRA_BG_SLOPE_NAME)),
sourceSensor = GlucoseValue.SourceSensor.fromString(bundle.getString(Intents.XDRIP_DATA_SOURCE_DESCRIPTION)
?: "")
)
xdripPlugin.disposable += repository.runTransactionForResult(CgmSourceTransaction(glucoseValues, emptyList(), null)).subscribe({ savedValues ->
@ -92,7 +98,7 @@ class XdripPlugin @Inject constructor(
}, {
xdripPlugin.aapsLogger.error(LTag.BGSOURCE, "Error while saving values from Eversense App", it)
})
xdripPlugin.sensorBatteryLevel = inputData.getInt(Intents.EXTRA_SENSOR_BATTERY, -1)
xdripPlugin.sensorBatteryLevel = bundle.getInt(Intents.EXTRA_SENSOR_BATTERY, -1)
return Result.success()
}
}

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.receivers
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.provider.Telephony
import androidx.work.Data
import androidx.work.ExistingWorkPolicy
@ -39,10 +40,7 @@ open class DataReceiver : DaggerBroadcastReceiver() {
when (intent.action) {
Intents.ACTION_NEW_BG_ESTIMATE ->
OneTimeWorkRequest.Builder(XdripPlugin.XdripWorker::class.java)
.setInputData(Data.Builder().also {
it.copyString("collection", bundle, null)
it.copyString("data", bundle)
}.build()).build()
.setInputData(bundleInputData(bundle, intent)).build()
Intents.POCTECH_BG ->
OneTimeWorkRequest.Builder(PoctechPlugin.PoctechWorker::class.java)
.setInputData(Data.Builder().also {
@ -84,36 +82,32 @@ open class DataReceiver : DaggerBroadcastReceiver() {
}.build()).build()
Telephony.Sms.Intents.SMS_RECEIVED_ACTION ->
OneTimeWorkRequest.Builder(SmsCommunicatorPlugin.SmsCommunicatorWorker::class.java)
.setInputData(Data.Builder().also {
it.putLong("storeKey", bundleStore.store(bundle))
it.putString("action", intent.action)
}.build()).build()
.setInputData(bundleInputData(bundle, intent)).build()
Intents.EVERSENSE_BG ->
OneTimeWorkRequest.Builder(EversensePlugin.EversenseWorker::class.java)
.setInputData(Data.Builder().also {
it.putLong("storeKey", bundleStore.store(bundle))
it.putString("action", intent.action)
}.build()).build()
.setInputData(bundleInputData(bundle, intent)).build()
Intents.DEXCOM_BG ->
OneTimeWorkRequest.Builder(DexcomPlugin.DexcomWorker::class.java)
.setInputData(Data.Builder().also {
it.putLong("storeKey", bundleStore.store(bundle))
it.putString("action", intent.action)
}.build()).build()
.setInputData(bundleInputData(bundle, intent)).build()
Intents.ACTION_NEW_TREATMENT,
Intents.ACTION_CHANGED_TREATMENT,
Intents.ACTION_REMOVED_TREATMENT,
Intents.ACTION_NEW_CAL,
Intents.ACTION_NEW_MBG ->
OneTimeWorkRequest.Builder(NSClientWorker::class.java)
.setInputData(Data.Builder().also {
it.putLong("storeKey", bundleStore.store(bundle))
it.putString("action", intent.action)
}.build()).build()
.setInputData(bundleInputData(bundle, intent)).build()
else -> null
}?.let { request ->
WorkManager.getInstance(context)
.enqueueUniqueWork(jobGroupName, ExistingWorkPolicy.APPEND_OR_REPLACE , request)
}
}
private fun bundleInputData(bundle: Bundle, intent: Intent) =
Data.Builder().putLong(STORE_KEY, bundleStore.store(bundle)).putString(ACTION_KEY, intent.action).build()
companion object {
const val STORE_KEY = "storeKey"
const val ACTION_KEY = "action"
}
}