contraints plugins -> plugins module

This commit is contained in:
Milos Kozak 2022-11-04 21:51:37 +01:00
parent f0f5a89fe6
commit e0fba68fd2
59 changed files with 118 additions and 102 deletions

View file

@ -54,7 +54,6 @@ import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.interfaces.SmsCommunicator import info.nightscout.androidaps.interfaces.SmsCommunicator
import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.constraints.signatureVerifier.SignatureVerifierPlugin
import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerUtils import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerUtils
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus
import info.nightscout.androidaps.setupwizard.SetupWizardActivity import info.nightscout.androidaps.setupwizard.SetupWizardActivity
@ -67,6 +66,7 @@ import info.nightscout.androidaps.utils.protection.ProtectionCheck
import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.tabs.TabPageAdapter import info.nightscout.androidaps.utils.tabs.TabPageAdapter
import info.nightscout.androidaps.utils.ui.UIRunnable import info.nightscout.androidaps.utils.ui.UIRunnable
import info.nightscout.plugins.constraints.signatureVerifier.SignatureVerifierPlugin
import info.nightscout.shared.logging.LTag import info.nightscout.shared.logging.LTag
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.ui.activities.StatsActivity import info.nightscout.ui.activities.StatsActivity

View file

@ -16,13 +16,8 @@ import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin
import info.nightscout.androidaps.plugins.aps.openAPSSMBDynamicISF.OpenAPSSMBDynamicISFPlugin import info.nightscout.androidaps.plugins.aps.openAPSSMBDynamicISF.OpenAPSSMBDynamicISFPlugin
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.constraints.bgQualityCheck.BgQualityCheckPlugin
import info.nightscout.androidaps.plugins.constraints.dstHelper.DstHelperPlugin
import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin
import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin
import info.nightscout.androidaps.plugins.constraints.signatureVerifier.SignatureVerifierPlugin
import info.nightscout.androidaps.plugins.constraints.storage.StorageConstraintPlugin
import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerPlugin
import info.nightscout.androidaps.plugins.general.actions.ActionsPlugin import info.nightscout.androidaps.plugins.general.actions.ActionsPlugin
import info.nightscout.androidaps.plugins.general.dataBroadcaster.DataBroadcastPlugin import info.nightscout.androidaps.plugins.general.dataBroadcaster.DataBroadcastPlugin
import info.nightscout.androidaps.plugins.general.maintenance.MaintenancePlugin import info.nightscout.androidaps.plugins.general.maintenance.MaintenancePlugin
@ -54,6 +49,11 @@ import info.nightscout.androidaps.plugins.source.RandomBgPlugin
import info.nightscout.androidaps.plugins.source.TomatoPlugin import info.nightscout.androidaps.plugins.source.TomatoPlugin
import info.nightscout.androidaps.plugins.source.XdripPlugin import info.nightscout.androidaps.plugins.source.XdripPlugin
import info.nightscout.automation.AutomationPlugin import info.nightscout.automation.AutomationPlugin
import info.nightscout.plugins.constraints.bgQualityCheck.BgQualityCheckPlugin
import info.nightscout.plugins.constraints.dstHelper.DstHelperPlugin
import info.nightscout.plugins.constraints.signatureVerifier.SignatureVerifierPlugin
import info.nightscout.plugins.constraints.storage.StorageConstraintPlugin
import info.nightscout.plugins.constraints.versionChecker.VersionCheckerPlugin
import info.nightscout.plugins.general.autotune.AutotunePlugin import info.nightscout.plugins.general.autotune.AutotunePlugin
import info.nightscout.plugins.general.food.FoodPlugin import info.nightscout.plugins.general.food.FoodPlugin
import info.nightscout.plugins.general.smsCommunicator.SmsCommunicatorPlugin import info.nightscout.plugins.general.smsCommunicator.SmsCommunicatorPlugin

View file

