From 4c5d015b40e04232c016073da4c6f7e27c810be1 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 1 Nov 2022 11:39:40 +0100 Subject: [PATCH] CommandQueueImpl -> implementation module --- .../nightscout/androidaps/MainActivity.kt | 6 +- .../info/nightscout/androidaps/MainApp.kt | 4 +- .../nightscout/androidaps/di/AppComponent.kt | 1 + .../nightscout/androidaps/di/AppModule.kt | 43 +++- .../androidaps/di/OverviewModule.kt | 1 - .../maintenance/ImportExportPrefsImpl.kt | 24 ++- .../general/overview/OverviewPlugin.kt | 28 ++- .../general/smsCommunicator/AuthRequest.kt | 16 +- .../SmsCommunicatorFragment.kt | 1 + .../smsCommunicator/SmsCommunicatorPlugin.kt | 4 +- .../androidaps/receivers/KeepAliveWorker.kt | 2 +- .../androidaps/setupwizard/SWDefinition.kt | 36 +++- .../androidaps/utils/AndroidPermission.kt | 167 ---------------- app/src/main/res/values/strings.xml | 17 -- app/src/main/res/xml/pref_smscommunicator.xml | 2 +- .../smsCommunicator/AuthRequestTest.kt | 1 + .../SmsCommunicatorPluginTest.kt | 1 + .../general/smsCommunicator/SmsTest.kt | 1 + core/android_module_dependencies.gradle | 5 + .../info/nightscout/androidaps/data}/Sms.kt | 8 +- .../interfaces/AndroidPermission.kt | 17 ++ .../androidaps/interfaces/Insight.kt | 10 + .../androidaps/interfaces/LocalAlertUtils.kt | 17 ++ .../androidaps/interfaces/Overview.kt | 4 + .../androidaps/interfaces/SmsCommunicator.kt | 3 + core/src/main/res/values/strings.xml | 7 + .../implementation/AndroidPermissionImpl.kt | 185 ++++++++++++++++++ .../implementation/LocalAlertUtilsImpl.kt | 26 +-- .../implementation}/di/CommandQueueModule.kt | 22 ++- .../queue/CommandQueueImplementation.kt | 49 +++-- .../implementation}/queue/QueueThread.kt | 8 +- .../queue/commands/CommandBolus.kt | 7 +- .../commands/CommandCancelExtendedBolus.kt | 7 +- .../queue/commands/CommandCancelTempBasal.kt | 7 +- .../queue/commands/CommandCustomCommand.kt | 6 +- .../queue/commands/CommandExtendedBolus.kt | 7 +- .../CommandInsightSetTBROverNotification.kt | 11 +- .../queue/commands/CommandLoadEvents.kt | 7 +- .../queue/commands/CommandLoadHistory.kt | 7 +- .../queue/commands/CommandLoadTDDs.kt | 7 +- .../queue/commands/CommandReadStatus.kt | 9 +- .../queue/commands/CommandSMBBolus.kt | 7 +- .../queue/commands/CommandSetProfile.kt | 14 +- .../queue/commands/CommandSetUserSettings.kt | 7 +- .../queue/commands/CommandStartPump.kt | 9 +- .../queue/commands/CommandStopPump.kt | 9 +- .../commands/CommandTempBasalAbsolute.kt | 9 +- .../queue/commands/CommandTempBasalPercent.kt | 9 +- .../src/main/res/values/strings.xml | 11 ++ .../androidaps/TestBaseWithProfile.kt | 177 +++++++++++++++++ .../nightscout/androidaps/TestPumpPlugin.kt | 68 +++++++ .../queue/CommandQueueImplementationTest.kt | 58 +++--- .../implementation}/queue/QueueThreadTest.kt | 15 +- .../pump/insight/LocalInsightPlugin.java | 4 +- 54 files changed, 832 insertions(+), 356 deletions(-) delete mode 100644 app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.kt rename {app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator => core/src/main/java/info/nightscout/androidaps/data}/Sms.kt (77%) create mode 100644 core/src/main/java/info/nightscout/androidaps/interfaces/AndroidPermission.kt create mode 100644 core/src/main/java/info/nightscout/androidaps/interfaces/Insight.kt create mode 100644 core/src/main/java/info/nightscout/androidaps/interfaces/LocalAlertUtils.kt create mode 100644 implementation/src/main/java/info/nightscout/implementation/AndroidPermissionImpl.kt rename app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt => implementation/src/main/java/info/nightscout/implementation/LocalAlertUtilsImpl.kt (89%) rename {app/src/main/java/info/nightscout/androidaps => implementation/src/main/java/info/nightscout/implementation}/di/CommandQueueModule.kt (58%) rename {app/src/main/java/info/nightscout/androidaps => implementation/src/main/java/info/nightscout/implementation}/queue/CommandQueueImplementation.kt (92%) rename {app/src/main/java/info/nightscout/androidaps => implementation/src/main/java/info/nightscout/implementation}/queue/QueueThread.kt (98%) rename {app/src/main/java/info/nightscout/androidaps => implementation/src/main/java/info/nightscout/implementation}/queue/commands/CommandBolus.kt (92%) rename {app/src/main/java/info/nightscout/androidaps => implementation/src/main/java/info/nightscout/implementation}/queue/commands/CommandCancelExtendedBolus.kt (84%) rename {app/src/main/java/info/nightscout/androidaps => implementation/src/main/java/info/nightscout/implementation}/queue/commands/CommandCancelTempBasal.kt (84%) rename {app/src/main/java/info/nightscout/androidaps => implementation/src/main/java/info/nightscout/implementation}/queue/commands/CommandCustomCommand.kt (83%) rename {app/src/main/java/info/nightscout/androidaps => implementation/src/main/java/info/nightscout/implementation}/queue/commands/CommandExtendedBolus.kt (86%) rename {app/src/main/java/info/nightscout/androidaps => implementation/src/main/java/info/nightscout/implementation}/queue/commands/CommandInsightSetTBROverNotification.kt (78%) rename {app/src/main/java/info/nightscout/androidaps => implementation/src/main/java/info/nightscout/implementation}/queue/commands/CommandLoadEvents.kt (89%) rename {app/src/main/java/info/nightscout/androidaps => implementation/src/main/java/info/nightscout/implementation}/queue/commands/CommandLoadHistory.kt (89%) rename {app/src/main/java/info/nightscout/androidaps => implementation/src/main/java/info/nightscout/implementation}/queue/commands/CommandLoadTDDs.kt (83%) rename {app/src/main/java/info/nightscout/androidaps => implementation/src/main/java/info/nightscout/implementation}/queue/commands/CommandReadStatus.kt (85%) rename {app/src/main/java/info/nightscout/androidaps => implementation/src/main/java/info/nightscout/implementation}/queue/commands/CommandSMBBolus.kt (93%) rename {app/src/main/java/info/nightscout/androidaps => implementation/src/main/java/info/nightscout/implementation}/queue/commands/CommandSetProfile.kt (83%) rename {app/src/main/java/info/nightscout/androidaps => implementation/src/main/java/info/nightscout/implementation}/queue/commands/CommandSetUserSettings.kt (88%) rename {app/src/main/java/info/nightscout/androidaps => implementation/src/main/java/info/nightscout/implementation}/queue/commands/CommandStartPump.kt (73%) rename {app/src/main/java/info/nightscout/androidaps => implementation/src/main/java/info/nightscout/implementation}/queue/commands/CommandStopPump.kt (73%) rename {app/src/main/java/info/nightscout/androidaps => implementation/src/main/java/info/nightscout/implementation}/queue/commands/CommandTempBasalAbsolute.kt (89%) rename {app/src/main/java/info/nightscout/androidaps => implementation/src/main/java/info/nightscout/implementation}/queue/commands/CommandTempBasalPercent.kt (90%) create mode 100644 implementation/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt create mode 100644 implementation/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt rename {app/src/test/java/info/nightscout/androidaps => implementation/src/test/java/info/nightscout/implementation}/queue/CommandQueueImplementationTest.kt (90%) rename {app/src/test/java/info/nightscout/androidaps => implementation/src/test/java/info/nightscout/implementation}/queue/QueueThreadTest.kt (86%) diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt index 8822e8b7f3..90e09659e2 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt @@ -44,9 +44,7 @@ import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.constraints.signatureVerifier.SignatureVerifierPlugin import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerUtils import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus -import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin import info.nightscout.androidaps.setupwizard.SetupWizardActivity -import info.nightscout.androidaps.utils.AndroidPermission import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.extensions.isRunningRealPumpTest @@ -72,7 +70,7 @@ class MainActivity : NoSplashAppCompatActivity() { @Inject lateinit var androidPermission: AndroidPermission @Inject lateinit var sp: SP @Inject lateinit var versionCheckerUtils: VersionCheckerUtils - @Inject lateinit var smsCommunicatorPlugin: SmsCommunicatorPlugin + @Inject lateinit var smsCommunicator: SmsCommunicator @Inject lateinit var loop: Loop @Inject lateinit var nsSettingsStatus: NSSettingsStatus @Inject lateinit var buildHelper: BuildHelper @@ -152,7 +150,7 @@ class MainActivity : NoSplashAppCompatActivity() { androidPermission.notifyForBatteryOptimizationPermission(this) if (!config.NSCLIENT) androidPermission.notifyForLocationPermissions(this) if (config.PUMPDRIVERS) { - androidPermission.notifyForSMSPermissions(this, smsCommunicatorPlugin) + androidPermission.notifyForSMSPermissions(this, smsCommunicator) androidPermission.notifyForSystemWindowPermissions(this) androidPermission.notifyForBtConnectPermission(this) } diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.kt b/app/src/main/java/info/nightscout/androidaps/MainApp.kt index ec4215aaba..674cc9a10a 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.kt +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.kt @@ -23,8 +23,10 @@ import info.nightscout.androidaps.database.transactions.VersionChangeTransaction import info.nightscout.androidaps.db.CompatDBHelper import info.nightscout.androidaps.di.DaggerAppComponent import info.nightscout.androidaps.di.StaticInjector +import info.nightscout.androidaps.interfaces.BuildHelper import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.ConfigBuilder +import info.nightscout.androidaps.interfaces.LocalAlertUtils import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.logging.UserEntryLogger @@ -41,9 +43,7 @@ import info.nightscout.androidaps.receivers.TimeDateOrTZChangeReceiver import info.nightscout.androidaps.services.AlarmSoundServiceHelper import info.nightscout.androidaps.utils.ActivityMonitor import info.nightscout.androidaps.utils.DateUtil -import info.nightscout.androidaps.utils.LocalAlertUtils import info.nightscout.androidaps.utils.ProcessLifecycleListener -import info.nightscout.androidaps.interfaces.BuildHelper import info.nightscout.androidaps.utils.locale.LocaleHelper import info.nightscout.androidaps.widget.updateWidget import info.nightscout.shared.logging.AAPSLogger diff --git a/app/src/main/java/info/nightscout/androidaps/di/AppComponent.kt b/app/src/main/java/info/nightscout/androidaps/di/AppComponent.kt index ce05242c68..2f06684f31 100644 --- a/app/src/main/java/info/nightscout/androidaps/di/AppComponent.kt +++ b/app/src/main/java/info/nightscout/androidaps/di/AppComponent.kt @@ -22,6 +22,7 @@ import info.nightscout.androidaps.plugins.pump.common.di.RileyLinkModule import info.nightscout.androidaps.plugins.pump.medtronic.di.MedtronicModule import info.nightscout.androidaps.plugins.pump.omnipod.dash.di.OmnipodDashModule import info.nightscout.androidaps.plugins.pump.omnipod.eros.di.OmnipodErosModule +import info.nightscout.implementation.di.CommandQueueModule import info.nightscout.shared.di.SharedModule import info.nightscout.ui.di.UiModule import javax.inject.Singleton diff --git a/app/src/main/java/info/nightscout/androidaps/di/AppModule.kt b/app/src/main/java/info/nightscout/androidaps/di/AppModule.kt index 25509a99ce..5c119b31c8 100644 --- a/app/src/main/java/info/nightscout/androidaps/di/AppModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/di/AppModule.kt @@ -8,8 +8,28 @@ import dagger.Provides import dagger.android.HasAndroidInjector import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.database.AppRepository -import info.nightscout.androidaps.interfaces.* -import info.nightscout.shared.logging.AAPSLogger +import info.nightscout.androidaps.interfaces.ActivePlugin +import info.nightscout.androidaps.interfaces.AndroidPermission +import info.nightscout.androidaps.interfaces.Autotune +import info.nightscout.androidaps.interfaces.BolusTimer +import info.nightscout.androidaps.interfaces.BuildHelper +import info.nightscout.androidaps.interfaces.CarbTimer +import info.nightscout.androidaps.interfaces.CommandQueue +import info.nightscout.androidaps.interfaces.Config +import info.nightscout.androidaps.interfaces.ConfigBuilder +import info.nightscout.androidaps.interfaces.DataSyncSelector +import info.nightscout.androidaps.interfaces.IconsProvider +import info.nightscout.androidaps.interfaces.ImportExportPrefs +import info.nightscout.androidaps.interfaces.IobCobCalculator +import info.nightscout.androidaps.interfaces.LocalAlertUtils +import info.nightscout.androidaps.interfaces.Loop +import info.nightscout.androidaps.interfaces.NotificationHolder +import info.nightscout.androidaps.interfaces.PluginBase +import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.interfaces.PumpSync +import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.androidaps.interfaces.SmsCommunicator +import info.nightscout.androidaps.interfaces.XDripBroadcast import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin @@ -23,23 +43,24 @@ import info.nightscout.androidaps.plugins.general.nsclient.data.DeviceStatusData import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin import info.nightscout.androidaps.plugins.pump.PumpSyncImplementation -import info.nightscout.androidaps.queue.CommandQueueImplementation import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.HardLimits import info.nightscout.androidaps.utils.androidNotification.NotificationHolderImpl -import info.nightscout.androidaps.interfaces.BuildHelper import info.nightscout.androidaps.utils.buildHelper.BuildHelperImpl import info.nightscout.androidaps.utils.buildHelper.ConfigImpl import info.nightscout.androidaps.utils.resources.IconsProviderImplementation -import info.nightscout.androidaps.interfaces.ResourceHelper -import info.nightscout.implementation.XDripBroadcastImpl import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.rx.DefaultAapsSchedulers import info.nightscout.androidaps.utils.storage.FileStorage import info.nightscout.androidaps.utils.storage.Storage +import info.nightscout.implementation.AndroidPermissionImpl import info.nightscout.implementation.BolusTimerImpl import info.nightscout.implementation.CarbTimerImpl +import info.nightscout.implementation.LocalAlertUtilsImpl +import info.nightscout.implementation.XDripBroadcastImpl +import info.nightscout.implementation.queue.CommandQueueImplementation +import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.sharedPreferences.SP import javax.inject.Singleton @@ -109,10 +130,12 @@ open class AppModule { @Binds fun bindSmsCommunicatorInterface(smsCommunicatorPlugin: SmsCommunicatorPlugin): SmsCommunicator @Binds fun bindDataSyncSelector(dataSyncSelectorImplementation: DataSyncSelectorImplementation): DataSyncSelector - @Binds fun bindPumpSync(pumpSyncImplementation: PumpSyncImplementation): PumpSync - @Binds fun bindXDripBroadcast(xDripBroadcastImpl: XDripBroadcastImpl): XDripBroadcast - @Binds fun bindCarbTimer(carbTimer: CarbTimerImpl): CarbTimer - @Binds fun bindBolusTimer(bolusTimer: BolusTimerImpl): BolusTimer + @Binds fun bindPumpSyncInterface(pumpSyncImplementation: PumpSyncImplementation): PumpSync + @Binds fun bindXDripBroadcastInterface(xDripBroadcastImpl: XDripBroadcastImpl): XDripBroadcast + @Binds fun bindCarbTimerInterface(carbTimer: CarbTimerImpl): CarbTimer + @Binds fun bindBolusTimerInterface(bolusTimer: BolusTimerImpl): BolusTimer + @Binds fun bindAndroidPermissionInterface(androidPermission: AndroidPermissionImpl): AndroidPermission + @Binds fun bindLocalAlertUtilsInterface(localAlertUtils: LocalAlertUtilsImpl): LocalAlertUtils } } diff --git a/app/src/main/java/info/nightscout/androidaps/di/OverviewModule.kt b/app/src/main/java/info/nightscout/androidaps/di/OverviewModule.kt index 7b80d781ea..8bbc28a25d 100644 --- a/app/src/main/java/info/nightscout/androidaps/di/OverviewModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/di/OverviewModule.kt @@ -9,6 +9,5 @@ import info.nightscout.androidaps.plugins.general.overview.notifications.Notific @Suppress("unused") abstract class OverviewModule { @ContributesAndroidInjector abstract fun notificationWithActionInjector(): NotificationWithAction - @ContributesAndroidInjector abstract fun graphDataInjector(): GraphData } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefsImpl.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefsImpl.kt index 25a75d17ce..7ae9c83d2a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefsImpl.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefsImpl.kt @@ -13,7 +13,12 @@ import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentActivity -import androidx.work.* +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.androidaps.BuildConfig import info.nightscout.androidaps.R @@ -25,13 +30,21 @@ import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Sources import info.nightscout.androidaps.diaconn.events.EventDiaconnG8PumpLogReset import info.nightscout.androidaps.events.EventAppExit +import info.nightscout.androidaps.interfaces.AndroidPermission +import info.nightscout.androidaps.interfaces.BuildHelper import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.ImportExportPrefs import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.bus.RxBus -import info.nightscout.androidaps.plugins.general.maintenance.formats.* -import info.nightscout.androidaps.utils.AndroidPermission +import info.nightscout.androidaps.plugins.general.maintenance.formats.EncryptedPrefsFormat +import info.nightscout.androidaps.plugins.general.maintenance.formats.PrefFileNotFoundError +import info.nightscout.androidaps.plugins.general.maintenance.formats.PrefIOError +import info.nightscout.androidaps.plugins.general.maintenance.formats.PrefMetadata +import info.nightscout.androidaps.plugins.general.maintenance.formats.Prefs +import info.nightscout.androidaps.plugins.general.maintenance.formats.PrefsFormat +import info.nightscout.androidaps.plugins.general.maintenance.formats.PrefsMetadataKey +import info.nightscout.androidaps.plugins.general.maintenance.formats.PrefsStatus import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.MidnightTime import info.nightscout.androidaps.utils.T @@ -40,7 +53,6 @@ import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.alertDialogs.PrefImportSummaryDialog import info.nightscout.androidaps.utils.alertDialogs.TwoMessagesAlertDialog import info.nightscout.androidaps.utils.alertDialogs.WarningDialog -import info.nightscout.androidaps.interfaces.BuildHelper import info.nightscout.androidaps.utils.protection.PasswordCheck import info.nightscout.androidaps.utils.storage.Storage import info.nightscout.androidaps.utils.userEntry.UserEntryPresentationHelper @@ -251,13 +263,13 @@ class ImportExportPrefsImpl @Inject constructor( activity, rh.gs(R.string.preferences_export_canceled) + "\n\n" + rh.gs(R.string.filenotfound) + ": " + e.message - + "\n\n" + rh.gs(R.string.needstoragepermission) + + "\n\n" + rh.gs(R.string.need_storage_permission) ) log.error(LTag.CORE, "File system exception", e) } catch (e: PrefIOError) { ToastUtils.Long.errorToast( activity, rh.gs(R.string.preferences_export_canceled) - + "\n\n" + rh.gs(R.string.needstoragepermission) + + "\n\n" + rh.gs(R.string.need_storage_permission) + ": " + e.message ) log.error(LTag.CORE, "File system exception", e) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.kt index 58b2de95d6..9131b131df 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.kt @@ -1,12 +1,23 @@ package info.nightscout.androidaps.plugins.general.overview +import androidx.annotation.StringRes import androidx.preference.PreferenceFragmentCompat import androidx.preference.SwitchPreference import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R import info.nightscout.androidaps.events.EventPumpStatusChanged -import info.nightscout.androidaps.extensions.* -import info.nightscout.androidaps.interfaces.* +import info.nightscout.androidaps.extensions.putDouble +import info.nightscout.androidaps.extensions.putInt +import info.nightscout.androidaps.extensions.putString +import info.nightscout.androidaps.extensions.storeDouble +import info.nightscout.androidaps.extensions.storeInt +import info.nightscout.androidaps.extensions.storeString +import info.nightscout.androidaps.interfaces.Config +import info.nightscout.androidaps.interfaces.Overview +import info.nightscout.androidaps.interfaces.PluginBase +import info.nightscout.androidaps.interfaces.PluginDescription +import info.nightscout.androidaps.interfaces.PluginType +import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification @@ -15,6 +26,7 @@ import info.nightscout.androidaps.plugins.general.overview.events.EventUpdateOve import info.nightscout.androidaps.plugins.general.overview.graphExtensions.Scale import info.nightscout.androidaps.plugins.general.overview.graphExtensions.ScaledDataPoint import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationStore +import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationWithAction import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.rx.AapsSchedulers @@ -56,6 +68,18 @@ class OverviewPlugin @Inject constructor( private var disposable: CompositeDisposable = CompositeDisposable() override val overviewBus = RxBus(aapsSchedulers, aapsLogger) + override fun addNotification(id: Int, text: String, level: Int, @StringRes actionButtonId: Int, action: Runnable) { + rxBus.send( + EventNewNotification( + NotificationWithAction(injector, id, text, level).apply { + action(actionButtonId, action) + }) + ) + } + + override fun dismissNotification(id: Int) { + rxBus.send(EventDismissNotification(id)) + } class DeviationDataPoint(x: Double, y: Double, var color: Int, scale: Scale) : ScaledDataPoint(x, y, scale) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequest.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequest.kt index f4c41c42c4..fd61e12c9f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequest.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequest.kt @@ -4,14 +4,16 @@ import android.os.SystemClock import dagger.android.HasAndroidInjector import info.nightscout.androidaps.Constants import info.nightscout.androidaps.R +import info.nightscout.androidaps.data.Sms import info.nightscout.androidaps.interfaces.CommandQueue -import info.nightscout.shared.logging.AAPSLogger -import info.nightscout.shared.logging.LTag +import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.androidaps.interfaces.SmsCommunicator import info.nightscout.androidaps.plugins.general.smsCommunicator.otp.OneTimePassword import info.nightscout.androidaps.plugins.general.smsCommunicator.otp.OneTimePasswordValidationResult import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.T -import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.shared.logging.AAPSLogger +import info.nightscout.shared.logging.LTag import javax.inject.Inject class AuthRequest internal constructor( @@ -22,7 +24,7 @@ class AuthRequest internal constructor( val action: SmsAction) { @Inject lateinit var aapsLogger: AAPSLogger - @Inject lateinit var smsCommunicatorPlugin: SmsCommunicatorPlugin + @Inject lateinit var smsCommunicator: SmsCommunicator @Inject lateinit var rh: ResourceHelper @Inject lateinit var otp: OneTimePassword @Inject lateinit var dateUtil: DateUtil @@ -34,7 +36,7 @@ class AuthRequest internal constructor( init { injector.androidInjector().inject(this) date = dateUtil.now() - smsCommunicatorPlugin.sendSMS(Sms(requester.phoneNumber, requestText)) + smsCommunicator.sendSMS(Sms(requester.phoneNumber, requestText)) } private fun codeIsValid(toValidate: String): Boolean = @@ -48,7 +50,7 @@ class AuthRequest internal constructor( if (!codeIsValid(codeReceived)) { processed = true aapsLogger.debug(LTag.SMS, "Wrong code") - smsCommunicatorPlugin.sendSMS(Sms(requester.phoneNumber, rh.gs(R.string.sms_wrongcode))) + smsCommunicator.sendSMS(Sms(requester.phoneNumber, rh.gs(R.string.sms_wrongcode))) return } if (dateUtil.now() - date < Constants.SMS_CONFIRM_TIMEOUT) { @@ -62,7 +64,7 @@ class AuthRequest internal constructor( } if (commandQueue.size() != 0) { aapsLogger.debug(LTag.SMS, "Command timed out: " + requester.text) - smsCommunicatorPlugin.sendSMS(Sms(requester.phoneNumber, rh.gs(R.string.sms_timeout_while_wating))) + smsCommunicator.sendSMS(Sms(requester.phoneNumber, rh.gs(R.string.sms_timeout_while_wating))) return } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorFragment.kt index 666097d017..67e2ea7518 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorFragment.kt @@ -5,6 +5,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import dagger.android.support.DaggerFragment +import info.nightscout.androidaps.data.Sms import info.nightscout.androidaps.databinding.SmscommunicatorFragmentBinding import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.general.smsCommunicator.events.EventSmsCommunicatorUpdateGui diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt index 63a5d28493..0bcc5b3c82 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt @@ -15,6 +15,7 @@ import info.nightscout.androidaps.Constants import info.nightscout.androidaps.R import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.data.DetailedBolusInfo +import info.nightscout.androidaps.data.Sms import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.entities.OfflineEvent import info.nightscout.androidaps.database.entities.TemporaryTarget @@ -184,7 +185,6 @@ class SmsCommunicatorPlugin @Inject constructor( (context.applicationContext as HasAndroidInjector).androidInjector().inject(this) } - @Suppress("SpellCheckingInspection") override fun doWork(): Result { val bundle = dataWorkerStorage.pickupBundle(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) ?: return Result.failure(workDataOf("Error" to "missing input data")) @@ -1099,7 +1099,7 @@ class SmsCommunicatorPlugin @Inject constructor( } } - fun sendSMS(sms: Sms): Boolean { + override fun sendSMS(sms: Sms): Boolean { sms.text = stripAccents(sms.text) try { aapsLogger.debug(LTag.SMS, "Sending SMS to " + sms.phoneNumber + ": " + sms.text) 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 8a07fe9afe..8cf63218e9 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveWorker.kt +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveWorker.kt @@ -22,6 +22,7 @@ import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.CommandQueue import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.IobCobCalculator +import info.nightscout.androidaps.interfaces.LocalAlertUtils import info.nightscout.androidaps.interfaces.Loop import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.ProfileFunction @@ -32,7 +33,6 @@ import info.nightscout.androidaps.plugins.general.maintenance.MaintenancePlugin import info.nightscout.androidaps.queue.commands.Command import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy -import info.nightscout.androidaps.utils.LocalAlertUtils import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.widget.updateWidget import info.nightscout.shared.logging.AAPSLogger diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt index 8e26f60532..547db33f78 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt @@ -12,7 +12,15 @@ import info.nightscout.androidaps.R import info.nightscout.androidaps.data.ProfileSealed import info.nightscout.androidaps.dialogs.ProfileSwitchDialog import info.nightscout.androidaps.events.EventPumpStatusChanged -import info.nightscout.androidaps.interfaces.* +import info.nightscout.androidaps.interfaces.ActivePlugin +import info.nightscout.androidaps.interfaces.AndroidPermission +import info.nightscout.androidaps.interfaces.CommandQueue +import info.nightscout.androidaps.interfaces.Config +import info.nightscout.androidaps.interfaces.ConfigBuilder +import info.nightscout.androidaps.interfaces.ImportExportPrefs +import info.nightscout.androidaps.interfaces.PluginType +import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesFragment @@ -24,15 +32,25 @@ import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange import info.nightscout.androidaps.plugins.pump.omnipod.dash.OmnipodDashPumpPlugin import info.nightscout.androidaps.plugins.pump.omnipod.eros.OmnipodErosPumpPlugin -import info.nightscout.androidaps.setupwizard.elements.* +import info.nightscout.androidaps.setupwizard.elements.SWBreak +import info.nightscout.androidaps.setupwizard.elements.SWButton +import info.nightscout.androidaps.setupwizard.elements.SWEditEncryptedPassword +import info.nightscout.androidaps.setupwizard.elements.SWEditIntNumber +import info.nightscout.androidaps.setupwizard.elements.SWEditNumber +import info.nightscout.androidaps.setupwizard.elements.SWEditNumberWithUnits +import info.nightscout.androidaps.setupwizard.elements.SWEditString +import info.nightscout.androidaps.setupwizard.elements.SWEditUrl +import info.nightscout.androidaps.setupwizard.elements.SWFragment +import info.nightscout.androidaps.setupwizard.elements.SWHtmlLink +import info.nightscout.androidaps.setupwizard.elements.SWInfoText +import info.nightscout.androidaps.setupwizard.elements.SWPlugin +import info.nightscout.androidaps.setupwizard.elements.SWPreference +import info.nightscout.androidaps.setupwizard.elements.SWRadioButton import info.nightscout.androidaps.setupwizard.events.EventSWUpdate -import info.nightscout.androidaps.utils.AndroidPermission import info.nightscout.androidaps.utils.CryptoUtil import info.nightscout.androidaps.utils.HardLimits import info.nightscout.androidaps.utils.extensions.isRunningTest -import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP -import java.util.* import javax.inject.Inject import javax.inject.Singleton @@ -110,7 +128,7 @@ class SWDefinition @Inject constructor( private val screenPermissionWindow = SWScreen(injector, R.string.permission) .skippable(false) .add(SWInfoText(injector) - .label(rh.gs(R.string.needsystemwindowpermission))) + .label(rh.gs(R.string.need_system_window_permission))) .add(SWBreak(injector)) .add(SWButton(injector) .text(R.string.askforpermission) @@ -121,7 +139,7 @@ class SWDefinition @Inject constructor( private val screenPermissionBattery = SWScreen(injector, R.string.permission) .skippable(false) .add(SWInfoText(injector) - .label(rh.gs(R.string.needwhitelisting, rh.gs(R.string.app_name)))) + .label(rh.gs(R.string.need_whitelisting, rh.gs(R.string.app_name)))) .add(SWBreak(injector)) .add(SWButton(injector) .text(R.string.askforpermission) @@ -132,7 +150,7 @@ class SWDefinition @Inject constructor( private val screenPermissionBt = SWScreen(injector, R.string.permission) .skippable(false) .add(SWInfoText(injector) - .label(rh.gs(R.string.needlocationpermission))) + .label(rh.gs(R.string.need_location_permission))) .add(SWBreak(injector)) .add(SWButton(injector) .text(R.string.askforpermission) @@ -143,7 +161,7 @@ class SWDefinition @Inject constructor( private val screenPermissionStore = SWScreen(injector, R.string.permission) .skippable(false) .add(SWInfoText(injector) - .label(rh.gs(R.string.needstoragepermission))) + .label(rh.gs(R.string.need_storage_permission))) .add(SWBreak(injector)) .add(SWButton(injector) .text(R.string.askforpermission) diff --git a/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.kt b/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.kt deleted file mode 100644 index cea1f8bb35..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.kt +++ /dev/null @@ -1,167 +0,0 @@ -package info.nightscout.androidaps.utils - -import android.Manifest -import android.annotation.SuppressLint -import android.bluetooth.BluetoothAdapter -import android.content.ActivityNotFoundException -import android.content.Context -import android.content.Intent -import android.content.pm.PackageManager -import android.net.Uri -import android.os.Build -import android.os.PowerManager -import android.provider.Settings -import androidx.core.content.ContextCompat -import androidx.fragment.app.FragmentActivity -import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R -import info.nightscout.androidaps.activities.DaggerAppCompatActivityWithResult -import info.nightscout.androidaps.plugins.bus.RxBus -import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification -import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification -import info.nightscout.androidaps.plugins.general.overview.notifications.Notification -import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationWithAction -import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin -import info.nightscout.androidaps.utils.alertDialogs.OKDialog -import info.nightscout.androidaps.interfaces.ResourceHelper -import javax.inject.Inject -import javax.inject.Singleton - -@Singleton -class AndroidPermission @Inject constructor( - val rh: ResourceHelper, - val rxBus: RxBus, - val injector: HasAndroidInjector -) { - - private var permissionBatteryOptimizationFailed = false - - @SuppressLint("BatteryLife") - fun askForPermission(activity: FragmentActivity, permissions: Array) { - var test = false - var testBattery = false - for (s in permissions) { - test = test || ContextCompat.checkSelfPermission(activity, s) != PackageManager.PERMISSION_GRANTED - if (s == Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) { - val powerManager = activity.getSystemService(Context.POWER_SERVICE) as PowerManager - val packageName = activity.packageName - testBattery = testBattery || !powerManager.isIgnoringBatteryOptimizations(packageName) - } - } - if (test) { - if (activity is DaggerAppCompatActivityWithResult) - try { - activity.requestMultiplePermissions.launch(permissions) - } catch (ignored: IllegalStateException) { - ToastUtils.errorToast(activity, rh.gs(R.string.error_asking_for_permissions)) - } - } - if (testBattery) { - try { - if (activity is DaggerAppCompatActivityWithResult) - try { - activity.callForBatteryOptimization.launch(null) - } catch (ignored: IllegalStateException) { - ToastUtils.errorToast(activity, rh.gs(R.string.error_asking_for_permissions)) - } - } catch (e: ActivityNotFoundException) { - permissionBatteryOptimizationFailed = true - OKDialog.show(activity, rh.gs(R.string.permission), rh.gs(R.string.alert_dialog_permission_battery_optimization_failed)) { activity.recreate() } - } - } - } - - fun askForPermission(activity: FragmentActivity, permission: String) = askForPermission(activity, arrayOf(permission)) - - fun permissionNotGranted(context: Context, permission: String): Boolean { - var selfCheck = ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED - if (permission == Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) { - if (!permissionBatteryOptimizationFailed) { - val powerManager = context.getSystemService(Context.POWER_SERVICE) as PowerManager - val packageName = context.packageName - selfCheck = selfCheck && powerManager.isIgnoringBatteryOptimizations(packageName) - } - } - return !selfCheck - } - - @Synchronized - fun notifyForSMSPermissions(activity: FragmentActivity, smsCommunicatorPlugin: SmsCommunicatorPlugin) { - if (smsCommunicatorPlugin.isEnabled()) { - if (permissionNotGranted(activity, Manifest.permission.RECEIVE_SMS)) { - val notification = NotificationWithAction(injector, Notification.PERMISSION_SMS, rh.gs(R.string.smscommunicator_missingsmspermission), Notification.URGENT) - notification.action(R.string.request) { askForPermission(activity, arrayOf(Manifest.permission.RECEIVE_SMS, Manifest.permission.SEND_SMS, Manifest.permission.RECEIVE_MMS)) } - rxBus.send(EventNewNotification(notification)) - } else rxBus.send(EventDismissNotification(Notification.PERMISSION_SMS)) - // Following is a bug in Android 8 -// if (permissionNotGranted(activity, Manifest.permission.READ_PHONE_STATE)) { -// val notification = NotificationWithAction(injector, Notification.PERMISSION_PHONE_STATE, rh.gs(R.string.smscommunicator_missingphonestatepermission), Notification.URGENT) -// notification.action(R.string.request) { askForPermission(activity, arrayOf(Manifest.permission.READ_PHONE_STATE)) } -// rxBus.send(EventNewNotification(notification)) -// } else rxBus.send(EventDismissNotification(Notification.PERMISSION_PHONE_STATE)) - } - } - - @SuppressLint("MissingPermission") - @Synchronized - fun notifyForBtConnectPermission(activity: FragmentActivity) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - // Manifest.permission.BLUETOOTH_CONNECT - if (permissionNotGranted(activity, Manifest.permission.BLUETOOTH_CONNECT) || permissionNotGranted(activity, Manifest.permission.BLUETOOTH_SCAN)) { - val notification = NotificationWithAction(injector, Notification.PERMISSION_BT, rh.gs(R.string.needconnectpermission), Notification.URGENT) - notification.action(R.string.request) { askForPermission(activity, arrayOf(Manifest.permission.BLUETOOTH_SCAN, Manifest.permission.BLUETOOTH_CONNECT)) } - rxBus.send(EventNewNotification(notification)) - } else { - activity.startActivity(Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)) - rxBus.send(EventDismissNotification(Notification.PERMISSION_BT)) - } - } - } - - @Synchronized - fun notifyForBatteryOptimizationPermission(activity: FragmentActivity) { - if (permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) { - val notification = NotificationWithAction(injector, Notification.PERMISSION_BATTERY, rh.gs(R.string.needwhitelisting, rh.gs(R.string.app_name)), Notification.URGENT) - notification.action(R.string.request) { askForPermission(activity, arrayOf(Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) } - rxBus.send(EventNewNotification(notification)) - } else rxBus.send(EventDismissNotification(Notification.PERMISSION_BATTERY)) - } - - @Synchronized fun notifyForStoragePermission(activity: FragmentActivity) { - if (permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - val notification = NotificationWithAction(injector, Notification.PERMISSION_STORAGE, rh.gs(R.string.needstoragepermission), Notification.URGENT) - notification.action(R.string.request) { askForPermission(activity, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE)) } - rxBus.send(EventNewNotification(notification)) - } else rxBus.send(EventDismissNotification(Notification.PERMISSION_STORAGE)) - } - - @Synchronized fun notifyForLocationPermissions(activity: FragmentActivity) { - if (permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION)) { - val notification = NotificationWithAction(injector, Notification.PERMISSION_LOCATION, rh.gs(R.string.needlocationpermission), Notification.URGENT) - notification.action(R.string.request) { askForPermission(activity, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION)) } - rxBus.send(EventNewNotification(notification)) - } else rxBus.send(EventDismissNotification(Notification.PERMISSION_LOCATION)) - } - - @Synchronized fun notifyForSystemWindowPermissions(activity: FragmentActivity) { - // Check if Android Q or higher - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) { - if (!Settings.canDrawOverlays(activity)) { - val notification = NotificationWithAction(injector, Notification.PERMISSION_SYSTEM_WINDOW, rh.gs(R.string.needsystemwindowpermission), Notification.URGENT) - notification.action(R.string.request) { - // Check if Android Q or higher - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) { - // Show alert dialog to the user saying a separate permission is needed - // Launch the settings activity if the user prefers - val intent = Intent( - Settings.ACTION_MANAGE_OVERLAY_PERMISSION, - Uri.parse("package:" + activity.packageName) - ) - activity.startActivity(intent) - } - } - rxBus.send(EventNewNotification(notification)) - } else rxBus.send(EventDismissNotification(Notification.PERMISSION_SYSTEM_WINDOW)) - } - } -} \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a4bc2cc03f..95603b7207 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -67,7 +67,6 @@ Reset Databases Do you really want to reset the databases? Exit - This device does not appear to support battery optimization whitelisting - you may experience performance issues. Some buttons to quickly access common features Used for configuring the active plugins Learning program @@ -225,7 +224,6 @@ Minimum number of minutes that must elapse between one remote bolus and the next How many minutes must elapse, at least, between one bolus and the next For your safety, to edit this preference you need to add at least 2 phone numbers. - Going to deliver %1$.2f U Bolus %1$.2f U delivered successfully Meal Bolus %1$.2f U delivered successfully Target %1$s for %2$d minutes @@ -295,7 +293,6 @@ Resend All Data Open Settings on Wear Basal rate - Basal value below minimum. Profile not set! BG: Last BG: MM640g @@ -386,7 +383,6 @@ patient_name I_understand Glimp - %1$s needs battery optimization whitelisting for proper performance Loop suspended Suspended (%1$d m) Suspend loop for 1h @@ -460,7 +456,6 @@ ABS DEVSLOPE About - Missing SMS permission Missing phone state permission xDrip+ Status (watch) xDrip+ Statusline (watch) @@ -551,14 +546,9 @@ En Pr Fat - Command is executed right now - Missed BG readings raise_urgent_alarms_as_android_notification Use system notifications for alerts and notifications Gradually increase the volume for alerts and notifications - enable_pump_unreachable_alert - enable_missed_bg_readings - enable_carbs_required_alert_local Local alerts Alert if no BG data is received Alert if pump is unreachable @@ -765,12 +755,7 @@ Please configure your RileyLink below. After selecting a RileyLink, it will be possible to continue setup once the RileyLink status is \"Connected\". This might take a minute.\n Note: You can continue setup once the pump has been set up.\n Start your first objective - Permission Ask for permission - Application needs system window permission for notifications - Application needs location permission for BT scan and WiFi identification - Application needs storage permission to be able store log files and export settings - Request Open navigation Close navigation Plugin preferences @@ -1020,7 +1005,6 @@ Filter Unable to create profile. Profile is invalid. Don\'t kill my app? - smscommunicator_report_pump_ureachable Send SMS if unreachable pump event is triggered Report pump unreachable Run alarm when is time to eat @@ -1220,7 +1204,6 @@ Blocked by charging options Blocked by connectivity options (No Watch Connected) - Error asking for permissions dynisf_adjust_sensitivity Adjust sensitivity and BG Database cleanup diff --git a/app/src/main/res/xml/pref_smscommunicator.xml b/app/src/main/res/xml/pref_smscommunicator.xml index e0fb8ea94c..396c8ab3f2 100644 --- a/app/src/main/res/xml/pref_smscommunicator.xml +++ b/app/src/main/res/xml/pref_smscommunicator.xml @@ -44,7 +44,7 @@ diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequestTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequestTest.kt index c29ca22e65..33af627a8c 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequestTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequestTest.kt @@ -5,6 +5,7 @@ import dagger.android.HasAndroidInjector import info.nightscout.androidaps.Constants import info.nightscout.androidaps.R import info.nightscout.androidaps.TestBase +import info.nightscout.androidaps.data.Sms import info.nightscout.androidaps.plugins.general.smsCommunicator.otp.OneTimePassword import info.nightscout.androidaps.plugins.general.smsCommunicator.otp.OneTimePasswordValidationResult import info.nightscout.androidaps.utils.DateUtil diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt index 9b70fcfbfd..f4ef917cfc 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt @@ -8,6 +8,7 @@ import info.nightscout.androidaps.R import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.data.IobTotal import info.nightscout.androidaps.data.PumpEnactResult +import info.nightscout.androidaps.data.Sms import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.entities.GlucoseValue import info.nightscout.androidaps.database.transactions.CancelCurrentOfflineEventIfAnyTransaction diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsTest.kt index 31b315a8df..ea3f5d582d 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsTest.kt @@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.general.smsCommunicator import android.telephony.SmsMessage import info.nightscout.androidaps.TestBase +import info.nightscout.androidaps.data.Sms import org.junit.Assert import org.junit.Test import org.mockito.Mockito diff --git a/core/android_module_dependencies.gradle b/core/android_module_dependencies.gradle index a1912540c7..26c180a46b 100644 --- a/core/android_module_dependencies.gradle +++ b/core/android_module_dependencies.gradle @@ -15,6 +15,11 @@ android { dimension "standard" } } + + // disable for modules here + buildFeatures { + buildConfig = true + } } dependencies { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/Sms.kt b/core/src/main/java/info/nightscout/androidaps/data/Sms.kt similarity index 77% rename from app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/Sms.kt rename to core/src/main/java/info/nightscout/androidaps/data/Sms.kt index cfbfbd163b..370b591f31 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/Sms.kt +++ b/core/src/main/java/info/nightscout/androidaps/data/Sms.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.general.smsCommunicator +package info.nightscout.androidaps.data import android.telephony.SmsMessage @@ -12,21 +12,21 @@ class Sms { var processed = false var ignored = false - internal constructor(message: SmsMessage) { + constructor(message: SmsMessage) { phoneNumber = message.originatingAddress ?: "" text = message.messageBody date = message.timestampMillis received = true } - internal constructor(phoneNumber: String, text: String) { + constructor(phoneNumber: String, text: String) { this.phoneNumber = phoneNumber this.text = text date = System.currentTimeMillis() sent = true } - internal constructor(other: Sms, number: String? = null) { + constructor(other: Sms, number: String? = null) { phoneNumber = number ?: other.phoneNumber text = other.text date = other.date diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/AndroidPermission.kt b/core/src/main/java/info/nightscout/androidaps/interfaces/AndroidPermission.kt new file mode 100644 index 0000000000..2dfa77836c --- /dev/null +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/AndroidPermission.kt @@ -0,0 +1,17 @@ +package info.nightscout.androidaps.interfaces + +import android.content.Context +import androidx.fragment.app.FragmentActivity + +interface AndroidPermission { + + fun askForPermission(activity: FragmentActivity, permissions: Array) + fun askForPermission(activity: FragmentActivity, permission: String) = askForPermission(activity, arrayOf(permission)) + fun permissionNotGranted(context: Context, permission: String): Boolean + fun notifyForSMSPermissions(activity: FragmentActivity, smsCommunicator: SmsCommunicator) + fun notifyForBtConnectPermission(activity: FragmentActivity) + fun notifyForBatteryOptimizationPermission(activity: FragmentActivity) + fun notifyForStoragePermission(activity: FragmentActivity) + fun notifyForLocationPermissions(activity: FragmentActivity) + fun notifyForSystemWindowPermissions(activity: FragmentActivity) +} \ No newline at end of file diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/Insight.kt b/core/src/main/java/info/nightscout/androidaps/interfaces/Insight.kt new file mode 100644 index 0000000000..911f2b32ff --- /dev/null +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/Insight.kt @@ -0,0 +1,10 @@ +package info.nightscout.androidaps.interfaces + +import info.nightscout.androidaps.data.PumpEnactResult + +interface Insight { + + fun setTBROverNotification(enabled: Boolean): PumpEnactResult + fun startPump(): PumpEnactResult + fun stopPump(): PumpEnactResult +} \ No newline at end of file diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/LocalAlertUtils.kt b/core/src/main/java/info/nightscout/androidaps/interfaces/LocalAlertUtils.kt new file mode 100644 index 0000000000..928bac8726 --- /dev/null +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/LocalAlertUtils.kt @@ -0,0 +1,17 @@ +package info.nightscout.androidaps.interfaces + +interface LocalAlertUtils { + + fun checkPumpUnreachableAlarm(lastConnection: Long, isStatusOutdated: Boolean, isDisconnected: Boolean) + + /* Pre-snoozes the alarms with 5 minutes if no snooze exists. + * Call only at startup! + */ + fun preSnoozeAlarms() + + /* shortens alarm times in case of setting changes or future data + */ + fun shortenSnoozeInterval() + fun notifyPumpStatusRead() + fun checkStaleBGAlert() +} \ No newline at end of file diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/Overview.kt b/core/src/main/java/info/nightscout/androidaps/interfaces/Overview.kt index ac2e321155..780bb5caea 100644 --- a/core/src/main/java/info/nightscout/androidaps/interfaces/Overview.kt +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/Overview.kt @@ -1,8 +1,12 @@ package info.nightscout.androidaps.interfaces +import androidx.annotation.StringRes import info.nightscout.androidaps.plugins.bus.RxBus interface Overview : ConfigExportImport { val overviewBus: RxBus + + fun addNotification(id: Int, text: String, level: Int, @StringRes actionButtonId: Int, action: Runnable) + fun dismissNotification(id: Int) } \ No newline at end of file diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/SmsCommunicator.kt b/core/src/main/java/info/nightscout/androidaps/interfaces/SmsCommunicator.kt index e753ea049f..1f272e4e31 100644 --- a/core/src/main/java/info/nightscout/androidaps/interfaces/SmsCommunicator.kt +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/SmsCommunicator.kt @@ -1,6 +1,9 @@ package info.nightscout.androidaps.interfaces +import info.nightscout.androidaps.data.Sms + interface SmsCommunicator { fun sendNotificationToAllNumbers(text: String): Boolean + fun sendSMS(sms: Sms): Boolean } \ No newline at end of file diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index c53f59bf2d..69811b2488 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -80,6 +80,10 @@ carbs_button_increment_1 carbs_button_increment_2 carbs_button_increment_3 + enable_pump_unreachable_alert + enable_missed_bg_readings + enable_carbs_required_alert_local + smscommunicator_report_pump_unreachable Refresh @@ -617,6 +621,9 @@ Another run of Autotune is detected, run cancelled Application needs bluetooth permission + + Missing SMS permission + %1$d day %1$d days diff --git a/implementation/src/main/java/info/nightscout/implementation/AndroidPermissionImpl.kt b/implementation/src/main/java/info/nightscout/implementation/AndroidPermissionImpl.kt new file mode 100644 index 0000000000..7d5c100abc --- /dev/null +++ b/implementation/src/main/java/info/nightscout/implementation/AndroidPermissionImpl.kt @@ -0,0 +1,185 @@ +package info.nightscout.implementation + +import android.Manifest +import android.annotation.SuppressLint +import android.bluetooth.BluetoothAdapter +import android.content.ActivityNotFoundException +import android.content.Context +import android.content.Intent +import android.content.pm.PackageManager +import android.net.Uri +import android.os.Build +import android.os.PowerManager +import android.provider.Settings +import androidx.core.content.ContextCompat +import androidx.fragment.app.FragmentActivity +import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.activities.DaggerAppCompatActivityWithResult +import info.nightscout.androidaps.interfaces.ActivePlugin +import info.nightscout.androidaps.interfaces.AndroidPermission +import info.nightscout.androidaps.interfaces.PluginBase +import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.androidaps.interfaces.SmsCommunicator +import info.nightscout.androidaps.plugins.bus.RxBus +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification +import info.nightscout.androidaps.utils.ToastUtils +import info.nightscout.androidaps.utils.alertDialogs.OKDialog +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class AndroidPermissionImpl @Inject constructor( + val rh: ResourceHelper, + val rxBus: RxBus, + val injector: HasAndroidInjector, + val activePlugin: ActivePlugin +) : AndroidPermission { + + private var permissionBatteryOptimizationFailed = false + + @SuppressLint("BatteryLife") + override fun askForPermission(activity: FragmentActivity, permissions: Array) { + var test = false + var testBattery = false + for (s in permissions) { + test = test || ContextCompat.checkSelfPermission(activity, s) != PackageManager.PERMISSION_GRANTED + if (s == Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) { + val powerManager = activity.getSystemService(Context.POWER_SERVICE) as PowerManager + val packageName = activity.packageName + testBattery = testBattery || !powerManager.isIgnoringBatteryOptimizations(packageName) + } + } + if (test) { + if (activity is DaggerAppCompatActivityWithResult) + try { + activity.requestMultiplePermissions.launch(permissions) + } catch (ignored: IllegalStateException) { + ToastUtils.errorToast(activity, rh.gs(R.string.error_asking_for_permissions)) + } + } + if (testBattery) { + try { + if (activity is DaggerAppCompatActivityWithResult) + try { + activity.callForBatteryOptimization.launch(null) + } catch (ignored: IllegalStateException) { + ToastUtils.errorToast(activity, rh.gs(R.string.error_asking_for_permissions)) + } + } catch (e: ActivityNotFoundException) { + permissionBatteryOptimizationFailed = true + OKDialog.show(activity, rh.gs(R.string.permission), rh.gs(R.string.alert_dialog_permission_battery_optimization_failed)) { activity.recreate() } + } + } + } + + override fun askForPermission(activity: FragmentActivity, permission: String) = askForPermission(activity, arrayOf(permission)) + + override fun permissionNotGranted(context: Context, permission: String): Boolean { + var selfCheck = ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED + if (permission == Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) { + if (!permissionBatteryOptimizationFailed) { + val powerManager = context.getSystemService(Context.POWER_SERVICE) as PowerManager + val packageName = context.packageName + selfCheck = selfCheck && powerManager.isIgnoringBatteryOptimizations(packageName) + } + } + return !selfCheck + } + + @Synchronized + override fun notifyForSMSPermissions(activity: FragmentActivity, smsCommunicator: SmsCommunicator) { + if ((smsCommunicator as PluginBase).isEnabled()) { + if (permissionNotGranted(activity, Manifest.permission.RECEIVE_SMS)) + activePlugin.activeOverview.addNotification( + id = Notification.PERMISSION_SMS, + text = rh.gs(R.string.smscommunicator_missingsmspermission), + level = Notification.URGENT, + actionButtonId = R.string.request + ) { + askForPermission( + activity, + arrayOf(Manifest.permission.RECEIVE_SMS, Manifest.permission.SEND_SMS, Manifest.permission.RECEIVE_MMS) + ) + } + else activePlugin.activeOverview.dismissNotification(Notification.PERMISSION_SMS) + } + } + + @SuppressLint("MissingPermission") + @Synchronized + override fun notifyForBtConnectPermission(activity: FragmentActivity) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + // Manifest.permission.BLUETOOTH_CONNECT + if (permissionNotGranted(activity, Manifest.permission.BLUETOOTH_CONNECT) || permissionNotGranted(activity, Manifest.permission.BLUETOOTH_SCAN)) + activePlugin.activeOverview.addNotification( + id = Notification.PERMISSION_BT, + text = rh.gs(R.string.needconnectpermission), + level = Notification.URGENT, + actionButtonId = R.string.request + ) { askForPermission(activity, arrayOf(Manifest.permission.BLUETOOTH_SCAN, Manifest.permission.BLUETOOTH_CONNECT)) } + else { + activity.startActivity(Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)) + activePlugin.activeOverview.dismissNotification(Notification.PERMISSION_BT) + } + } + } + + @Synchronized + override fun notifyForBatteryOptimizationPermission(activity: FragmentActivity) { + if (permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) + activePlugin.activeOverview.addNotification( + id = Notification.PERMISSION_BATTERY, + text = rh.gs(R.string.need_whitelisting, rh.gs(R.string.app_name)), + level = Notification.URGENT, + actionButtonId = R.string.request + ) { askForPermission(activity, arrayOf(Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) } + else activePlugin.activeOverview.dismissNotification(Notification.PERMISSION_BATTERY) + } + + @Synchronized override fun notifyForStoragePermission(activity: FragmentActivity) { + if (permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)) + activePlugin.activeOverview.addNotification( + id = Notification.PERMISSION_STORAGE, + text = rh.gs(R.string.need_storage_permission), + level = Notification.URGENT, + actionButtonId = R.string.request + ) { askForPermission(activity, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE)) } + else activePlugin.activeOverview.dismissNotification(Notification.PERMISSION_STORAGE) + } + + @Synchronized override fun notifyForLocationPermissions(activity: FragmentActivity) { + if (permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION)) { + activePlugin.activeOverview.addNotification( + id = Notification.PERMISSION_LOCATION, + text = rh.gs(R.string.need_location_permission), + level = Notification.URGENT, + actionButtonId = R.string.request + ) { askForPermission(activity, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION)) } + } else activePlugin.activeOverview.dismissNotification(Notification.PERMISSION_LOCATION) + } + + @Synchronized override fun notifyForSystemWindowPermissions(activity: FragmentActivity) { + // Check if Android Q or higher + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) { + if (!Settings.canDrawOverlays(activity)) + activePlugin.activeOverview.addNotification( + id = Notification.PERMISSION_SYSTEM_WINDOW, + text = rh.gs(R.string.need_location_permission), + level = Notification.URGENT, + actionButtonId = R.string.request + ) { + // Check if Android Q or higher + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) { + // Show alert dialog to the user saying a separate permission is needed + // Launch the settings activity if the user prefers + val intent = Intent( + Settings.ACTION_MANAGE_OVERLAY_PERMISSION, + Uri.parse("package:" + activity.packageName) + ) + activity.startActivity(intent) + } + } + else activePlugin.activeOverview.dismissNotification(Notification.PERMISSION_SYSTEM_WINDOW) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt b/implementation/src/main/java/info/nightscout/implementation/LocalAlertUtilsImpl.kt similarity index 89% rename from app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt rename to implementation/src/main/java/info/nightscout/implementation/LocalAlertUtilsImpl.kt index 512f1b2d53..85b9961a53 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt +++ b/implementation/src/main/java/info/nightscout/implementation/LocalAlertUtilsImpl.kt @@ -1,7 +1,6 @@ -package info.nightscout.androidaps.utils +package info.nightscout.implementation import info.nightscout.androidaps.Constants -import info.nightscout.androidaps.R import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.ValueWrapper import info.nightscout.androidaps.database.entities.TherapyEvent @@ -11,14 +10,17 @@ import info.nightscout.androidaps.database.entities.ValueWithUnit import info.nightscout.androidaps.database.transactions.InsertTherapyEventAnnouncementTransaction import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.Config +import info.nightscout.androidaps.interfaces.LocalAlertUtils import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.androidaps.interfaces.SmsCommunicator import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification import info.nightscout.androidaps.plugins.general.overview.notifications.Notification -import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin +import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.T import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.LTag import info.nightscout.shared.sharedPreferences.SP @@ -32,19 +34,19 @@ import kotlin.math.min * Created by adrian on 17/12/17. */ @Singleton -class LocalAlertUtils @Inject constructor( +class LocalAlertUtilsImpl @Inject constructor( private val aapsLogger: AAPSLogger, private val sp: SP, private val rxBus: RxBus, private val rh: ResourceHelper, private val activePlugin: ActivePlugin, private val profileFunction: ProfileFunction, - private val smsCommunicatorPlugin: SmsCommunicatorPlugin, + private val smsCommunicatorPlugin: SmsCommunicator, private val config: Config, private val repository: AppRepository, private val dateUtil: DateUtil, private val uel: UserEntryLogger -) { +) : LocalAlertUtils { private val disposable = CompositeDisposable() @@ -56,7 +58,7 @@ class LocalAlertUtils @Inject constructor( return T.mins(sp.getInt(R.string.key_pump_unreachable_threshold_minutes, Constants.DEFAULT_PUMP_UNREACHABLE_THRESHOLD_MINUTES).toLong()).msecs() } - fun checkPumpUnreachableAlarm(lastConnection: Long, isStatusOutdated: Boolean, isDisconnected: Boolean) { + override fun checkPumpUnreachableAlarm(lastConnection: Long, isStatusOutdated: Boolean, isDisconnected: Boolean) { val alarmTimeoutExpired = isAlarmTimeoutExpired(lastConnection, pumpUnreachableThreshold()) val nextAlarmOccurrenceReached = sp.getLong("nextPumpDisconnectedAlarm", 0L) < System.currentTimeMillis() if (config.APS && isStatusOutdated && alarmTimeoutExpired && nextAlarmOccurrenceReached && !isDisconnected) { @@ -68,7 +70,7 @@ class LocalAlertUtils @Inject constructor( if (sp.getBoolean(R.string.key_ns_create_announcements_from_errors, true)) disposable += repository.runTransaction(InsertTherapyEventAnnouncementTransaction(rh.gs(R.string.pump_unreachable))).subscribe() } - if (sp.getBoolean(R.string.key_smscommunicator_report_pump_ureachable, true)) + if (sp.getBoolean(R.string.key_smscommunicator_report_pump_unreachable, true)) smsCommunicatorPlugin.sendNotificationToAllNumbers(rh.gs(R.string.pump_unreachable)) } if (!isStatusOutdated && !alarmTimeoutExpired) rxBus.send(EventDismissNotification(Notification.PUMP_UNREACHABLE)) @@ -85,7 +87,7 @@ class LocalAlertUtils @Inject constructor( /*Pre-snoozes the alarms with 5 minutes if no snooze exists. * Call only at startup! */ - fun preSnoozeAlarms() { + override fun preSnoozeAlarms() { if (sp.getLong("nextMissedReadingsAlarm", 0L) < System.currentTimeMillis()) { sp.putLong("nextMissedReadingsAlarm", System.currentTimeMillis() + 5 * 60 * 1000) } @@ -94,7 +96,7 @@ class LocalAlertUtils @Inject constructor( } } - fun shortenSnoozeInterval() { //shortens alarm times in case of setting changes or future data + override fun shortenSnoozeInterval() { //shortens alarm times in case of setting changes or future data var nextMissedReadingsAlarm = sp.getLong("nextMissedReadingsAlarm", 0L) nextMissedReadingsAlarm = min(System.currentTimeMillis() + missedReadingsThreshold(), nextMissedReadingsAlarm) sp.putLong("nextMissedReadingsAlarm", nextMissedReadingsAlarm) @@ -103,7 +105,7 @@ class LocalAlertUtils @Inject constructor( sp.putLong("nextPumpDisconnectedAlarm", nextPumpDisconnectedAlarm) } - fun notifyPumpStatusRead() { //TODO: persist the actual time the pump is read and simplify the whole logic when to alarm + override fun notifyPumpStatusRead() { //TODO: persist the actual time the pump is read and simplify the whole logic when to alarm val pump = activePlugin.activePump val profile = profileFunction.getProfile() if (profile != null) { @@ -115,7 +117,7 @@ class LocalAlertUtils @Inject constructor( } } - fun checkStaleBGAlert() { + override fun checkStaleBGAlert() { val bgReadingWrapped = repository.getLastGlucoseValueWrapped().blockingGet() val bgReading = if (bgReadingWrapped is ValueWrapper.Existing) bgReadingWrapped.value else return if (sp.getBoolean(R.string.key_enable_missed_bg_readings_alert, false) diff --git a/app/src/main/java/info/nightscout/androidaps/di/CommandQueueModule.kt b/implementation/src/main/java/info/nightscout/implementation/di/CommandQueueModule.kt similarity index 58% rename from app/src/main/java/info/nightscout/androidaps/di/CommandQueueModule.kt rename to implementation/src/main/java/info/nightscout/implementation/di/CommandQueueModule.kt index 7f68cca9c9..e6864c9508 100644 --- a/app/src/main/java/info/nightscout/androidaps/di/CommandQueueModule.kt +++ b/implementation/src/main/java/info/nightscout/implementation/di/CommandQueueModule.kt @@ -1,9 +1,25 @@ -package info.nightscout.androidaps.di +package info.nightscout.implementation.di import dagger.Module import dagger.android.ContributesAndroidInjector -import info.nightscout.androidaps.queue.CommandQueueImplementation -import info.nightscout.androidaps.queue.commands.* +import info.nightscout.implementation.queue.CommandQueueImplementation +import info.nightscout.implementation.queue.commands.CommandReadStatus +import info.nightscout.implementation.queue.commands.CommandSMBBolus +import info.nightscout.implementation.queue.commands.CommandSetProfile +import info.nightscout.implementation.queue.commands.CommandSetUserSettings +import info.nightscout.implementation.queue.commands.CommandStartPump +import info.nightscout.implementation.queue.commands.CommandStopPump +import info.nightscout.implementation.queue.commands.CommandTempBasalAbsolute +import info.nightscout.implementation.queue.commands.CommandTempBasalPercent +import info.nightscout.implementation.queue.commands.CommandBolus +import info.nightscout.implementation.queue.commands.CommandCancelExtendedBolus +import info.nightscout.implementation.queue.commands.CommandCancelTempBasal +import info.nightscout.implementation.queue.commands.CommandCustomCommand +import info.nightscout.implementation.queue.commands.CommandExtendedBolus +import info.nightscout.implementation.queue.commands.CommandInsightSetTBROverNotification +import info.nightscout.implementation.queue.commands.CommandLoadEvents +import info.nightscout.implementation.queue.commands.CommandLoadHistory +import info.nightscout.implementation.queue.commands.CommandLoadTDDs @Module @Suppress("unused") diff --git a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueueImplementation.kt b/implementation/src/main/java/info/nightscout/implementation/queue/CommandQueueImplementation.kt similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/queue/CommandQueueImplementation.kt rename to implementation/src/main/java/info/nightscout/implementation/queue/CommandQueueImplementation.kt index fc3e39daa6..e4cbcc9253 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueueImplementation.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/CommandQueueImplementation.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.queue +package info.nightscout.implementation.queue import android.content.Context import android.content.Intent @@ -6,7 +6,6 @@ import android.os.SystemClock import android.text.Spanned import androidx.appcompat.app.AppCompatActivity import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R import info.nightscout.androidaps.activities.BolusProgressHelperActivity import info.nightscout.androidaps.activities.ErrorHelperActivity import info.nightscout.androidaps.annotations.OpenForTesting @@ -22,22 +21,48 @@ import info.nightscout.androidaps.dialogs.BolusProgressDialog import info.nightscout.androidaps.events.EventMobileToWear import info.nightscout.androidaps.events.EventProfileSwitchChanged import info.nightscout.androidaps.extensions.getCustomizedName -import info.nightscout.androidaps.interfaces.* +import info.nightscout.androidaps.interfaces.ActivePlugin +import info.nightscout.androidaps.interfaces.AndroidPermission +import info.nightscout.androidaps.interfaces.BuildHelper +import info.nightscout.androidaps.interfaces.CommandQueue +import info.nightscout.androidaps.interfaces.Config +import info.nightscout.androidaps.interfaces.Constraint +import info.nightscout.androidaps.interfaces.Profile +import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.interfaces.PumpSync +import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusProgressIfRunning import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification import info.nightscout.androidaps.plugins.general.overview.notifications.Notification -import info.nightscout.androidaps.queue.commands.* +import info.nightscout.androidaps.queue.Callback +import info.nightscout.androidaps.queue.commands.Command import info.nightscout.androidaps.queue.commands.Command.CommandType -import info.nightscout.androidaps.utils.AndroidPermission +import info.nightscout.androidaps.queue.commands.CustomCommand import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.HtmlHelper -import info.nightscout.androidaps.interfaces.BuildHelper -import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers +import info.nightscout.implementation.R +import info.nightscout.implementation.queue.commands.CommandBolus +import info.nightscout.implementation.queue.commands.CommandCancelExtendedBolus +import info.nightscout.implementation.queue.commands.CommandCancelTempBasal +import info.nightscout.implementation.queue.commands.CommandCustomCommand +import info.nightscout.implementation.queue.commands.CommandExtendedBolus +import info.nightscout.implementation.queue.commands.CommandInsightSetTBROverNotification +import info.nightscout.implementation.queue.commands.CommandLoadEvents +import info.nightscout.implementation.queue.commands.CommandLoadHistory +import info.nightscout.implementation.queue.commands.CommandLoadTDDs +import info.nightscout.implementation.queue.commands.CommandReadStatus +import info.nightscout.implementation.queue.commands.CommandSMBBolus +import info.nightscout.implementation.queue.commands.CommandSetProfile +import info.nightscout.implementation.queue.commands.CommandSetUserSettings +import info.nightscout.implementation.queue.commands.CommandStartPump +import info.nightscout.implementation.queue.commands.CommandStopPump +import info.nightscout.implementation.queue.commands.CommandTempBasalAbsolute +import info.nightscout.implementation.queue.commands.CommandTempBasalPercent import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.LTag import info.nightscout.shared.sharedPreferences.SP @@ -45,7 +70,7 @@ import info.nightscout.shared.weardata.EventData import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign import io.reactivex.rxjava3.kotlin.subscribeBy -import java.util.* +import java.util.LinkedList import java.util.concurrent.TimeUnit import javax.inject.Inject import javax.inject.Singleton @@ -121,7 +146,7 @@ class CommandQueueImplementation @Inject constructor( } private fun executingNowError(): PumpEnactResult = - PumpEnactResult(injector).success(false).enacted(false).comment(R.string.executingrightnow) + PumpEnactResult(injector).success(false).enacted(false).comment(R.string.executing_right_now) override fun isRunning(type: CommandType): Boolean = performing?.commandType == type @@ -300,7 +325,7 @@ class CommandQueueImplementation @Inject constructor( // not when the Bolus command is starting. The command closes the dialog upon completion). showBolusProgressDialog(detailedBolusInfo) // Notify Wear about upcoming bolus - rxBus.send(EventMobileToWear(EventData.BolusProgress(percent = 0, status = rh.gs(R.string.bolusrequested, detailedBolusInfo.insulin)))) + rxBus.send(EventMobileToWear(EventData.BolusProgress(percent = 0, status = rh.gs(R.string.goingtodeliver, detailedBolusInfo.insulin)))) } } notifyAboutNewCommand() @@ -421,9 +446,9 @@ class CommandQueueImplementation @Inject constructor( val basalValues = profile.getBasalValues() for (basalValue in basalValues) { if (basalValue.value < activePlugin.activePump.pumpDescription.basalMinimumRate) { - val notification = Notification(Notification.BASAL_VALUE_BELOW_MINIMUM, rh.gs(R.string.basalvaluebelowminimum), Notification.URGENT) + val notification = Notification(Notification.BASAL_VALUE_BELOW_MINIMUM, rh.gs(R.string.basal_value_below_minimum), Notification.URGENT) rxBus.send(EventNewNotification(notification)) - callback?.result(PumpEnactResult(injector).success(false).enacted(false).comment(R.string.basalvaluebelowminimum))?.run() + callback?.result(PumpEnactResult(injector).success(false).enacted(false).comment(R.string.basal_value_below_minimum))?.run() return false } } diff --git a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.kt b/implementation/src/main/java/info/nightscout/implementation/queue/QueueThread.kt similarity index 98% rename from app/src/main/java/info/nightscout/androidaps/queue/QueueThread.kt rename to implementation/src/main/java/info/nightscout/implementation/queue/QueueThread.kt index edf8fac07c..86e7887daf 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/QueueThread.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.queue +package info.nightscout.implementation.queue import android.bluetooth.BluetoothManager import android.content.Context @@ -6,19 +6,19 @@ import android.os.Build import android.os.PowerManager import android.os.SystemClock import info.nightscout.androidaps.Constants -import info.nightscout.androidaps.R import info.nightscout.androidaps.events.EventPumpStatusChanged import info.nightscout.androidaps.extensions.safeDisable import info.nightscout.androidaps.extensions.safeEnable import info.nightscout.androidaps.interfaces.ActivePlugin +import info.nightscout.androidaps.interfaces.AndroidPermission import info.nightscout.androidaps.interfaces.CommandQueue import info.nightscout.androidaps.interfaces.Config +import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusProgressIfRunning import info.nightscout.androidaps.queue.events.EventQueueChanged -import info.nightscout.androidaps.utils.AndroidPermission import info.nightscout.androidaps.utils.T -import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.implementation.R import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.LTag import info.nightscout.shared.sharedPreferences.SP diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandBolus.kt b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandBolus.kt similarity index 92% rename from app/src/main/java/info/nightscout/androidaps/queue/commands/CommandBolus.kt rename to implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandBolus.kt index 03c852754d..66c933aa16 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandBolus.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandBolus.kt @@ -1,14 +1,15 @@ -package info.nightscout.androidaps.queue.commands +package info.nightscout.implementation.queue.commands import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.dialogs.BolusProgressDialog import info.nightscout.androidaps.interfaces.ActivePlugin -import info.nightscout.shared.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusProgressIfRunning import info.nightscout.androidaps.queue.Callback +import info.nightscout.androidaps.queue.commands.Command +import info.nightscout.implementation.R +import info.nightscout.shared.logging.LTag import javax.inject.Inject class CommandBolus( diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandCancelExtendedBolus.kt b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandCancelExtendedBolus.kt similarity index 84% rename from app/src/main/java/info/nightscout/androidaps/queue/commands/CommandCancelExtendedBolus.kt rename to implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandCancelExtendedBolus.kt index 9513083a5d..4a88bee589 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandCancelExtendedBolus.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandCancelExtendedBolus.kt @@ -1,10 +1,11 @@ -package info.nightscout.androidaps.queue.commands +package info.nightscout.implementation.queue.commands import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R import info.nightscout.androidaps.interfaces.ActivePlugin -import info.nightscout.shared.logging.LTag import info.nightscout.androidaps.queue.Callback +import info.nightscout.androidaps.queue.commands.Command +import info.nightscout.implementation.R +import info.nightscout.shared.logging.LTag import javax.inject.Inject class CommandCancelExtendedBolus constructor( diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandCancelTempBasal.kt b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandCancelTempBasal.kt similarity index 84% rename from app/src/main/java/info/nightscout/androidaps/queue/commands/CommandCancelTempBasal.kt rename to implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandCancelTempBasal.kt index 2496f36e7f..41092b6311 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandCancelTempBasal.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandCancelTempBasal.kt @@ -1,10 +1,11 @@ -package info.nightscout.androidaps.queue.commands +package info.nightscout.implementation.queue.commands import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R import info.nightscout.androidaps.interfaces.ActivePlugin -import info.nightscout.shared.logging.LTag import info.nightscout.androidaps.queue.Callback +import info.nightscout.androidaps.queue.commands.Command +import info.nightscout.implementation.R +import info.nightscout.shared.logging.LTag import javax.inject.Inject class CommandCancelTempBasal( diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandCustomCommand.kt b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandCustomCommand.kt similarity index 83% rename from app/src/main/java/info/nightscout/androidaps/queue/commands/CommandCustomCommand.kt rename to implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandCustomCommand.kt index 59df7544d8..318131629e 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandCustomCommand.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandCustomCommand.kt @@ -1,9 +1,11 @@ -package info.nightscout.androidaps.queue.commands +package info.nightscout.implementation.queue.commands import dagger.android.HasAndroidInjector import info.nightscout.androidaps.interfaces.ActivePlugin -import info.nightscout.shared.logging.LTag import info.nightscout.androidaps.queue.Callback +import info.nightscout.androidaps.queue.commands.Command +import info.nightscout.androidaps.queue.commands.CustomCommand +import info.nightscout.shared.logging.LTag import javax.inject.Inject class CommandCustomCommand( diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandExtendedBolus.kt b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandExtendedBolus.kt similarity index 86% rename from app/src/main/java/info/nightscout/androidaps/queue/commands/CommandExtendedBolus.kt rename to implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandExtendedBolus.kt index 7cd755b50b..62d7aef111 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandExtendedBolus.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandExtendedBolus.kt @@ -1,10 +1,11 @@ -package info.nightscout.androidaps.queue.commands +package info.nightscout.implementation.queue.commands import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R import info.nightscout.androidaps.interfaces.ActivePlugin -import info.nightscout.shared.logging.LTag import info.nightscout.androidaps.queue.Callback +import info.nightscout.androidaps.queue.commands.Command +import info.nightscout.implementation.R +import info.nightscout.shared.logging.LTag import javax.inject.Inject class CommandExtendedBolus constructor( diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandInsightSetTBROverNotification.kt b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandInsightSetTBROverNotification.kt similarity index 78% rename from app/src/main/java/info/nightscout/androidaps/queue/commands/CommandInsightSetTBROverNotification.kt rename to implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandInsightSetTBROverNotification.kt index 7ea827e510..c4fbdf7c7d 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandInsightSetTBROverNotification.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandInsightSetTBROverNotification.kt @@ -1,10 +1,11 @@ -package info.nightscout.androidaps.queue.commands +package info.nightscout.implementation.queue.commands import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R import info.nightscout.androidaps.interfaces.ActivePlugin -import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin +import info.nightscout.androidaps.interfaces.Insight import info.nightscout.androidaps.queue.Callback +import info.nightscout.androidaps.queue.commands.Command +import info.nightscout.implementation.R import javax.inject.Inject class CommandInsightSetTBROverNotification constructor( @@ -17,14 +18,14 @@ class CommandInsightSetTBROverNotification constructor( override fun execute() { val pump = activePlugin.activePump - if (pump is LocalInsightPlugin) { + if (pump is Insight) { val result = pump.setTBROverNotification(enabled) callback?.result(result)?.run() } } - @Suppress("SpellCheckingInspection") override fun status(): String = rh.gs(R.string.insight_set_tbr_over_notification) + @Suppress("SpellCheckingInspection") override fun log(): String = "INSIGHTSETTBROVERNOTIFICATION" } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadEvents.kt b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandLoadEvents.kt similarity index 89% rename from app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadEvents.kt rename to implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandLoadEvents.kt index 9df10bd36a..a8f515370f 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadEvents.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandLoadEvents.kt @@ -1,12 +1,13 @@ -package info.nightscout.androidaps.queue.commands +package info.nightscout.implementation.queue.commands import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.Dana import info.nightscout.androidaps.interfaces.Diaconn -import info.nightscout.shared.logging.LTag import info.nightscout.androidaps.queue.Callback +import info.nightscout.androidaps.queue.commands.Command +import info.nightscout.implementation.R +import info.nightscout.shared.logging.LTag import javax.inject.Inject class CommandLoadEvents( diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadHistory.kt b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandLoadHistory.kt similarity index 89% rename from app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadHistory.kt rename to implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandLoadHistory.kt index 2ff78788e3..89939c2b4c 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadHistory.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandLoadHistory.kt @@ -1,12 +1,13 @@ -package info.nightscout.androidaps.queue.commands +package info.nightscout.implementation.queue.commands import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.Dana import info.nightscout.androidaps.interfaces.Diaconn -import info.nightscout.shared.logging.LTag import info.nightscout.androidaps.queue.Callback +import info.nightscout.androidaps.queue.commands.Command +import info.nightscout.implementation.R +import info.nightscout.shared.logging.LTag import javax.inject.Inject class CommandLoadHistory( diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadTDDs.kt b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandLoadTDDs.kt similarity index 83% rename from app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadTDDs.kt rename to implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandLoadTDDs.kt index 1099c6be59..138cebbfd6 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandLoadTDDs.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandLoadTDDs.kt @@ -1,10 +1,11 @@ -package info.nightscout.androidaps.queue.commands +package info.nightscout.implementation.queue.commands import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R import info.nightscout.androidaps.interfaces.ActivePlugin -import info.nightscout.shared.logging.LTag import info.nightscout.androidaps.queue.Callback +import info.nightscout.androidaps.queue.commands.Command +import info.nightscout.implementation.R +import info.nightscout.shared.logging.LTag import javax.inject.Inject class CommandLoadTDDs( diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandReadStatus.kt b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandReadStatus.kt similarity index 85% rename from app/src/main/java/info/nightscout/androidaps/queue/commands/CommandReadStatus.kt rename to implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandReadStatus.kt index 2c98f7a9cf..8c709856e9 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandReadStatus.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandReadStatus.kt @@ -1,13 +1,14 @@ -package info.nightscout.androidaps.queue.commands +package info.nightscout.implementation.queue.commands import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.interfaces.ActivePlugin -import info.nightscout.shared.logging.LTag +import info.nightscout.androidaps.interfaces.LocalAlertUtils import info.nightscout.androidaps.queue.Callback -import info.nightscout.androidaps.utils.LocalAlertUtils +import info.nightscout.androidaps.queue.commands.Command import info.nightscout.androidaps.utils.T +import info.nightscout.implementation.R +import info.nightscout.shared.logging.LTag import javax.inject.Inject class CommandReadStatus( diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSMBBolus.kt b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandSMBBolus.kt similarity index 93% rename from app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSMBBolus.kt rename to implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandSMBBolus.kt index 76895ddcce..8d1585c46d 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSMBBolus.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandSMBBolus.kt @@ -1,14 +1,15 @@ -package info.nightscout.androidaps.queue.commands +package info.nightscout.implementation.queue.commands import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.interfaces.ActivePlugin -import info.nightscout.shared.logging.LTag import info.nightscout.androidaps.queue.Callback +import info.nightscout.androidaps.queue.commands.Command import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.T +import info.nightscout.implementation.R +import info.nightscout.shared.logging.LTag import javax.inject.Inject class CommandSMBBolus( diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetProfile.kt b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandSetProfile.kt similarity index 83% rename from app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetProfile.kt rename to implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandSetProfile.kt index cef321bc11..030c751f5a 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetProfile.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandSetProfile.kt @@ -1,17 +1,19 @@ -package info.nightscout.androidaps.queue.commands +package info.nightscout.implementation.queue.commands import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.database.ValueWrapper import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.CommandQueue import info.nightscout.androidaps.interfaces.Config +import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.Profile -import info.nightscout.shared.logging.LTag -import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin +import info.nightscout.androidaps.interfaces.SmsCommunicator import info.nightscout.androidaps.queue.Callback +import info.nightscout.androidaps.queue.commands.Command import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.implementation.R +import info.nightscout.shared.logging.LTag import javax.inject.Inject class CommandSetProfile constructor( @@ -21,7 +23,7 @@ class CommandSetProfile constructor( callback: Callback? ) : Command(injector, CommandType.BASAL_PROFILE, callback) { - @Inject lateinit var smsCommunicatorPlugin: SmsCommunicatorPlugin + @Inject lateinit var smsCommunicatorPlugin: SmsCommunicator @Inject lateinit var activePlugin: ActivePlugin @Inject lateinit var dateUtil: DateUtil @Inject lateinit var commandQueue: CommandQueue @@ -39,7 +41,7 @@ class CommandSetProfile constructor( // Send SMS notification if ProfileSwitch is coming from NS val profileSwitch = repository.getEffectiveProfileSwitchActiveAt(dateUtil.now()).blockingGet() if (profileSwitch is ValueWrapper.Existing && r.enacted && hasNsId && !config.NSCLIENT) { - if (smsCommunicatorPlugin.isEnabled()) + if ((smsCommunicatorPlugin as PluginBase).isEnabled()) smsCommunicatorPlugin.sendNotificationToAllNumbers(rh.gs(R.string.profile_set_ok)) } } diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetUserSettings.kt b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandSetUserSettings.kt similarity index 88% rename from app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetUserSettings.kt rename to implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandSetUserSettings.kt index 2ada46280a..0881228712 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetUserSettings.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandSetUserSettings.kt @@ -1,12 +1,13 @@ -package info.nightscout.androidaps.queue.commands +package info.nightscout.implementation.queue.commands import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.Dana import info.nightscout.androidaps.interfaces.Diaconn -import info.nightscout.shared.logging.LTag import info.nightscout.androidaps.queue.Callback +import info.nightscout.androidaps.queue.commands.Command +import info.nightscout.implementation.R +import info.nightscout.shared.logging.LTag import javax.inject.Inject class CommandSetUserSettings( diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandStartPump.kt b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandStartPump.kt similarity index 73% rename from app/src/main/java/info/nightscout/androidaps/queue/commands/CommandStartPump.kt rename to implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandStartPump.kt index 33b8296d05..6c80cd3e8a 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandStartPump.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandStartPump.kt @@ -1,10 +1,11 @@ -package info.nightscout.androidaps.queue.commands +package info.nightscout.implementation.queue.commands import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R import info.nightscout.androidaps.interfaces.ActivePlugin -import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin +import info.nightscout.androidaps.interfaces.Insight import info.nightscout.androidaps.queue.Callback +import info.nightscout.androidaps.queue.commands.Command +import info.nightscout.implementation.R import javax.inject.Inject class CommandStartPump( @@ -16,7 +17,7 @@ class CommandStartPump( override fun execute() { val pump = activePlugin.activePump - if (pump is LocalInsightPlugin) { + if (pump is Insight) { val result = pump.startPump() callback?.result(result)?.run() } diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandStopPump.kt b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandStopPump.kt similarity index 73% rename from app/src/main/java/info/nightscout/androidaps/queue/commands/CommandStopPump.kt rename to implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandStopPump.kt index 80fdd90702..9bab352e82 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandStopPump.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandStopPump.kt @@ -1,10 +1,11 @@ -package info.nightscout.androidaps.queue.commands +package info.nightscout.implementation.queue.commands import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R import info.nightscout.androidaps.interfaces.ActivePlugin -import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin +import info.nightscout.androidaps.interfaces.Insight import info.nightscout.androidaps.queue.Callback +import info.nightscout.androidaps.queue.commands.Command +import info.nightscout.implementation.R import javax.inject.Inject class CommandStopPump( @@ -16,7 +17,7 @@ class CommandStopPump( override fun execute() { val pump = activePlugin.activePump - if (pump is LocalInsightPlugin) { + if (pump is Insight) { val result = pump.stopPump() callback?.result(result)?.run() } diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalAbsolute.kt b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandTempBasalAbsolute.kt similarity index 89% rename from app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalAbsolute.kt rename to implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandTempBasalAbsolute.kt index 25e66b9565..3ac8bd25ab 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalAbsolute.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandTempBasalAbsolute.kt @@ -1,12 +1,13 @@ -package info.nightscout.androidaps.queue.commands +package info.nightscout.implementation.queue.commands import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R -import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.interfaces.ActivePlugin +import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.interfaces.PumpSync -import info.nightscout.shared.logging.LTag import info.nightscout.androidaps.queue.Callback +import info.nightscout.androidaps.queue.commands.Command +import info.nightscout.implementation.R +import info.nightscout.shared.logging.LTag import javax.inject.Inject class CommandTempBasalAbsolute( diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalPercent.kt b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandTempBasalPercent.kt similarity index 90% rename from app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalPercent.kt rename to implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandTempBasalPercent.kt index edc12d1c16..09351cf5b3 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalPercent.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/commands/CommandTempBasalPercent.kt @@ -1,12 +1,13 @@ -package info.nightscout.androidaps.queue.commands +package info.nightscout.implementation.queue.commands import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R -import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.interfaces.ActivePlugin +import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.interfaces.PumpSync -import info.nightscout.shared.logging.LTag import info.nightscout.androidaps.queue.Callback +import info.nightscout.androidaps.queue.commands.Command +import info.nightscout.implementation.R +import info.nightscout.shared.logging.LTag import javax.inject.Inject class CommandTempBasalPercent( diff --git a/implementation/src/main/res/values/strings.xml b/implementation/src/main/res/values/strings.xml index 4ccd5d28b4..62774daa74 100644 --- a/implementation/src/main/res/values/strings.xml +++ b/implementation/src/main/res/values/strings.xml @@ -4,6 +4,7 @@ Calibration sent to xDrip+ BG + Missed BG readings Time to eat Enable bolus advisor @@ -11,5 +12,15 @@ Bolus advisor You have high glycemia. Instead of eating now it\'s recommended to wait for better glycemia. Do you want to do a correction bolus now and remind you when it\'s time to eat? In this case no carbs will be recorded and you must use wizard again when we remind you. Time to bolus!\nRun Bolus wizard and do calculation again. + Command is executed right now + Basal value below minimum. Profile not set! + Request + Permission + %1$s needs battery optimization whitelisting for proper performance + Application needs system window permission for notifications + Application needs location permission for BT scan and WiFi identification + Application needs storage permission to be able store log files and export settings + Error asking for permissions + This device does not appear to support battery optimization whitelisting - you may experience performance issues. diff --git a/implementation/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt b/implementation/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt new file mode 100644 index 0000000000..0eb177fb7c --- /dev/null +++ b/implementation/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt @@ -0,0 +1,177 @@ +package info.nightscout.androidaps + +import android.content.Context +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.data.ProfileSealed +import info.nightscout.androidaps.database.embedments.InsulinConfiguration +import info.nightscout.androidaps.database.entities.EffectiveProfileSwitch +import info.nightscout.androidaps.extensions.pureProfileFromJson +import info.nightscout.androidaps.interfaces.ActivePlugin +import info.nightscout.androidaps.interfaces.Config +import info.nightscout.androidaps.interfaces.IobCobCalculator +import info.nightscout.androidaps.interfaces.ProfileFunction +import info.nightscout.androidaps.interfaces.ProfileStore +import info.nightscout.androidaps.plugins.bus.RxBus +import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.FabricPrivacy +import info.nightscout.androidaps.interfaces.ResourceHelper +import org.json.JSONObject +import org.junit.Before +import org.mockito.ArgumentMatchers.anyDouble +import org.mockito.ArgumentMatchers.anyInt +import org.mockito.ArgumentMatchers.anyString +import org.mockito.Mock +import org.mockito.Mockito +import org.mockito.Mockito.`when` +import org.mockito.invocation.InvocationOnMock + +@Suppress("SpellCheckingInspection") +open class TestBaseWithProfile : TestBase() { + + @Mock lateinit var activePluginProvider: ActivePlugin + @Mock lateinit var rh: ResourceHelper + @Mock lateinit var iobCobCalculator: IobCobCalculator + @Mock lateinit var fabricPrivacy: FabricPrivacy + @Mock lateinit var profileFunction: ProfileFunction + @Mock lateinit var config: Config + @Mock lateinit var context: Context + + lateinit var dateUtil: DateUtil + val rxBus = RxBus(aapsSchedulers, aapsLogger) + + val profileInjector = HasAndroidInjector { AndroidInjector { } } + + private lateinit var validProfileJSON: String + lateinit var validProfile: ProfileSealed.Pure + lateinit var effectiveProfileSwitch: EffectiveProfileSwitch + + @Suppress("PropertyName") val TESTPROFILENAME = "someProfile" + + @Before + fun prepareMock() { + validProfileJSON = "{\"dia\":\"5\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," + + "{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," + + "\"target_high\":[{\"time\":\"00:00\",\"value\":\"7\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}" + dateUtil = Mockito.spy(DateUtil(context)) + `when`(dateUtil.now()).thenReturn(1656358822000) + validProfile = ProfileSealed.Pure(pureProfileFromJson(JSONObject(validProfileJSON), dateUtil)!!) + effectiveProfileSwitch = EffectiveProfileSwitch( + timestamp = dateUtil.now(), + basalBlocks = validProfile.basalBlocks, + isfBlocks = validProfile.isfBlocks, + icBlocks = validProfile.icBlocks, + targetBlocks = validProfile.targetBlocks, + glucoseUnit = EffectiveProfileSwitch.GlucoseUnit.MMOL, + originalProfileName = "", + originalCustomizedName = "", + originalTimeshift = 0, + originalPercentage = 100, + originalDuration = 0, + originalEnd = 0, + insulinConfiguration = InsulinConfiguration("", 0, 0) + ) + + Mockito.doAnswer { invocation: InvocationOnMock -> + val string = invocation.getArgument(0) + val arg1 = invocation.getArgument(1) + String.format(rh.gs(string), arg1) + }.`when`(rh).gs(anyInt(), anyInt()) + + Mockito.doAnswer { invocation: InvocationOnMock -> + val string = invocation.getArgument(0) + val arg1 = invocation.getArgument(1) + String.format(rh.gs(string), arg1) + }.`when`(rh).gs(anyInt(), anyDouble()) + + Mockito.doAnswer { invocation: InvocationOnMock -> + val string = invocation.getArgument(0) + val arg1 = invocation.getArgument(1) + String.format(rh.gs(string), arg1) + }.`when`(rh).gs(anyInt(), anyString()) + + Mockito.doAnswer { invocation: InvocationOnMock -> + val string = invocation.getArgument(0) + val arg1 = invocation.getArgument(1) + val arg2 = invocation.getArgument(2) + String.format(rh.gs(string), arg1, arg2) + }.`when`(rh).gs(anyInt(), anyString(), anyString()) + + Mockito.doAnswer { invocation: InvocationOnMock -> + val string = invocation.getArgument(0) + val arg1 = invocation.getArgument(1) + val arg2 = invocation.getArgument(2) + String.format(rh.gs(string), arg1, arg2) + }.`when`(rh).gs(anyInt(), anyString(), anyInt()) + + Mockito.doAnswer { invocation: InvocationOnMock -> + val string = invocation.getArgument(0) + val arg1 = invocation.getArgument(1) + val arg2 = invocation.getArgument(2) + String.format(rh.gs(string), arg1, arg2) + }.`when`(rh).gs(anyInt(), anyDouble(), anyString()) + + Mockito.doAnswer { invocation: InvocationOnMock -> + val string = invocation.getArgument(0) + val arg1 = invocation.getArgument(1) + val arg2 = invocation.getArgument(2) + String.format(rh.gs(string), arg1, arg2) + }.`when`(rh).gs(anyInt(), anyDouble(), anyInt()) + + Mockito.doAnswer { invocation: InvocationOnMock -> + val string = invocation.getArgument(0) + val arg1 = invocation.getArgument(1) + val arg2 = invocation.getArgument(2) + String.format(rh.gs(string), arg1, arg2) + }.`when`(rh).gs(anyInt(), anyInt(), anyInt()) + + Mockito.doAnswer { invocation: InvocationOnMock -> + val string = invocation.getArgument(0) + val arg1 = invocation.getArgument(1) + val arg2 = invocation.getArgument(2) + String.format(rh.gs(string), arg1, arg2) + }.`when`(rh).gs(anyInt(), anyInt(), anyString()) + + Mockito.doAnswer { invocation: InvocationOnMock -> + val string = invocation.getArgument(0) + val arg1 = invocation.getArgument(1) + val arg2 = invocation.getArgument(2) + val arg3 = invocation.getArgument(3) + String.format(rh.gs(string), arg1, arg2, arg3) + }.`when`(rh).gs(anyInt(), anyInt(), anyInt(), anyString()) + + Mockito.doAnswer { invocation: InvocationOnMock -> + val string = invocation.getArgument(0) + val arg1 = invocation.getArgument(1) + val arg2 = invocation.getArgument(2) + val arg3 = invocation.getArgument(3) + String.format(rh.gs(string), arg1, arg2, arg3) + }.`when`(rh).gs(anyInt(), anyInt(), anyString(), anyString()) + + Mockito.doAnswer { invocation: InvocationOnMock -> + val string = invocation.getArgument(0) + val arg1 = invocation.getArgument(1) + val arg2 = invocation.getArgument(2) + val arg3 = invocation.getArgument(3) + String.format(rh.gs(string), arg1, arg2, arg3) + }.`when`(rh).gs(anyInt(), anyDouble(), anyInt(), anyString()) + + Mockito.doAnswer { invocation: InvocationOnMock -> + val string = invocation.getArgument(0) + val arg1 = invocation.getArgument(1) + val arg2 = invocation.getArgument(2) + val arg3 = invocation.getArgument(3) + String.format(rh.gs(string), arg1, arg2, arg3) + }.`when`(rh).gs(anyInt(), anyString(), anyInt(), anyString()) + + } + + fun getValidProfileStore(): ProfileStore { + val json = JSONObject() + val store = JSONObject() + store.put(TESTPROFILENAME, JSONObject(validProfileJSON)) + json.put("defaultProfile", TESTPROFILENAME) + json.put("store", store) + return ProfileStore(profileInjector, json, dateUtil) + } +} diff --git a/implementation/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt b/implementation/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt new file mode 100644 index 0000000000..c533893b3f --- /dev/null +++ b/implementation/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt @@ -0,0 +1,68 @@ +package info.nightscout.androidaps + +import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.data.DetailedBolusInfo +import info.nightscout.androidaps.interfaces.Profile +import info.nightscout.androidaps.data.PumpEnactResult +import info.nightscout.androidaps.interfaces.PumpDescription +import info.nightscout.androidaps.interfaces.Pump +import info.nightscout.androidaps.interfaces.PumpSync +import info.nightscout.androidaps.plugins.common.ManufacturerType +import info.nightscout.androidaps.plugins.pump.common.defs.PumpType +import info.nightscout.androidaps.utils.TimeChangeType +import org.json.JSONObject + +@Suppress("MemberVisibilityCanBePrivate") +class TestPumpPlugin(val injector: HasAndroidInjector) : Pump { + + var connected = false + var isProfileSet = true + + override fun isConnected() = connected + override fun isConnecting() = false + override fun isHandshakeInProgress() = false + val lastData = 0L + + val baseBasal = 0.0 + override val pumpDescription = PumpDescription() + + override fun isInitialized(): Boolean = true + override fun isSuspended(): Boolean = false + override fun isBusy(): Boolean = false + override fun connect(reason: String) { + connected = true + } + + override fun disconnect(reason: String) { + connected = false + } + + override fun stopConnecting() { + connected = false + } + + override fun waitForDisconnectionInSeconds(): Int = 0 + override fun getPumpStatus(reason: String) {} + override fun setNewBasalProfile(profile: Profile): PumpEnactResult = PumpEnactResult(injector) + override fun isThisProfileSet(profile: Profile): Boolean = isProfileSet + override fun lastDataTime(): Long = lastData + override val baseBasalRate: Double = baseBasal + override val reservoirLevel: Double = 0.0 + override val batteryLevel: Int = 0 + override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult = PumpEnactResult(injector).success(true) + override fun stopBolusDelivering() {} + override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult = PumpEnactResult(injector).success(true) + override fun setTempBasalPercent(percent: Int, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult = PumpEnactResult(injector).success(true) + override fun setExtendedBolus(insulin: Double, durationInMinutes: Int): PumpEnactResult = PumpEnactResult(injector).success(true) + override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult = PumpEnactResult(injector).success(true) + override fun cancelExtendedBolus(): PumpEnactResult = PumpEnactResult(injector).success(true) + override fun getJSONStatus(profile: Profile, profileName: String, version: String): JSONObject = JSONObject() + override fun manufacturer(): ManufacturerType = ManufacturerType.AAPS + override fun model(): PumpType = PumpType.GENERIC_AAPS + override fun serialNumber(): String = "1" + override fun shortStatus(veryShort: Boolean): String = "" + override val isFakingTempsByExtendedBoluses: Boolean = false + override fun loadTDDs(): PumpEnactResult = PumpEnactResult(injector).success(true) + override fun canHandleDST(): Boolean = true + override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) {} +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueImplementationTest.kt b/implementation/src/test/java/info/nightscout/implementation/queue/CommandQueueImplementationTest.kt similarity index 90% rename from app/src/test/java/info/nightscout/androidaps/queue/CommandQueueImplementationTest.kt rename to implementation/src/test/java/info/nightscout/implementation/queue/CommandQueueImplementationTest.kt index 7c694189da..0113dc3f62 100644 --- a/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueImplementationTest.kt +++ b/implementation/src/test/java/info/nightscout/implementation/queue/CommandQueueImplementationTest.kt @@ -1,10 +1,10 @@ -package info.nightscout.androidaps.queue +package info.nightscout.implementation.queue import android.content.Context import android.os.PowerManager import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R +import info.nightscout.implementation.R import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.TestPumpPlugin import info.nightscout.androidaps.data.DetailedBolusInfo @@ -13,30 +13,35 @@ import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.ValueWrapper import info.nightscout.androidaps.database.entities.Bolus import info.nightscout.androidaps.interfaces.ActivePlugin +import info.nightscout.androidaps.interfaces.AndroidPermission +import info.nightscout.androidaps.interfaces.BuildHelper import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.PumpSync -import info.nightscout.shared.logging.AAPSLogger +import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.general.maintenance.PrefFileListProvider +import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.commands.* -import info.nightscout.androidaps.utils.AndroidPermission import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy -import info.nightscout.androidaps.interfaces.BuildHelper -import info.nightscout.androidaps.utils.buildHelper.BuildHelperImpl -import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers +import info.nightscout.implementation.queue.commands.CommandBolus +import info.nightscout.implementation.queue.commands.CommandCustomCommand +import info.nightscout.implementation.queue.commands.CommandExtendedBolus +import info.nightscout.implementation.queue.commands.CommandLoadHistory +import info.nightscout.implementation.queue.commands.CommandTempBasalPercent +import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.sharedPreferences.SP import io.reactivex.rxjava3.core.Single import org.junit.Assert import org.junit.Before import org.junit.Test import org.mockito.Mock -import org.mockito.Mockito.`when` import org.mockito.Mockito.anyLong +import org.mockito.Mockito.`when` import java.util.* class CommandQueueImplementationTest : TestBaseWithProfile() { @@ -47,6 +52,7 @@ class CommandQueueImplementationTest : TestBaseWithProfile() { @Mock lateinit var powerManager: PowerManager @Mock lateinit var repository: AppRepository @Mock lateinit var fileListProvider: PrefFileListProvider + @Mock lateinit var buildHelper: BuildHelper @Mock lateinit var androidPermission: AndroidPermission class CommandQueueMocked( @@ -66,8 +72,10 @@ class CommandQueueImplementationTest : TestBaseWithProfile() { fabricPrivacy: FabricPrivacy, config: Config, androidPermission: AndroidPermission - ) : CommandQueueImplementation(injector, aapsLogger, rxBus, aapsSchedulers, rh, constraintChecker, profileFunction, - activePlugin, context, sp, buildHelper, dateUtil, repository, fabricPrivacy, config, androidPermission) { + ) : CommandQueueImplementation( + injector, aapsLogger, rxBus, aapsSchedulers, rh, constraintChecker, profileFunction, + activePlugin, context, sp, buildHelper, dateUtil, repository, fabricPrivacy, config, androidPermission + ) { override fun notifyAboutNewCommand() {} @@ -95,7 +103,7 @@ class CommandQueueImplementationTest : TestBaseWithProfile() { if (it is CommandLoadHistory) { it.activePlugin = activePlugin } - if (it is PumpEnactResult) { + if (it is PumpEnactResult) { it.rh = rh } } @@ -106,11 +114,13 @@ class CommandQueueImplementationTest : TestBaseWithProfile() { @Before fun prepare() { - commandQueue = CommandQueueMocked(injector, aapsLogger, rxBus, aapsSchedulers, rh, - constraintChecker, profileFunction, activePlugin, context, sp, - BuildHelperImpl(config, fileListProvider), dateUtil, - repository, - fabricPrivacy, config, androidPermission) + commandQueue = CommandQueueMocked( + injector, aapsLogger, rxBus, aapsSchedulers, rh, + constraintChecker, profileFunction, activePlugin, context, sp, + buildHelper, dateUtil, + repository, + fabricPrivacy, config, androidPermission + ) testPumpPlugin = TestPumpPlugin(injector) testPumpPlugin.pumpDescription.basalMinimumRate = 0.1 @@ -136,18 +146,20 @@ class CommandQueueImplementationTest : TestBaseWithProfile() { `when`(constraintChecker.applyBasalConstraints(anyObject(), anyObject())).thenReturn(rateConstraint) val percentageConstraint = Constraint(0) `when`(constraintChecker.applyBasalPercentConstraints(anyObject(), anyObject())).thenReturn(percentageConstraint) - `when`(rh.gs(R.string.connectiontimedout)).thenReturn("Connection timed out") + val thenReturn = `when`(rh.gs(R.string.connectiontimedout)).thenReturn("Connection timed out") `when`(rh.gs(R.string.formatinsulinunits)).thenReturn("%1\$.2f U") - `when`(rh.gs(R.string.bolusrequested)).thenReturn("Going to deliver %1\$.2f U") + `when`(rh.gs(R.string.goingtodeliver)).thenReturn("Going to deliver %1\$.2f U") } @Test fun commandIsPickedUp() { - val commandQueue = CommandQueueImplementation(injector, aapsLogger, rxBus, aapsSchedulers, rh, - constraintChecker, profileFunction, activePlugin, context, sp, - BuildHelperImpl(config, fileListProvider), - dateUtil, repository, - fabricPrivacy, config, androidPermission) + val commandQueue = CommandQueueImplementation( + injector, aapsLogger, rxBus, aapsSchedulers, rh, + constraintChecker, profileFunction, activePlugin, context, sp, + buildHelper, + dateUtil, repository, + fabricPrivacy, config, androidPermission + ) // start with empty queue Assert.assertEquals(0, commandQueue.size()) diff --git a/app/src/test/java/info/nightscout/androidaps/queue/QueueThreadTest.kt b/implementation/src/test/java/info/nightscout/implementation/queue/QueueThreadTest.kt similarity index 86% rename from app/src/test/java/info/nightscout/androidaps/queue/QueueThreadTest.kt rename to implementation/src/test/java/info/nightscout/implementation/queue/QueueThreadTest.kt index 2f41e05e2f..cb34c49793 100644 --- a/app/src/test/java/info/nightscout/androidaps/queue/QueueThreadTest.kt +++ b/implementation/src/test/java/info/nightscout/implementation/queue/QueueThreadTest.kt @@ -1,23 +1,22 @@ -package info.nightscout.androidaps.queue +package info.nightscout.implementation.queue import android.content.Context import android.os.PowerManager import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.R import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.androidaps.TestPumpPlugin import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.interfaces.ActivePlugin +import info.nightscout.androidaps.interfaces.AndroidPermission +import info.nightscout.androidaps.interfaces.BuildHelper import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.PumpDescription import info.nightscout.androidaps.interfaces.PumpSync import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker -import info.nightscout.androidaps.plugins.general.maintenance.PrefFileListProvider import info.nightscout.androidaps.queue.commands.Command -import info.nightscout.androidaps.queue.commands.CommandTempBasalAbsolute -import info.nightscout.androidaps.utils.AndroidPermission -import info.nightscout.androidaps.utils.buildHelper.BuildHelperImpl +import info.nightscout.implementation.R +import info.nightscout.implementation.queue.commands.CommandTempBasalAbsolute import info.nightscout.shared.sharedPreferences.SP import org.junit.Assert import org.junit.Before @@ -31,9 +30,9 @@ class QueueThreadTest : TestBaseWithProfile() { @Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var activePlugin: ActivePlugin @Mock lateinit var sp: SP - @Mock lateinit var fileListProvider: PrefFileListProvider @Mock lateinit var powerManager: PowerManager @Mock lateinit var repository: AppRepository + @Mock lateinit var buildHelper: BuildHelper @Mock lateinit var androidPermission: AndroidPermission val injector = HasAndroidInjector { @@ -59,7 +58,7 @@ class QueueThreadTest : TestBaseWithProfile() { commandQueue = CommandQueueImplementation( injector, aapsLogger, rxBus, aapsSchedulers, rh, constraintChecker, profileFunction, activePlugin, context, sp, - BuildHelperImpl(config, fileListProvider), dateUtil, repository, fabricPrivacy, config, androidPermission + buildHelper, dateUtil, repository, fabricPrivacy, config, androidPermission ) val pumpDescription = PumpDescription() diff --git a/insight/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java b/insight/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java index 772a3282c0..8ef2bc3e8f 100644 --- a/insight/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java +++ b/insight/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java @@ -31,6 +31,7 @@ import javax.inject.Singleton; import dagger.android.HasAndroidInjector; import info.nightscout.androidaps.data.DetailedBolusInfo; +import info.nightscout.androidaps.interfaces.Insight; import info.nightscout.androidaps.interfaces.Profile; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.events.EventInitializationChanged; @@ -134,7 +135,8 @@ import info.nightscout.androidaps.interfaces.ResourceHelper; import info.nightscout.shared.sharedPreferences.SP; @Singleton -public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constraints, InsightConnectionService.StateCallback { +public class LocalInsightPlugin extends PumpPluginBase implements Pump, Insight, Constraints, + InsightConnectionService.StateCallback { private final AAPSLogger aapsLogger; private final RxBus rxBus;