diff --git a/app-wear-shared/shared/src/main/java/info/nightscout/rx/logging/LTag.kt b/app-wear-shared/shared/src/main/java/info/nightscout/rx/logging/LTag.kt index 7ed26eda4d..f7633acac9 100644 --- a/app-wear-shared/shared/src/main/java/info/nightscout/rx/logging/LTag.kt +++ b/app-wear-shared/shared/src/main/java/info/nightscout/rx/logging/LTag.kt @@ -26,5 +26,6 @@ enum class LTag(val tag: String, val defaultValue : Boolean = true, val requires TIDEPOOL("TIDEPOOL"), UI("UI", defaultValue = false), WEAR("WEAR"), - WIDGET("WIDGET") + WIDGET("WIDGET"), + WORKER("WORKER") } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveWorker.kt b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveWorker.kt index 59e72f03ee..539eb6f7d1 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveWorker.kt +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveWorker.kt @@ -7,16 +7,15 @@ import androidx.work.OneTimeWorkRequest import androidx.work.WorkInfo import androidx.work.WorkManager import androidx.work.WorkQuery -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf import com.google.common.util.concurrent.ListenableFuture -import dagger.android.HasAndroidInjector import info.nightscout.androidaps.BuildConfig import info.nightscout.androidaps.R import info.nightscout.configuration.maintenance.MaintenancePlugin import info.nightscout.core.profile.ProfileSealed import info.nightscout.core.utils.fabric.FabricPrivacy +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.database.impl.AppRepository import info.nightscout.interfaces.Config import info.nightscout.interfaces.LocalAlertUtils @@ -31,7 +30,6 @@ import info.nightscout.interfaces.queue.CommandQueue import info.nightscout.interfaces.receivers.ReceiverStatusStore import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventProfileSwitchChanged -import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP @@ -45,9 +43,8 @@ import kotlin.math.abs class KeepAliveWorker( private val context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var localAlertUtils: LocalAlertUtils @Inject lateinit var repository: AppRepository @Inject lateinit var config: Config @@ -65,10 +62,6 @@ class KeepAliveWorker( @Inject lateinit var rh: ResourceHelper @Inject lateinit var sp: SP - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - companion object { private val STATUS_UPDATE_FREQUENCY = T.mins(15).msecs() @@ -83,7 +76,7 @@ class KeepAliveWorker( private const val KA_10 = "KeepAlive_10" } - override fun doWork(): Result { + override fun doWorkAndLog(): Result { aapsLogger.debug(LTag.CORE, "KeepAlive received from: " + inputData.getString("schedule")) // 15 min interval is WorkManager minimum so schedule another instances to have 5 min interval diff --git a/core/utils/src/main/java/info/nightscout/core/utils/worker/LoggingWorker.kt b/core/utils/src/main/java/info/nightscout/core/utils/worker/LoggingWorker.kt new file mode 100644 index 0000000000..8f3ae52609 --- /dev/null +++ b/core/utils/src/main/java/info/nightscout/core/utils/worker/LoggingWorker.kt @@ -0,0 +1,25 @@ +package info.nightscout.core.utils.worker + +import android.content.Context +import androidx.work.Worker +import androidx.work.WorkerParameters +import dagger.android.HasAndroidInjector +import info.nightscout.rx.logging.AAPSLogger +import info.nightscout.rx.logging.LTag +import javax.inject.Inject + +abstract class LoggingWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) { + + @Inject lateinit var aapsLogger: AAPSLogger + + init { + (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) + } + + override fun doWork(): Result = + doWorkAndLog().also { + aapsLogger.debug(LTag.WORKER, "Worker result ${it::class.java.simpleName.uppercase()} for ${this::class.java}") + } + + abstract fun doWorkAndLog(): Result +} \ No newline at end of file diff --git a/plugins/configuration/src/main/java/info/nightscout/configuration/maintenance/ImportExportPrefsImpl.kt b/plugins/configuration/src/main/java/info/nightscout/configuration/maintenance/ImportExportPrefsImpl.kt index 24d4859cb9..0b090cec5c 100644 --- a/plugins/configuration/src/main/java/info/nightscout/configuration/maintenance/ImportExportPrefsImpl.kt +++ b/plugins/configuration/src/main/java/info/nightscout/configuration/maintenance/ImportExportPrefsImpl.kt @@ -16,7 +16,6 @@ import androidx.fragment.app.FragmentActivity import androidx.work.ExistingWorkPolicy import androidx.work.OneTimeWorkRequest import androidx.work.WorkManager -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf import dagger.android.HasAndroidInjector @@ -28,6 +27,7 @@ import info.nightscout.core.ui.dialogs.OKDialog import info.nightscout.core.ui.dialogs.TwoMessagesAlertDialog import info.nightscout.core.ui.dialogs.WarningDialog import info.nightscout.core.ui.toast.ToastUtils +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.database.entities.UserEntry import info.nightscout.database.entities.UserEntry.Action import info.nightscout.database.entities.UserEntry.Sources @@ -381,10 +381,9 @@ class ImportExportPrefsImpl @Inject constructor( class CsvExportWorker( context: Context, params: WorkerParameters - ) : Worker(context, params) { + ) : LoggingWorker(context, params) { @Inject lateinit var injector: HasAndroidInjector - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var rh: ResourceHelper @Inject lateinit var prefFileList: PrefFileListProvider @Inject lateinit var context: Context @@ -392,11 +391,7 @@ class ImportExportPrefsImpl @Inject constructor( @Inject lateinit var storage: Storage @Inject lateinit var persistenceLayer: PersistenceLayer - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - - override fun doWork(): Result { + override fun doWorkAndLog(): Result { val entries = persistenceLayer.getUserEntryFilteredDataFromTime(MidnightTime.calc() - T.days(90).msecs()).blockingGet() prefFileList.ensureExportDirExists() val newFile = prefFileList.newExportCsvFile() diff --git a/plugins/main/src/main/java/info/nightscout/plugins/general/food/FoodPlugin.kt b/plugins/main/src/main/java/info/nightscout/plugins/general/food/FoodPlugin.kt index 2e41152a37..7f8b689328 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/general/food/FoodPlugin.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/general/food/FoodPlugin.kt @@ -1,12 +1,12 @@ package info.nightscout.plugins.general.food import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf import dagger.android.HasAndroidInjector import info.nightscout.core.extensions.foodFromJson import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.database.entities.Food import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.transactions.SyncNsFoodTransaction @@ -43,19 +43,14 @@ class FoodPlugin @Inject constructor( class FoodWorker( context: Context, params: WorkerParameters - ) : Worker(context, params) { + ) : LoggingWorker(context, params) { @Inject lateinit var injector: HasAndroidInjector - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var repository: AppRepository @Inject lateinit var sp: SP @Inject lateinit var dataWorkerStorage: DataWorkerStorage - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - - override fun doWork(): Result { + override fun doWorkAndLog(): Result { val foods = dataWorkerStorage.pickupJSONArray(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) ?: return Result.failure(workDataOf("Error" to "missing input data")) aapsLogger.debug(LTag.DATABASE, "Received Food Data: $foods") diff --git a/plugins/main/src/main/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt b/plugins/main/src/main/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt index 431387538d..21ff73ca69 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt @@ -7,7 +7,6 @@ import android.text.TextUtils import androidx.preference.EditTextPreference import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf import dagger.android.HasAndroidInjector @@ -19,6 +18,7 @@ import info.nightscout.core.iob.iobCobCalculator.GlucoseStatusProvider import info.nightscout.core.iob.round import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.core.validators.ValidatingEditTextPreference import info.nightscout.database.entities.OfflineEvent import info.nightscout.database.entities.TemporaryTarget @@ -196,16 +196,12 @@ class SmsCommunicatorPlugin @Inject constructor( class SmsCommunicatorWorker( context: Context, params: WorkerParameters - ) : Worker(context, params) { + ) : LoggingWorker(context, params) { @Inject lateinit var smsCommunicatorPlugin: SmsCommunicatorPlugin @Inject lateinit var dataWorkerStorage: DataWorkerStorage - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - - override fun doWork(): Result { + override fun doWorkAndLog(): Result { val bundle = dataWorkerStorage.pickupBundle(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) ?: return Result.failure(workDataOf("Error" to "missing input data")) val format = bundle.getString("format") diff --git a/plugins/main/src/main/java/info/nightscout/plugins/profile/ProfilePlugin.kt b/plugins/main/src/main/java/info/nightscout/plugins/profile/ProfilePlugin.kt index 8265630a34..f0c83c1e40 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/profile/ProfilePlugin.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/profile/ProfilePlugin.kt @@ -2,7 +2,6 @@ package info.nightscout.plugins.profile import android.content.Context import androidx.fragment.app.FragmentActivity -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf import dagger.android.HasAndroidInjector @@ -13,6 +12,7 @@ import info.nightscout.core.profile.ProfileSealed import info.nightscout.core.ui.dialogs.OKDialog import info.nightscout.core.ui.toast.ToastUtils import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.interfaces.Config import info.nightscout.interfaces.Constants import info.nightscout.interfaces.GlucoseUnit @@ -434,10 +434,9 @@ class ProfilePlugin @Inject constructor( class NSProfileWorker( context: Context, params: WorkerParameters - ) : Worker(context, params) { + ) : LoggingWorker(context, params) { @Inject lateinit var injector: HasAndroidInjector - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var rxBus: RxBus @Inject lateinit var dateUtil: DateUtil @Inject lateinit var dataWorkerStorage: DataWorkerStorage @@ -447,11 +446,7 @@ class ProfilePlugin @Inject constructor( @Inject lateinit var xDripBroadcast: XDripBroadcast @Inject lateinit var profileInstantiator: ProfileInstantiator - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - - override fun doWork(): Result { + override fun doWorkAndLog(): Result { val profileJson = dataWorkerStorage.pickupJSONObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) ?: return Result.failure(workDataOf("Error" to "missing input data")) xDripBroadcast.sendProfile(profileJson) @@ -471,5 +466,4 @@ class ProfilePlugin @Inject constructor( return Result.success(workDataOf("Result" to "Sync not enabled")) } } - } \ No newline at end of file diff --git a/plugins/main/src/main/java/info/nightscout/plugins/source/AidexPlugin.kt b/plugins/main/src/main/java/info/nightscout/plugins/source/AidexPlugin.kt index 2b5431682e..53efc33d2f 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/source/AidexPlugin.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/source/AidexPlugin.kt @@ -1,11 +1,11 @@ package info.nightscout.plugins.source import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf import dagger.android.HasAndroidInjector import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.transactions.CgmSourceTransaction @@ -61,18 +61,13 @@ class AidexPlugin @Inject constructor( class AidexWorker( context: Context, params: WorkerParameters - ) : Worker(context, params) { + ) : LoggingWorker(context, params) { - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var aidexPlugin: AidexPlugin @Inject lateinit var repository: AppRepository @Inject lateinit var dataWorkerStorage: DataWorkerStorage - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - - override fun doWork(): Result { + override fun doWorkAndLog(): Result { var ret = Result.success() if (!aidexPlugin.isEnabled()) return Result.success(workDataOf("Result" to "Plugin not enabled")) diff --git a/plugins/main/src/main/java/info/nightscout/plugins/source/DexcomPlugin.kt b/plugins/main/src/main/java/info/nightscout/plugins/source/DexcomPlugin.kt index 110eaa5da1..5b6319982b 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/source/DexcomPlugin.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/source/DexcomPlugin.kt @@ -4,12 +4,12 @@ import android.content.Context import android.content.Intent import android.content.pm.PackageManager import androidx.core.content.ContextCompat -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf import dagger.android.HasAndroidInjector import info.nightscout.core.extensions.fromConstant import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.entities.TherapyEvent import info.nightscout.database.entities.UserEntry.Action @@ -85,9 +85,8 @@ class DexcomPlugin @Inject constructor( class DexcomWorker( context: Context, params: WorkerParameters - ) : Worker(context, params) { + ) : LoggingWorker(context, params) { - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var injector: HasAndroidInjector @Inject lateinit var dexcomPlugin: DexcomPlugin @Inject lateinit var sp: SP @@ -97,11 +96,7 @@ class DexcomPlugin @Inject constructor( @Inject lateinit var repository: AppRepository @Inject lateinit var uel: UserEntryLogger - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - - override fun doWork(): Result { + override fun doWorkAndLog(): Result { var ret = Result.success() if (!dexcomPlugin.isEnabled()) return Result.success(workDataOf("Result" to "Plugin not enabled")) diff --git a/plugins/main/src/main/java/info/nightscout/plugins/source/EversensePlugin.kt b/plugins/main/src/main/java/info/nightscout/plugins/source/EversensePlugin.kt index 4ed94b2692..ea965806fa 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/source/EversensePlugin.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/source/EversensePlugin.kt @@ -1,11 +1,11 @@ package info.nightscout.plugins.source import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf import dagger.android.HasAndroidInjector import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.entities.TherapyEvent import info.nightscout.database.impl.AppRepository @@ -54,21 +54,16 @@ class EversensePlugin @Inject constructor( class EversenseWorker( context: Context, params: WorkerParameters - ) : Worker(context, params) { + ) : LoggingWorker(context, params) { @Inject lateinit var injector: HasAndroidInjector @Inject lateinit var eversensePlugin: EversensePlugin - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var dateUtil: DateUtil @Inject lateinit var dataWorkerStorage: DataWorkerStorage @Inject lateinit var repository: AppRepository @Inject lateinit var xDripBroadcast: XDripBroadcast - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - - override fun doWork(): Result { + override fun doWorkAndLog(): Result { var ret = Result.success() if (!eversensePlugin.isEnabled()) return Result.success(workDataOf("Result" to "Plugin not enabled")) diff --git a/plugins/main/src/main/java/info/nightscout/plugins/source/GlimpPlugin.kt b/plugins/main/src/main/java/info/nightscout/plugins/source/GlimpPlugin.kt index b4c9bd6a5f..d529078a33 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/source/GlimpPlugin.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/source/GlimpPlugin.kt @@ -1,11 +1,11 @@ package info.nightscout.plugins.source import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf import dagger.android.HasAndroidInjector import info.nightscout.androidaps.annotations.OpenForTesting +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.transactions.CgmSourceTransaction @@ -45,19 +45,14 @@ class GlimpPlugin @Inject constructor( class GlimpWorker( context: Context, params: WorkerParameters - ) : Worker(context, params) { + ) : LoggingWorker(context, params) { @Inject lateinit var injector: HasAndroidInjector @Inject lateinit var glimpPlugin: GlimpPlugin - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var repository: AppRepository @Inject lateinit var xDripBroadcast: XDripBroadcast - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - - override fun doWork(): Result { + override fun doWorkAndLog(): Result { var ret = Result.success() if (!glimpPlugin.isEnabled()) return Result.success(workDataOf("Result" to "Plugin not enabled")) diff --git a/plugins/main/src/main/java/info/nightscout/plugins/source/MM640gPlugin.kt b/plugins/main/src/main/java/info/nightscout/plugins/source/MM640gPlugin.kt index 55ac46eab2..027e6bdc67 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/source/MM640gPlugin.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/source/MM640gPlugin.kt @@ -1,11 +1,11 @@ package info.nightscout.plugins.source import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf import dagger.android.HasAndroidInjector import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.transactions.CgmSourceTransaction @@ -46,21 +46,16 @@ class MM640gPlugin @Inject constructor( class MM640gWorker( context: Context, params: WorkerParameters - ) : Worker(context, params) { + ) : LoggingWorker(context, params) { @Inject lateinit var mM640gPlugin: MM640gPlugin @Inject lateinit var injector: HasAndroidInjector - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var dateUtil: DateUtil @Inject lateinit var dataWorkerStorage: DataWorkerStorage @Inject lateinit var repository: AppRepository @Inject lateinit var xDripBroadcast: XDripBroadcast - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - - override fun doWork(): Result { + override fun doWorkAndLog(): Result { var ret = Result.success() if (!mM640gPlugin.isEnabled()) return Result.success() diff --git a/plugins/main/src/main/java/info/nightscout/plugins/source/NSClientSourcePlugin.kt b/plugins/main/src/main/java/info/nightscout/plugins/source/NSClientSourcePlugin.kt index 6c5d9318c0..901c5c6aa8 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/source/NSClientSourcePlugin.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/source/NSClientSourcePlugin.kt @@ -1,11 +1,11 @@ package info.nightscout.plugins.source import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf import dagger.android.HasAndroidInjector import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.impl.AppRepository import info.nightscout.database.transactions.TransactionGlucoseValue @@ -87,11 +87,11 @@ class NSClientSourcePlugin @Inject constructor( class NSClientSourceWorker( context: Context, params: WorkerParameters - ) : Worker(context, params) { + ) : + LoggingWorker(context, params) { @Inject lateinit var nsClientSourcePlugin: NSClientSourcePlugin @Inject lateinit var injector: HasAndroidInjector - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var sp: SP @Inject lateinit var rxBus: RxBus @Inject lateinit var dateUtil: DateUtil @@ -101,10 +101,6 @@ class NSClientSourcePlugin @Inject constructor( @Inject lateinit var activePlugin: ActivePlugin @Inject lateinit var storeDataForDb: StoreDataForDb - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - private fun toGv(jsonObject: JSONObject): TransactionGlucoseValue? { val sgv = NSSgv(jsonObject) return TransactionGlucoseValue( @@ -132,7 +128,7 @@ class NSClientSourcePlugin @Inject constructor( } @Suppress("SpellCheckingInspection") - override fun doWork(): Result { + override fun doWorkAndLog(): Result { var ret = Result.success() val sgvs = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) ?: return Result.failure(workDataOf("Error" to "missing input data")) diff --git a/plugins/main/src/main/java/info/nightscout/plugins/source/PoctechPlugin.kt b/plugins/main/src/main/java/info/nightscout/plugins/source/PoctechPlugin.kt index b17f450715..7e9de5b405 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/source/PoctechPlugin.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/source/PoctechPlugin.kt @@ -1,10 +1,10 @@ package info.nightscout.plugins.source import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf import dagger.android.HasAndroidInjector +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.transactions.CgmSourceTransaction @@ -47,19 +47,14 @@ class PoctechPlugin @Inject constructor( class PoctechWorker( context: Context, params: WorkerParameters - ) : Worker(context, params) { + ) : LoggingWorker(context, params) { @Inject lateinit var injector: HasAndroidInjector @Inject lateinit var poctechPlugin: PoctechPlugin - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var repository: AppRepository @Inject lateinit var xDripBroadcast: XDripBroadcast - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - - override fun doWork(): Result { + override fun doWorkAndLog(): Result { var ret = Result.success() if (!poctechPlugin.isEnabled()) return Result.success(workDataOf("Result" to "Plugin not enabled")) diff --git a/plugins/main/src/main/java/info/nightscout/plugins/source/TomatoPlugin.kt b/plugins/main/src/main/java/info/nightscout/plugins/source/TomatoPlugin.kt index 222c1984ce..93afb3bf50 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/source/TomatoPlugin.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/source/TomatoPlugin.kt @@ -1,10 +1,10 @@ package info.nightscout.plugins.source import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf import dagger.android.HasAndroidInjector +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.transactions.CgmSourceTransaction @@ -44,21 +44,16 @@ class TomatoPlugin @Inject constructor( class TomatoWorker( context: Context, params: WorkerParameters - ) : Worker(context, params) { + ) : LoggingWorker(context, params) { @Inject lateinit var injector: HasAndroidInjector @Inject lateinit var tomatoPlugin: TomatoPlugin - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var sp: SP @Inject lateinit var repository: AppRepository @Inject lateinit var xDripBroadcast: XDripBroadcast - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - @Suppress("SpellCheckingInspection") - override fun doWork(): Result { + override fun doWorkAndLog(): Result { var ret = Result.success() if (!tomatoPlugin.isEnabled()) return Result.success(workDataOf("Result" to "Plugin not enabled")) diff --git a/plugins/main/src/main/java/info/nightscout/plugins/source/XdripPlugin.kt b/plugins/main/src/main/java/info/nightscout/plugins/source/XdripPlugin.kt index 273497e84a..fcf8ff8fce 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/source/XdripPlugin.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/source/XdripPlugin.kt @@ -1,11 +1,11 @@ package info.nightscout.plugins.source import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf import dagger.android.HasAndroidInjector import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.transactions.CgmSourceTransaction @@ -62,18 +62,13 @@ class XdripPlugin @Inject constructor( class XdripWorker( context: Context, params: WorkerParameters - ) : Worker(context, params) { + ) : LoggingWorker(context, params) { - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var xdripPlugin: XdripPlugin @Inject lateinit var repository: AppRepository @Inject lateinit var dataWorkerStorage: DataWorkerStorage - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - - override fun doWork(): Result { + override fun doWorkAndLog(): Result { var ret = Result.success() if (!xdripPlugin.isEnabled()) return Result.success(workDataOf("Result" to "Plugin not enabled")) diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsShared/StoreDataForDbImpl.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsShared/StoreDataForDbImpl.kt index 79d957b2ed..8c28a366b0 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsShared/StoreDataForDbImpl.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsShared/StoreDataForDbImpl.kt @@ -2,9 +2,8 @@ package info.nightscout.plugins.sync.nsShared import android.content.Context import android.os.SystemClock -import androidx.work.Worker import androidx.work.WorkerParameters -import dagger.android.HasAndroidInjector +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.database.entities.Bolus import info.nightscout.database.entities.BolusCalculatorResult import info.nightscout.database.entities.Carbs @@ -102,18 +101,14 @@ class StoreDataForDbImpl @Inject constructor( class StoreBgWorker( context: Context, params: WorkerParameters - ) : Worker(context, params) { + ) : LoggingWorker(context, params) { @Inject lateinit var storeDataForDb: StoreDataForDbImpl - override fun doWork(): Result { + override fun doWorkAndLog(): Result { storeDataForDb.storeGlucoseValuesToDb() return Result.success() } - - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } } fun HashMap.inc(key: T) = diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientAddAckWorker.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientAddAckWorker.kt index e2f3102e17..ad0e5946cd 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientAddAckWorker.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientAddAckWorker.kt @@ -2,11 +2,10 @@ package info.nightscout.plugins.sync.nsclient.workers import android.content.Context import android.os.SystemClock -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf -import dagger.android.HasAndroidInjector import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.database.entities.DeviceStatus import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.transactions.UpdateNsIdBolusCalculatorResultTransaction @@ -41,7 +40,6 @@ import info.nightscout.plugins.sync.nsclient.acks.NSAddAck import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventNSClientNewLog -import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag import info.nightscout.shared.sharedPreferences.SP import javax.inject.Inject @@ -49,17 +47,16 @@ import javax.inject.Inject class NSClientAddAckWorker( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { @Inject lateinit var dataWorkerStorage: DataWorkerStorage - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var repository: AppRepository @Inject lateinit var rxBus: RxBus @Inject lateinit var dataSyncSelector: DataSyncSelector @Inject lateinit var aapsSchedulers: AapsSchedulers @Inject lateinit var sp: SP - override fun doWork(): Result { + override fun doWorkAndLog(): Result { var ret = Result.success() val ack = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as NSAddAck? @@ -323,8 +320,4 @@ class NSClientAddAckWorker( } return ret } - - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } } \ No newline at end of file diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientAddUpdateWorker.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientAddUpdateWorker.kt index f097fb3044..7c79f38715 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientAddUpdateWorker.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientAddUpdateWorker.kt @@ -1,12 +1,11 @@ package info.nightscout.plugins.sync.nsclient.workers import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf -import dagger.android.HasAndroidInjector import info.nightscout.core.extensions.bolusCalculatorResultFromJson import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.database.entities.TherapyEvent import info.nightscout.database.impl.AppRepository import info.nightscout.interfaces.Config @@ -28,7 +27,6 @@ import info.nightscout.plugins.sync.nsclient.extensions.temporaryBasalFromJson import info.nightscout.plugins.sync.nsclient.extensions.temporaryTargetFromJson import info.nightscout.plugins.sync.nsclient.extensions.therapyEventFromJson import info.nightscout.rx.bus.RxBus -import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.utils.DateUtil @@ -37,10 +35,9 @@ import javax.inject.Inject class NSClientAddUpdateWorker( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { @Inject lateinit var dataWorkerStorage: DataWorkerStorage - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var config: Config @Inject lateinit var sp: SP @Inject lateinit var dateUtil: DateUtil @@ -51,7 +48,7 @@ class NSClientAddUpdateWorker( @Inject lateinit var xDripBroadcast: XDripBroadcast @Inject lateinit var storeDataForDb: StoreDataForDbImpl - override fun doWork(): Result { + override fun doWorkAndLog(): Result { val treatments = dataWorkerStorage.pickupJSONArray(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) ?: return Result.failure(workDataOf("Error" to "missing input data")) @@ -171,8 +168,4 @@ class NSClientAddUpdateWorker( xDripBroadcast.sendTreatments(treatments) return ret } - - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } } \ No newline at end of file diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientMbgWorker.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientMbgWorker.kt index 3fc13dc5dc..26cb5321b0 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientMbgWorker.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientMbgWorker.kt @@ -1,11 +1,10 @@ package info.nightscout.plugins.sync.nsclient.workers import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf -import dagger.android.HasAndroidInjector import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.interfaces.Config import info.nightscout.plugins.sync.nsShared.StoreDataForDbImpl import info.nightscout.plugins.sync.nsclient.data.NSMbg @@ -16,14 +15,14 @@ import javax.inject.Inject class NSClientMbgWorker( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { @Inject lateinit var dataWorkerStorage: DataWorkerStorage @Inject lateinit var sp: SP @Inject lateinit var config: Config @Inject lateinit var storeDataForDb: StoreDataForDbImpl - override fun doWork(): Result { + override fun doWorkAndLog(): Result { val ret = Result.success() val acceptNSData = sp.getBoolean(info.nightscout.core.utils.R.string.key_ns_receive_therapy_events, false) || config.NSCLIENT @@ -39,8 +38,4 @@ class NSClientMbgWorker( // storeDataForDb.storeTreatmentsToDb() don't do this. It will be stored along with other treatments return ret } - - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } } \ No newline at end of file diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientUpdateRemoveAckWorker.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientUpdateRemoveAckWorker.kt index 4052d17fad..bf000d9c03 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientUpdateRemoveAckWorker.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclient/workers/NSClientUpdateRemoveAckWorker.kt @@ -1,11 +1,10 @@ package info.nightscout.plugins.sync.nsclient.workers import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf -import dagger.android.HasAndroidInjector import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.database.impl.AppRepository import info.nightscout.interfaces.sync.DataSyncSelector import info.nightscout.interfaces.sync.DataSyncSelector.PairBolus @@ -24,22 +23,20 @@ import info.nightscout.plugins.sync.nsclient.acks.NSUpdateAck import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventNSClientNewLog -import info.nightscout.rx.logging.AAPSLogger import javax.inject.Inject class NSClientUpdateRemoveAckWorker( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { @Inject lateinit var dataWorkerStorage: DataWorkerStorage - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var repository: AppRepository @Inject lateinit var rxBus: RxBus @Inject lateinit var dataSyncSelector: DataSyncSelector @Inject lateinit var aapsSchedulers: AapsSchedulers - override fun doWork(): Result { + override fun doWorkAndLog(): Result { var ret = Result.success() val ack = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as NSUpdateAck? @@ -157,8 +154,4 @@ class NSClientUpdateRemoveAckWorker( } return ret } - - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } } \ No newline at end of file diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadBgWorker.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadBgWorker.kt index f42f9a76fc..8bccefe53f 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadBgWorker.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadBgWorker.kt @@ -4,17 +4,15 @@ import android.content.Context import androidx.work.ExistingWorkPolicy import androidx.work.OneTimeWorkRequest import androidx.work.WorkManager -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf -import dagger.android.HasAndroidInjector import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.interfaces.workflow.WorkerClasses import info.nightscout.plugins.sync.nsShared.StoreDataForDbImpl import info.nightscout.plugins.sync.nsclientV3.NSClientV3Plugin import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventNSClientNewLog -import info.nightscout.rx.logging.AAPSLogger import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.utils.DateUtil import kotlinx.coroutines.runBlocking @@ -22,9 +20,8 @@ import javax.inject.Inject class LoadBgWorker( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var dataWorkerStorage: DataWorkerStorage @Inject lateinit var rxBus: RxBus @Inject lateinit var sp: SP @@ -38,7 +35,7 @@ class LoadBgWorker( val JOB_NAME: String = this::class.java.simpleName } - override fun doWork(): Result { + override fun doWorkAndLog(): Result { var ret = Result.success() runBlocking { @@ -91,8 +88,4 @@ class LoadBgWorker( } return ret } - - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } } \ No newline at end of file diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadDeviceStatusWorker.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadDeviceStatusWorker.kt index b75fcde257..693ea1374a 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadDeviceStatusWorker.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadDeviceStatusWorker.kt @@ -1,16 +1,14 @@ package info.nightscout.plugins.sync.nsclientV3.workers import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf -import dagger.android.HasAndroidInjector import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.plugins.sync.nsclient.data.NSDeviceStatusHandler import info.nightscout.plugins.sync.nsclientV3.NSClientV3Plugin import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventNSClientNewLog -import info.nightscout.rx.logging.AAPSLogger import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.T import kotlinx.coroutines.runBlocking @@ -19,9 +17,8 @@ import javax.inject.Inject class LoadDeviceStatusWorker( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var dataWorkerStorage: DataWorkerStorage @Inject lateinit var rxBus: RxBus @Inject lateinit var context: Context @@ -29,7 +26,7 @@ class LoadDeviceStatusWorker( @Inject lateinit var dateUtil: DateUtil @Inject lateinit var nsDeviceStatusHandler: NSDeviceStatusHandler - override fun doWork(): Result { + override fun doWorkAndLog(): Result { var ret = Result.success() runBlocking { @@ -50,8 +47,4 @@ class LoadDeviceStatusWorker( } return ret } - - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } } \ No newline at end of file diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadLastModificationWorker.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadLastModificationWorker.kt index d231df9543..1dbf94d6a7 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadLastModificationWorker.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadLastModificationWorker.kt @@ -1,23 +1,20 @@ package info.nightscout.plugins.sync.nsclientV3.workers import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf -import dagger.android.HasAndroidInjector +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.plugins.sync.nsclientV3.NSClientV3Plugin -import info.nightscout.rx.logging.AAPSLogger import kotlinx.coroutines.runBlocking import javax.inject.Inject class LoadLastModificationWorker( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var nsClientV3Plugin: NSClientV3Plugin - override fun doWork(): Result { + override fun doWorkAndLog(): Result { var ret = Result.success() runBlocking { @@ -32,8 +29,4 @@ class LoadLastModificationWorker( } return ret } - - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } } \ No newline at end of file diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadStatusWorker.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadStatusWorker.kt index 0ffef7ffeb..b58bdcf552 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadStatusWorker.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadStatusWorker.kt @@ -1,23 +1,20 @@ package info.nightscout.plugins.sync.nsclientV3.workers import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf -import dagger.android.HasAndroidInjector +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.plugins.sync.nsclientV3.NSClientV3Plugin -import info.nightscout.rx.logging.AAPSLogger import kotlinx.coroutines.runBlocking import javax.inject.Inject class LoadStatusWorker( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var nsClientV3Plugin: NSClientV3Plugin - override fun doWork(): Result { + override fun doWorkAndLog(): Result { var ret = Result.success() runBlocking { @@ -31,8 +28,4 @@ class LoadStatusWorker( } return ret } - - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } } \ No newline at end of file diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadTreatmentsWorker.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadTreatmentsWorker.kt index 0e127c2374..21ac3717fb 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadTreatmentsWorker.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadTreatmentsWorker.kt @@ -4,17 +4,14 @@ import android.content.Context import androidx.work.ExistingWorkPolicy import androidx.work.OneTimeWorkRequest import androidx.work.WorkManager -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf -import dagger.android.HasAndroidInjector import info.nightscout.core.utils.receivers.DataWorkerStorage -import info.nightscout.interfaces.nsclient.StoreDataForDb +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.plugins.sync.nsShared.StoreDataForDbImpl import info.nightscout.plugins.sync.nsclientV3.NSClientV3Plugin import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventNSClientNewLog -import info.nightscout.rx.logging.AAPSLogger import info.nightscout.shared.utils.DateUtil import kotlinx.coroutines.runBlocking import javax.inject.Inject @@ -22,9 +19,8 @@ import javax.inject.Inject class LoadTreatmentsWorker( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var dataWorkerStorage: DataWorkerStorage @Inject lateinit var rxBus: RxBus @Inject lateinit var context: Context @@ -32,7 +28,7 @@ class LoadTreatmentsWorker( @Inject lateinit var dateUtil: DateUtil @Inject lateinit var storeDataForDb: StoreDataForDbImpl - override fun doWork(): Result { + override fun doWorkAndLog(): Result { var ret = Result.success() runBlocking { @@ -88,8 +84,4 @@ class LoadTreatmentsWorker( } return ret } - - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } } \ No newline at end of file diff --git a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/ProcessTreatmentsWorker.kt b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/ProcessTreatmentsWorker.kt index 33b6e1fd4b..096f746e20 100644 --- a/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/ProcessTreatmentsWorker.kt +++ b/plugins/sync/src/main/java/info/nightscout/plugins/sync/nsclientV3/workers/ProcessTreatmentsWorker.kt @@ -1,11 +1,10 @@ package info.nightscout.plugins.sync.nsclientV3.workers import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf -import dagger.android.HasAndroidInjector import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.database.impl.AppRepository import info.nightscout.interfaces.Config import info.nightscout.interfaces.Constants @@ -25,7 +24,6 @@ import info.nightscout.plugins.sync.nsclientV3.extensions.toTemporaryBasal import info.nightscout.plugins.sync.nsclientV3.extensions.toTemporaryTarget import info.nightscout.plugins.sync.nsclientV3.extensions.toTherapyEvent import info.nightscout.rx.bus.RxBus -import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag import info.nightscout.sdk.localmodel.treatment.NSBolus import info.nightscout.sdk.localmodel.treatment.NSBolusWizard @@ -45,10 +43,9 @@ import javax.inject.Inject class ProcessTreatmentsWorker( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { @Inject lateinit var dataWorkerStorage: DataWorkerStorage - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var config: Config @Inject lateinit var sp: SP @Inject lateinit var dateUtil: DateUtil @@ -59,7 +56,7 @@ class ProcessTreatmentsWorker( @Inject lateinit var xDripBroadcast: XDripBroadcast @Inject lateinit var storeDataForDb: StoreDataForDbImpl - override fun doWork(): Result { + override fun doWorkAndLog(): Result { @Suppress("UNCHECKED_CAST") val treatments = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as List? ?: return Result.failure(workDataOf("Error" to "missing input data")) @@ -147,8 +144,4 @@ class ProcessTreatmentsWorker( // xDripBroadcast.sendTreatments(treatments) return ret } - - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } } \ No newline at end of file diff --git a/workflow/src/main/java/info/nightscout/workflow/DummyWorker.kt b/workflow/src/main/java/info/nightscout/workflow/DummyWorker.kt index b53496eb57..16de31068c 100644 --- a/workflow/src/main/java/info/nightscout/workflow/DummyWorker.kt +++ b/workflow/src/main/java/info/nightscout/workflow/DummyWorker.kt @@ -1,13 +1,13 @@ package info.nightscout.workflow import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters +import info.nightscout.core.utils.worker.LoggingWorker class DummyWorker( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { - override fun doWork(): Result = Result.success() + override fun doWorkAndLog(): Result = Result.success() } \ No newline at end of file diff --git a/workflow/src/main/java/info/nightscout/workflow/InvokeLoopWorker.kt b/workflow/src/main/java/info/nightscout/workflow/InvokeLoopWorker.kt index 35fa137425..0f539c4e9a 100644 --- a/workflow/src/main/java/info/nightscout/workflow/InvokeLoopWorker.kt +++ b/workflow/src/main/java/info/nightscout/workflow/InvokeLoopWorker.kt @@ -1,11 +1,10 @@ package info.nightscout.workflow import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf -import dagger.android.HasAndroidInjector import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.interfaces.aps.Loop import info.nightscout.interfaces.iob.IobCobCalculator import info.nightscout.rx.events.Event @@ -15,16 +14,12 @@ import javax.inject.Inject class InvokeLoopWorker( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { @Inject lateinit var dataWorkerStorage: DataWorkerStorage @Inject lateinit var iobCobCalculator: IobCobCalculator @Inject lateinit var loop: Loop - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - class InvokeLoopData( val cause: Event? ) @@ -36,7 +31,7 @@ class InvokeLoopWorker( the event causing the calculation is not EventNewBg.

*/ - override fun doWork(): Result { + override fun doWorkAndLog(): Result { val data = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as InvokeLoopData? ?: return Result.failure(workDataOf("Error" to "missing input data")) diff --git a/workflow/src/main/java/info/nightscout/workflow/LoadBgDataWorker.kt b/workflow/src/main/java/info/nightscout/workflow/LoadBgDataWorker.kt index 03edabdc2d..5d343f64cf 100644 --- a/workflow/src/main/java/info/nightscout/workflow/LoadBgDataWorker.kt +++ b/workflow/src/main/java/info/nightscout/workflow/LoadBgDataWorker.kt @@ -1,11 +1,10 @@ package info.nightscout.workflow import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf -import dagger.android.HasAndroidInjector import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.database.impl.AppRepository import info.nightscout.interfaces.aps.AutosensDataStore import info.nightscout.interfaces.iob.IobCobCalculator @@ -20,18 +19,13 @@ import javax.inject.Inject class LoadBgDataWorker( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { @Inject lateinit var dataWorkerStorage: DataWorkerStorage - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var dateUtil: DateUtil @Inject lateinit var rxBus: RxBus @Inject lateinit var repository: AppRepository - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - class LoadBgData( val iobCobCalculator: IobCobCalculator, val end: Long @@ -53,7 +47,7 @@ class LoadBgDataWorker( } } - override fun doWork(): Result { + override fun doWorkAndLog(): Result { val data = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as LoadBgData? ?: return Result.failure(workDataOf("Error" to "missing input data")) diff --git a/workflow/src/main/java/info/nightscout/workflow/PrepareBasalDataWorker.kt b/workflow/src/main/java/info/nightscout/workflow/PrepareBasalDataWorker.kt index 65fadec8a5..2d4deb16dc 100644 --- a/workflow/src/main/java/info/nightscout/workflow/PrepareBasalDataWorker.kt +++ b/workflow/src/main/java/info/nightscout/workflow/PrepareBasalDataWorker.kt @@ -3,15 +3,14 @@ package info.nightscout.workflow import android.content.Context import android.graphics.DashPathEffect import android.graphics.Paint -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf import com.jjoe64.graphview.series.LineGraphSeries -import dagger.android.HasAndroidInjector import info.nightscout.core.events.EventIobCalculationProgress import info.nightscout.core.graph.OverviewData import info.nightscout.core.graph.data.ScaledDataPoint import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.core.workflow.CalculationWorkflow import info.nightscout.interfaces.iob.IobCobCalculator import info.nightscout.interfaces.profile.ProfileFunction @@ -22,7 +21,7 @@ import javax.inject.Inject class PrepareBasalDataWorker( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { @Inject lateinit var dataWorkerStorage: DataWorkerStorage @Inject lateinit var profileFunction: ProfileFunction @@ -30,7 +29,6 @@ class PrepareBasalDataWorker( @Inject lateinit var rxBus: RxBus private var ctx: Context init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) ctx = rh.getThemedCtx(context) } @@ -39,7 +37,7 @@ class PrepareBasalDataWorker( val overviewData: OverviewData ) - override fun doWork(): Result { + override fun doWorkAndLog(): Result { val data = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as PrepareBasalData? ?: return Result.failure(workDataOf("Error" to "missing input data")) diff --git a/workflow/src/main/java/info/nightscout/workflow/PrepareBgDataWorker.kt b/workflow/src/main/java/info/nightscout/workflow/PrepareBgDataWorker.kt index 83b4efbb35..53abd72181 100644 --- a/workflow/src/main/java/info/nightscout/workflow/PrepareBgDataWorker.kt +++ b/workflow/src/main/java/info/nightscout/workflow/PrepareBgDataWorker.kt @@ -1,15 +1,14 @@ package info.nightscout.workflow import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf -import dagger.android.HasAndroidInjector import info.nightscout.core.graph.OverviewData import info.nightscout.core.graph.data.DataPointWithLabelInterface import info.nightscout.core.graph.data.GlucoseValueDataPoint import info.nightscout.core.graph.data.PointsWithLabelGraphSeries import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.database.impl.AppRepository import info.nightscout.interfaces.GlucoseUnit import info.nightscout.interfaces.iob.IobCobCalculator @@ -23,7 +22,7 @@ import javax.inject.Inject class PrepareBgDataWorker( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { @Inject lateinit var dataWorkerStorage: DataWorkerStorage @Inject lateinit var profileFunction: ProfileFunction @@ -31,16 +30,12 @@ class PrepareBgDataWorker( @Inject lateinit var defaultValueHelper: DefaultValueHelper @Inject lateinit var repository: AppRepository - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - class PrepareBgData( val iobCobCalculator: IobCobCalculator, // cannot be injected : HistoryBrowser uses different instance val overviewData: OverviewData ) - override fun doWork(): Result { + override fun doWorkAndLog(): Result { val data = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as PrepareBgData? ?: return Result.failure(workDataOf("Error" to "missing input data")) diff --git a/workflow/src/main/java/info/nightscout/workflow/PrepareBucketedDataWorker.kt b/workflow/src/main/java/info/nightscout/workflow/PrepareBucketedDataWorker.kt index 4a71703d1a..e05caf2414 100644 --- a/workflow/src/main/java/info/nightscout/workflow/PrepareBucketedDataWorker.kt +++ b/workflow/src/main/java/info/nightscout/workflow/PrepareBucketedDataWorker.kt @@ -1,41 +1,34 @@ package info.nightscout.workflow import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf -import dagger.android.HasAndroidInjector import info.nightscout.core.graph.OverviewData import info.nightscout.core.graph.data.DataPointWithLabelInterface import info.nightscout.core.graph.data.InMemoryGlucoseValueDataPoint import info.nightscout.core.graph.data.PointsWithLabelGraphSeries import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.interfaces.iob.IobCobCalculator import info.nightscout.interfaces.profile.ProfileFunction -import info.nightscout.rx.logging.AAPSLogger import info.nightscout.shared.interfaces.ResourceHelper import javax.inject.Inject class PrepareBucketedDataWorker( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { @Inject lateinit var dataWorkerStorage: DataWorkerStorage @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var rh: ResourceHelper - @Inject lateinit var aapsLogger: AAPSLogger - - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } class PrepareBucketedData( val iobCobCalculator: IobCobCalculator, // cannot be injected : HistoryBrowser uses different instance val overviewData: OverviewData ) - override fun doWork(): Result { + override fun doWorkAndLog(): Result { val data = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as PrepareBucketedData? ?: return Result.failure(workDataOf("Error" to "missing input data")) diff --git a/workflow/src/main/java/info/nightscout/workflow/PrepareIobAutosensGraphDataWorker.kt b/workflow/src/main/java/info/nightscout/workflow/PrepareIobAutosensGraphDataWorker.kt index 75a416d69a..dfe9b26daa 100644 --- a/workflow/src/main/java/info/nightscout/workflow/PrepareIobAutosensGraphDataWorker.kt +++ b/workflow/src/main/java/info/nightscout/workflow/PrepareIobAutosensGraphDataWorker.kt @@ -3,12 +3,10 @@ package info.nightscout.workflow import android.content.Context import android.graphics.DashPathEffect import android.graphics.Paint -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf import com.jjoe64.graphview.series.BarGraphSeries import com.jjoe64.graphview.series.LineGraphSeries -import dagger.android.HasAndroidInjector import info.nightscout.core.events.EventIobCalculationProgress import info.nightscout.core.graph.OverviewData import info.nightscout.core.graph.data.DataPointWithLabelInterface @@ -21,6 +19,7 @@ import info.nightscout.core.iob.combine import info.nightscout.core.iob.copy import info.nightscout.core.iob.iobCobCalculator.data.AutosensDataObject import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.core.workflow.CalculationWorkflow import info.nightscout.database.ValueWrapper import info.nightscout.database.impl.AppRepository @@ -32,7 +31,6 @@ import info.nightscout.interfaces.overview.OverviewMenus import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.interfaces.utils.DecimalFormatter import info.nightscout.rx.bus.RxBus -import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.utils.DateUtil @@ -44,20 +42,18 @@ import kotlin.math.min class PrepareIobAutosensGraphDataWorker( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { @Inject lateinit var dataWorkerStorage: DataWorkerStorage @Inject lateinit var dateUtil: DateUtil @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var rh: ResourceHelper @Inject lateinit var overviewMenus: OverviewMenus - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var repository: AppRepository @Inject lateinit var rxBus: RxBus private var ctx: Context init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) ctx = rh.getThemedCtx(context) } @@ -116,7 +112,7 @@ class PrepareIobAutosensGraphDataWorker( } } - override fun doWork(): Result { + override fun doWorkAndLog(): Result { val data = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as PrepareIobAutosensData? ?: return Result.failure(workDataOf("Error" to "missing input data")) rxBus.send(EventIobCalculationProgress(CalculationWorkflow.ProgressData.PREPARE_IOB_AUTOSENS_DATA, 0, null)) diff --git a/workflow/src/main/java/info/nightscout/workflow/PreparePredictionsWorker.kt b/workflow/src/main/java/info/nightscout/workflow/PreparePredictionsWorker.kt index 61dd6958b5..e86dff512c 100644 --- a/workflow/src/main/java/info/nightscout/workflow/PreparePredictionsWorker.kt +++ b/workflow/src/main/java/info/nightscout/workflow/PreparePredictionsWorker.kt @@ -1,7 +1,6 @@ package info.nightscout.workflow import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf import dagger.android.HasAndroidInjector @@ -10,6 +9,7 @@ import info.nightscout.core.graph.data.DataPointWithLabelInterface import info.nightscout.core.graph.data.GlucoseValueDataPoint import info.nightscout.core.graph.data.PointsWithLabelGraphSeries import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.database.impl.AppRepository import info.nightscout.interfaces.Config import info.nightscout.interfaces.aps.Loop @@ -29,7 +29,7 @@ import kotlin.math.min class PreparePredictionsWorker( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { @Inject lateinit var injector: HasAndroidInjector @Inject lateinit var overviewData: OverviewData @@ -44,15 +44,11 @@ class PreparePredictionsWorker( @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var rh: ResourceHelper - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - class PreparePredictionsData( val overviewData: OverviewData ) - override fun doWork(): Result { + override fun doWorkAndLog(): Result { val data = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as PreparePredictionsData? ?: return Result.failure(workDataOf("Error" to "missing input data")) diff --git a/workflow/src/main/java/info/nightscout/workflow/PrepareTemporaryTargetDataWorker.kt b/workflow/src/main/java/info/nightscout/workflow/PrepareTemporaryTargetDataWorker.kt index a3bde22ec0..107a063ad4 100644 --- a/workflow/src/main/java/info/nightscout/workflow/PrepareTemporaryTargetDataWorker.kt +++ b/workflow/src/main/java/info/nightscout/workflow/PrepareTemporaryTargetDataWorker.kt @@ -1,16 +1,15 @@ package info.nightscout.workflow import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf import com.jjoe64.graphview.series.DataPoint import com.jjoe64.graphview.series.LineGraphSeries -import dagger.android.HasAndroidInjector import info.nightscout.core.events.EventIobCalculationProgress import info.nightscout.core.extensions.target import info.nightscout.core.graph.OverviewData import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.core.workflow.CalculationWorkflow import info.nightscout.database.ValueWrapper import info.nightscout.database.impl.AppRepository @@ -25,7 +24,7 @@ import kotlin.math.max class PrepareTemporaryTargetDataWorker( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { @Inject lateinit var dataWorkerStorage: DataWorkerStorage @Inject lateinit var profileFunction: ProfileFunction @@ -35,7 +34,6 @@ class PrepareTemporaryTargetDataWorker( @Inject lateinit var rxBus: RxBus private var ctx: Context init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) ctx = rh.getThemedCtx(context) } @@ -43,7 +41,7 @@ class PrepareTemporaryTargetDataWorker( val overviewData: OverviewData ) - override fun doWork(): Result { + override fun doWorkAndLog(): Result { val data = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as PrepareTemporaryTargetData? ?: return Result.failure(workDataOf("Error" to "missing input data")) diff --git a/workflow/src/main/java/info/nightscout/workflow/PrepareTreatmentsDataWorker.kt b/workflow/src/main/java/info/nightscout/workflow/PrepareTreatmentsDataWorker.kt index ddd0e367c7..a6ca42538a 100644 --- a/workflow/src/main/java/info/nightscout/workflow/PrepareTreatmentsDataWorker.kt +++ b/workflow/src/main/java/info/nightscout/workflow/PrepareTreatmentsDataWorker.kt @@ -1,10 +1,8 @@ package info.nightscout.workflow import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf -import dagger.android.HasAndroidInjector import info.nightscout.core.events.EventIobCalculationProgress import info.nightscout.core.graph.OverviewData import info.nightscout.core.graph.data.BolusDataPoint @@ -15,6 +13,7 @@ import info.nightscout.core.graph.data.ExtendedBolusDataPoint import info.nightscout.core.graph.data.PointsWithLabelGraphSeries import info.nightscout.core.graph.data.TherapyEventDataPoint import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.core.workflow.CalculationWorkflow import info.nightscout.database.entities.Bolus import info.nightscout.database.entities.TherapyEvent @@ -34,7 +33,7 @@ import javax.inject.Inject class PrepareTreatmentsDataWorker( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { @Inject lateinit var dataWorkerStorage: DataWorkerStorage @Inject lateinit var profileFunction: ProfileFunction @@ -45,15 +44,11 @@ class PrepareTreatmentsDataWorker( @Inject lateinit var repository: AppRepository @Inject lateinit var defaultValueHelper: DefaultValueHelper - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - class PrepareTreatmentsData( val overviewData: OverviewData ) - override fun doWork(): Result { + override fun doWorkAndLog(): Result { val data = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as PrepareTreatmentsData? ?: return Result.failure(workDataOf("Error" to "missing input data")) diff --git a/workflow/src/main/java/info/nightscout/workflow/UpdateGraphWorker.kt b/workflow/src/main/java/info/nightscout/workflow/UpdateGraphWorker.kt index 89675364f4..768586e633 100644 --- a/workflow/src/main/java/info/nightscout/workflow/UpdateGraphWorker.kt +++ b/workflow/src/main/java/info/nightscout/workflow/UpdateGraphWorker.kt @@ -1,10 +1,9 @@ package info.nightscout.workflow import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters -import dagger.android.HasAndroidInjector import info.nightscout.core.events.EventIobCalculationProgress +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.core.workflow.CalculationWorkflow import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.rx.bus.RxBus @@ -14,16 +13,12 @@ import javax.inject.Inject class UpdateGraphWorker( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { @Inject lateinit var rxBus: RxBus @Inject lateinit var activePlugin: ActivePlugin - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - - override fun doWork(): Result { + override fun doWorkAndLog(): Result { if (inputData.getString(CalculationWorkflow.JOB) == CalculationWorkflow.MAIN_CALCULATION) activePlugin.activeOverview.overviewBus.send(EventUpdateOverviewGraph("UpdateGraphWorker")) else diff --git a/workflow/src/main/java/info/nightscout/workflow/UpdateIobCobSensWorker.kt b/workflow/src/main/java/info/nightscout/workflow/UpdateIobCobSensWorker.kt index 435635c485..b0650fc2f2 100644 --- a/workflow/src/main/java/info/nightscout/workflow/UpdateIobCobSensWorker.kt +++ b/workflow/src/main/java/info/nightscout/workflow/UpdateIobCobSensWorker.kt @@ -1,9 +1,8 @@ package info.nightscout.workflow import android.content.Context -import androidx.work.Worker import androidx.work.WorkerParameters -import dagger.android.HasAndroidInjector +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventUpdateOverviewIobCob @@ -13,16 +12,12 @@ import javax.inject.Inject class UpdateIobCobSensWorker( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { @Inject lateinit var rxBus: RxBus @Inject lateinit var activePlugin: ActivePlugin - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - - override fun doWork(): Result { + override fun doWorkAndLog(): Result { activePlugin.activeOverview.overviewBus.send(EventUpdateOverviewIobCob("UpdateIobCobSensWorker")) activePlugin.activeOverview.overviewBus.send(EventUpdateOverviewSensitivity("UpdateIobCobSensWorker")) return Result.success() diff --git a/workflow/src/main/java/info/nightscout/workflow/iob/IobCobOref1Worker.kt b/workflow/src/main/java/info/nightscout/workflow/iob/IobCobOref1Worker.kt index ead05f44f6..795764b0bc 100644 --- a/workflow/src/main/java/info/nightscout/workflow/iob/IobCobOref1Worker.kt +++ b/workflow/src/main/java/info/nightscout/workflow/iob/IobCobOref1Worker.kt @@ -2,7 +2,6 @@ package info.nightscout.workflow.iob import android.content.Context import android.os.SystemClock -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf import dagger.android.HasAndroidInjector @@ -11,6 +10,7 @@ import info.nightscout.core.extensions.target import info.nightscout.core.iob.iobCobCalculator.data.AutosensDataObject import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.core.workflow.CalculationWorkflow import info.nightscout.database.ValueWrapper import info.nightscout.database.impl.AppRepository @@ -27,7 +27,6 @@ import info.nightscout.plugins.iob.iobCobCalculator.fromCarbs import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.Event import info.nightscout.rx.events.EventAutosensCalculationFinished -import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP @@ -44,9 +43,8 @@ import kotlin.math.roundToLong class IobCobOref1Worker( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var sp: SP @Inject lateinit var rxBus: RxBus @Inject lateinit var rh: ResourceHelper @@ -60,10 +58,6 @@ class IobCobOref1Worker( @Inject lateinit var repository: AppRepository @Inject lateinit var dataWorkerStorage: DataWorkerStorage - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - class IobCobOref1WorkerData( val injector: HasAndroidInjector, val iobCobCalculator: IobCobCalculator, // cannot be injected : HistoryBrowser uses different instance @@ -73,7 +67,7 @@ class IobCobOref1Worker( val cause: Event? ) - override fun doWork(): Result { + override fun doWorkAndLog(): Result { val data = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as IobCobOref1WorkerData? ?: return Result.success(workDataOf("Error" to "missing input data")) diff --git a/workflow/src/main/java/info/nightscout/workflow/iob/IobCobOrefWorker.kt b/workflow/src/main/java/info/nightscout/workflow/iob/IobCobOrefWorker.kt index 0a6c26c86d..9abf378e38 100644 --- a/workflow/src/main/java/info/nightscout/workflow/iob/IobCobOrefWorker.kt +++ b/workflow/src/main/java/info/nightscout/workflow/iob/IobCobOrefWorker.kt @@ -2,7 +2,6 @@ package info.nightscout.workflow.iob import android.content.Context import android.os.SystemClock -import androidx.work.Worker import androidx.work.WorkerParameters import androidx.work.workDataOf import dagger.android.HasAndroidInjector @@ -10,6 +9,7 @@ import info.nightscout.core.events.EventIobCalculationProgress import info.nightscout.core.iob.iobCobCalculator.data.AutosensDataObject import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.receivers.DataWorkerStorage +import info.nightscout.core.utils.worker.LoggingWorker import info.nightscout.core.workflow.CalculationWorkflow import info.nightscout.database.impl.AppRepository import info.nightscout.interfaces.Config @@ -25,7 +25,6 @@ import info.nightscout.plugins.iob.iobCobCalculator.fromCarbs import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.Event import info.nightscout.rx.events.EventAutosensCalculationFinished -import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP @@ -40,9 +39,8 @@ import kotlin.math.roundToLong class IobCobOrefWorker @Inject internal constructor( context: Context, params: WorkerParameters -) : Worker(context, params) { +) : LoggingWorker(context, params) { - @Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var sp: SP @Inject lateinit var rxBus: RxBus @Inject lateinit var rh: ResourceHelper @@ -56,10 +54,6 @@ class IobCobOrefWorker @Inject internal constructor( @Inject lateinit var repository: AppRepository @Inject lateinit var dataWorkerStorage: DataWorkerStorage - init { - (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) - } - class IobCobOrefWorkerData( val injector: HasAndroidInjector, val iobCobCalculatorPlugin: IobCobCalculator, // cannot be injected : HistoryBrowser uses different instance @@ -69,7 +63,7 @@ class IobCobOrefWorker @Inject internal constructor( val cause: Event? ) - override fun doWork(): Result { + override fun doWorkAndLog(): Result { val data = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as IobCobOrefWorkerData? ?: return Result.success(workDataOf("Error" to "missing input data"))