@ -75,7 +75,6 @@ import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.aps.loop.events.EventNewOpenLoopNotification import info.nightscout.androidaps.plugins.aps.loop.events.EventNewOpenLoopNotification
import info.nightscout.androidaps.plugins.aps.openAPSSMB.DetermineBasalResultSMB import info.nightscout.androidaps.plugins.aps.openAPSSMB.DetermineBasalResultSMB
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.constraints.bgQualityCheck.BgQualityCheckPlugin
import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus
import info.nightscout.androidaps.plugins.general.overview.activities.QuickWizardListActivity import info.nightscout.androidaps.plugins.general.overview.activities.QuickWizardListActivity
import info.nightscout.androidaps.plugins.general.overview.events.EventUpdateOverviewCalcProgress import info.nightscout.androidaps.plugins.general.overview.events.EventUpdateOverviewCalcProgress
@ -103,6 +102,7 @@ import info.nightscout.androidaps.utils.ui.SingleClickButton
import info.nightscout.androidaps.utils.ui.UIRunnable import info.nightscout.androidaps.utils.ui.UIRunnable
import info.nightscout.androidaps.utils.wizard.QuickWizard import info.nightscout.androidaps.utils.wizard.QuickWizard
import info.nightscout.automation.AutomationPlugin import info.nightscout.automation.AutomationPlugin
import info.nightscout.plugins.constraints.bgQualityCheck.BgQualityCheckPlugin
import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.weardata.EventData import info.nightscout.shared.weardata.EventData

View file

@ -1,5 +0,0 @@
package info.nightscout.androidaps.utils.extensions
import java.util.concurrent.TimeUnit
fun Long.daysToMillis() = TimeUnit.DAYS.toMillis(this)

View file

