diff --git a/app/build.gradle b/app/build.gradle index ec79ad34e9..6e818131e5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -201,6 +201,7 @@ dependencies { implementation project(':plugins:main') implementation project(':plugins:openhumans') implementation project(':plugins:sensitivity') + implementation project(':plugins:support') implementation project(':implementation') implementation project(':database:entities') implementation project(':database:impl') diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt index f911c8ba84..4a1232daec 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt @@ -42,7 +42,7 @@ import info.nightscout.core.ui.toast.ToastUtils import info.nightscout.core.utils.CryptoUtil import info.nightscout.core.utils.fabric.FabricPrivacy 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.Sources import info.nightscout.interfaces.AndroidPermission diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.kt b/app/src/main/java/info/nightscout/androidaps/MainApp.kt index 202c36e034..9778886116 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.kt +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.kt @@ -24,7 +24,7 @@ import info.nightscout.androidaps.services.AlarmSoundServiceHelper import info.nightscout.androidaps.utils.ProcessLifecycleListener import info.nightscout.core.ui.locale.LocaleHelper 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.UserEntry import info.nightscout.database.impl.AppRepository 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 a989fc87f5..05fce0f281 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.database.impl.DatabaseModule import info.nightscout.implementation.di.ImplementationModule import info.nightscout.plugins.aps.di.ApsModule import info.nightscout.plugins.di.PluginsModule +import info.nightscout.plugins.support.di.PluginsSupportModule import info.nightscout.pump.combo.di.ComboModule import info.nightscout.pump.combov2.di.ComboV2Module import info.nightscout.pump.common.di.PumpCommonModule @@ -65,6 +66,8 @@ import javax.inject.Singleton SharedImplModule::class, UiModule::class, ValidatorsModule::class, + PluginsSupportModule::class, + PluginsSupportModule.Bindings::class, // pumps ComboModule::class, diff --git a/app/src/main/java/info/nightscout/androidaps/di/PluginsListModule.kt b/app/src/main/java/info/nightscout/androidaps/di/PluginsListModule.kt index a37c95e2e6..a315e1b9f4 100644 --- a/app/src/main/java/info/nightscout/androidaps/di/PluginsListModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/di/PluginsListModule.kt @@ -267,7 +267,7 @@ abstract class PluginsListModule { @NotNSClient @IntoMap @IntKey(270) - abstract fun bindVersionCheckerPlugin(plugin: VersionCheckerPlugin): PluginBase + abstract fun bindVersionCheckerPlugin(plugin: info.nightscout.plugins.constraints.versionChecker.VersionCheckerPlugin): PluginBase @Binds @NotNSClient @@ -279,7 +279,7 @@ abstract class PluginsListModule { @APS @IntoMap @IntKey(290) - abstract fun bindStorageConstraintPlugin(plugin: StorageConstraintPlugin): PluginBase + abstract fun bindStorageConstraintPlugin(plugin: info.nightscout.plugins.constraints.storage.StorageConstraintPlugin): PluginBase @Binds @APS @@ -339,7 +339,7 @@ abstract class PluginsListModule { @AllConfigs @IntoMap @IntKey(380) - abstract fun bindDstHelperPlugin(plugin: DstHelperPlugin): PluginBase + abstract fun bindDstHelperPlugin(plugin: info.nightscout.plugins.constraints.dstHelper.DstHelperPlugin): PluginBase @Binds @AllConfigs diff --git a/core/core-main/src/main/res/values/strings.xml b/core/core-main/src/main/res/values/strings.xml index bd869c91b0..2e1d9d8670 100644 --- a/core/core-main/src/main/res/values/strings.xml +++ b/core/core-main/src/main/res/values/strings.xml @@ -259,16 +259,6 @@ Missing encryption configuration, settings format is invalid! Unsupported or not specified encryption algorithm! - - last_time_this_version_detected - last_versionchecker_warning - last_expired_version_checker_warning - last_versionchecker_plugin_waring - last_revoked_certs_check - We have detected that you are running an invalid version. Loop disabled! - Version %1$s available - Version %1$s expire on %2$s - 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)! diff --git a/core/core-main/src/test/java/info/nightscout/androidaps/plugins/contraints/versionChecker/VersionCheckerUtilsKtTest.kt b/core/core-main/src/test/java/info/nightscout/androidaps/plugins/contraints/versionChecker/VersionCheckerUtilsKtTest.kt index 1777c033e5..068ce45542 100644 --- a/core/core-main/src/test/java/info/nightscout/androidaps/plugins/contraints/versionChecker/VersionCheckerUtilsKtTest.kt +++ b/core/core-main/src/test/java/info/nightscout/androidaps/plugins/contraints/versionChecker/VersionCheckerUtilsKtTest.kt @@ -3,7 +3,7 @@ package info.nightscout.androidaps.plugins.contraints.versionChecker import dagger.Lazy import info.nightscout.androidaps.TestBase 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.interfaces.Config import info.nightscout.rx.bus.RxBus diff --git a/core/interfaces/src/main/java/info/nightscout/interfaces/versionChecker/VersionCheckerUtils.kt b/core/interfaces/src/main/java/info/nightscout/interfaces/versionChecker/VersionCheckerUtils.kt new file mode 100644 index 0000000000..106ef9e9bd --- /dev/null +++ b/core/interfaces/src/main/java/info/nightscout/interfaces/versionChecker/VersionCheckerUtils.kt @@ -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? + +} \ No newline at end of file diff --git a/core/ui/src/main/res/values/strings.xml b/core/ui/src/main/res/values/strings.xml index 9a45041549..a2083b818c 100644 --- a/core/ui/src/main/res/values/strings.xml +++ b/core/ui/src/main/res/values/strings.xml @@ -23,6 +23,7 @@ mg/dl mmol/l Save + Snooze Battery diff --git a/implementation/src/main/java/info/nightscout/implementation/maintenance/PrefFileListProviderImpl.kt b/implementation/src/main/java/info/nightscout/implementation/maintenance/PrefFileListProviderImpl.kt index 97d3d0292b..09554293aa 100644 --- a/implementation/src/main/java/info/nightscout/implementation/maintenance/PrefFileListProviderImpl.kt +++ b/implementation/src/main/java/info/nightscout/implementation/maintenance/PrefFileListProviderImpl.kt @@ -7,7 +7,7 @@ import dagger.Reusable import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.plugins.general.maintenance.formats.EncryptedPrefsFormat 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.maintenance.PrefFileListProvider import info.nightscout.interfaces.maintenance.PrefMetadata diff --git a/plugins/main/build.gradle b/plugins/main/build.gradle index 0f66b012b7..e4e0a3c2bf 100644 --- a/plugins/main/build.gradle +++ b/plugins/main/build.gradle @@ -46,9 +46,6 @@ dependencies { api "com.squareup.retrofit2:converter-gson:$retrofit2_version" - // Phone checker - api 'com.scottyab:rootbeer-lib:0.1.0' - //SmsCommunicator api 'com.eatthepath:java-otp:0.3.1' api 'com.github.kenglxn.QRGen:android:2.6.0' diff --git a/plugins/main/src/main/res/values/strings.xml b/plugins/main/src/main/res/values/strings.xml index a79ec11cdb..e56c15916c 100644 --- a/plugins/main/src/main/res/values/strings.xml +++ b/plugins/main/src/main/res/values/strings.xml @@ -203,31 +203,6 @@ recalculated double entries - - snooze_dst_in24h - snooze_loop_disabled - - Daylight Saving time - Daylight Saving time change in 24h or less - Daylight Saving time change less than 3 hours ago - Closed loop disabled - - - Storage constraint - Free at least %1$d MB from internal storage! Loop disabled! - - - Signature verifier - - - Version Checker - old version - very old version - Application expired - New version for at least %1$d days available! Fallback to LGS after %2$d days, loop will be disabled after %3$d days - - - PhoneChecker - ObjectivesbgIsAvailableInNS ObjectivespumpStatusIsAvailableInNS @@ -289,7 +264,6 @@ statuslights_copy_ns statuslights_overview_advanced - Snooze Copy NS settings (if exists)? show_statuslights Show status lights on home screen diff --git a/plugins/main/src/test/java/info/nightscout/plugins/constraints/dstHelper/DstHelperPluginTest.kt b/plugins/main/src/test/java/info/nightscout/plugins/constraints/dstHelper/DstHelperPluginTest.kt index fc6565c187..db16b67350 100644 --- a/plugins/main/src/test/java/info/nightscout/plugins/constraints/dstHelper/DstHelperPluginTest.kt +++ b/plugins/main/src/test/java/info/nightscout/plugins/constraints/dstHelper/DstHelperPluginTest.kt @@ -24,13 +24,13 @@ class DstHelperPluginTest : TestBase() { @Mock lateinit var activePlugin: ActivePlugin @Mock lateinit var loop: Loop - private lateinit var plugin: DstHelperPlugin + private lateinit var plugin: info.nightscout.plugins.constraints.dstHelper.DstHelperPlugin val injector = HasAndroidInjector { AndroidInjector { } } @Before fun mock() { - plugin = DstHelperPlugin(injector, aapsLogger, rh, sp, activePlugin, loop) + plugin = info.nightscout.plugins.constraints.dstHelper.DstHelperPlugin(injector, aapsLogger, rh, sp, activePlugin, loop) } @Test diff --git a/plugins/main/src/test/java/info/nightscout/plugins/constraints/signatureVerifier/SignatureVerifierPluginTest.kt b/plugins/main/src/test/java/info/nightscout/plugins/constraints/signatureVerifier/SignatureVerifierPluginTest.kt index ba81af98bd..f76f7df142 100644 --- a/plugins/main/src/test/java/info/nightscout/plugins/constraints/signatureVerifier/SignatureVerifierPluginTest.kt +++ b/plugins/main/src/test/java/info/nightscout/plugins/constraints/signatureVerifier/SignatureVerifierPluginTest.kt @@ -22,7 +22,7 @@ class SignatureVerifierPluginTest : TestBase() { @Test 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 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) diff --git a/plugins/main/src/test/java/info/nightscout/plugins/constraints/storage/StorageConstraintPluginTest.kt b/plugins/main/src/test/java/info/nightscout/plugins/constraints/storage/StorageConstraintPluginTest.kt index 8eb0e6427a..fff1ed9911 100644 --- a/plugins/main/src/test/java/info/nightscout/plugins/constraints/storage/StorageConstraintPluginTest.kt +++ b/plugins/main/src/test/java/info/nightscout/plugins/constraints/storage/StorageConstraintPluginTest.kt @@ -20,10 +20,10 @@ class StorageConstraintPluginTest : TestBase() { @Mock lateinit var rh: ResourceHelper private val rxBusWrapper = RxBus(aapsSchedulers, aapsLogger) - private lateinit var storageConstraintPlugin: StorageConstraintPlugin + private lateinit var storageConstraintPlugin: info.nightscout.plugins.constraints.storage.StorageConstraintPlugin @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("") } @@ -32,7 +32,7 @@ class StorageConstraintPluginTest : TestBase() { aapsLogger: AAPSLogger, rh: ResourceHelper, rxBus: RxBus - ) : StorageConstraintPlugin(injector, aapsLogger, rh, rxBus) { + ) : info.nightscout.plugins.constraints.storage.StorageConstraintPlugin(injector, aapsLogger, rh, rxBus) { var memSize = 150L override fun availableInternalMemorySize(): Long = memSize diff --git a/plugins/support/.gitignore b/plugins/support/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/plugins/support/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/plugins/support/build.gradle b/plugins/support/build.gradle new file mode 100644 index 0000000000..4c4733d186 --- /dev/null +++ b/plugins/support/build.gradle @@ -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' + +} \ No newline at end of file diff --git a/plugins/support/consumer-rules.pro b/plugins/support/consumer-rules.pro new file mode 100644 index 0000000000..e69de29bb2 diff --git a/plugins/support/proguard-rules.pro b/plugins/support/proguard-rules.pro new file mode 100644 index 0000000000..481bb43481 --- /dev/null +++ b/plugins/support/proguard-rules.pro @@ -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 \ No newline at end of file diff --git a/plugins/support/src/main/AndroidManifest.xml b/plugins/support/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..a5918e68ab --- /dev/null +++ b/plugins/support/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/plugins/main/src/main/java/info/nightscout/plugins/constraints/dstHelper/DstHelperPlugin.kt b/plugins/support/src/main/java/info/nightscout/plugins/constraints/dstHelper/DstHelperPlugin.kt similarity index 96% rename from plugins/main/src/main/java/info/nightscout/plugins/constraints/dstHelper/DstHelperPlugin.kt rename to plugins/support/src/main/java/info/nightscout/plugins/constraints/dstHelper/DstHelperPlugin.kt index dbf1562014..49bfe97d9f 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/constraints/dstHelper/DstHelperPlugin.kt +++ b/plugins/support/src/main/java/info/nightscout/plugins/constraints/dstHelper/DstHelperPlugin.kt @@ -9,7 +9,7 @@ import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginDescription 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.LTag import info.nightscout.shared.interfaces.ResourceHelper @@ -79,13 +79,13 @@ class DstHelperPlugin @Inject constructor( return value } - fun wasDST(now: Calendar): Boolean { + private fun wasDST(now: Calendar): Boolean { val ago = now.clone() as Calendar ago.add(Calendar.HOUR, DISABLE_TIME_FRAME_HOURS) 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 ago.add(Calendar.HOUR, WARN_PRIOR_TIME_FRAME_HOURS) return now[Calendar.DST_OFFSET] != ago[Calendar.DST_OFFSET] diff --git a/plugins/main/src/main/java/info/nightscout/plugins/constraints/phoneChecker/PhoneCheckerPlugin.kt b/plugins/support/src/main/java/info/nightscout/plugins/constraints/phoneChecker/PhoneCheckerPlugin.kt similarity index 97% rename from plugins/main/src/main/java/info/nightscout/plugins/constraints/phoneChecker/PhoneCheckerPlugin.kt rename to plugins/support/src/main/java/info/nightscout/plugins/constraints/phoneChecker/PhoneCheckerPlugin.kt index c6a0cb9000..351738d076 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/constraints/phoneChecker/PhoneCheckerPlugin.kt +++ b/plugins/support/src/main/java/info/nightscout/plugins/constraints/phoneChecker/PhoneCheckerPlugin.kt @@ -8,7 +8,7 @@ import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginDescription 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.shared.interfaces.ResourceHelper import javax.inject.Inject diff --git a/plugins/main/src/main/java/info/nightscout/plugins/constraints/signatureVerifier/SignatureVerifierPlugin.kt b/plugins/support/src/main/java/info/nightscout/plugins/constraints/signatureVerifier/SignatureVerifierPlugin.kt similarity index 96% rename from plugins/main/src/main/java/info/nightscout/plugins/constraints/signatureVerifier/SignatureVerifierPlugin.kt rename to plugins/support/src/main/java/info/nightscout/plugins/constraints/signatureVerifier/SignatureVerifierPlugin.kt index 9ef27b5602..a0c4e3a0f6 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/constraints/signatureVerifier/SignatureVerifierPlugin.kt +++ b/plugins/support/src/main/java/info/nightscout/plugins/constraints/signatureVerifier/SignatureVerifierPlugin.kt @@ -5,15 +5,14 @@ import android.content.pm.PackageManager import android.os.Handler import android.os.HandlerThread import dagger.android.HasAndroidInjector -import info.nightscout.core.events.EventNewNotification import info.nightscout.interfaces.constraints.Constraint import info.nightscout.interfaces.constraints.Constraints import info.nightscout.interfaces.notifications.Notification import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginType -import info.nightscout.plugins.R -import info.nightscout.rx.bus.RxBus +import info.nightscout.interfaces.ui.ActivityNames +import info.nightscout.plugins.support.R import info.nightscout.rx.logging.AAPSLogger import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP @@ -45,8 +44,8 @@ class SignatureVerifierPlugin @Inject constructor( aapsLogger: AAPSLogger, rh: ResourceHelper, private val sp: SP, - private val rxBus: RxBus, - private val context: Context + private val context: Context, + private val activityNames: ActivityNames ) : PluginBase( PluginDescription() .mainType(PluginType.CONSTRAINTS) @@ -104,8 +103,7 @@ class SignatureVerifierPlugin @Inject constructor( } private fun showNotification() { - val notification = Notification(Notification.INVALID_VERSION, rh.gs(R.string.running_invalid_version), Notification.URGENT) - rxBus.send(EventNewNotification(notification)) + activityNames.addNotification(Notification.INVALID_VERSION, rh.gs(R.string.running_invalid_version), Notification.URGENT) } private fun hasIllegalSignature(): Boolean { @@ -170,6 +168,7 @@ class SignatureVerifierPlugin @Inject constructor( return sb.toString() } +/* fun singleCharUnMap(shortHash: String): String { val array = ByteArray(shortHash.length) val sb = StringBuilder() @@ -179,6 +178,7 @@ class SignatureVerifierPlugin @Inject constructor( } return sb.toString() } +*/ private fun shouldDownloadCerts(): Boolean { return System.currentTimeMillis() - sp.getLong(R.string.key_last_revoked_certs_check, 0L) >= UPDATE_INTERVAL diff --git a/plugins/main/src/main/java/info/nightscout/plugins/constraints/storage/StorageConstraintPlugin.kt b/plugins/support/src/main/java/info/nightscout/plugins/constraints/storage/StorageConstraintPlugin.kt similarity index 84% rename from plugins/main/src/main/java/info/nightscout/plugins/constraints/storage/StorageConstraintPlugin.kt rename to plugins/support/src/main/java/info/nightscout/plugins/constraints/storage/StorageConstraintPlugin.kt index aa467502e6..15cea33109 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/constraints/storage/StorageConstraintPlugin.kt +++ b/plugins/support/src/main/java/info/nightscout/plugins/constraints/storage/StorageConstraintPlugin.kt @@ -4,7 +4,6 @@ import android.os.Environment import android.os.StatFs import dagger.android.HasAndroidInjector import info.nightscout.androidaps.annotations.OpenForTesting -import info.nightscout.core.events.EventNewNotification import info.nightscout.interfaces.Constants import info.nightscout.interfaces.constraints.Constraint 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.PluginDescription import info.nightscout.interfaces.plugin.PluginType -import info.nightscout.plugins.R -import info.nightscout.rx.bus.RxBus +import info.nightscout.interfaces.ui.ActivityNames +import info.nightscout.plugins.support.R import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag import info.nightscout.shared.interfaces.ResourceHelper @@ -26,7 +25,7 @@ class StorageConstraintPlugin @Inject constructor( injector: HasAndroidInjector, aapsLogger: AAPSLogger, rh: ResourceHelper, - private val rxBus: RxBus + private val activeNames: ActivityNames ) : PluginBase( PluginDescription() .mainType(PluginType.CONSTRAINTS) @@ -42,8 +41,7 @@ class StorageConstraintPlugin @Inject constructor( if (diskFree < Constants.MINIMUM_FREE_SPACE) { 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) - val notification = Notification(Notification.DISK_FULL, rh.gs(R.string.disk_full, Constants.MINIMUM_FREE_SPACE), Notification.NORMAL) - rxBus.send(EventNewNotification(notification)) + activeNames.addNotification(Notification.DISK_FULL, rh.gs(R.string.disk_full, Constants.MINIMUM_FREE_SPACE), Notification.NORMAL) } return value } diff --git a/plugins/main/src/main/java/info/nightscout/plugins/constraints/versionChecker/VersionCheckerPlugin.kt b/plugins/support/src/main/java/info/nightscout/plugins/constraints/versionChecker/VersionCheckerPlugin.kt similarity index 89% rename from plugins/main/src/main/java/info/nightscout/plugins/constraints/versionChecker/VersionCheckerPlugin.kt rename to plugins/support/src/main/java/info/nightscout/plugins/constraints/versionChecker/VersionCheckerPlugin.kt index dd98cbb211..6dc3d9e4ad 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/constraints/versionChecker/VersionCheckerPlugin.kt +++ b/plugins/support/src/main/java/info/nightscout/plugins/constraints/versionChecker/VersionCheckerPlugin.kt @@ -1,8 +1,6 @@ package info.nightscout.plugins.constraints.versionChecker 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.constraints.Constraint 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.PluginDescription 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.logging.AAPSLogger import info.nightscout.shared.interfaces.ResourceHelper @@ -30,7 +30,8 @@ class VersionCheckerPlugin @Inject constructor( val rxBus: RxBus, aapsLogger: AAPSLogger, private val config: Config, - private val dateUtil: DateUtil + private val dateUtil: DateUtil, + private val activityNames: ActivityNames ) : PluginBase( PluginDescription() .mainType(PluginType.CONSTRAINTS) @@ -95,7 +96,7 @@ class VersionCheckerPlugin @Inject constructor( gracePeriod.old, 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) @@ -104,7 +105,7 @@ class VersionCheckerPlugin @Inject constructor( sp.putLong(R.string.key_last_versionchecker_plugin_warning, now) //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) } } diff --git a/core/core-main/src/main/java/info/nightscout/core/versionChecker/VersionCheckerUtils.kt b/plugins/support/src/main/java/info/nightscout/plugins/constraints/versionChecker/VersionCheckerUtilsImpl.kt similarity index 87% rename from core/core-main/src/main/java/info/nightscout/core/versionChecker/VersionCheckerUtils.kt rename to plugins/support/src/main/java/info/nightscout/plugins/constraints/versionChecker/VersionCheckerUtilsImpl.kt index 00132f3890..a3b97cf40c 100644 --- a/core/core-main/src/main/java/info/nightscout/core/versionChecker/VersionCheckerUtils.kt +++ b/plugins/support/src/main/java/info/nightscout/plugins/constraints/versionChecker/VersionCheckerUtilsImpl.kt @@ -1,14 +1,14 @@ -package info.nightscout.core.versionChecker +package info.nightscout.plugins.constraints.versionChecker import android.os.Build 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.interfaces.Config import info.nightscout.interfaces.constraints.versionChecker.AllowedVersions 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.LTag import info.nightscout.shared.interfaces.ResourceHelper @@ -22,19 +22,19 @@ import javax.inject.Inject import javax.inject.Singleton @Singleton -class VersionCheckerUtils @Inject constructor( +class VersionCheckerUtilsImpl @Inject constructor( private val aapsLogger: AAPSLogger, private val sp: SP, private val rh: ResourceHelper, - private val rxBus: RxBus, private val config: Lazy, private val receiverStatusStore: ReceiverStatusStore, - private val dateUtil: DateUtil -) { + private val dateUtil: DateUtil, + private val activityNames: ActivityNames +) : VersionCheckerUtils { private fun isConnected(): Boolean = receiverStatusStore.isConnected - fun triggerCheckVersion() { + override fun triggerCheckVersion() { 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. @@ -73,7 +73,7 @@ class VersionCheckerUtils @Inject constructor( aapsLogger.debug(LTag.CORE, "Github master version not checked. No connectivity") @Suppress("SameParameterValue") - internal fun compareWithCurrentVersion(newVersion: String?, currentVersion: String) { + override fun compareWithCurrentVersion(newVersion: String?, currentVersion: String) { val newVersionElements = newVersion.toNumberList() val currentVersionElements = currentVersion.toNumberList() @@ -121,7 +121,7 @@ class VersionCheckerUtils @Inject constructor( val now = dateUtil.now() if (now > sp.getLong(R.string.key_last_versionchecker_warning, 0) + WARN_EVERY) { 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) } } @@ -130,7 +130,7 @@ class VersionCheckerUtils @Inject constructor( val now = dateUtil.now() 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)) - 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) } } @@ -138,7 +138,7 @@ class VersionCheckerUtils @Inject constructor( private fun String?.toNumberList() = this?.numericVersionPart().takeIf { !it.isNullOrBlank() }?.split(".")?.map { it.toInt() } - fun versionDigits(versionString: String?): IntArray { + override fun versionDigits(versionString: String?): IntArray { val digits = mutableListOf() versionString?.numericVersionPart().toNumberList()?.let { digits.addAll(it.take(4)) @@ -146,7 +146,7 @@ class VersionCheckerUtils @Inject constructor( return digits.toIntArray() } - internal fun findVersion(file: String?): String? { + override fun findVersion(file: String?): String? { val regex = "(.*)version(.*)\"(((\\d+)\\.)+(\\d+))\"(.*)".toRegex() return file?.lines()?.filter { regex.matches(it) }?.firstNotNullOfOrNull { regex.matchEntire(it)?.groupValues?.getOrNull(3) } } diff --git a/plugins/support/src/main/java/info/nightscout/plugins/support/di/PluginsSupportModule.kt b/plugins/support/src/main/java/info/nightscout/plugins/support/di/PluginsSupportModule.kt new file mode 100644 index 0000000000..72371e4afd --- /dev/null +++ b/plugins/support/src/main/java/info/nightscout/plugins/support/di/PluginsSupportModule.kt @@ -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 + } +} \ No newline at end of file diff --git a/plugins/support/src/main/res/values/strings.xml b/plugins/support/src/main/res/values/strings.xml new file mode 100644 index 0000000000..fe1172832e --- /dev/null +++ b/plugins/support/src/main/res/values/strings.xml @@ -0,0 +1,36 @@ + + + + PhoneChecker + + + snooze_dst_in24h + snooze_loop_disabled + + Daylight Saving time + Daylight Saving time change in 24h or less + Daylight Saving time change less than 3 hours ago - Closed loop disabled + + + Storage constraint + Free at least %1$d MB from internal storage! Loop disabled! + + + Version Checker + old version + very old version + Application expired + New version for at least %1$d days available! Fallback to LGS after %2$d days, loop will be disabled after %3$d days + last_time_this_version_detected + last_versionchecker_warning + last_expired_version_checker_warning + last_versionchecker_plugin_waring + last_revoked_certs_check + We have detected that you are running an invalid version. Loop disabled! + Version %1$s available + Version %1$s expire on %2$s + + + Signature verifier + + \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index cbe83eaa1e..2b2c70a1fc 100644 --- a/settings.gradle +++ b/settings.gradle @@ -21,6 +21,7 @@ include ':plugins:configuration' include ':plugins:main' include ':plugins:openhumans' include ':plugins:sensitivity' +include ':plugins:support' include ':pump:combo' include ':pump:combov2' include ':pump:combov2:comboctl'