:plugins:support module

This commit is contained in:
Milos Kozak 2022-11-26 23:45:20 +01:00
parent 6c86619a35
commit dcd70acbe7
29 changed files with 175 additions and 89 deletions

View file

@ -201,6 +201,7 @@ dependencies {
implementation project(':plugins:main') implementation project(':plugins:main')
implementation project(':plugins:openhumans') implementation project(':plugins:openhumans')
implementation project(':plugins:sensitivity') implementation project(':plugins:sensitivity')
implementation project(':plugins:support')
implementation project(':implementation') implementation project(':implementation')
implementation project(':database:entities') implementation project(':database:entities')
implementation project(':database:impl') implementation project(':database:impl')

View file

@ -42,7 +42,7 @@ import info.nightscout.core.ui.toast.ToastUtils
import info.nightscout.core.utils.CryptoUtil import info.nightscout.core.utils.CryptoUtil
import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.core.utils.isRunningRealPumpTest import info.nightscout.core.utils.isRunningRealPumpTest
import info.nightscout.core.versionChecker.VersionCheckerUtils import info.nightscout.interfaces.versionChecker.VersionCheckerUtils
import info.nightscout.database.entities.UserEntry.Action import info.nightscout.database.entities.UserEntry.Action
import info.nightscout.database.entities.UserEntry.Sources import info.nightscout.database.entities.UserEntry.Sources
import info.nightscout.interfaces.AndroidPermission import info.nightscout.interfaces.AndroidPermission

View file

@ -24,7 +24,7 @@ import info.nightscout.androidaps.services.AlarmSoundServiceHelper
import info.nightscout.androidaps.utils.ProcessLifecycleListener import info.nightscout.androidaps.utils.ProcessLifecycleListener
import info.nightscout.core.ui.locale.LocaleHelper import info.nightscout.core.ui.locale.LocaleHelper
import info.nightscout.core.utils.receivers.NetworkChangeReceiver import info.nightscout.core.utils.receivers.NetworkChangeReceiver
import info.nightscout.core.versionChecker.VersionCheckerUtils import info.nightscout.interfaces.versionChecker.VersionCheckerUtils
import info.nightscout.database.entities.TherapyEvent import info.nightscout.database.entities.TherapyEvent
import info.nightscout.database.entities.UserEntry import info.nightscout.database.entities.UserEntry
import info.nightscout.database.impl.AppRepository import info.nightscout.database.impl.AppRepository

View file

@ -22,6 +22,7 @@ import info.nightscout.database.impl.DatabaseModule
import info.nightscout.implementation.di.ImplementationModule import info.nightscout.implementation.di.ImplementationModule
import info.nightscout.plugins.aps.di.ApsModule import info.nightscout.plugins.aps.di.ApsModule
import info.nightscout.plugins.di.PluginsModule import info.nightscout.plugins.di.PluginsModule
import info.nightscout.plugins.support.di.PluginsSupportModule
import info.nightscout.pump.combo.di.ComboModule import info.nightscout.pump.combo.di.ComboModule
import info.nightscout.pump.combov2.di.ComboV2Module import info.nightscout.pump.combov2.di.ComboV2Module
import info.nightscout.pump.common.di.PumpCommonModule import info.nightscout.pump.common.di.PumpCommonModule
@ -65,6 +66,8 @@ import javax.inject.Singleton
SharedImplModule::class, SharedImplModule::class,
UiModule::class, UiModule::class,
ValidatorsModule::class, ValidatorsModule::class,
PluginsSupportModule::class,
PluginsSupportModule.Bindings::class,
// pumps // pumps
ComboModule::class, ComboModule::class,

View file

@ -267,7 +267,7 @@ abstract class PluginsListModule {
@NotNSClient @NotNSClient
@IntoMap @IntoMap
@IntKey(270) @IntKey(270)
abstract fun bindVersionCheckerPlugin(plugin: VersionCheckerPlugin): PluginBase abstract fun bindVersionCheckerPlugin(plugin: info.nightscout.plugins.constraints.versionChecker.VersionCheckerPlugin): PluginBase
@Binds @Binds
@NotNSClient @NotNSClient
@ -279,7 +279,7 @@ abstract class PluginsListModule {
@APS @APS
@IntoMap @IntoMap
@IntKey(290) @IntKey(290)
abstract fun bindStorageConstraintPlugin(plugin: StorageConstraintPlugin): PluginBase abstract fun bindStorageConstraintPlugin(plugin: info.nightscout.plugins.constraints.storage.StorageConstraintPlugin): PluginBase
@Binds @Binds
@APS @APS
@ -339,7 +339,7 @@ abstract class PluginsListModule {
@AllConfigs @AllConfigs
@IntoMap @IntoMap
@IntKey(380) @IntKey(380)
abstract fun bindDstHelperPlugin(plugin: DstHelperPlugin): PluginBase abstract fun bindDstHelperPlugin(plugin: info.nightscout.plugins.constraints.dstHelper.DstHelperPlugin): PluginBase
@Binds @Binds
@AllConfigs @AllConfigs

View file

@ -259,16 +259,6 @@
<string name="prefdecrypt_issue_wrong_format">Missing encryption configuration, settings format is invalid!</string> <string name="prefdecrypt_issue_wrong_format">Missing encryption configuration, settings format is invalid!</string>
<string name="prefdecrypt_issue_wrong_algorithm">Unsupported or not specified encryption algorithm!</string> <string name="prefdecrypt_issue_wrong_algorithm">Unsupported or not specified encryption algorithm!</string>
<!-- VersionChecker -->
<string name="key_last_time_this_version_detected_as_ok" translatable="false">last_time_this_version_detected</string>
<string name="key_last_versionchecker_warning" translatable="false">last_versionchecker_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_revoked_certs_check" translatable="false">last_revoked_certs_check</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="version_expire">Version %1$s expire on %2$s</string>
<!-- Permissions --> <!-- Permissions -->
<string name="alert_dialog_storage_permission_text">Please reboot your phone or restart AAPS from the System Settings \notherwise Android APS will not have logging (important to track and verify that the algorithms are working correctly)!</string> <string name="alert_dialog_storage_permission_text">Please reboot your phone or restart AAPS from the System Settings \notherwise Android APS will not have logging (important to track and verify that the algorithms are working correctly)!</string>

View file

@ -3,7 +3,7 @@ package info.nightscout.androidaps.plugins.contraints.versionChecker
import dagger.Lazy import dagger.Lazy
import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.TestBase
import info.nightscout.core.utils.receivers.ReceiverStatusStore import info.nightscout.core.utils.receivers.ReceiverStatusStore
import info.nightscout.core.versionChecker.VersionCheckerUtils import info.nightscout.interfaces.versionChecker.VersionCheckerUtils
import info.nightscout.core.versionChecker.numericVersionPart import info.nightscout.core.versionChecker.numericVersionPart
import info.nightscout.interfaces.Config import info.nightscout.interfaces.Config
import info.nightscout.rx.bus.RxBus import info.nightscout.rx.bus.RxBus

View file

@ -0,0 +1,10 @@
package info.nightscout.interfaces.versionChecker
interface VersionCheckerUtils {
fun triggerCheckVersion()
fun compareWithCurrentVersion(newVersion: String?, currentVersion: String)
fun versionDigits(versionString: String?): IntArray
fun findVersion(file: String?): String?
}

View file

@ -23,6 +23,7 @@
<string name="mgdl">mg/dl</string> <string name="mgdl">mg/dl</string>
<string name="mmol">mmol/l</string> <string name="mmol">mmol/l</string>
<string name="save">Save</string> <string name="save">Save</string>
<string name="snooze">Snooze</string>
<!-- Pumps --> <!-- Pumps -->
<string name="battery_label">Battery</string> <string name="battery_label">Battery</string>

View file

@ -7,7 +7,7 @@ import dagger.Reusable
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.annotations.OpenForTesting
import info.nightscout.androidaps.plugins.general.maintenance.formats.EncryptedPrefsFormat import info.nightscout.androidaps.plugins.general.maintenance.formats.EncryptedPrefsFormat
import info.nightscout.core.main.R import info.nightscout.core.main.R
import info.nightscout.core.versionChecker.VersionCheckerUtils import info.nightscout.interfaces.versionChecker.VersionCheckerUtils
import info.nightscout.interfaces.Config import info.nightscout.interfaces.Config
import info.nightscout.interfaces.maintenance.PrefFileListProvider import info.nightscout.interfaces.maintenance.PrefFileListProvider
import info.nightscout.interfaces.maintenance.PrefMetadata import info.nightscout.interfaces.maintenance.PrefMetadata

View file

@ -46,9 +46,6 @@ dependencies {
api "com.squareup.retrofit2:converter-gson:$retrofit2_version" api "com.squareup.retrofit2:converter-gson:$retrofit2_version"
// Phone checker
api 'com.scottyab:rootbeer-lib:0.1.0'
//SmsCommunicator //SmsCommunicator
api 'com.eatthepath:java-otp:0.3.1' api 'com.eatthepath:java-otp:0.3.1'
api 'com.github.kenglxn.QRGen:android:2.6.0' api 'com.github.kenglxn.QRGen:android:2.6.0'

View file

@ -203,31 +203,6 @@
<string name="a11y_bg_quality_recalculated">recalculated</string> <string name="a11y_bg_quality_recalculated">recalculated</string>
<string name="a11y_bg_quality_doubles">double entries</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 --> <!-- Objectives -->
<string name="key_objectives_bg_is_available_in_ns" translatable="false">ObjectivesbgIsAvailableInNS</string> <string name="key_objectives_bg_is_available_in_ns" translatable="false">ObjectivesbgIsAvailableInNS</string>
<string name="key_objectives_pump_status_is_available_in_ns" translatable="false">ObjectivespumpStatusIsAvailableInNS</string> <string name="key_objectives_pump_status_is_available_in_ns" translatable="false">ObjectivespumpStatusIsAvailableInNS</string>
@ -289,7 +264,6 @@
<string name="key_statuslights_copy_ns" translatable="false">statuslights_copy_ns</string> <string name="key_statuslights_copy_ns" translatable="false">statuslights_copy_ns</string>
<string name="key_statuslights_overview_advanced" translatable="false">statuslights_overview_advanced</string> <string name="key_statuslights_overview_advanced" translatable="false">statuslights_overview_advanced</string>
<string name="snooze">Snooze</string>
<string name="copy_existing_values">Copy NS settings (if exists)?</string> <string name="copy_existing_values">Copy NS settings (if exists)?</string>
<string name="key_show_statuslights" translatable="false">show_statuslights</string> <string name="key_show_statuslights" translatable="false">show_statuslights</string>
<string name="show_statuslights">Show status lights on home screen</string> <string name="show_statuslights">Show status lights on home screen</string>

View file

@ -24,13 +24,13 @@ class DstHelperPluginTest : TestBase() {
@Mock lateinit var activePlugin: ActivePlugin @Mock lateinit var activePlugin: ActivePlugin
@Mock lateinit var loop: Loop @Mock lateinit var loop: Loop
private lateinit var plugin: DstHelperPlugin private lateinit var plugin: info.nightscout.plugins.constraints.dstHelper.DstHelperPlugin
val injector = HasAndroidInjector { AndroidInjector { } } val injector = HasAndroidInjector { AndroidInjector { } }
@Before @Before
fun mock() { fun mock() {
plugin = DstHelperPlugin(injector, aapsLogger, rh, sp, activePlugin, loop) plugin = info.nightscout.plugins.constraints.dstHelper.DstHelperPlugin(injector, aapsLogger, rh, sp, activePlugin, loop)
} }
@Test @Test

View file

@ -22,7 +22,7 @@ class SignatureVerifierPluginTest : TestBase() {
@Test @Test
fun singleCharUnMapTest() { fun singleCharUnMapTest() {
val plugin = SignatureVerifierPlugin(injector, aapsLogger, rh, sp, rxBus, context) val plugin = info.nightscout.plugins.constraints.signatureVerifier.SignatureVerifierPlugin(injector, aapsLogger, rh, sp, rxBus, context)
val key = "2ΙšÄΠΒϨÒÇeЄtЄЗž-*Ж*ZcHijЊÄœ<|x\"Ε" val key = "2ΙšÄΠΒϨÒÇeЄtЄЗž-*Ж*ZcHijЊÄœ<|x\"Ε"
val unmapped = plugin.singleCharUnMap(key) val unmapped = plugin.singleCharUnMap(key)
Assert.assertEquals("32:99:61:C4:A0:92:E8:D2:C7:65:04:74:04:17:7E:2D:2A:16:2A:5A:63:48:69:6A:0A:C4:53:3C:7C:78:22:95", unmapped) Assert.assertEquals("32:99:61:C4:A0:92:E8:D2:C7:65:04:74:04:17:7E:2D:2A:16:2A:5A:63:48:69:6A:0A:C4:53:3C:7C:78:22:95", unmapped)

View file

@ -20,10 +20,10 @@ class StorageConstraintPluginTest : TestBase() {
@Mock lateinit var rh: ResourceHelper @Mock lateinit var rh: ResourceHelper
private val rxBusWrapper = RxBus(aapsSchedulers, aapsLogger) private val rxBusWrapper = RxBus(aapsSchedulers, aapsLogger)
private lateinit var storageConstraintPlugin: StorageConstraintPlugin private lateinit var storageConstraintPlugin: info.nightscout.plugins.constraints.storage.StorageConstraintPlugin
@Before fun prepareMock() { @Before fun prepareMock() {
storageConstraintPlugin = StorageConstraintPlugin({ AndroidInjector { } }, aapsLogger, rh, rxBusWrapper) storageConstraintPlugin = info.nightscout.plugins.constraints.storage.StorageConstraintPlugin({ AndroidInjector { } }, aapsLogger, rh, rxBusWrapper)
`when`(rh.gs(anyInt(), anyLong())).thenReturn("") `when`(rh.gs(anyInt(), anyLong())).thenReturn("")
} }
@ -32,7 +32,7 @@ class StorageConstraintPluginTest : TestBase() {
aapsLogger: AAPSLogger, aapsLogger: AAPSLogger,
rh: ResourceHelper, rh: ResourceHelper,
rxBus: RxBus rxBus: RxBus
) : StorageConstraintPlugin(injector, aapsLogger, rh, rxBus) { ) : info.nightscout.plugins.constraints.storage.StorageConstraintPlugin(injector, aapsLogger, rh, rxBus) {
var memSize = 150L var memSize = 150L
override fun availableInternalMemorySize(): Long = memSize override fun availableInternalMemorySize(): Long = memSize

1
plugins/support/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/build

View file

@ -0,0 +1,27 @@
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'kotlin-kapt'
id 'kotlin-allopen'
id 'com.hiya.jacoco-android'
}
apply from: "${project.rootDir}/core/core-main/android_dependencies.gradle"
apply from: "${project.rootDir}/core/core-main/android_module_dependencies.gradle"
apply from: "${project.rootDir}/core/core-main/test_dependencies.gradle"
apply from: "${project.rootDir}/core/core-main/allopen_dependencies.gradle"
apply from: "${project.rootDir}/core/core-main/jacoco_global.gradle"
android {
namespace 'info.nightscout.plugins.support'
}
dependencies {
implementation project(':app-wear-shared:shared')
implementation project(':core:interfaces')
implementation project(':core:ui')
implementation project(':core:utils')
// Phone checker
api 'com.scottyab:rootbeer-lib:0.1.0'
}

View file

21
plugins/support/proguard-rules.pro vendored Normal file
View file

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>

View file

@ -9,7 +9,7 @@ import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginBase
import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginDescription
import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.plugin.PluginType
import info.nightscout.plugins.R import info.nightscout.plugins.support.R
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag import info.nightscout.rx.logging.LTag
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
@ -79,13 +79,13 @@ class DstHelperPlugin @Inject constructor(
return value return value
} }
fun wasDST(now: Calendar): Boolean { private fun wasDST(now: Calendar): Boolean {
val ago = now.clone() as Calendar val ago = now.clone() as Calendar
ago.add(Calendar.HOUR, DISABLE_TIME_FRAME_HOURS) ago.add(Calendar.HOUR, DISABLE_TIME_FRAME_HOURS)
return now[Calendar.DST_OFFSET] != ago[Calendar.DST_OFFSET] return now[Calendar.DST_OFFSET] != ago[Calendar.DST_OFFSET]
} }
fun willBeDST(now: Calendar): Boolean { private fun willBeDST(now: Calendar): Boolean {
val ago = now.clone() as Calendar val ago = now.clone() as Calendar
ago.add(Calendar.HOUR, WARN_PRIOR_TIME_FRAME_HOURS) ago.add(Calendar.HOUR, WARN_PRIOR_TIME_FRAME_HOURS)
return now[Calendar.DST_OFFSET] != ago[Calendar.DST_OFFSET] return now[Calendar.DST_OFFSET] != ago[Calendar.DST_OFFSET]

View file

@ -8,7 +8,7 @@ import info.nightscout.interfaces.constraints.Constraints
import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginBase
import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginDescription
import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.plugin.PluginType
import info.nightscout.plugins.R import info.nightscout.plugins.support.R
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import javax.inject.Inject import javax.inject.Inject

View file

@ -5,15 +5,14 @@ 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.core.events.EventNewNotification
import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.constraints.Constraints
import info.nightscout.interfaces.notifications.Notification import info.nightscout.interfaces.notifications.Notification
import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginBase
import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginDescription
import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.plugin.PluginType
import info.nightscout.plugins.R import info.nightscout.interfaces.ui.ActivityNames
import info.nightscout.rx.bus.RxBus import info.nightscout.plugins.support.R
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
@ -45,8 +44,8 @@ class SignatureVerifierPlugin @Inject constructor(
aapsLogger: AAPSLogger, aapsLogger: AAPSLogger,
rh: ResourceHelper, rh: ResourceHelper,
private val sp: SP, private val sp: SP,
private val rxBus: RxBus, private val context: Context,
private val context: Context private val activityNames: ActivityNames
) : PluginBase( ) : PluginBase(
PluginDescription() PluginDescription()
.mainType(PluginType.CONSTRAINTS) .mainType(PluginType.CONSTRAINTS)
@ -104,8 +103,7 @@ class SignatureVerifierPlugin @Inject constructor(
} }
private fun showNotification() { private fun showNotification() {
val notification = Notification(Notification.INVALID_VERSION, rh.gs(R.string.running_invalid_version), Notification.URGENT) activityNames.addNotification(Notification.INVALID_VERSION, rh.gs(R.string.running_invalid_version), Notification.URGENT)
rxBus.send(EventNewNotification(notification))
} }
private fun hasIllegalSignature(): Boolean { private fun hasIllegalSignature(): Boolean {
@ -170,6 +168,7 @@ class SignatureVerifierPlugin @Inject constructor(
return sb.toString() return sb.toString()
} }
/*
fun singleCharUnMap(shortHash: String): String { fun singleCharUnMap(shortHash: String): String {
val array = ByteArray(shortHash.length) val array = ByteArray(shortHash.length)
val sb = StringBuilder() val sb = StringBuilder()
@ -179,6 +178,7 @@ class SignatureVerifierPlugin @Inject constructor(
} }
return sb.toString() return sb.toString()
} }
*/
private fun shouldDownloadCerts(): Boolean { private fun shouldDownloadCerts(): Boolean {
return System.currentTimeMillis() - sp.getLong(R.string.key_last_revoked_certs_check, 0L) >= UPDATE_INTERVAL return System.currentTimeMillis() - sp.getLong(R.string.key_last_revoked_certs_check, 0L) >= UPDATE_INTERVAL

View file

@ -4,7 +4,6 @@ import android.os.Environment
import android.os.StatFs import android.os.StatFs
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.annotations.OpenForTesting
import info.nightscout.core.events.EventNewNotification
import info.nightscout.interfaces.Constants import info.nightscout.interfaces.Constants
import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.constraints.Constraints
@ -12,8 +11,8 @@ import info.nightscout.interfaces.notifications.Notification
import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginBase
import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginDescription
import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.plugin.PluginType
import info.nightscout.plugins.R import info.nightscout.interfaces.ui.ActivityNames
import info.nightscout.rx.bus.RxBus import info.nightscout.plugins.support.R
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag import info.nightscout.rx.logging.LTag
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
@ -26,7 +25,7 @@ class StorageConstraintPlugin @Inject constructor(
injector: HasAndroidInjector, injector: HasAndroidInjector,
aapsLogger: AAPSLogger, aapsLogger: AAPSLogger,
rh: ResourceHelper, rh: ResourceHelper,
private val rxBus: RxBus private val activeNames: ActivityNames
) : PluginBase( ) : PluginBase(
PluginDescription() PluginDescription()
.mainType(PluginType.CONSTRAINTS) .mainType(PluginType.CONSTRAINTS)
@ -42,8 +41,7 @@ class StorageConstraintPlugin @Inject constructor(
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.disk_full, 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.disk_full, Constants.MINIMUM_FREE_SPACE), Notification.NORMAL) activeNames.addNotification(Notification.DISK_FULL, rh.gs(R.string.disk_full, Constants.MINIMUM_FREE_SPACE), Notification.NORMAL)
rxBus.send(EventNewNotification(notification))
} }
return value return value
} }

View file

@ -1,8 +1,6 @@
package info.nightscout.plugins.constraints.versionChecker package info.nightscout.plugins.constraints.versionChecker
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.core.events.EventNewNotification
import info.nightscout.core.versionChecker.VersionCheckerUtils
import info.nightscout.interfaces.Config import info.nightscout.interfaces.Config
import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.constraints.Constraints
@ -10,7 +8,9 @@ import info.nightscout.interfaces.notifications.Notification
import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginBase
import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginDescription
import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.plugin.PluginType
import info.nightscout.plugins.R import info.nightscout.interfaces.ui.ActivityNames
import info.nightscout.interfaces.versionChecker.VersionCheckerUtils
import info.nightscout.plugins.support.R
import info.nightscout.rx.bus.RxBus import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
@ -30,7 +30,8 @@ class VersionCheckerPlugin @Inject constructor(
val rxBus: RxBus, val rxBus: RxBus,
aapsLogger: AAPSLogger, aapsLogger: AAPSLogger,
private val config: Config, private val config: Config,
private val dateUtil: DateUtil private val dateUtil: DateUtil,
private val activityNames: ActivityNames
) : PluginBase( ) : PluginBase(
PluginDescription() PluginDescription()
.mainType(PluginType.CONSTRAINTS) .mainType(PluginType.CONSTRAINTS)
@ -95,7 +96,7 @@ class VersionCheckerPlugin @Inject constructor(
gracePeriod.old, gracePeriod.old,
gracePeriod.veryOld gracePeriod.veryOld
) )
rxBus.send(EventNewNotification(Notification(Notification.OLD_VERSION, message, Notification.NORMAL))) activityNames.addNotification(Notification.OLD_VERSION, message, Notification.NORMAL)
} }
val endDate = sp.getLong(rh.gs(R.string.key_app_expiration) + "_" + config.VERSION_NAME, 0) val endDate = sp.getLong(rh.gs(R.string.key_app_expiration) + "_" + config.VERSION_NAME, 0)
@ -104,7 +105,7 @@ class VersionCheckerPlugin @Inject constructor(
sp.putLong(R.string.key_last_versionchecker_plugin_warning, now) sp.putLong(R.string.key_last_versionchecker_plugin_warning, now)
//notify //notify
rxBus.send(EventNewNotification(Notification(Notification.VERSION_EXPIRE, rh.gs(R.string.application_expired), Notification.URGENT))) activityNames.addNotification(Notification.VERSION_EXPIRE, rh.gs(R.string.application_expired), Notification.URGENT)
} }
} }

View file

@ -1,14 +1,14 @@
package info.nightscout.core.versionChecker package info.nightscout.plugins.constraints.versionChecker
import android.os.Build import android.os.Build
import dagger.Lazy import dagger.Lazy
import info.nightscout.core.events.EventNewNotification
import info.nightscout.core.main.R
import info.nightscout.core.utils.receivers.ReceiverStatusStore import info.nightscout.core.utils.receivers.ReceiverStatusStore
import info.nightscout.interfaces.Config import info.nightscout.interfaces.Config
import info.nightscout.interfaces.constraints.versionChecker.AllowedVersions import info.nightscout.interfaces.constraints.versionChecker.AllowedVersions
import info.nightscout.interfaces.notifications.Notification import info.nightscout.interfaces.notifications.Notification
import info.nightscout.rx.bus.RxBus import info.nightscout.interfaces.ui.ActivityNames
import info.nightscout.interfaces.versionChecker.VersionCheckerUtils
import info.nightscout.plugins.support.R
import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag import info.nightscout.rx.logging.LTag
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
@ -22,19 +22,19 @@ import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@Singleton @Singleton
class VersionCheckerUtils @Inject constructor( class VersionCheckerUtilsImpl @Inject constructor(
private val aapsLogger: AAPSLogger, private val aapsLogger: AAPSLogger,
private val sp: SP, private val sp: SP,
private val rh: ResourceHelper, private val rh: ResourceHelper,
private val rxBus: RxBus,
private val config: Lazy<Config>, private val config: Lazy<Config>,
private val receiverStatusStore: ReceiverStatusStore, private val receiverStatusStore: ReceiverStatusStore,
private val dateUtil: DateUtil private val dateUtil: DateUtil,
) { private val activityNames: ActivityNames
) : VersionCheckerUtils {
private fun isConnected(): Boolean = receiverStatusStore.isConnected private fun isConnected(): Boolean = receiverStatusStore.isConnected
fun triggerCheckVersion() { override fun triggerCheckVersion() {
if (!sp.contains(R.string.key_last_time_this_version_detected_as_ok)) { if (!sp.contains(R.string.key_last_time_this_version_detected_as_ok)) {
// On a new installation, set it as 30 days old in order to warn that there is a new version. // On a new installation, set it as 30 days old in order to warn that there is a new version.
@ -73,7 +73,7 @@ class VersionCheckerUtils @Inject constructor(
aapsLogger.debug(LTag.CORE, "Github master version not checked. No connectivity") aapsLogger.debug(LTag.CORE, "Github master version not checked. No connectivity")
@Suppress("SameParameterValue") @Suppress("SameParameterValue")
internal fun compareWithCurrentVersion(newVersion: String?, currentVersion: String) { override fun compareWithCurrentVersion(newVersion: String?, currentVersion: String) {
val newVersionElements = newVersion.toNumberList() val newVersionElements = newVersion.toNumberList()
val currentVersionElements = currentVersion.toNumberList() val currentVersionElements = currentVersion.toNumberList()
@ -121,7 +121,7 @@ class VersionCheckerUtils @Inject constructor(
val now = dateUtil.now() val now = dateUtil.now()
if (now > sp.getLong(R.string.key_last_versionchecker_warning, 0) + WARN_EVERY) { if (now > sp.getLong(R.string.key_last_versionchecker_warning, 0) + WARN_EVERY) {
aapsLogger.debug(LTag.CORE, "Version $currentVersion outdated. Found $newVersion") aapsLogger.debug(LTag.CORE, "Version $currentVersion outdated. Found $newVersion")
rxBus.send(EventNewNotification(Notification(Notification.NEW_VERSION_DETECTED, rh.gs(R.string.versionavailable, newVersion.toString()), Notification.LOW))) activityNames.addNotification(Notification.NEW_VERSION_DETECTED, rh.gs(R.string.versionavailable, newVersion.toString()), Notification.LOW)
sp.putLong(R.string.key_last_versionchecker_warning, now) sp.putLong(R.string.key_last_versionchecker_warning, now)
} }
} }
@ -130,7 +130,7 @@ class VersionCheckerUtils @Inject constructor(
val now = dateUtil.now() val now = dateUtil.now()
if (now > sp.getLong(R.string.key_last_expired_versionchecker_warning, 0) + WARN_EVERY) { if (now > sp.getLong(R.string.key_last_expired_versionchecker_warning, 0) + WARN_EVERY) {
aapsLogger.debug(LTag.CORE, rh.gs(R.string.version_expire, currentVersion, endDate)) aapsLogger.debug(LTag.CORE, rh.gs(R.string.version_expire, currentVersion, endDate))
rxBus.send(EventNewNotification(Notification(Notification.VERSION_EXPIRE, rh.gs(R.string.version_expire, currentVersion, endDate), Notification.LOW))) activityNames.addNotification(Notification.VERSION_EXPIRE, rh.gs(R.string.version_expire, currentVersion, endDate), Notification.LOW)
sp.putLong(R.string.key_last_expired_versionchecker_warning, now) sp.putLong(R.string.key_last_expired_versionchecker_warning, now)
} }
} }
@ -138,7 +138,7 @@ class VersionCheckerUtils @Inject constructor(
private fun String?.toNumberList() = private fun String?.toNumberList() =
this?.numericVersionPart().takeIf { !it.isNullOrBlank() }?.split(".")?.map { it.toInt() } this?.numericVersionPart().takeIf { !it.isNullOrBlank() }?.split(".")?.map { it.toInt() }
fun versionDigits(versionString: String?): IntArray { override fun versionDigits(versionString: String?): IntArray {
val digits = mutableListOf<Int>() val digits = mutableListOf<Int>()
versionString?.numericVersionPart().toNumberList()?.let { versionString?.numericVersionPart().toNumberList()?.let {
digits.addAll(it.take(4)) digits.addAll(it.take(4))
@ -146,7 +146,7 @@ class VersionCheckerUtils @Inject constructor(
return digits.toIntArray() return digits.toIntArray()
} }
internal fun findVersion(file: String?): String? { override fun findVersion(file: String?): String? {
val regex = "(.*)version(.*)\"(((\\d+)\\.)+(\\d+))\"(.*)".toRegex() val regex = "(.*)version(.*)\"(((\\d+)\\.)+(\\d+))\"(.*)".toRegex()
return file?.lines()?.filter { regex.matches(it) }?.firstNotNullOfOrNull { regex.matchEntire(it)?.groupValues?.getOrNull(3) } return file?.lines()?.filter { regex.matches(it) }?.firstNotNullOfOrNull { regex.matchEntire(it)?.groupValues?.getOrNull(3) }
} }

View file

@ -0,0 +1,21 @@
package info.nightscout.plugins.support.di
import dagger.Binds
import dagger.Module
import info.nightscout.interfaces.versionChecker.VersionCheckerUtils
import info.nightscout.plugins.constraints.versionChecker.VersionCheckerUtilsImpl
@Module(
includes = [
]
)
@Suppress("unused")
abstract class PluginsSupportModule {
@Module
interface Bindings {
@Binds fun bindProcessedDeviceStatusData(versionCheckerUtils: VersionCheckerUtilsImpl): VersionCheckerUtils
}
}

View file

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- PhoneChecker -->
<string name="phone_checker" translatable="false">PhoneChecker</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>
<!-- 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>
<string name="key_last_time_this_version_detected_as_ok" translatable="false">last_time_this_version_detected</string>
<string name="key_last_versionchecker_warning" translatable="false">last_versionchecker_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_revoked_certs_check" translatable="false">last_revoked_certs_check</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="version_expire">Version %1$s expire on %2$s</string>
<!-- Signature verifier -->
<string name="signature_verifier" translatable="false">Signature verifier</string>
</resources>

View file

@ -21,6 +21,7 @@ include ':plugins:configuration'
include ':plugins:main' include ':plugins:main'
include ':plugins:openhumans' include ':plugins:openhumans'
include ':plugins:sensitivity' include ':plugins:sensitivity'
include ':plugins:support'
include ':pump:combo' include ':pump:combo'
include ':pump:combov2' include ':pump:combov2'
include ':pump:combov2:comboctl' include ':pump:combov2:comboctl'