@ -624,9 +624,6 @@
<string name="open_navigation">Open navigation</string> <string name="open_navigation">Open navigation</string>
<string name="close_navigation">Close navigation</string> <string name="close_navigation">Close navigation</string>
<string name="nav_plugin_preferences">Plugin preferences</string> <string name="nav_plugin_preferences">Plugin preferences</string>
<string name="completed_well_done">Completed, well done!</string>
<string name="not_completed_yet">Not completed yet</string>
<string name="time_elapsed">Time elapsed</string>
<string name="poctech">Poctech</string> <string name="poctech">Poctech</string>
<string name="description_source_poctech">Receive BG values from Poctech app</string> <string name="description_source_poctech">Receive BG values from Poctech app</string>
<string name="glunovo">Glunovo</string> <string name="glunovo">Glunovo</string>
@ -717,16 +714,6 @@
<string name="tidepool_upload_bg">Upload BG tests</string> <string name="tidepool_upload_bg">Upload BG tests</string>
<string name="key_smbmaxminutes" translatable="false">smbmaxminutes</string> <string name="key_smbmaxminutes" translatable="false">smbmaxminutes</string>
<string name="key_uamsmbmaxminutes" translatable="false">uamsmbmaxminutes</string> <string name="key_uamsmbmaxminutes" translatable="false">uamsmbmaxminutes</string>
<string name="dst_plugin_name" translatable="false">Daylight Saving time</string>
<string name="dst_in_24h_warning">Daylight Saving time change in 24h or less</string>
<string name="dst_loop_disabled_warning">Daylight Saving time change less than 3 hours ago - Closed loop disabled</string>
<string name="storage">internal storage constraint</string>
<string name="diskfull">Free at least %1$d MB from internal storage! Loop disabled!</string>
<string name="versionChecker">Version Checker</string>
<string name="old_version">old version</string>
<string name="very_old_version">very old version</string>
<string name="application_expired">Application expired</string>
<string name="new_version_warning">New version for at least %1$d days available! Fallback to LGS after %2$d days, loop will be disabled after %3$d days</string>
<string name="twohours">2h</string> <string name="twohours">2h</string>
<string name="dexcom_app_patched">BYODA</string> <string name="dexcom_app_patched">BYODA</string>
<string name="dexcom_short">BYODA</string> <string name="dexcom_short">BYODA</string>
@ -737,7 +724,6 @@
<string name="key_boluswizard_percentage" translatable="false">boluswizard_percentage</string> <string name="key_boluswizard_percentage" translatable="false">boluswizard_percentage</string>
<string name="partialboluswizard">Deliver this part of bolus wizard result [%]</string> <string name="partialboluswizard">Deliver this part of bolus wizard result [%]</string>
<string name="deliverpartofboluswizard">Bolus wizard performs calculation but only this part of calculated insulin is delivered. Useful with SMB algorithm.</string> <string name="deliverpartofboluswizard">Bolus wizard performs calculation but only this part of calculated insulin is delivered. Useful with SMB algorithm.</string>
<string name="snooze">Snooze</string>
<string name="increasingmaxbasal">Increasing max basal value because setting is lower than your max basal in profile</string> <string name="increasingmaxbasal">Increasing max basal value because setting is lower than your max basal in profile</string>
<string name="format_bg_isf">%1$s ISF: %2$.1f</string> <string name="format_bg_isf">%1$s ISF: %2$.1f</string>
<string name="format_carbs_ic">%1$.0fg IC: %2$.1f</string> <string name="format_carbs_ic">%1$.0fg IC: %2$.1f</string>
@ -766,11 +752,8 @@
<string name="clearqueueconfirm">Clear queue? All data in queue will be lost!</string> <string name="clearqueueconfirm">Clear queue? All data in queue will be lost!</string>
<string name="key_wear_detailed_delta" translatable="false">wear_detailed_delta</string> <string name="key_wear_detailed_delta" translatable="false">wear_detailed_delta</string>
<string name="key_snoozedTo" translatable="false">snoozedTo</string> <string name="key_snoozedTo" translatable="false">snoozedTo</string>
<string name="key_snooze_dst_in24h" translatable="false">snooze_dst_in24h</string>
<string name="key_snooze_loopdisabled" translatable="false">snooze_loopdisabled</string>
<string name="ebstopsloop">Use of Extended bolus feature will stop closed loop mode for the time of running extended bolus. Do you really want it?</string> <string name="ebstopsloop">Use of Extended bolus feature will stop closed loop mode for the time of running extended bolus. Do you really want it?</string>
<string name="closed_loop_disabled_with_eb">Closed loop disabled because of running Extended bolus</string> <string name="closed_loop_disabled_with_eb">Closed loop disabled because of running Extended bolus</string>
<string name="phonechecker">\"PhoneChecker\"</string>
<string name="chartmenu">Chart menu</string> <string name="chartmenu">Chart menu</string>
<string name="databroadcaster" translatable="false">Data Broadcaster</string> <string name="databroadcaster" translatable="false">Data Broadcaster</string>
<string name="loop_smbrequest_time_label">SMB request time</string> <string name="loop_smbrequest_time_label">SMB request time</string>
@ -866,11 +849,8 @@
<string name="statuslights_cannula_age">cannula age</string> <string name="statuslights_cannula_age">cannula age</string>
<string name="statuslights_patch_pump_age">patch pump age</string> <string name="statuslights_patch_pump_age">patch pump age</string>
<string name="patch_pump">Patch pump</string> <string name="patch_pump">Patch pump</string>
<string name="recalculated_data_used">Recalculated data used</string>
<string name="bg_too_close">BG too close:\n%1$s\n%2$s</string>
<string name="key_last_processed_glunovo_timestamp" translatable="false">last_processed_glunovo_timestamp</string> <string name="key_last_processed_glunovo_timestamp" translatable="false">last_processed_glunovo_timestamp</string>
<string name="key_last_processed_intelligo_timestamp" translatable="false"> <string name="key_last_processed_intelligo_timestamp" translatable="false">last_processed_intelligo_timestamp</string>
last_processed_intelligo_timestamp</string>
<string name="identification">Identification (email, FB or Discord nick etc)</string> <string name="identification">Identification (email, FB or Discord nick etc)</string>
<string name="identification_not_set">Identification not set in dev mode</string> <string name="identification_not_set">Identification not set in dev mode</string>
<string name="a11y_dialog">dialog</string> <string name="a11y_dialog">dialog</string>
@ -880,8 +860,6 @@
<string name="not_available_full">Not available</string> <string name="not_available_full">Not available</string>
<string name="a11y_graph">graph</string> <string name="a11y_graph">graph</string>
<string name="a11y_bg_quality">blood glucose quality</string> <string name="a11y_bg_quality">blood glucose quality</string>
<string name="a11y_bg_quality_recalculated">recalculated</string>
<string name="a11y_bg_quality_doubles">double entries</string>
<string name="a11y_insulin_label">insulin</string> <string name="a11y_insulin_label">insulin</string>
<string name="a11y_blood_glucose">blood glucose</string> <string name="a11y_blood_glucose">blood glucose</string>
<string name="a11y_bg_outdated">outdated</string> <string name="a11y_bg_outdated">outdated</string>

View file

@ -422,7 +422,6 @@
<string name="key_last_expired_versionchecker_warning" translatable="false">last_expired_version_checker_warning</string> <string name="key_last_expired_versionchecker_warning" translatable="false">last_expired_version_checker_warning</string>
<string name="key_last_versionchecker_plugin_warning" translatable="false">last_versionchecker_plugin_waring</string> <string name="key_last_versionchecker_plugin_warning" translatable="false">last_versionchecker_plugin_waring</string>
<string name="key_last_revoked_certs_check" translatable="false">last_revoked_certs_check</string> <string name="key_last_revoked_certs_check" translatable="false">last_revoked_certs_check</string>
<string name="signature_verifier">Signature verifier</string>
<string name="running_invalid_version">We have detected that you are running an invalid version. Loop disabled!</string> <string name="running_invalid_version">We have detected that you are running an invalid version. Loop disabled!</string>
<string name="versionavailable">Version %1$s available</string> <string name="versionavailable">Version %1$s available</string>
<string name="version_expire">Version %1$s expire on %2$s</string> <string name="version_expire">Version %1$s expire on %2$s</string>

View file

@ -1,15 +1,20 @@
package info.nightscout.androidaps.plugins.constraints.bgQualityCheck package info.nightscout.plugins.constraints.bgQualityCheck
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.interfaces.Constraints
import info.nightscout.androidaps.interfaces.IobCobCalculator
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.bus.RxBus
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventBucketedDataCreated import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventBucketedDataCreated
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.plugins.R
import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag import info.nightscout.shared.logging.LTag
import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.disposables.CompositeDisposable
@ -35,7 +40,7 @@ class BgQualityCheckPlugin @Inject constructor(
.neverVisible(true) .neverVisible(true)
.alwaysEnabled(true) .alwaysEnabled(true)
.showInList(false) .showInList(false)
.pluginName(R.string.dst_plugin_name), .pluginName(R.string.bg_quality),
aapsLogger, rh, injector aapsLogger, rh, injector
), Constraints { ), Constraints {

View file

@ -1,18 +1,21 @@
package info.nightscout.androidaps.plugins.constraints.dstHelper package info.nightscout.plugins.constraints.dstHelper
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.interfaces.Constraints
import info.nightscout.androidaps.interfaces.Loop
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.general.overview.notifications.Notification
import info.nightscout.androidaps.utils.T
import info.nightscout.plugins.R
import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag import info.nightscout.shared.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBus
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.utils.T
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import java.util.* import java.util.Calendar
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -20,27 +23,27 @@ import javax.inject.Singleton
class DstHelperPlugin @Inject constructor( class DstHelperPlugin @Inject constructor(
injector: HasAndroidInjector, injector: HasAndroidInjector,
aapsLogger: AAPSLogger, aapsLogger: AAPSLogger,
private val rxBus: RxBus,
rh: ResourceHelper, rh: ResourceHelper,
private val sp: SP, private val sp: SP,
private val activePlugin: ActivePlugin, private val activePlugin: ActivePlugin,
private val loop: Loop private val loop: Loop
) : PluginBase(PluginDescription() ) : PluginBase(
.mainType(PluginType.CONSTRAINTS) PluginDescription()
.neverVisible(true) .mainType(PluginType.CONSTRAINTS)
.alwaysEnabled(true) .neverVisible(true)
.showInList(false) .alwaysEnabled(true)
.pluginName(R.string.dst_plugin_name), .showInList(false)
.pluginName(R.string.dst_plugin_name),
aapsLogger, rh, injector aapsLogger, rh, injector
), Constraints { ), Constraints {
companion object { companion object {
private const val DISABLE_TIME_FRAME_HOURS = -3 private const val DISABLE_TIME_FRAME_HOURS = -3
private const val WARN_PRIOR_TIME_FRAME_HOURS = 12 private const val WARN_PRIOR_TIME_FRAME_HOURS = 12
} }
//Return false if time to DST change happened in the last 3 hours. //Return false if time to DST change happened in the last 3 hours.
@Suppress("ReplaceGetOrSet")
override fun isLoopInvocationAllowed(value: Constraint<Boolean>): Constraint<Boolean> { override fun isLoopInvocationAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
val pump = activePlugin.activePump val pump = activePlugin.activePump
if (pump.canHandleDST()) { if (pump.canHandleDST()) {
@ -51,11 +54,9 @@ class DstHelperPlugin @Inject constructor(
if (willBeDST(cal)) { if (willBeDST(cal)) {
val snoozedTo: Long = sp.getLong(R.string.key_snooze_dst_in24h, 0L) val snoozedTo: Long = sp.getLong(R.string.key_snooze_dst_in24h, 0L)
if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo) { if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo) {
val notification = NotificationWithAction(injector, Notification.DST_IN_24H, rh.gs(R.string.dst_in_24h_warning), Notification.LOW) activePlugin.activeOverview.addNotification(Notification.DST_IN_24H, rh.gs(R.string.dst_in_24h_warning), Notification.LOW, R.string.snooze) {
notification.action(R.string.snooze) {
sp.putLong(R.string.key_snooze_dst_in24h, System.currentTimeMillis() + T.hours(24).msecs()) sp.putLong(R.string.key_snooze_dst_in24h, System.currentTimeMillis() + T.hours(24).msecs())
} }
rxBus.send(EventNewNotification(notification))
} }
} }
if (!value.value()) { if (!value.value()) {
@ -64,13 +65,11 @@ class DstHelperPlugin @Inject constructor(
} }
if (wasDST(cal)) { if (wasDST(cal)) {
if (!loop.isSuspended) { if (!loop.isSuspended) {
val snoozedTo: Long = sp.getLong(R.string.key_snooze_loopdisabled, 0L) val snoozedTo: Long = sp.getLong(R.string.key_snooze_loop_disabled, 0L)
if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo) { if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo) {
val notification = NotificationWithAction(injector, Notification.DST_LOOP_DISABLED, rh.gs(R.string.dst_loop_disabled_warning), Notification.LOW) activePlugin.activeOverview.addNotification(Notification.DST_LOOP_DISABLED, rh.gs(R.string.dst_loop_disabled_warning), Notification.LOW, R.string.snooze) {
notification.action(R.string.snooze) { sp.putLong(R.string.key_snooze_loop_disabled, System.currentTimeMillis() + T.hours(24).msecs())
sp.putLong(R.string.key_snooze_loopdisabled, System.currentTimeMillis() + T.hours(24).msecs())
} }
rxBus.send(EventNewNotification(notification))
} }
} else { } else {
aapsLogger.debug(LTag.CONSTRAINTS, "Loop already suspended") aapsLogger.debug(LTag.CONSTRAINTS, "Loop already suspended")

View file

@ -1,16 +1,16 @@
package info.nightscout.androidaps.plugins.constraints.phoneChecker package info.nightscout.plugins.constraints.phoneChecker
import android.content.Context import android.content.Context
import android.os.Build import android.os.Build
import com.scottyab.rootbeer.RootBeer import com.scottyab.rootbeer.RootBeer
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.Constraints import info.nightscout.androidaps.interfaces.Constraints
import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginDescription import info.nightscout.androidaps.interfaces.PluginDescription
import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.plugins.R
import info.nightscout.shared.logging.AAPSLogger
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -25,8 +25,8 @@ class PhoneCheckerPlugin @Inject constructor(
.neverVisible(true) .neverVisible(true)
.alwaysEnabled(true) .alwaysEnabled(true)
.showInList(false) .showInList(false)
.pluginName(R.string.phonechecker), .pluginName(R.string.phone_checker),
aapsLogger, rh, injector aapsLogger, rh, injector
), Constraints { ), Constraints {
var phoneRooted: Boolean = false var phoneRooted: Boolean = false

View file

@ -1,11 +1,10 @@
package info.nightscout.androidaps.plugins.constraints.signatureVerifier package info.nightscout.plugins.constraints.signatureVerifier
import android.content.Context import android.content.Context
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.os.Handler import android.os.Handler
import android.os.HandlerThread import android.os.HandlerThread
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.interfaces.Constraints import info.nightscout.androidaps.interfaces.Constraints
import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.PluginBase
@ -15,6 +14,7 @@ import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification 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.Notification
import info.nightscout.plugins.R
import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import org.spongycastle.util.encoders.Hex import org.spongycastle.util.encoders.Hex

View file

@ -1,10 +1,9 @@
package info.nightscout.androidaps.plugins.constraints.storage package info.nightscout.plugins.constraints.storage
import android.os.Environment import android.os.Environment
import android.os.StatFs import android.os.StatFs
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Constants import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.annotations.OpenForTesting
import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.interfaces.Constraints import info.nightscout.androidaps.interfaces.Constraints
@ -17,6 +16,7 @@ import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification 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.Notification
import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.plugins.R
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -37,13 +37,12 @@ class StorageConstraintPlugin @Inject constructor(
aapsLogger, rh, injector aapsLogger, rh, injector
), Constraints { ), Constraints {
@Suppress("ReplaceGetOrSet")
override fun isClosedLoopAllowed(value: Constraint<Boolean>): Constraint<Boolean> { override fun isClosedLoopAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
val diskFree = availableInternalMemorySize() val diskFree = availableInternalMemorySize()
if (diskFree < Constants.MINIMUM_FREE_SPACE) { if (diskFree < Constants.MINIMUM_FREE_SPACE) {
aapsLogger.debug(LTag.CONSTRAINTS, "Closed loop disabled. Internal storage free (Mb):$diskFree") aapsLogger.debug(LTag.CONSTRAINTS, "Closed loop disabled. Internal storage free (Mb):$diskFree")
value.set(aapsLogger, false, rh.gs(R.string.diskfull, Constants.MINIMUM_FREE_SPACE), this) value.set(aapsLogger, false, rh.gs(R.string.disk_full, Constants.MINIMUM_FREE_SPACE), this)
val notification = Notification(Notification.DISK_FULL, rh.gs(R.string.diskfull, Constants.MINIMUM_FREE_SPACE), Notification.NORMAL) val notification = Notification(Notification.DISK_FULL, rh.gs(R.string.disk_full, Constants.MINIMUM_FREE_SPACE), Notification.NORMAL)
rxBus.send(EventNewNotification(notification)) rxBus.send(EventNewNotification(notification))
} }
return value return value

View file

@ -1,15 +1,14 @@
package info.nightscout.androidaps.plugins.constraints.versionChecker package info.nightscout.plugins.constraints.versionChecker
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.BuildConfig
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.interfaces.*
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification 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.Notification
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.extensions.daysToMillis
import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerUtils
import info.nightscout.plugins.R
import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@ -33,7 +32,7 @@ class VersionCheckerPlugin @Inject constructor(
.neverVisible(true) .neverVisible(true)
.alwaysEnabled(true) .alwaysEnabled(true)
.showInList(false) .showInList(false)
.pluginName(R.string.versionChecker), .pluginName(R.string.version_checker),
aapsLogger, rh, injector aapsLogger, rh, injector
), Constraints { ), Constraints {
@ -43,7 +42,7 @@ class VersionCheckerPlugin @Inject constructor(
} }
private val gracePeriod: GracePeriod private val gracePeriod: GracePeriod
get() = if ((BuildConfig.VERSION_NAME.contains("RC", ignoreCase = true))) { get() = if ((config.VERSION_NAME.contains("RC", ignoreCase = true))) {
GracePeriod.RC GracePeriod.RC
} else { } else {
GracePeriod.RELEASE GracePeriod.RELEASE
@ -109,4 +108,6 @@ class VersionCheckerPlugin @Inject constructor(
private fun isOldVersion(gracePeriod: Long): Boolean = private fun isOldVersion(gracePeriod: Long): Boolean =
dateUtil.now() > sp.getLong(R.string.key_last_time_this_version_detected_as_ok, 0) + gracePeriod dateUtil.now() > sp.getLong(R.string.key_last_time_this_version_detected_as_ok, 0) + gracePeriod
private fun Long.daysToMillis() = TimeUnit.DAYS.toMillis(this)
} }

View file

@ -162,7 +162,7 @@
<string name="calculator_label">Calculator</string> <string name="calculator_label">Calculator</string>
<!-- Theme switcher dark and light mode--> <!-- Theme switcher dark and light mode-->
<string name="theme_switcher">Theme switcher</string> <string name="theme_switcher" translatable="false">Theme switcher</string>
<string name="theme_switcher_summary">Choose dark, light, or to follow the system theme</string> <string name="theme_switcher_summary">Choose dark, light, or to follow the system theme</string>
<string name="app_color_scheme">App Color Scheme</string> <string name="app_color_scheme">App Color Scheme</string>
<string name="dark_theme">Dark theme</string> <string name="dark_theme">Dark theme</string>
@ -202,4 +202,44 @@
<string name="clone_label">Clone</string> <string name="clone_label">Clone</string>
<string name="basal_short">BAS</string> <string name="basal_short">BAS</string>
<!-- BG Quality -->
<string name="bg_quality" translatable="false">BG Quality</string>
<string name="recalculated_data_used">Recalculated data used</string>
<string name="bg_too_close">BG too close:\n%1$s\n%2$s</string>
<string name="a11y_bg_quality_recalculated">recalculated</string>
<string name="a11y_bg_quality_doubles">double entries</string>
<!-- DST Helper -->
<string name="key_snooze_dst_in24h" translatable="false">snooze_dst_in24h</string>
<string name="key_snooze_loop_disabled" translatable="false">snooze_loop_disabled</string>
<string name="dst_plugin_name" translatable="false">Daylight Saving time</string>
<string name="dst_in_24h_warning">Daylight Saving time change in 24h or less</string>
<string name="dst_loop_disabled_warning">Daylight Saving time change less than 3 hours ago - Closed loop disabled</string>
<!-- Storage constraint -->
<string name="storage" translatable="false">Storage constraint</string>
<string name="disk_full">Free at least %1$d MB from internal storage! Loop disabled!</string>
<!-- Signature verifier -->
<string name="signature_verifier" translatable="false">Signature verifier</string>
<!-- Version Checker -->
<string name="version_checker" translatable="false">Version Checker</string>
<string name="old_version">old version</string>
<string name="very_old_version">very old version</string>
<string name="application_expired">Application expired</string>
<string name="new_version_warning">New version for at least %1$d days available! Fallback to LGS after %2$d days, loop will be disabled after %3$d days</string>
<!-- PhoneChecker -->
<string name="phone_checker" translatable="false">PhoneChecker</string>
<!-- Objectives -->
<string name="completed_well_done">Completed, well done!</string>
<string name="not_completed_yet">Not completed yet</string>
<string name="time_elapsed">Time elapsed</string>
<!-- Overview -->
<string name="snooze">Snooze</string>
</resources> </resources>

View file

@ -1,24 +1,23 @@
package info.nightscout.androidaps.plugins.constraints.bgQualityCheck package info.nightscout.plugins.constraints.bgQualityCheck
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.database.entities.GlucoseValue import info.nightscout.androidaps.database.entities.GlucoseValue
import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.interfaces.IobCobCalculator import info.nightscout.androidaps.interfaces.IobCobCalculator
import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensDataStore import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensDataStore
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.plugins.R
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito import org.mockito.Mockito
import java.util.*
class BgQualityCheckPluginTest : TestBase() { class BgQualityCheckPluginTest : TestBase() {

View file

@ -1,11 +1,10 @@
package info.nightscout.androidaps.plugins.constraints.dstHelper package info.nightscout.plugins.constraints.dstHelper
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.ActivePlugin
import info.nightscout.androidaps.interfaces.Loop import info.nightscout.androidaps.interfaces.Loop
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import org.junit.Assert import org.junit.Assert
@ -14,7 +13,9 @@ import org.junit.Test
import org.mockito.Mock import org.mockito.Mock
import java.text.DateFormat import java.text.DateFormat
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.Calendar
import java.util.Locale
import java.util.TimeZone
class DstHelperPluginTest : TestBase() { class DstHelperPluginTest : TestBase() {
@ -29,8 +30,7 @@ class DstHelperPluginTest : TestBase() {
@Before @Before
fun mock() { fun mock() {
plugin = DstHelperPlugin(injector, aapsLogger, RxBus(aapsSchedulers, aapsLogger), rh, plugin = DstHelperPlugin(injector, aapsLogger, rh, sp, activePlugin, loop)
sp, activePlugin, loop)
} }
@Test @Test

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.plugins.constraints.signatureVerifier package info.nightscout.plugins.constraints.signatureVerifier
import android.content.Context import android.content.Context
import dagger.android.AndroidInjector import dagger.android.AndroidInjector

View file

@ -1,19 +1,19 @@
package info.nightscout.androidaps.plugins.constraints.storage package info.nightscout.plugins.constraints.storage
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.interfaces.ResourceHelper
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.shared.logging.AAPSLogger
import org.junit.Assert import org.junit.Assert
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito.`when`
import org.mockito.Mockito.anyInt import org.mockito.Mockito.anyInt
import org.mockito.Mockito.anyLong import org.mockito.Mockito.anyLong
import org.mockito.Mockito.`when`
class StorageConstraintPluginTest : TestBase() { class StorageConstraintPluginTest : TestBase() {

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.constraints.versionChecker package info.nightscout.plugins.constraints.versionChecker
import info.nightscout.androidaps.plugins.constraints.versionChecker.AllowedVersions
import org.joda.time.LocalDate import org.joda.time.LocalDate
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONObject import org.json.JSONObject
@ -11,7 +12,7 @@ import org.junit.Test
class AllowedVersionsTest { class AllowedVersionsTest {
fun generateSupportedVersions(): String = private fun generateSupportedVersions(): String =
JSONArray() JSONArray()
// Android API versions // Android API versions
.put(JSONObject().apply { .put(JSONObject().apply {