From c17f8d10ad9a0cce57ac7f9bd5f6dd467ecc4dfa Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 3 May 2020 17:50:33 +0200 Subject: [PATCH 01/16] split dependency to IconsProvider --- .../nightscout/androidaps/MainActivity.kt | 4 +++- .../notifications/NotificationStore.kt | 8 ++++--- .../PersistentNotificationPlugin.kt | 8 ++++--- .../androidNotification/NotificationHolder.kt | 8 ++++--- .../utils/resources/IconsProvider.kt | 24 +++++++++++++++++++ .../utils/resources/ResourceHelper.kt | 2 -- .../resources/ResourceHelperImplementation.kt | 14 ----------- 7 files changed, 42 insertions(+), 26 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/utils/resources/IconsProvider.kt diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt index 778d2cf985..adc325293c 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt @@ -53,6 +53,7 @@ import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.buildHelper.BuildHelper import info.nightscout.androidaps.utils.extensions.isRunningRealPumpTest import info.nightscout.androidaps.utils.protection.ProtectionCheck +import info.nightscout.androidaps.utils.resources.IconsProvider import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import io.reactivex.android.schedulers.AndroidSchedulers @@ -77,6 +78,7 @@ class MainActivity : NoSplashAppCompatActivity() { @Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var protectionCheck: ProtectionCheck + @Inject lateinit var iconsProvider: IconsProvider private lateinit var actionBarDrawerToggle: ActionBarDrawerToggle private var pluginPreferencesMenuItem: MenuItem? = null @@ -283,7 +285,7 @@ class MainActivity : NoSplashAppCompatActivity() { Linkify.addLinks(messageSpanned, Linkify.WEB_URLS) AlertDialog.Builder(this) .setTitle(resourceHelper.gs(R.string.app_name) + " " + BuildConfig.VERSION) - .setIcon(resourceHelper.getIcon()) + .setIcon(iconsProvider.getIcon()) .setMessage(messageSpanned) .setPositiveButton(resourceHelper.gs(R.string.ok), null) .create().also { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.kt index fd1ca3fce1..b07e9756e9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.kt @@ -24,6 +24,7 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification import info.nightscout.androidaps.services.AlarmSoundService import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.resources.IconsProvider import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import java.util.* @@ -36,7 +37,8 @@ class NotificationStore @Inject constructor( private val sp: SP, private val rxBus: RxBusWrapper, private val resourceHelper: ResourceHelper, - private val context: Context + private val context: Context, + private val iconsProvider: IconsProvider ) { var store: MutableList = ArrayList() @@ -109,8 +111,8 @@ class NotificationStore @Inject constructor( private fun raiseSystemNotification(n: Notification) { val mgr = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager - val largeIcon = resourceHelper.decodeResource(resourceHelper.getIcon()) - val smallIcon = resourceHelper.getNotificationIcon() + val largeIcon = resourceHelper.decodeResource(iconsProvider.getIcon()) + val smallIcon = iconsProvider.getNotificationIcon() val sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM) val notificationBuilder = NotificationCompat.Builder(context, CHANNEL_ID) .setSmallIcon(smallIcon) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt index cabbf3b1ef..c1a203a343 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.kt @@ -28,6 +28,7 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutos import info.nightscout.androidaps.utils.DecimalFormatter import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.androidNotification.NotificationHolder +import info.nightscout.androidaps.utils.resources.IconsProvider import info.nightscout.androidaps.utils.resources.ResourceHelper import io.reactivex.disposables.CompositeDisposable import io.reactivex.schedulers.Schedulers @@ -45,7 +46,8 @@ class PersistentNotificationPlugin @Inject constructor( private var iobCobCalculatorPlugin: IobCobCalculatorPlugin, private var rxBus: RxBusWrapper, private var context: Context, - private var notificationHolder: NotificationHolder + private var notificationHolder: NotificationHolder, + private val iconsProvider: IconsProvider ) : PluginBase(PluginDescription() .mainType(PluginType.GENERAL) .neverVisible(true) @@ -209,8 +211,8 @@ class PersistentNotificationPlugin @Inject constructor( builder.setOngoing(true) builder.setOnlyAlertOnce(true) builder.setCategory(NotificationCompat.CATEGORY_STATUS) - builder.setSmallIcon(resourceHelper.getNotificationIcon()) - builder.setLargeIcon(resourceHelper.decodeResource(resourceHelper.getIcon())) + builder.setSmallIcon(iconsProvider.getNotificationIcon()) + builder.setLargeIcon(resourceHelper.decodeResource(iconsProvider.getIcon())) if (line1 != null) builder.setContentTitle(line1) if (line2 != null) builder.setContentText(line2) if (line3 != null) builder.setSubText(line3) diff --git a/app/src/main/java/info/nightscout/androidaps/utils/androidNotification/NotificationHolder.kt b/app/src/main/java/info/nightscout/androidaps/utils/androidNotification/NotificationHolder.kt index 9ec04d59d7..6ee23a85f5 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/androidNotification/NotificationHolder.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/androidNotification/NotificationHolder.kt @@ -10,6 +10,7 @@ import androidx.core.app.TaskStackBuilder import info.nightscout.androidaps.MainActivity import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.R +import info.nightscout.androidaps.utils.resources.IconsProvider import info.nightscout.androidaps.utils.resources.ResourceHelper import javax.inject.Inject import javax.inject.Singleton @@ -17,7 +18,8 @@ import javax.inject.Singleton @Singleton class NotificationHolder @Inject constructor( private val resourceHelper: ResourceHelper, - private val context: Context + private val context: Context, + private val iconsProvider: IconsProvider ) { val channelID = "AndroidAPS-Ongoing" @@ -32,8 +34,8 @@ class NotificationHolder @Inject constructor( .setOngoing(true) .setOnlyAlertOnce(true) .setCategory(NotificationCompat.CATEGORY_STATUS) - .setSmallIcon(resourceHelper.getNotificationIcon()) - .setLargeIcon(resourceHelper.decodeResource(resourceHelper.getIcon())) + .setSmallIcon(iconsProvider.getNotificationIcon()) + .setLargeIcon(resourceHelper.decodeResource(iconsProvider.getIcon())) .setContentTitle(resourceHelper.gs(R.string.loading)) .setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)) notification = builder.build() diff --git a/app/src/main/java/info/nightscout/androidaps/utils/resources/IconsProvider.kt b/app/src/main/java/info/nightscout/androidaps/utils/resources/IconsProvider.kt new file mode 100644 index 0000000000..d707caaaa1 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/utils/resources/IconsProvider.kt @@ -0,0 +1,24 @@ +package info.nightscout.androidaps.utils.resources + +import info.nightscout.androidaps.Config +import info.nightscout.androidaps.R +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class IconsProvider @Inject constructor() { + + fun getIcon(): Int = + when { + Config.NSCLIENT -> R.mipmap.ic_yellowowl + Config.PUMPCONTROL -> R.mipmap.ic_pumpcontrol + else -> R.mipmap.ic_launcher + } + + fun getNotificationIcon(): Int = + when { + Config.NSCLIENT -> R.drawable.ic_notif_nsclient + Config.PUMPCONTROL -> R.drawable.ic_notif_pumpcontrol + else -> R.drawable.ic_notif_aaps + } +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelper.kt b/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelper.kt index 9b03902883..8bb879fa80 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelper.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelper.kt @@ -15,8 +15,6 @@ interface ResourceHelper { fun gsa(@ArrayRes id:Int): Array fun openRawResourceFd(@RawRes id : Int) : AssetFileDescriptor? - fun getIcon() : Int - fun getNotificationIcon() : Int fun decodeResource(id : Int) : Bitmap fun getDisplayMetrics(): DisplayMetrics fun dpToPx(dp: Int): Int diff --git a/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt b/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt index 0773b8a859..3cd72d5f4a 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt @@ -42,20 +42,6 @@ class ResourceHelperImplementation @Inject constructor(private val context: Cont override fun openRawResourceFd(id: Int): AssetFileDescriptor = context.resources.openRawResourceFd(id) - override fun getIcon(): Int = - when { - Config.NSCLIENT -> R.mipmap.ic_yellowowl - Config.PUMPCONTROL -> R.mipmap.ic_pumpcontrol - else -> R.mipmap.ic_launcher - } - - override fun getNotificationIcon(): Int = - when { - Config.NSCLIENT -> R.drawable.ic_notif_nsclient - Config.PUMPCONTROL -> R.drawable.ic_notif_pumpcontrol - else -> R.drawable.ic_notif_aaps - } - override fun decodeResource(id: Int): Bitmap = BitmapFactory.decodeResource(context.resources, id) From 53383461f0051c86d0325d83f86a52280f97b0b6 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 3 May 2020 21:27:42 +0200 Subject: [PATCH 02/16] core module --- app/build.gradle | 2 + .../dependencyInjection/AppComponent.kt | 2 + .../dependencyInjection/AppModule.kt | 8 +--- build.gradle | 11 ++++- core/.gitignore | 1 + core/build.gradle | 45 +++++++++++++++++++ core/consumer-rules.pro | 0 core/proguard-rules.pro | 21 +++++++++ .../core/ExampleInstrumentedTest.kt | 25 +++++++++++ core/src/main/AndroidManifest.xml | 2 + .../core/dependencyInjection/CoreModule.kt | 18 ++++++++ .../core}/resources/ResourceHelper.kt | 0 .../resources/ResourceHelperImplementation.kt | 3 +- .../src/main/res/values-sw600dp/layout.xml | 0 {app => core}/src/main/res/values/layout.xml | 0 .../androidaps/core/ExampleUnitTest.kt | 18 ++++++++ settings.gradle | 2 +- 17 files changed, 148 insertions(+), 10 deletions(-) create mode 100644 core/.gitignore create mode 100644 core/build.gradle create mode 100644 core/consumer-rules.pro create mode 100644 core/proguard-rules.pro create mode 100644 core/src/androidTest/java/info/nightscout/androidaps/core/ExampleInstrumentedTest.kt create mode 100644 core/src/main/AndroidManifest.xml create mode 100644 core/src/main/java/info/nightscout/androidaps/core/dependencyInjection/CoreModule.kt rename {app/src/main/java/info/nightscout/androidaps/utils => core/src/main/java/info/nightscout/androidaps/core}/resources/ResourceHelper.kt (100%) rename {app/src/main/java/info/nightscout/androidaps/utils => core/src/main/java/info/nightscout/androidaps/core}/resources/ResourceHelperImplementation.kt (96%) rename {app => core}/src/main/res/values-sw600dp/layout.xml (100%) rename {app => core}/src/main/res/values/layout.xml (100%) create mode 100644 core/src/test/java/info/nightscout/androidaps/core/ExampleUnitTest.kt diff --git a/app/build.gradle b/app/build.gradle index fe6ce65442..6f613d0f64 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -242,6 +242,8 @@ allprojects { dependencies { wearApp project(':wear') + implementation project(':core') + implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.google.android.gms:play-services-wearable:17.0.0' implementation "com.google.android.gms:play-services-location:17.0.0" diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt index 91153bd867..1bb1595863 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt @@ -5,6 +5,7 @@ import dagger.Component import dagger.android.AndroidInjectionModule import dagger.android.AndroidInjector import info.nightscout.androidaps.MainApp +import info.nightscout.androidaps.core.dependencyInjection.CoreModule import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.data.ProfileStore import info.nightscout.androidaps.data.PumpEnactResult @@ -53,6 +54,7 @@ import javax.inject.Singleton @Component( modules = [ AndroidInjectionModule::class, + CoreModule::class, ActivitiesModule::class, FragmentsModule::class, AppModule::class, diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt index 871f88a503..4bfabbdfed 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt @@ -1,5 +1,6 @@ package info.nightscout.androidaps.dependencyInjection +import android.app.Application import android.content.Context import androidx.preference.PreferenceManager import dagger.Binds @@ -89,12 +90,6 @@ open class AppModule { return ProfileFunctionImplementation(injector, aapsLogger, sp, resourceHelper, activePlugin, fabricPrivacy) } - @Provides - @Singleton - fun provideResources(mainApp: MainApp): ResourceHelper { - return ResourceHelperImplementation(mainApp) - } - @Provides @Singleton fun provideAAPSLogger(): AAPSLogger { @@ -132,6 +127,7 @@ open class AppModule { interface AppBindings { @Binds fun bindContext(mainApp: MainApp): Context + @Binds fun bindApplication(mainApp: MainApp): Application @Binds fun bindInjector(mainApp: MainApp): HasAndroidInjector @Binds diff --git a/build.gradle b/build.gradle index 579db1fcbf..23ca45ba11 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,16 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.71' + ext { + kotlin_version = '1.3.71' + android_ktx_version = '1.2.0' + rxjava_version = '2.2.19' + rxandroid_version = '2.1.1' + rxkotlin_version = '2.4.0' + room_version = '2.2.5' + lifecycle_version = '2.2.0' + dagger_version = '2.27' + } repositories { google() jcenter() diff --git a/core/.gitignore b/core/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/core/.gitignore @@ -0,0 +1 @@ +/build diff --git a/core/build.gradle b/core/build.gradle new file mode 100644 index 0000000000..19c024a1de --- /dev/null +++ b/core/build.gradle @@ -0,0 +1,45 @@ +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-kapt' +apply plugin: 'kotlin-android-extensions' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.3" + + defaultConfig { + minSdkVersion 23 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles 'consumer-rules.pro' + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.core:core-ktx:1.2.0' + + implementation "com.google.dagger:dagger-android:$dagger_version" + implementation "com.google.dagger:dagger-android-support:$dagger_version" + annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version" + annotationProcessor "com.google.dagger:dagger-android-processor:$dagger_version" + kapt "com.google.dagger:dagger-android-processor:$dagger_version" + kapt "com.google.dagger:dagger-compiler:$dagger_version" + + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' +} diff --git a/core/consumer-rules.pro b/core/consumer-rules.pro new file mode 100644 index 0000000000..e69de29bb2 diff --git a/core/proguard-rules.pro b/core/proguard-rules.pro new file mode 100644 index 0000000000..f1b424510d --- /dev/null +++ b/core/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 diff --git a/core/src/androidTest/java/info/nightscout/androidaps/core/ExampleInstrumentedTest.kt b/core/src/androidTest/java/info/nightscout/androidaps/core/ExampleInstrumentedTest.kt new file mode 100644 index 0000000000..f0f2aec62c --- /dev/null +++ b/core/src/androidTest/java/info/nightscout/androidaps/core/ExampleInstrumentedTest.kt @@ -0,0 +1,25 @@ +package info.nightscout.androidaps.core + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("info.nightscout.androidaps.core.test", appContext.packageName) + } +} diff --git a/core/src/main/AndroidManifest.xml b/core/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..46d6d492d4 --- /dev/null +++ b/core/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + diff --git a/core/src/main/java/info/nightscout/androidaps/core/dependencyInjection/CoreModule.kt b/core/src/main/java/info/nightscout/androidaps/core/dependencyInjection/CoreModule.kt new file mode 100644 index 0000000000..3d022dfd6f --- /dev/null +++ b/core/src/main/java/info/nightscout/androidaps/core/dependencyInjection/CoreModule.kt @@ -0,0 +1,18 @@ +package info.nightscout.androidaps.core.dependencyInjection + +import android.content.Context +import dagger.Module +import dagger.Provides +import info.nightscout.androidaps.utils.resources.ResourceHelper +import info.nightscout.androidaps.utils.resources.ResourceHelperImplementation +import javax.inject.Singleton + +@Module +open class CoreModule { + + @Provides + @Singleton + fun provideResources(context: Context): ResourceHelper { + return ResourceHelperImplementation(context) + } +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelper.kt b/core/src/main/java/info/nightscout/androidaps/core/resources/ResourceHelper.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelper.kt rename to core/src/main/java/info/nightscout/androidaps/core/resources/ResourceHelper.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt b/core/src/main/java/info/nightscout/androidaps/core/resources/ResourceHelperImplementation.kt similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt rename to core/src/main/java/info/nightscout/androidaps/core/resources/ResourceHelperImplementation.kt index 3cd72d5f4a..573f19f065 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt +++ b/core/src/main/java/info/nightscout/androidaps/core/resources/ResourceHelperImplementation.kt @@ -12,8 +12,7 @@ import androidx.annotation.ColorRes import androidx.annotation.PluralsRes import androidx.annotation.StringRes import androidx.core.content.ContextCompat -import info.nightscout.androidaps.Config -import info.nightscout.androidaps.R +import info.nightscout.androidaps.core.R import javax.inject.Inject /** diff --git a/app/src/main/res/values-sw600dp/layout.xml b/core/src/main/res/values-sw600dp/layout.xml similarity index 100% rename from app/src/main/res/values-sw600dp/layout.xml rename to core/src/main/res/values-sw600dp/layout.xml diff --git a/app/src/main/res/values/layout.xml b/core/src/main/res/values/layout.xml similarity index 100% rename from app/src/main/res/values/layout.xml rename to core/src/main/res/values/layout.xml diff --git a/core/src/test/java/info/nightscout/androidaps/core/ExampleUnitTest.kt b/core/src/test/java/info/nightscout/androidaps/core/ExampleUnitTest.kt new file mode 100644 index 0000000000..35bc1a6629 --- /dev/null +++ b/core/src/test/java/info/nightscout/androidaps/core/ExampleUnitTest.kt @@ -0,0 +1,18 @@ +package info.nightscout.androidaps.core + +import org.junit.Test + +import org.junit.Assert.* + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} diff --git a/settings.gradle b/settings.gradle index 9ccfb61915..f7c8a5fc0a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app', ':wear' +include ':app', ':wear', ':core' \ No newline at end of file From 4451039566ca21f69aa54eb20f8be5e0aae821b6 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 3 May 2020 21:37:02 +0200 Subject: [PATCH 03/16] unify versions --- core/build.gradle | 5 ++--- .../androidaps/{core => utils}/resources/ResourceHelper.kt | 0 .../resources/ResourceHelperImplementation.kt | 0 3 files changed, 2 insertions(+), 3 deletions(-) rename core/src/main/java/info/nightscout/androidaps/{core => utils}/resources/ResourceHelper.kt (100%) rename core/src/main/java/info/nightscout/androidaps/{core => utils}/resources/ResourceHelperImplementation.kt (100%) diff --git a/core/build.gradle b/core/build.gradle index 19c024a1de..2c3a561ac7 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -4,12 +4,11 @@ apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-android-extensions' android { - compileSdkVersion 29 - buildToolsVersion "29.0.3" + compileSdkVersion 28 defaultConfig { minSdkVersion 23 - targetSdkVersion 29 + targetSdkVersion 28 versionCode 1 versionName "1.0" diff --git a/core/src/main/java/info/nightscout/androidaps/core/resources/ResourceHelper.kt b/core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelper.kt similarity index 100% rename from core/src/main/java/info/nightscout/androidaps/core/resources/ResourceHelper.kt rename to core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelper.kt diff --git a/core/src/main/java/info/nightscout/androidaps/core/resources/ResourceHelperImplementation.kt b/core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt similarity index 100% rename from core/src/main/java/info/nightscout/androidaps/core/resources/ResourceHelperImplementation.kt rename to core/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt From db164341545b2beb5c5e4ed440afcdb4ac0f7574 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 3 May 2020 22:18:58 +0200 Subject: [PATCH 04/16] build.gradle unify --- .../androidaps/dependencyInjection/AppModule.kt | 1 - core/build.gradle | 17 +++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt index 4bfabbdfed..7261fac6b7 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt @@ -127,7 +127,6 @@ open class AppModule { interface AppBindings { @Binds fun bindContext(mainApp: MainApp): Context - @Binds fun bindApplication(mainApp: MainApp): Application @Binds fun bindInjector(mainApp: MainApp): HasAndroidInjector @Binds diff --git a/core/build.gradle b/core/build.gradle index 2c3a561ac7..58ed7cbfb3 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -16,13 +16,26 @@ android { consumerProguardFiles 'consumer-rules.pro' } + kotlinOptions { + jvmTarget = '1.8' + } + buildTypes { release { minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + debug { + testCoverageEnabled(project.hasProperty('coverage')) + } + firebaseDisable { + System.setProperty("disableFirebase", "true") } } - + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } } dependencies { From 7e6f82d0688a2348ffb48b821d11753e66995eb9 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 4 May 2020 00:14:23 +0200 Subject: [PATCH 05/16] Lgging cleanup --- .../androidaps/db/CareportalEvent.java | 5 +- .../androidaps/db/DatabaseHelper.java | 87 ++++++++++--------- .../nightscout/androidaps/db/DbRequest.java | 15 ++-- .../androidaps/db/ProfileSwitch.java | 7 +- .../nightscout/androidaps/db/TempTarget.java | 3 +- .../dependencyInjection/AppModule.kt | 60 +------------ .../androidaps/logging/AAPSLoggerDebug.kt | 68 --------------- .../logging/AAPSLoggerProduction.kt | 32 +++---- .../info/nightscout/androidaps/logging/L.kt | 57 ++++++------ .../logging/StacktraceLoggerWrapper.kt | 2 +- .../plugins/aps/loop/DeviceStatus.java | 5 +- .../plugins/general/food/FoodService.java | 16 ++-- .../general/maintenance/LoggerUtils.java | 5 -- .../activities/LogSettingActivity.kt | 7 +- .../plugins/general/nsclient/NSUpload.java | 5 +- .../plugins/general/nsclient/UploadQueue.java | 14 +-- .../general/nsclient/acks/NSAddAck.java | 6 +- .../general/nsclient/acks/NSUpdateAck.java | 10 +-- .../plugins/general/nsclient/data/NSMbg.java | 5 +- .../plugins/general/nsclient/data/NSSgv.java | 3 +- .../general/nsclient/data/NSTreatment.java | 59 ++++++++++--- .../nsclient/services/NSClientService.java | 8 +- .../plugins/pump/danaR/SerialIOThread.java | 22 ++--- .../activities/DanaRUserOptionsActivity.kt | 20 ++--- .../plugins/pump/danaR/comm/MessageBase.java | 5 +- .../pump/danaR/comm/MsgSetTempBasalStop.kt | 4 - ...General_Set_User_Time_Change_Flag_Clear.kt | 4 +- .../plugins/pump/danaRS/services/BLEComm.java | 69 +++++++-------- .../cgms/MedtronicCGMSHistoryDecoder.java | 5 +- .../pump/medtronic/data/dto/BasalProfile.java | 2 +- .../medtronic/data/dto/TempBasalPair.java | 2 +- .../driver/ui/OmnipodUIPostprocessor.java | 5 +- .../plugins/source/EversensePlugin.kt | 50 +++++------ .../androidaps/utils/SntpClient.java | 5 +- 34 files changed, 276 insertions(+), 396 deletions(-) delete mode 100644 app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerDebug.kt diff --git a/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java b/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java index bfe24a008b..d77d563e09 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java +++ b/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java @@ -26,7 +26,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.interfaces.Interval; import info.nightscout.androidaps.logging.AAPSLogger; -import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction; import info.nightscout.androidaps.plugins.general.nsclient.data.NSMbg; import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface; @@ -156,8 +156,7 @@ public class CareportalEvent implements DataPointWithLabelInterface, Interval { for (int i = 0; i < list.size(); i++) { CareportalEvent event = list.get(i); if (event.date <= time && event.date > (time - T.mins(5).msecs())) { - if (L.isEnabled(L.DATABASE)) - aapsLogger.debug("Found event for time: " + DateUtil.dateAndTimeString(time) + " " + event.toString()); + aapsLogger.debug(LTag.DATABASE, "Found event for time: " + DateUtil.dateAndTimeString(time) + " " + event.toString()); return true; } } diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index d1c63d284c..616108669f 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -47,6 +47,7 @@ import info.nightscout.androidaps.events.EventTempTargetChange; import info.nightscout.androidaps.interfaces.ActivePluginProvider; import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; @@ -72,7 +73,7 @@ import info.nightscout.androidaps.utils.ToastUtils; * direct calls to the corresponding methods (eg. resetDatabases) should be done by a central service. */ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { - private static Logger log = StacktraceLoggerWrapper.getLogger(L.DATABASE); + private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.DATABASE); public static final String DATABASE_NAME = "AndroidAPSDb"; public static final String DATABASE_BGREADINGS = "BgReadings"; @@ -123,7 +124,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { @Override public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) { try { - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.info("onCreate"); TableUtils.createTableIfNotExists(connectionSource, TempTarget.class); TableUtils.createTableIfNotExists(connectionSource, BgReading.class); @@ -366,7 +367,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { public static long roundDateToSec(long date) { long rounded = date - date % 1000; if (rounded != date) - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("Rounding " + date + " to " + rounded); return rounded; } @@ -378,17 +379,17 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { BgReading old = getDaoBgReadings().queryForId(bgReading.date); if (old == null) { getDaoBgReadings().create(bgReading); - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("BG: New record from: " + from + " " + bgReading.toString()); scheduleBgChange(bgReading); return true; } if (!old.isEqual(bgReading)) { - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("BG: Similiar found: " + old.toString()); old.copyFrom(bgReading); getDaoBgReadings().update(old); - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("BG: Updating record from: " + from + " New data: " + old.toString()); scheduleBgChange(bgReading); return false; @@ -411,7 +412,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { private static void scheduleBgChange(@Nullable final BgReading bgReading) { class PostRunnable implements Runnable { public void run() { - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("Firing EventNewBg"); RxBus.Companion.getINSTANCE().send(new EventNewBG(bgReading)); scheduledBgPost = null; @@ -640,7 +641,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { getDaoTempTargets().delete(old); // need to delete/create because date may change too old.copyFrom(tempTarget); getDaoTempTargets().create(old); - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("TEMPTARGET: Updating record by date from: " + Source.getString(tempTarget.source) + " " + old.toString()); scheduleTemporaryTargetChange(); return true; @@ -660,7 +661,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { getDaoTempTargets().delete(old); // need to delete/create because date may change too old.copyFrom(tempTarget); getDaoTempTargets().create(old); - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("TEMPTARGET: Updating record by _id from: " + Source.getString(tempTarget.source) + " " + old.toString()); scheduleTemporaryTargetChange(); return true; @@ -668,14 +669,14 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } getDaoTempTargets().create(tempTarget); - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("TEMPTARGET: New record from: " + Source.getString(tempTarget.source) + " " + tempTarget.toString()); scheduleTemporaryTargetChange(); return true; } if (tempTarget.source == Source.USER) { getDaoTempTargets().create(tempTarget); - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("TEMPTARGET: New record from: " + Source.getString(tempTarget.source) + " " + tempTarget.toString()); scheduleTemporaryTargetChange(); return true; @@ -698,7 +699,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { private static void scheduleTemporaryTargetChange() { class PostRunnable implements Runnable { public void run() { - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("Firing EventTempTargetChange"); RxBus.Companion.getINSTANCE().send(new EventTempTargetChange()); scheduledTemTargetPost = null; @@ -824,7 +825,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { List trList = getDaoTemporaryBasal().query(preparedQuery); if (trList.size() > 0) { // do nothing, pump history record cannot be changed - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("TEMPBASAL: Already exists from: " + Source.getString(tempBasal.source) + " " + tempBasal.toString()); return false; } @@ -842,7 +843,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { old.copyFromPump(tempBasal); old.source = Source.PUMP; - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("TEMPBASAL: Updated record with Pump Data : " + Source.getString(tempBasal.source) + " " + tempBasal.toString()); getDaoTemporaryBasal().update(old); @@ -854,7 +855,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } getDaoTemporaryBasal().create(tempBasal); - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("TEMPBASAL: New record from: " + Source.getString(tempBasal.source) + " " + tempBasal.toString()); updateEarliestDataChange(tempBasal.date); scheduleTemporaryBasalChange(); @@ -872,7 +873,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { getDaoTemporaryBasal().delete(old); // need to delete/create because date may change too old.copyFrom(tempBasal); getDaoTemporaryBasal().create(old); - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("TEMPBASAL: Updating record by date from: " + Source.getString(tempBasal.source) + " " + old.toString()); updateEarliestDataChange(oldDate); updateEarliestDataChange(old.date); @@ -895,7 +896,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { getDaoTemporaryBasal().delete(old); // need to delete/create because date may change too old.copyFrom(tempBasal); getDaoTemporaryBasal().create(old); - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("TEMPBASAL: Updating record by _id from: " + Source.getString(tempBasal.source) + " " + old.toString()); updateEarliestDataChange(oldDate); updateEarliestDataChange(old.date); @@ -905,7 +906,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } getDaoTemporaryBasal().create(tempBasal); - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("TEMPBASAL: New record from: " + Source.getString(tempBasal.source) + " " + tempBasal.toString()); updateEarliestDataChange(tempBasal.date); scheduleTemporaryBasalChange(); @@ -913,7 +914,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } if (tempBasal.source == Source.USER) { getDaoTemporaryBasal().create(tempBasal); - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("TEMPBASAL: New record from: " + Source.getString(tempBasal.source) + " " + tempBasal.toString()); updateEarliestDataChange(tempBasal.date); scheduleTemporaryBasalChange(); @@ -970,7 +971,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { private static void scheduleTemporaryBasalChange() { class PostRunnable implements Runnable { public void run() { - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("Firing EventTempBasalChange"); RxBus.Companion.getINSTANCE().send(new EventReloadTempBasalData()); RxBus.Companion.getINSTANCE().send(new EventTempBasalChange()); @@ -1065,7 +1066,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { public void deleteTempBasalById(String _id) { TemporaryBasal stored = findTempBasalById(_id); if (stored != null) { - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("TEMPBASAL: Removing TempBasal record from database: " + stored.toString()); delete(stored); updateEarliestDataChange(stored.date); @@ -1120,7 +1121,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { public boolean createOrUpdate(ExtendedBolus extendedBolus) { try { - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("EXTENDEDBOLUS: createOrUpdate: " + Source.getString(extendedBolus.source) + " " + extendedBolus.log()); ExtendedBolus old; @@ -1145,7 +1146,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } getDaoExtendedBolus().createOrUpdate(extendedBolus); } - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("EXTENDEDBOLUS: New record from: " + Source.getString(extendedBolus.source) + " " + extendedBolus.log()); updateEarliestDataChange(extendedBolus.date); scheduleExtendedBolusChange(); @@ -1159,7 +1160,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { getDaoExtendedBolus().delete(old); // need to delete/create because date may change too old.copyFrom(extendedBolus); getDaoExtendedBolus().create(old); - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("EXTENDEDBOLUS: Updating record by date from: " + Source.getString(extendedBolus.source) + " " + old.log()); updateEarliestDataChange(oldDate); updateEarliestDataChange(old.date); @@ -1182,7 +1183,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { getDaoExtendedBolus().delete(old); // need to delete/create because date may change too old.copyFrom(extendedBolus); getDaoExtendedBolus().create(old); - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("EXTENDEDBOLUS: Updating record by _id from: " + Source.getString(extendedBolus.source) + " " + old.log()); updateEarliestDataChange(oldDate); updateEarliestDataChange(old.date); @@ -1192,7 +1193,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } getDaoExtendedBolus().create(extendedBolus); - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("EXTENDEDBOLUS: New record from: " + Source.getString(extendedBolus.source) + " " + extendedBolus.log()); updateEarliestDataChange(extendedBolus.date); scheduleExtendedBolusChange(); @@ -1200,7 +1201,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } if (extendedBolus.source == Source.USER) { getDaoExtendedBolus().create(extendedBolus); - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("EXTENDEDBOLUS: New record from: " + Source.getString(extendedBolus.source) + " " + extendedBolus.log()); updateEarliestDataChange(extendedBolus.date); scheduleExtendedBolusChange(); @@ -1252,7 +1253,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { public void deleteExtendedBolusById(String _id) { ExtendedBolus stored = findExtendedBolusById(_id); if (stored != null) { - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("EXTENDEDBOLUS: Removing ExtendedBolus record from database: " + stored.toString()); delete(stored); updateEarliestDataChange(stored.date); @@ -1306,7 +1307,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { private static void scheduleExtendedBolusChange() { class PostRunnable implements Runnable { public void run() { - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("Firing EventExtendedBolusChange"); RxBus.Companion.getINSTANCE().send(new EventReloadTreatmentData(new EventExtendedBolusChange())); if (earliestDataChange != null) @@ -1468,11 +1469,11 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { if (list.size() == 1) { CareportalEvent record = list.get(0); - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("Removing CareportalEvent record from database: " + record.toString()); delete(record); } else { - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("CareportalEvent not found database: " + _id); } } catch (SQLException e) { @@ -1492,12 +1493,12 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { if (list.size() == 0) { careportalEvent = new CareportalEvent(MainApp.instance()); careportalEvent.source = Source.NIGHTSCOUT; - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("Adding CareportalEvent record to database: " + trJson.toString()); // Record does not exists. add } else if (list.size() == 1) { careportalEvent = list.get(0); - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("Updating CareportalEvent record in database: " + trJson.toString()); } else { log.error("Something went wrong"); @@ -1516,7 +1517,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { private static void scheduleCareportalEventChange() { class PostRunnable implements Runnable { public void run() { - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("Firing scheduleCareportalEventChange"); RxBus.Companion.getINSTANCE().send(new EventCareportalEventChange()); scheduledCareportalEventPost = null; @@ -1629,7 +1630,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { profileSwitch.profileName = old.profileName; // preserver profileName to prevent multiple CPP extension getDaoProfileSwitch().delete(old); // need to delete/create because date may change too getDaoProfileSwitch().create(profileSwitch); - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("PROFILESWITCH: Updating record by date from: " + Source.getString(profileSwitch.source) + " " + old.toString()); scheduleProfileSwitchChange(); return true; @@ -1649,7 +1650,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { getDaoProfileSwitch().delete(old); // need to delete/create because date may change too old.copyFrom(profileSwitch); getDaoProfileSwitch().create(old); - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("PROFILESWITCH: Updating record by _id from: " + Source.getString(profileSwitch.source) + " " + old.toString()); scheduleProfileSwitchChange(); return true; @@ -1659,14 +1660,14 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { // look for already added percentage from NS profileSwitch.profileName = PercentageSplitter.pureName(profileSwitch.profileName); getDaoProfileSwitch().create(profileSwitch); - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("PROFILESWITCH: New record from: " + Source.getString(profileSwitch.source) + " " + profileSwitch.toString()); scheduleProfileSwitchChange(); return true; } if (profileSwitch.source == Source.USER) { getDaoProfileSwitch().create(profileSwitch); - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("PROFILESWITCH: New record from: " + Source.getString(profileSwitch.source) + " " + profileSwitch.toString()); scheduleProfileSwitchChange(); return true; @@ -1689,7 +1690,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { private static void scheduleProfileSwitchChange() { class PostRunnable implements Runnable { public void run() { - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("Firing EventProfileNeedsUpdate"); RxBus.Companion.getINSTANCE().send(new EventReloadProfileSwitchData()); RxBus.Companion.getINSTANCE().send(new EventProfileNeedsUpdate()); @@ -1741,17 +1742,17 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { Profile profile = store.getSpecificProfile(profileSwitch.profileName); if (profile != null) { profileSwitch.profileJson = profile.getData().toString(); - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("Profile switch prefilled with JSON from local store"); // Update data in NS NSUpload.updateProfileSwitch(profileSwitch); } else { - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("JSON for profile switch doesn't exist. Ignoring: " + trJson.toString()); return; } } else { - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("Store for profile switch doesn't exist. Ignoring: " + trJson.toString()); return; } @@ -1767,7 +1768,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { public void deleteProfileSwitchById(String _id) { ProfileSwitch stored = findProfileSwitchById(_id); if (stored != null) { - if (L.isEnabled(L.DATABASE)) + if (L.isEnabled(LTag.DATABASE)) log.debug("PROFILESWITCH: Removing ProfileSwitch record from database: " + stored.toString()); delete(stored); scheduleTemporaryTargetChange(); diff --git a/app/src/main/java/info/nightscout/androidaps/db/DbRequest.java b/app/src/main/java/info/nightscout/androidaps/db/DbRequest.java index 2754bd1f8c..60da1d2bca 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DbRequest.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DbRequest.java @@ -1,16 +1,13 @@ package info.nightscout.androidaps.db; -import com.google.common.base.Charsets; -import com.google.common.hash.Hashing; import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.table.DatabaseTable; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; import info.nightscout.androidaps.utils.DateUtil; @@ -21,7 +18,7 @@ import info.nightscout.androidaps.utils.DateUtil; */ @DatabaseTable(tableName = DatabaseHelper.DATABASE_DBREQUESTS) public class DbRequest { - private static Logger log = StacktraceLoggerWrapper.getLogger(L.DATABASE); + private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.DATABASE); @DatabaseField(id = true) public String nsClientID = null; @@ -88,9 +85,9 @@ public class DbRequest { public String log() { return "\nnsClientID:" + nsClientID + - "\naction:" + action + - "\ncollection:" + collection + - "\ndata:" + data + - "\n_id:" + _id; + "\naction:" + action + + "\ncollection:" + collection + + "\ndata:" + data + + "\n_id:" + _id; } } diff --git a/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java b/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java index 00c31586f4..06174c9c66 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java +++ b/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java @@ -22,6 +22,7 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.interfaces.Interval; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface; @@ -253,13 +254,11 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface { if (event.date <= time && event.date > (time - T.mins(5).msecs())) { if (zeroDurationOnly) { if (event.durationInMinutes == 0) { - if (L.isEnabled(L.DATABASE)) - aapsLogger.debug("Found ProfileSwitch event for time: " + DateUtil.dateAndTimeString(time) + " " + event.toString()); + aapsLogger.debug(LTag.DATABASE, "Found ProfileSwitch event for time: " + DateUtil.dateAndTimeString(time) + " " + event.toString()); return true; } } else { - if (L.isEnabled(L.DATABASE)) - aapsLogger.debug("Found ProfileSwitch event for time: " + DateUtil.dateAndTimeString(time) + " " + event.toString()); + aapsLogger.debug(LTag.DATABASE, "Found ProfileSwitch event for time: " + DateUtil.dateAndTimeString(time) + " " + event.toString()); return true; } } diff --git a/app/src/main/java/info/nightscout/androidaps/db/TempTarget.java b/app/src/main/java/info/nightscout/androidaps/db/TempTarget.java index 925d56e81d..be7b76c554 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/TempTarget.java +++ b/app/src/main/java/info/nightscout/androidaps/db/TempTarget.java @@ -14,6 +14,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.interfaces.Interval; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DecimalFormatter; @@ -21,7 +22,7 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper; @DatabaseTable(tableName = DatabaseHelper.DATABASE_TEMPTARGETS) public class TempTarget implements Interval { - private static Logger log = StacktraceLoggerWrapper.getLogger(L.DATABASE); + private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.DATABASE); @DatabaseField(id = true) public long date; diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt index 7261fac6b7..bb968938d5 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt @@ -1,78 +1,30 @@ package info.nightscout.androidaps.dependencyInjection -import android.app.Application import android.content.Context import androidx.preference.PreferenceManager import dagger.Binds import dagger.Lazy import dagger.Module import dagger.Provides -import dagger.android.ContributesAndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.Config import info.nightscout.androidaps.MainApp -import info.nightscout.androidaps.data.Profile -import info.nightscout.androidaps.data.ProfileStore -import info.nightscout.androidaps.data.PumpEnactResult -import info.nightscout.androidaps.db.BgReading -import info.nightscout.androidaps.db.CareportalEvent -import info.nightscout.androidaps.db.ProfileSwitch -import info.nightscout.androidaps.db.TemporaryBasal import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLoggerProduction -import info.nightscout.androidaps.plugins.aps.loop.APSResult -import info.nightscout.androidaps.plugins.aps.openAPSAMA.DetermineBasalResultAMA -import info.nightscout.androidaps.plugins.aps.logger.LoggerCallback -import info.nightscout.androidaps.plugins.aps.openAPSSMB.DetermineBasalAdapterSMBJS -import info.nightscout.androidaps.plugins.aps.openAPSSMB.DetermineBasalResultSMB +import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.plugins.configBuilder.PluginStore import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImplementation -import info.nightscout.androidaps.plugins.constraints.objectives.objectives.* -import info.nightscout.androidaps.plugins.general.automation.AutomationEvent -import info.nightscout.androidaps.plugins.general.automation.actions.* -import info.nightscout.androidaps.plugins.general.automation.elements.* -import info.nightscout.androidaps.plugins.general.automation.triggers.* -import info.nightscout.androidaps.plugins.general.overview.graphData.GraphData -import info.nightscout.androidaps.plugins.general.maintenance.ImportExportPrefs -import info.nightscout.androidaps.plugins.general.maintenance.formats.ClassicPrefsFormat -import info.nightscout.androidaps.plugins.general.maintenance.formats.EncryptedPrefsFormat -import info.nightscout.androidaps.plugins.general.nsclient.NSUpload -import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationWithAction -import info.nightscout.androidaps.plugins.general.smsCommunicator.AuthRequest -import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData -import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus -import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobOref1Thread -import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobThread -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkBLE -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command.SendAndListen -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command.SetPreamble -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RadioPacket -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RadioResponse -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.* -import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager -import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUITask -import info.nightscout.androidaps.plugins.treatments.Treatment import info.nightscout.androidaps.queue.CommandQueue -import info.nightscout.androidaps.queue.commands.* -import info.nightscout.androidaps.setupwizard.SWEventListener -import info.nightscout.androidaps.setupwizard.SWScreen -import info.nightscout.androidaps.setupwizard.elements.* -import info.nightscout.androidaps.utils.CryptoUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.resources.ResourceHelper -import info.nightscout.androidaps.utils.resources.ResourceHelperImplementation import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SPImplementation import info.nightscout.androidaps.utils.storage.FileStorage import info.nightscout.androidaps.utils.storage.Storage -import info.nightscout.androidaps.utils.wizard.BolusWizard -import info.nightscout.androidaps.utils.wizard.QuickWizardEntry import javax.inject.Singleton @Module(includes = [AppModule.AppBindings::class, PluginsModule::class]) @@ -92,15 +44,7 @@ open class AppModule { @Provides @Singleton - fun provideAAPSLogger(): AAPSLogger { - return AAPSLoggerProduction() -/* if (BuildConfig.DEBUG) { - AAPSLoggerDebug() - } else { - AAPSLoggerProduction() - } - */ - } + fun provideAAPSLogger(l: L): AAPSLogger = AAPSLoggerProduction(l) @Provides fun providesPlugins(@PluginsModule.AllConfigs allConfigs: Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>, diff --git a/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerDebug.kt b/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerDebug.kt deleted file mode 100644 index ba7f88712d..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerDebug.kt +++ /dev/null @@ -1,68 +0,0 @@ -package info.nightscout.androidaps.logging - -import android.util.Log - -/** - * Created by adrian on 2019-12-27. - */ - -class AAPSLoggerDebug : AAPSLogger { - - override fun debug(message: String) { - Log.d(LTag.CORE.tag, message) - } - - override fun debug(enable: Boolean, tag: LTag, message: String) { - if (enable) Log.d(LTag.CORE.tag, message) - } - - override fun debug(tag: LTag, message: String) { - Log.d(tag.tag, message) - } - - override fun debug(tag: LTag, format: String, vararg arguments: Any?) { - Log.d(tag.tag, String.format(format, arguments)) - } - - override fun warn(tag: LTag, message: String) { - Log.w(tag.tag, message) - } - - override fun warn(tag: LTag, format: String, vararg arguments: Any?) { - Log.w(tag.tag, String.format(format, arguments)) - } - - override fun info(tag: LTag, message: String) { - Log.i(tag.tag, message) - } - - override fun info(tag: LTag, format: String, vararg arguments: Any?) { - Log.i(tag.tag, String.format(format, arguments)) - } - - override fun error(tag: LTag, message: String) { - Log.e(tag.tag, message) - - } - - override fun error(message: String) { - Log.e(LTag.CORE.tag, message) - } - - override fun error(message: String, throwable: Throwable) { - Log.e(LTag.CORE.tag, message, throwable) - } - - override fun error(format: String, vararg arguments: Any?) { - Log.e(LTag.CORE.tag, String.format(format, arguments)) - } - - override fun error(tag: LTag, message: String, throwable: Throwable) { - Log.e(tag.tag, message, throwable) - - } - - override fun error(tag: LTag, format: String, vararg arguments: Any?) { - Log.e(tag.tag, String.format(format, arguments)) - } -} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerProduction.kt b/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerProduction.kt index 3b71419cab..ef7c63e096 100644 --- a/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerProduction.kt +++ b/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerProduction.kt @@ -6,33 +6,30 @@ import org.slf4j.LoggerFactory * Created by adrian on 2019-12-27. */ -class AAPSLoggerProduction : AAPSLogger { +class AAPSLoggerProduction constructor(val l: L) : AAPSLogger { override fun debug(message: String) { LoggerFactory.getLogger(LTag.CORE.tag).debug(stackLogMarker() + message) } override fun debug(enable: Boolean, tag: LTag, message: String) { - if (enable && L.isEnabled(tag.tag)) { + if (enable && l.findByName(tag.tag).enabled) LoggerFactory.getLogger(tag.tag).debug(stackLogMarker() + message) - } } override fun debug(tag: LTag, message: String) { - if (L.isEnabled(tag.tag)) { + if (l.findByName(tag.tag).enabled) LoggerFactory.getLogger(tag.tag).debug(stackLogMarker() + message) - } } override fun debug(tag: LTag, format: String, vararg arguments: Any?) { - if (L.isEnabled(tag.tag)) + if (l.findByName(tag.tag).enabled) LoggerFactory.getLogger(tag.tag).debug(stackLogMarker() + format, arguments) } override fun warn(tag: LTag, message: String) { - if (L.isEnabled(tag.tag)) { + if (l.findByName(tag.tag).enabled) LoggerFactory.getLogger(tag.tag).warn(stackLogMarker() + message) - } } override fun warn(tag: LTag, format: String, vararg arguments: Any?) { @@ -40,20 +37,17 @@ class AAPSLoggerProduction : AAPSLogger { } override fun info(tag: LTag, message: String) { - if (L.isEnabled(tag.tag)) { + if (l.findByName(tag.tag).enabled) LoggerFactory.getLogger(tag.tag).info(stackLogMarker() + message) - - } } override fun info(tag: LTag, format: String, vararg arguments: Any?) { - LoggerFactory.getLogger(tag.tag).info(stackLogMarker() + format, arguments) + if (l.findByName(tag.tag).enabled) + LoggerFactory.getLogger(tag.tag).info(stackLogMarker() + format, arguments) } override fun error(tag: LTag, message: String) { - if (L.isEnabled(tag.tag)) { - LoggerFactory.getLogger(tag.tag).error(stackLogMarker() + message) - } + LoggerFactory.getLogger(tag.tag).error(stackLogMarker() + message) } override fun error(message: String) { @@ -69,15 +63,11 @@ class AAPSLoggerProduction : AAPSLogger { } override fun error(tag: LTag, message: String, throwable: Throwable) { - if (L.isEnabled(tag.tag)) { - LoggerFactory.getLogger(tag.tag).error(stackLogMarker() + message, throwable) - } + LoggerFactory.getLogger(tag.tag).error(stackLogMarker() + message, throwable) } override fun error(tag: LTag, format: String, vararg arguments: Any?) { - if (L.isEnabled(tag.tag)) { - LoggerFactory.getLogger(tag.tag).error(stackLogMarker() + format, arguments) - } + LoggerFactory.getLogger(tag.tag).error(stackLogMarker() + format, arguments) } } diff --git a/app/src/main/java/info/nightscout/androidaps/logging/L.kt b/app/src/main/java/info/nightscout/androidaps/logging/L.kt index 2411e76c5e..5decfceb53 100644 --- a/app/src/main/java/info/nightscout/androidaps/logging/L.kt +++ b/app/src/main/java/info/nightscout/androidaps/logging/L.kt @@ -2,36 +2,39 @@ package info.nightscout.androidaps.logging import androidx.preference.PreferenceManager import info.nightscout.androidaps.MainApp +import info.nightscout.androidaps.utils.sharedPreferences.SP import java.util.* +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class L @Inject constructor( + private val sp: SP +) { -object L { private var logElements: MutableList = ArrayList() - const val CORE = "CORE" - const val BGSOURCE = "BGSOURCE" - const val DATASERVICE = "DATASERVICE" - const val DATABASE = "DATABASE" - const val DATAFOOD = "DATAFOOD" - const val DATATREATMENTS = "DATATREATMENTS" - const val NSCLIENT = "NSCLIENT" - const val PUMP = "PUMP" - const val PUMPCOMM = "PUMPCOMM" - const val PUMPBTCOMM = "PUMPBTCOMM" + companion object { + @Deprecated("Use Dagger") + lateinit var instance: L - init { - LTag.values().forEach { logElements.add(LogElement(it)) } + @Deprecated("Use Dagger") + @JvmStatic + fun isEnabled(ltag: LTag): Boolean { + return instance.findByName(ltag.name).enabled + } } - private fun findByName(name: String): LogElement { + init { + instance= this + LTag.values().forEach { logElements.add(LogElement(it, sp)) } + } + + fun findByName(name: String): LogElement { for (element in logElements) { if (element.name == name) return element } - return LogElement(false) - } - - @JvmStatic - fun isEnabled(name: String): Boolean { - return findByName(name).enabled + return LogElement(false, sp) } fun getLogElements(): List { @@ -45,21 +48,22 @@ object L { } class LogElement { + var sp : SP var name: String var defaultValue: Boolean var enabled: Boolean private var requiresRestart = false - internal constructor(tag: LTag) { + internal constructor(tag: LTag, sp: SP) { + this.sp = sp this.name = tag.tag this.defaultValue = tag.defaultValue this.requiresRestart = tag.requiresRestart - //TODO: remove after getting rid of old logging style "if (L.isEnabled(...))" - @Suppress("DEPRECATION") - enabled = PreferenceManager.getDefaultSharedPreferences(MainApp.instance()).getBoolean(getSPName(), defaultValue) + enabled = sp.getBoolean(getSPName(), defaultValue) } - internal constructor(defaultValue: Boolean) { + internal constructor(defaultValue: Boolean, sp: SP) { + this.sp = sp name = "NONEXISTING" this.defaultValue = defaultValue enabled = defaultValue @@ -69,8 +73,7 @@ object L { fun enable(enabled: Boolean) { this.enabled = enabled - @Suppress("DEPRECATION") - PreferenceManager.getDefaultSharedPreferences(MainApp.instance()).edit().putBoolean(getSPName(), enabled).apply() + sp.putBoolean(getSPName(), enabled) } fun resetToDefault() { diff --git a/app/src/main/java/info/nightscout/androidaps/logging/StacktraceLoggerWrapper.kt b/app/src/main/java/info/nightscout/androidaps/logging/StacktraceLoggerWrapper.kt index 0d724a5008..38b2b84f9f 100644 --- a/app/src/main/java/info/nightscout/androidaps/logging/StacktraceLoggerWrapper.kt +++ b/app/src/main/java/info/nightscout/androidaps/logging/StacktraceLoggerWrapper.kt @@ -34,7 +34,7 @@ class StacktraceLoggerWrapper(private val delegate: Logger) : Logger by delegate companion object { @JvmStatic @Deprecated("please inject AAPSLogger") - fun getLogger(name: String) = StacktraceLoggerWrapper(LoggerFactory.getLogger(name)) + fun getLogger(ltag: LTag) = StacktraceLoggerWrapper(LoggerFactory.getLogger(ltag.name)) @JvmStatic @Deprecated("please inject AAPSLogger") diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/DeviceStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/DeviceStatus.java index 42f25cce8f..c8e49d013a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/DeviceStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/DeviceStatus.java @@ -3,9 +3,8 @@ package info.nightscout.androidaps.plugins.aps.loop; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; /* @@ -366,7 +365,7 @@ import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; */ public class DeviceStatus { - private static Logger log = StacktraceLoggerWrapper.getLogger(L.NSCLIENT); + private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.NSCLIENT); public String device = null; public JSONObject pump = null; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodService.java index 19ceb73ca6..405fc22b50 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/food/FoodService.java @@ -16,7 +16,6 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.sql.SQLException; import java.util.ArrayList; @@ -32,6 +31,7 @@ import info.nightscout.androidaps.events.Event; import info.nightscout.androidaps.events.EventFoodDatabaseChanged; import info.nightscout.androidaps.events.EventNsFood; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.utils.FabricPrivacy; @@ -43,7 +43,7 @@ import io.reactivex.schedulers.Schedulers; */ public class FoodService extends OrmLiteBaseService { - private Logger log = StacktraceLoggerWrapper.getLogger(L.DATAFOOD); + private Logger log = StacktraceLoggerWrapper.getLogger(LTag.DATAFOOD); private CompositeDisposable disposable = new CompositeDisposable(); private static final ScheduledExecutorService foodEventWorker = Executors.newSingleThreadScheduledExecutor(); @@ -98,7 +98,7 @@ public class FoodService extends OrmLiteBaseService { public void onCreate() { super.onCreate(); try { - if (L.isEnabled(L.DATAFOOD)) + if (L.isEnabled(LTag.DATAFOOD)) log.info("onCreate"); TableUtils.createTableIfNotExists(this.getConnectionSource(), Food.class); } catch (SQLException e) { @@ -108,7 +108,7 @@ public class FoodService extends OrmLiteBaseService { } public void onUpgrade(ConnectionSource connectionSource, int oldVersion, int newVersion) { - if (L.isEnabled(L.DATAFOOD)) + if (L.isEnabled(LTag.DATAFOOD)) log.info("onUpgrade"); // this.resetFood(); } @@ -147,7 +147,7 @@ public class FoodService extends OrmLiteBaseService { class PostRunnable implements Runnable { public void run() { - if (L.isEnabled(L.DATAFOOD)) + if (L.isEnabled(LTag.DATAFOOD)) log.debug("Firing EventFoodChange"); RxBus.Companion.getINSTANCE().send(event); callback.setPost(null); @@ -258,7 +258,7 @@ public class FoodService extends OrmLiteBaseService { public void deleteByNSId(String _id) throws SQLException { Food stored = this.findByNSId(_id); if (stored != null) { - if (L.isEnabled(L.DATAFOOD)) + if (L.isEnabled(LTag.DATAFOOD)) log.debug("Removing Food record from database: " + stored.toString()); this.delete(stored); } @@ -312,7 +312,7 @@ public class FoodService extends OrmLiteBaseService { public void createOrUpdate(Food food) { try { this.getDao().createOrUpdate(food); - if (L.isEnabled(L.DATAFOOD)) + if (L.isEnabled(LTag.DATAFOOD)) log.debug("Created or Updated: " + food.toString()); } catch (SQLException e) { log.error("Unable to createOrUpdate Food", e); @@ -323,7 +323,7 @@ public class FoodService extends OrmLiteBaseService { public void create(Food food) { try { this.getDao().create(food); - if (L.isEnabled(L.DATAFOOD)) + if (L.isEnabled(LTag.DATAFOOD)) log.debug("New record: " + food.toString()); } catch (SQLException e) { log.error("Unable to create Food", e); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/LoggerUtils.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/LoggerUtils.java index 9205dc0ccd..2d1dcb19b8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/LoggerUtils.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/LoggerUtils.java @@ -1,19 +1,14 @@ package info.nightscout.androidaps.plugins.general.maintenance; -import org.slf4j.Logger; import org.slf4j.LoggerFactory; import ch.qos.logback.classic.LoggerContext; -import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; /** * This class provides serveral methods for log-handling (eg. sending logs as emails). */ public class LoggerUtils { - private static final Logger LOGGER = StacktraceLoggerWrapper.getLogger(L.CORE); - public static String SUFFIX = ".log.zip"; /** diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/LogSettingActivity.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/LogSettingActivity.kt index c6cdaa4397..17a18629d3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/LogSettingActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/LogSettingActivity.kt @@ -9,9 +9,12 @@ import info.nightscout.androidaps.R import info.nightscout.androidaps.activities.NoSplashAppCompatActivity import info.nightscout.androidaps.logging.L import kotlinx.android.synthetic.main.activity_logsetting.* +import javax.inject.Inject class LogSettingActivity : NoSplashAppCompatActivity() { + @Inject lateinit var l :L + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_logsetting) @@ -19,7 +22,7 @@ class LogSettingActivity : NoSplashAppCompatActivity() { createViewsForSettings() logsettings_reset.setOnClickListener { - L.resetToDefaults() + l.resetToDefaults() createViewsForSettings() } ok.setOnClickListener { finish() } @@ -27,7 +30,7 @@ class LogSettingActivity : NoSplashAppCompatActivity() { private fun createViewsForSettings() { logsettings_placeholder.removeAllViews() - for (element in L.getLogElements()) { + for (element in l.getLogElements()) { val logViewHolder = LogViewHolder(element) logsettings_placeholder.addView(logViewHolder.baseView) } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java index 5b2fd496c7..75f1c9b30c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java @@ -35,6 +35,7 @@ import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; import info.nightscout.androidaps.plugins.aps.loop.APSResult; import info.nightscout.androidaps.plugins.aps.loop.DeviceStatus; @@ -50,7 +51,7 @@ import info.nightscout.androidaps.utils.SP; * Created by mike on 26.05.2017. */ public class NSUpload { - private static Logger log = StacktraceLoggerWrapper.getLogger(L.NSCLIENT); + private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.NSCLIENT); public static void uploadTempBasalStartAbsolute(TemporaryBasal temporaryBasal, Double originalExtendedAmount) { try { @@ -200,7 +201,7 @@ public class NSUpload { deviceStatus.enacted.put("requested", requested); } } else { - if (L.isEnabled(L.NSCLIENT)) + if (L.isEnabled(LTag.NSCLIENT)) log.debug("OpenAPS data too old to upload, sending iob only"); IobTotal[] iob = iobCobCalculatorPlugin.calculateIobArrayInDia(profile); if (iob.length > 0) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/UploadQueue.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/UploadQueue.java index fb425a23df..0786aae250 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/UploadQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/UploadQueue.java @@ -9,7 +9,6 @@ import com.j256.ormlite.dao.CloseableIterator; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.sql.SQLException; @@ -18,6 +17,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.DbRequest; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientResend; @@ -28,7 +28,7 @@ import info.nightscout.androidaps.utils.SP; * Created by mike on 21.02.2016. */ public class UploadQueue { - private static Logger log = StacktraceLoggerWrapper.getLogger(L.NSCLIENT); + private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.NSCLIENT); public static String status() { return "QUEUE: " + MainApp.getDbHelper().size(DatabaseHelper.DATABASE_DBREQUESTS); @@ -48,7 +48,7 @@ public class UploadQueue { public static void add(final DbRequest dbr) { if (SP.getBoolean(R.string.key_ns_noupload, false)) return; - if (L.isEnabled(L.NSCLIENT)) + if (L.isEnabled(LTag.NSCLIENT)) log.debug("Adding to queue: " + dbr.log()); try { MainApp.getDbHelper().create(dbr); @@ -62,10 +62,10 @@ public class UploadQueue { startService(); if (NSClientService.handler != null) { NSClientService.handler.post(() -> { - if (L.isEnabled(L.NSCLIENT)) + if (L.isEnabled(LTag.NSCLIENT)) log.debug("ClearQueue"); MainApp.getDbHelper().deleteAllDbRequests(); - if (L.isEnabled(L.NSCLIENT)) + if (L.isEnabled(LTag.NSCLIENT)) log.debug(status()); }); } @@ -83,7 +83,7 @@ public class UploadQueue { return; } if (MainApp.getDbHelper().deleteDbRequest(id) == 1) { - if (L.isEnabled(L.NSCLIENT)) + if (L.isEnabled(LTag.NSCLIENT)) log.debug("Removed item from UploadQueue. " + UploadQueue.status()); } } catch (JSONException e) { @@ -100,7 +100,7 @@ public class UploadQueue { if (NSClientService.handler != null) { NSClientService.handler.post(() -> { MainApp.getDbHelper().deleteDbRequestbyMongoId(action, _id); - if (L.isEnabled(L.NSCLIENT)) + if (L.isEnabled(LTag.NSCLIENT)) log.debug("Removing " + _id + " from UploadQueue. " + UploadQueue.status()); }); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSAddAck.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSAddAck.java index cd1b525d59..8541253f81 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSAddAck.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSAddAck.java @@ -3,10 +3,10 @@ package info.nightscout.androidaps.plugins.general.nsclient.acks; import org.json.JSONArray; import org.json.JSONObject; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import info.nightscout.androidaps.events.Event; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart; @@ -16,7 +16,7 @@ import io.socket.client.Ack; * Created by mike on 29.12.2015. */ public class NSAddAck extends Event implements Ack { - private static Logger log = StacktraceLoggerWrapper.getLogger(L.NSCLIENT); + private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.NSCLIENT); public String _id = null; public String nsClientID = null; public JSONObject json = null; @@ -48,7 +48,7 @@ public class NSAddAck extends Event implements Ack { RxBus.Companion.getINSTANCE().send(new EventNSClientRestart()); return; } - if (L.isEnabled(L.NSCLIENT)) + if (L.isEnabled(LTag.NSCLIENT)) log.debug("DBACCESS " + response.getString("result")); } return; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSUpdateAck.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSUpdateAck.java index 805a1495a8..bc79bd2739 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSUpdateAck.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/acks/NSUpdateAck.java @@ -3,10 +3,9 @@ package info.nightscout.androidaps.plugins.general.nsclient.acks; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import info.nightscout.androidaps.events.Event; -import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; import info.nightscout.androidaps.plugins.bus.RxBus; import io.socket.client.Ack; @@ -15,12 +14,13 @@ import io.socket.client.Ack; * Created by mike on 21.02.2016. */ public class NSUpdateAck extends Event implements Ack { - private static Logger log = StacktraceLoggerWrapper.getLogger(L.NSCLIENT); + private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.NSCLIENT); public boolean result = false; public String _id; public String action; - public void call(Object...args) { - JSONObject response = (JSONObject)args[0]; + + public void call(Object... args) { + JSONObject response = (JSONObject) args[0]; if (response.has("result")) try { if (response.getString("result").equals("success")) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSMbg.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSMbg.java index 537a08e363..380f082fd7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSMbg.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSMbg.java @@ -3,13 +3,12 @@ package info.nightscout.androidaps.plugins.general.nsclient.data; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; public class NSMbg { - private static Logger log = StacktraceLoggerWrapper.getLogger(L.NSCLIENT); + private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.NSCLIENT); public long date; public double mbg; public String json; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSgv.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSgv.java index ac6225813e..6fce93a3e3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSgv.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSgv.java @@ -6,6 +6,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; /** @@ -13,7 +14,7 @@ import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; * {"mgdl":105,"mills":1455136282375,"device":"xDrip-BluetoothWixel","direction":"Flat","filtered":98272,"unfiltered":98272,"noise":1,"rssi":100} */ public class NSSgv { - private static Logger log = StacktraceLoggerWrapper.getLogger(L.NSCLIENT); + private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.NSCLIENT); private JSONObject data; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSTreatment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSTreatment.java index 1c31922949..8eda8c7e70 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSTreatment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSTreatment.java @@ -3,15 +3,14 @@ package info.nightscout.androidaps.plugins.general.nsclient.data; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.Date; -import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; public class NSTreatment { - private static Logger log = StacktraceLoggerWrapper.getLogger(L.NSCLIENT); + private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.NSCLIENT); private JSONObject data; private String action = null; // "update", "remove" or null (add) @@ -82,15 +81,47 @@ public class NSTreatment { return ret; } - public String getAction() { return action; } - public JSONObject getData() { return data; } - public String get_id() { return getStringOrNull("_id"); } - public String getEnteredBy() { return getStringOrNull("enteredBy"); } - public String getEventType() { return getStringOrNull("eventType"); } - public Integer getHapp_id() { return getIntegerOrNull("happ_id"); } - public Integer getDuration() { return getIntegerOrNull("duration"); } - public Integer getMgdl() { return getIntegerOrNull("mgdl"); } - public Double getAbsolute() { return getDoubleOrNull("absolute"); } - public Long getMills() { return getLongOrNull("mills"); } - public Date getCreated_at() { return getDateOrNull("created_at"); } + public String getAction() { + return action; + } + + public JSONObject getData() { + return data; + } + + public String get_id() { + return getStringOrNull("_id"); + } + + public String getEnteredBy() { + return getStringOrNull("enteredBy"); + } + + public String getEventType() { + return getStringOrNull("eventType"); + } + + public Integer getHapp_id() { + return getIntegerOrNull("happ_id"); + } + + public Integer getDuration() { + return getIntegerOrNull("duration"); + } + + public Integer getMgdl() { + return getIntegerOrNull("mgdl"); + } + + public Double getAbsolute() { + return getDoubleOrNull("absolute"); + } + + public Long getMills() { + return getLongOrNull("mills"); + } + + public Date getCreated_at() { + return getDateOrNull("created_at"); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java index 5c43c96771..9c76a6e16b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java @@ -92,7 +92,7 @@ public class NSClientService extends DaggerService { @Inject NSClientPlugin nsClientPlugin; @Inject BuildHelper buildHelper; - private static Logger log = StacktraceLoggerWrapper.getLogger(L.NSCLIENT); + private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.NSCLIENT); private CompositeDisposable disposable = new CompositeDisposable(); static public PowerManager.WakeLock mWakeLock; @@ -178,7 +178,7 @@ public class NSClientService extends DaggerService { .toObservable(EventAppExit.class) .observeOn(Schedulers.io()) .subscribe(event -> { - if (L.isEnabled(L.NSCLIENT)) + if (L.isEnabled(LTag.NSCLIENT)) log.debug("EventAppExit received"); destroy(); stopSelf(); @@ -367,7 +367,7 @@ public class NSClientService extends DaggerService { private Emitter.Listener onDisconnect = new Emitter.Listener() { @Override public void call(Object... args) { - if (L.isEnabled(L.NSCLIENT)) + if (L.isEnabled(LTag.NSCLIENT)) log.debug("disconnect reason: {}", args); rxBus.send(new EventNSClientNewLog("NSCLIENT", "disconnect event")); } @@ -804,7 +804,7 @@ public class NSClientService extends DaggerService { if (mSocket == null || !mSocket.connected()) return; if (lastResendTime > System.currentTimeMillis() - 10 * 1000L) { - if (L.isEnabled(L.NSCLIENT)) + if (L.isEnabled(LTag.NSCLIENT)) log.debug("Skipping resend by lastResendTime: " + ((System.currentTimeMillis() - lastResendTime) / 1000L) + " sec"); return; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/SerialIOThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/SerialIOThread.java index 652ecf88b9..4b49d652a2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/SerialIOThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/SerialIOThread.java @@ -4,13 +4,13 @@ import android.bluetooth.BluetoothSocket; import android.os.SystemClock; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase; import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageHashTableBase; @@ -21,7 +21,7 @@ import info.nightscout.androidaps.utils.CRC; * Created by mike on 17.07.2016. */ public class SerialIOThread extends AbstractSerialIOThread { - private static Logger log = StacktraceLoggerWrapper.getLogger(L.PUMPBTCOMM); + private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.PUMPBTCOMM); private InputStream mInputStream = null; private OutputStream mOutputStream = null; @@ -76,7 +76,7 @@ public class SerialIOThread extends AbstractSerialIOThread { message = hashTable.findMessage(command); } - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("<<<<< " + message.getMessageName() + " " + MessageBase.toHexString(extractedBuff)); // process the message content @@ -152,7 +152,7 @@ public class SerialIOThread extends AbstractSerialIOThread { processedMessage = message; byte[] messageBytes = message.getRawMessageBytes(); - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug(">>>>> " + message.getMessageName() + " " + MessageBase.toHexString(messageBytes)); try { @@ -172,11 +172,11 @@ public class SerialIOThread extends AbstractSerialIOThread { SystemClock.sleep(200); if (!message.isReceived()) { message.handleMessageNotReceived(); - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.error("Reply not received " + message.getMessageName()); if (message.getCommand() == 0xF0F1) { danaRPump.setNewPump(false); - if (L.isEnabled(L.PUMPCOMM)) + if (L.isEnabled(LTag.PUMPCOMM)) log.debug("Old firmware detected"); } } @@ -188,28 +188,28 @@ public class SerialIOThread extends AbstractSerialIOThread { try { mInputStream.close(); } catch (Exception e) { - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug(e.getMessage()); } try { mOutputStream.close(); } catch (Exception e) { - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug(e.getMessage()); } try { mRfCommSocket.close(); } catch (Exception e) { - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug(e.getMessage()); } try { System.runFinalization(); } catch (Exception e) { - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug(e.getMessage()); } - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("Disconnected: " + reason); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRUserOptionsActivity.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRUserOptionsActivity.kt index 0c6a73a267..624b681dc5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRUserOptionsActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRUserOptionsActivity.kt @@ -11,7 +11,6 @@ import info.nightscout.androidaps.events.EventInitializationChanged import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.logging.AAPSLogger -import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin @@ -71,16 +70,15 @@ class DanaRUserOptionsActivity : NoSplashAppCompatActivity() { save_user_options.setOnClickListener { onSaveClick() } - if (L.isEnabled(L.PUMP)) - aapsLogger.debug(LTag.PUMP, - "UserOptionsLoaded:" + (System.currentTimeMillis() - danaRPump.lastConnection) / 1000 + " s ago" - + "\ntimeDisplayType:" + danaRPump.timeDisplayType - + "\nbuttonScroll:" + danaRPump.buttonScrollOnOff - + "\ntimeDisplayType:" + danaRPump.timeDisplayType - + "\nlcdOnTimeSec:" + danaRPump.lcdOnTimeSec - + "\nbackLight:" + danaRPump.backlightOnTimeSec - + "\npumpUnits:" + danaRPump.units - + "\nlowReservoir:" + danaRPump.lowReservoirRate) + aapsLogger.debug(LTag.PUMP, + "UserOptionsLoaded:" + (System.currentTimeMillis() - danaRPump.lastConnection) / 1000 + " s ago" + + "\ntimeDisplayType:" + danaRPump.timeDisplayType + + "\nbuttonScroll:" + danaRPump.buttonScrollOnOff + + "\ntimeDisplayType:" + danaRPump.timeDisplayType + + "\nlcdOnTimeSec:" + danaRPump.lcdOnTimeSec + + "\nbackLight:" + danaRPump.backlightOnTimeSec + + "\npumpUnits:" + danaRPump.units + + "\nlowReservoir:" + danaRPump.lowReservoirRate) danar_screentimeout.setParams(danaRPump.lcdOnTimeSec.toDouble(), 5.0, 240.0, 5.0, DecimalFormat("1"), false, save_user_options) danar_backlight.setParams(danaRPump.backlightOnTimeSec.toDouble(), 1.0, 60.0, 1.0, DecimalFormat("1"), false, save_user_options) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageBase.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageBase.java index f52d62d9c2..9ebf373795 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageBase.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MessageBase.java @@ -13,6 +13,7 @@ import java.util.Date; import java.util.GregorianCalendar; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; import info.nightscout.androidaps.utils.CRC; @@ -23,7 +24,7 @@ import info.nightscout.androidaps.utils.CRC; */ public class MessageBase { - private static Logger log = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM); + private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.PUMPCOMM); public byte[] buffer = new byte[512]; private int position = 6; @@ -96,7 +97,7 @@ public class MessageBase { } public void handleMessage(byte[] bytes) { - if (L.isEnabled(L.PUMPCOMM)) { + if (L.isEnabled(LTag.PUMPCOMM)) { if (bytes.length > 6) { int command = (bytes[5] & 0xFF) | ((bytes[4] << 8) & 0xFF00); log.debug("UNPROCESSED MSG: " + getMessageName() + " Command: " + String.format("%04X", command) + " Data: " + toHexString(bytes)); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTempBasalStop.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTempBasalStop.kt index b728b9e2ee..cc1308b5e3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTempBasalStop.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetTempBasalStop.kt @@ -1,11 +1,7 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm import info.nightscout.androidaps.logging.AAPSLogger -import info.nightscout.androidaps.logging.L -import info.nightscout.androidaps.logging.L.isEnabled import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.logging.StacktraceLoggerWrapper.Companion.getLogger -import org.slf4j.Logger class MsgSetTempBasalStop( private val aapsLogger: AAPSLogger diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.kt index 132141b808..f5be92ecd2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear.kt @@ -2,10 +2,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm import com.cozmo.danar.util.BleCommandUtil import info.nightscout.androidaps.logging.AAPSLogger -import info.nightscout.androidaps.logging.L -import info.nightscout.androidaps.logging.L.isEnabled import info.nightscout.androidaps.logging.LTag -import org.slf4j.LoggerFactory class DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear( private val aapsLogger: AAPSLogger @@ -15,6 +12,7 @@ class DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear( opCode = BleCommandUtil.DANAR_PACKET__OPCODE_REVIEW__SET_USER_TIME_CHANGE_FLAG_CLEAR aapsLogger.debug(LTag.PUMPCOMM, "New message") } + override fun handleMessage(data: ByteArray) { val result = intFromBuff(data, 0, 1) if (result == 0) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.java index 75ceba52ee..35097dcef5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.java @@ -26,6 +26,7 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; @@ -44,7 +45,7 @@ import info.nightscout.androidaps.utils.SP; */ public class BLEComm { - private Logger log = StacktraceLoggerWrapper.getLogger(L.PUMPBTCOMM); + private Logger log = StacktraceLoggerWrapper.getLogger(LTag.PUMPBTCOMM); private final long WRITE_DELAY_MILLIS = 50; @@ -81,7 +82,7 @@ public class BLEComm { private BluetoothGattCharacteristic UART_Write; private boolean initialize() { - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("Initializing BLEComm."); if (mBluetoothManager == null) { @@ -139,7 +140,7 @@ public class BLEComm { return false; } - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("Trying to create a new connection from: " + from); mBluetoothDeviceName = device.getName(); mBluetoothGatt = device.connectGatt(context, false, mGattCallback); @@ -152,7 +153,7 @@ public class BLEComm { } public synchronized void disconnect(String from) { - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("disconnect from: " + from); // cancel previous scheduled disconnection to prevent closing upcomming connection @@ -172,7 +173,7 @@ public class BLEComm { } public synchronized void close() { - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("BluetoothAdapter close"); if (mBluetoothGatt == null) { return; @@ -193,7 +194,7 @@ public class BLEComm { } public void onServicesDiscovered(BluetoothGatt gatt, int status) { - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("onServicesDiscovered"); if (status == BluetoothGatt.GATT_SUCCESS) { findCharacteristic(); @@ -203,21 +204,21 @@ public class BLEComm { } public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("onCharacteristicRead" + (characteristic != null ? ":" + DanaRS_Packet.toHexString(characteristic.getValue()) : "")); addToReadBuffer(characteristic.getValue()); readDataParsing(); } public void onCharacteristicChanged(BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) { - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("onCharacteristicChanged" + (characteristic != null ? ":" + DanaRS_Packet.toHexString(characteristic.getValue()) : "")); addToReadBuffer(characteristic.getValue()); new Thread(() -> readDataParsing()).start(); } public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("onCharacteristicWrite" + (characteristic != null ? ":" + DanaRS_Packet.toHexString(characteristic.getValue()) : "")); new Thread(() -> { synchronized (mSendQueue) { @@ -233,7 +234,7 @@ public class BLEComm { }; private synchronized void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) { - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("setCharacteristicNotification"); if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) { log.error("BluetoothAdapter not initialized_ERROR"); @@ -245,7 +246,7 @@ public class BLEComm { } public synchronized void readCharacteristic(BluetoothGattCharacteristic characteristic) { - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("readCharacteristic"); if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) { log.error("BluetoothAdapter not initialized_ERROR"); @@ -269,7 +270,7 @@ public class BLEComm { characteristic.setValue(data); characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE); - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("writeCharacteristic:" + DanaRS_Packet.toHexString(data)); mBluetoothGatt.writeCharacteristic(characteristic); }).start(); @@ -290,7 +291,7 @@ public class BLEComm { } private List getSupportedGattServices() { - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("getSupportedGattServices"); if ((mBluetoothAdapter == null) || (mBluetoothGatt == null)) { log.error("BluetoothAdapter not initialized_ERROR"); @@ -326,7 +327,7 @@ public class BLEComm { } private synchronized void onConnectionStateChangeSynchronized(BluetoothGatt gatt, int status, int newState) { - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("onConnectionStateChange"); if (newState == BluetoothProfile.STATE_CONNECTED) { @@ -336,7 +337,7 @@ public class BLEComm { isConnected = false; isConnecting = false; RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED)); - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("Device was disconnected " + gatt.getDevice().getName());//Device was disconnected } } @@ -372,7 +373,7 @@ public class BLEComm { if ((readBuffer[idxStartByte] == PACKET_START_BYTE) && (readBuffer[idxStartByte + 1] == PACKET_START_BYTE)) { if (idxStartByte > 0) { // if buffer doesn't start with signature remove the leading trash - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("Shifting the input buffer by " + idxStartByte + " bytes"); System.arraycopy(readBuffer, idxStartByte, readBuffer, 0, bufferLength - idxStartByte); bufferLength -= idxStartByte; @@ -427,16 +428,16 @@ public class BLEComm { // 1st packet case (byte) BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__PUMP_CHECK: if (inputBuffer.length == 4 && inputBuffer[2] == 'O' && inputBuffer[3] == 'K') { - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("<<<<< " + "ENCRYPTION__PUMP_CHECK (OK)" + " " + DanaRS_Packet.toHexString(inputBuffer)); // Grab pairing key from preferences if exists String pairingKey = SP.getString(MainApp.gs(R.string.key_danars_pairingkey) + DanaRSPlugin.mDeviceName, null); - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("Using stored pairing key: " + pairingKey); if (pairingKey != null) { byte[] encodedPairingKey = DanaRS_Packet.hexToBytes(pairingKey); byte[] bytes = BleCommandUtil.getInstance().getEncryptedPacket(BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__CHECK_PASSKEY, encodedPairingKey, null); - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug(">>>>> " + "ENCRYPTION__CHECK_PASSKEY" + " " + DanaRS_Packet.toHexString(bytes)); writeCharacteristic_NO_RESPONSE(getUARTWriteBTGattChar(), bytes); } else { @@ -445,7 +446,7 @@ public class BLEComm { } } else if (inputBuffer.length == 6 && inputBuffer[2] == 'P' && inputBuffer[3] == 'U' && inputBuffer[4] == 'M' && inputBuffer[5] == 'P') { - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("<<<<< " + "ENCRYPTION__PUMP_CHECK (PUMP)" + " " + DanaRS_Packet.toHexString(inputBuffer)); mSendQueue.clear(); RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, MainApp.gs(R.string.pumperror))); @@ -453,13 +454,13 @@ public class BLEComm { Notification n = new Notification(Notification.PUMPERROR, MainApp.gs(R.string.pumperror), Notification.URGENT); RxBus.Companion.getINSTANCE().send(new EventNewNotification(n)); } else if (inputBuffer.length == 6 && inputBuffer[2] == 'B' && inputBuffer[3] == 'U' && inputBuffer[4] == 'S' && inputBuffer[5] == 'Y') { - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("<<<<< " + "ENCRYPTION__PUMP_CHECK (BUSY)" + " " + DanaRS_Packet.toHexString(inputBuffer)); mSendQueue.clear(); RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, MainApp.gs(R.string.pumpbusy))); } else { // ERROR in response, wrong serial number - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("<<<<< " + "ENCRYPTION__PUMP_CHECK (ERROR)" + " " + DanaRS_Packet.toHexString(inputBuffer)); mSendQueue.clear(); RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTED, MainApp.gs(R.string.connectionerror))); @@ -470,7 +471,7 @@ public class BLEComm { break; // 2nd packet, pairing key case (byte) BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__CHECK_PASSKEY: - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("<<<<< " + "ENCRYPTION__CHECK_PASSKEY" + " " + DanaRS_Packet.toHexString(inputBuffer)); if (inputBuffer[2] == (byte) 0x00) { // Paring is not requested, sending time info @@ -481,7 +482,7 @@ public class BLEComm { } break; case (byte) BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_REQUEST: - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("<<<<< " + "ENCRYPTION__PASSKEY_REQUEST " + DanaRS_Packet.toHexString(inputBuffer)); if (inputBuffer[2] != (byte) 0x00) { disconnect("passkey request failed"); @@ -489,7 +490,7 @@ public class BLEComm { break; // Paring response, OK button on pump pressed case (byte) BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_RETURN: - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("<<<<< " + "ENCRYPTION__PASSKEY_RETURN " + DanaRS_Packet.toHexString(inputBuffer)); // Paring is successfull, sending time info RxBus.Companion.getINSTANCE().send(new EventDanaRSPairingSuccess()); @@ -497,24 +498,24 @@ public class BLEComm { byte[] pairingKey = {inputBuffer[2], inputBuffer[3]}; // store pairing key to preferences SP.putString(MainApp.gs(R.string.key_danars_pairingkey) + DanaRSPlugin.mDeviceName, DanaRS_Packet.bytesToHex(pairingKey)); - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("Got pairing key: " + DanaRS_Packet.bytesToHex(pairingKey)); break; // time and user password information. last packet in handshake case (byte) BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION: - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("<<<<< " + "ENCRYPTION__TIME_INFORMATION " + /*message.getMessageName() + " " + */ DanaRS_Packet.toHexString(inputBuffer)); int size = inputBuffer.length; int pass = ((inputBuffer[size - 1] & 0x000000FF) << 8) + ((inputBuffer[size - 2] & 0x000000FF)); pass = pass ^ 3463; danaRPump.setRsPassword(Integer.toHexString(pass)); - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("Pump user password: " + Integer.toHexString(pass)); RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.CONNECTED)); isConnected = true; isConnecting = false; - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("RS connected and status read"); break; } @@ -533,7 +534,7 @@ public class BLEComm { message = danaRSMessageHashTable.findMessage(receivedCommand); } if (message != null) { - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug("<<<<< " + message.getFriendlyName() + " " + DanaRS_Packet.toHexString(inputBuffer)); // process received data message.handleMessage(inputBuffer); @@ -570,7 +571,7 @@ public class BLEComm { byte[] command = {(byte) message.getType(), (byte) message.getOpCode()}; byte[] params = message.getRequestParams(); - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug(">>>>> " + message.getFriendlyName() + " " + DanaRS_Packet.toHexString(command) + " " + DanaRS_Packet.toHexString(params)); byte[] bytes = BleCommandUtil.getInstance().getEncryptedPacket(message.getOpCode(), params, null); // If there is another message not completely sent, add to queue only @@ -652,7 +653,7 @@ public class BLEComm { MainApp.instance().startActivity(i); byte[] bytes = BleCommandUtil.getInstance().getEncryptedPacket(BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__PASSKEY_REQUEST, null, null); - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug(">>>>> " + "ENCRYPTION__PASSKEY_REQUEST" + " " + DanaRS_Packet.toHexString(bytes)); writeCharacteristic_NO_RESPONSE(getUARTWriteBTGattChar(), bytes); } @@ -666,14 +667,14 @@ public class BLEComm { return; } byte[] bytes = BleCommandUtil.getInstance().getEncryptedPacket(BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__PUMP_CHECK, null, devicename); - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug(">>>>> " + "ENCRYPTION__PUMP_CHECK (0x00)" + " " + DanaRS_Packet.toHexString(bytes)); writeCharacteristic_NO_RESPONSE(getUARTWriteBTGattChar(), bytes); } private void SendTimeInfo() { byte[] bytes = BleCommandUtil.getInstance().getEncryptedPacket(BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__TIME_INFORMATION, null, null); - if (L.isEnabled(L.PUMPBTCOMM)) + if (L.isEnabled(LTag.PUMPBTCOMM)) log.debug(">>>>> " + "ENCRYPTION__TIME_INFORMATION" + " " + DanaRS_Packet.toHexString(bytes)); writeCharacteristic_NO_RESPONSE(getUARTWriteBTGattChar(), bytes); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/cgms/MedtronicCGMSHistoryDecoder.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/cgms/MedtronicCGMSHistoryDecoder.java index c3d39954a0..9d040fc105 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/cgms/MedtronicCGMSHistoryDecoder.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/cgms/MedtronicCGMSHistoryDecoder.java @@ -2,13 +2,12 @@ package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.cgms; import org.joda.time.LocalDateTime; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil; import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.MedtronicHistoryDecoder; @@ -23,7 +22,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.RecordDeco public class MedtronicCGMSHistoryDecoder extends MedtronicHistoryDecoder { - private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM); + private static final Logger LOG = StacktraceLoggerWrapper.getLogger(LTag.PUMPCOMM); // CGMSValuesWriter cgmsValuesWriter = null; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BasalProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BasalProfile.java index 475066cb6c..61b235f1d2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BasalProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/BasalProfile.java @@ -364,7 +364,7 @@ public class BasalProfile { private boolean isLogEnabled() { - return L.isEnabled(L.PUMPCOMM); + return L.isEnabled(LTag.PUMPCOMM); } public boolean verify(PumpType pumpType) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalPair.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalPair.java index 09dd929074..caac54e122 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalPair.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalPair.java @@ -42,7 +42,7 @@ public class TempBasalPair extends info.nightscout.androidaps.plugins.pump.commo public TempBasalPair(AAPSLogger aapsLogger, byte[] response) { super(); - if (L.isEnabled(L.PUMPCOMM)) + if (L.isEnabled(LTag.PUMPCOMM)) aapsLogger.debug(LTag.PUMPBTCOMM, "Received TempBasal response: " + ByteUtil.getHex(response)); isPercent = response[0] == 1; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIPostprocessor.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIPostprocessor.java index cc5878c27e..d206337384 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIPostprocessor.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIPostprocessor.java @@ -8,6 +8,7 @@ import java.util.Date; import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodPumpPluginInterface; import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; @@ -19,7 +20,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus; public class OmnipodUIPostprocessor { - private static final Logger LOG = LoggerFactory.getLogger(L.PUMP); + private static final Logger LOG = LoggerFactory.getLogger(LTag.PUMP.name()); private OmnipodPumpStatus pumpStatus; private OmnipodPumpPluginInterface omnipodPumpPlugin; @@ -102,7 +103,7 @@ public class OmnipodUIPostprocessor { private boolean isLogEnabled() { - return L.isEnabled(L.PUMP); + return L.isEnabled(LTag.PUMP); } public RxBusWrapper getRxBus() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/EversensePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/EversensePlugin.kt index 49e6ddbab8..91683b3f4f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/EversensePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/EversensePlugin.kt @@ -12,8 +12,6 @@ import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.PluginDescription import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.logging.AAPSLogger -import info.nightscout.androidaps.logging.L -import info.nightscout.androidaps.logging.L.isEnabled import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.utils.DateUtil @@ -48,33 +46,29 @@ class EversensePlugin @Inject constructor( override fun handleNewData(intent: Intent) { if (!isEnabled(PluginType.BGSOURCE)) return val bundle = intent.extras ?: return - if (isEnabled(L.BGSOURCE)) { - if (bundle.containsKey("currentCalibrationPhase")) aapsLogger.debug(LTag.BGSOURCE, "currentCalibrationPhase: " + bundle.getString("currentCalibrationPhase")) - if (bundle.containsKey("placementModeInProgress")) aapsLogger.debug(LTag.BGSOURCE, "placementModeInProgress: " + bundle.getBoolean("placementModeInProgress")) - if (bundle.containsKey("glucoseLevel")) aapsLogger.debug(LTag.BGSOURCE, "glucoseLevel: " + bundle.getInt("glucoseLevel")) - if (bundle.containsKey("glucoseTrendDirection")) aapsLogger.debug(LTag.BGSOURCE, "glucoseTrendDirection: " + bundle.getString("glucoseTrendDirection")) - if (bundle.containsKey("glucoseTimestamp")) aapsLogger.debug(LTag.BGSOURCE, "glucoseTimestamp: " + DateUtil.dateAndTimeString(bundle.getLong("glucoseTimestamp"))) - if (bundle.containsKey("batteryLevel")) aapsLogger.debug(LTag.BGSOURCE, "batteryLevel: " + bundle.getString("batteryLevel")) - if (bundle.containsKey("signalStrength")) aapsLogger.debug(LTag.BGSOURCE, "signalStrength: " + bundle.getString("signalStrength")) - if (bundle.containsKey("transmitterVersionNumber")) aapsLogger.debug(LTag.BGSOURCE, "transmitterVersionNumber: " + bundle.getString("transmitterVersionNumber")) - if (bundle.containsKey("isXLVersion")) aapsLogger.debug(LTag.BGSOURCE, "isXLVersion: " + bundle.getBoolean("isXLVersion")) - if (bundle.containsKey("transmitterModelNumber")) aapsLogger.debug(LTag.BGSOURCE, "transmitterModelNumber: " + bundle.getString("transmitterModelNumber")) - if (bundle.containsKey("transmitterSerialNumber")) aapsLogger.debug(LTag.BGSOURCE, "transmitterSerialNumber: " + bundle.getString("transmitterSerialNumber")) - if (bundle.containsKey("transmitterAddress")) aapsLogger.debug(LTag.BGSOURCE, "transmitterAddress: " + bundle.getString("transmitterAddress")) - if (bundle.containsKey("sensorInsertionTimestamp")) aapsLogger.debug(LTag.BGSOURCE, "sensorInsertionTimestamp: " + DateUtil.dateAndTimeString(bundle.getLong("sensorInsertionTimestamp"))) - if (bundle.containsKey("transmitterVersionNumber")) aapsLogger.debug(LTag.BGSOURCE, "transmitterVersionNumber: " + bundle.getString("transmitterVersionNumber")) - if (bundle.containsKey("transmitterConnectionState")) aapsLogger.debug(LTag.BGSOURCE, "transmitterConnectionState: " + bundle.getString("transmitterConnectionState")) - } + if (bundle.containsKey("currentCalibrationPhase")) aapsLogger.debug(LTag.BGSOURCE, "currentCalibrationPhase: " + bundle.getString("currentCalibrationPhase")) + if (bundle.containsKey("placementModeInProgress")) aapsLogger.debug(LTag.BGSOURCE, "placementModeInProgress: " + bundle.getBoolean("placementModeInProgress")) + if (bundle.containsKey("glucoseLevel")) aapsLogger.debug(LTag.BGSOURCE, "glucoseLevel: " + bundle.getInt("glucoseLevel")) + if (bundle.containsKey("glucoseTrendDirection")) aapsLogger.debug(LTag.BGSOURCE, "glucoseTrendDirection: " + bundle.getString("glucoseTrendDirection")) + if (bundle.containsKey("glucoseTimestamp")) aapsLogger.debug(LTag.BGSOURCE, "glucoseTimestamp: " + DateUtil.dateAndTimeString(bundle.getLong("glucoseTimestamp"))) + if (bundle.containsKey("batteryLevel")) aapsLogger.debug(LTag.BGSOURCE, "batteryLevel: " + bundle.getString("batteryLevel")) + if (bundle.containsKey("signalStrength")) aapsLogger.debug(LTag.BGSOURCE, "signalStrength: " + bundle.getString("signalStrength")) + if (bundle.containsKey("transmitterVersionNumber")) aapsLogger.debug(LTag.BGSOURCE, "transmitterVersionNumber: " + bundle.getString("transmitterVersionNumber")) + if (bundle.containsKey("isXLVersion")) aapsLogger.debug(LTag.BGSOURCE, "isXLVersion: " + bundle.getBoolean("isXLVersion")) + if (bundle.containsKey("transmitterModelNumber")) aapsLogger.debug(LTag.BGSOURCE, "transmitterModelNumber: " + bundle.getString("transmitterModelNumber")) + if (bundle.containsKey("transmitterSerialNumber")) aapsLogger.debug(LTag.BGSOURCE, "transmitterSerialNumber: " + bundle.getString("transmitterSerialNumber")) + if (bundle.containsKey("transmitterAddress")) aapsLogger.debug(LTag.BGSOURCE, "transmitterAddress: " + bundle.getString("transmitterAddress")) + if (bundle.containsKey("sensorInsertionTimestamp")) aapsLogger.debug(LTag.BGSOURCE, "sensorInsertionTimestamp: " + DateUtil.dateAndTimeString(bundle.getLong("sensorInsertionTimestamp"))) + if (bundle.containsKey("transmitterVersionNumber")) aapsLogger.debug(LTag.BGSOURCE, "transmitterVersionNumber: " + bundle.getString("transmitterVersionNumber")) + if (bundle.containsKey("transmitterConnectionState")) aapsLogger.debug(LTag.BGSOURCE, "transmitterConnectionState: " + bundle.getString("transmitterConnectionState")) if (bundle.containsKey("glucoseLevels")) { val glucoseLevels = bundle.getIntArray("glucoseLevels") val glucoseRecordNumbers = bundle.getIntArray("glucoseRecordNumbers") val glucoseTimestamps = bundle.getLongArray("glucoseTimestamps") if (glucoseLevels != null && glucoseRecordNumbers != null && glucoseTimestamps != null) { - if (isEnabled(L.BGSOURCE)) { - aapsLogger.debug(LTag.BGSOURCE, "glucoseLevels" + Arrays.toString(glucoseLevels)) - aapsLogger.debug(LTag.BGSOURCE, "glucoseRecordNumbers" + Arrays.toString(glucoseRecordNumbers)) - aapsLogger.debug(LTag.BGSOURCE, "glucoseTimestamps" + Arrays.toString(glucoseTimestamps)) - } + aapsLogger.debug(LTag.BGSOURCE, "glucoseLevels" + Arrays.toString(glucoseLevels)) + aapsLogger.debug(LTag.BGSOURCE, "glucoseRecordNumbers" + Arrays.toString(glucoseRecordNumbers)) + aapsLogger.debug(LTag.BGSOURCE, "glucoseTimestamps" + Arrays.toString(glucoseTimestamps)) for (i in glucoseLevels.indices) { val bgReading = BgReading() bgReading.value = glucoseLevels[i].toDouble() @@ -95,11 +89,9 @@ class EversensePlugin @Inject constructor( val calibrationTimestamps = bundle.getLongArray("calibrationTimestamps") val calibrationRecordNumbers = bundle.getLongArray("calibrationRecordNumbers") if (calibrationGlucoseLevels != null && calibrationTimestamps != null && calibrationRecordNumbers != null) { - if (isEnabled(L.BGSOURCE)) { - aapsLogger.debug(LTag.BGSOURCE, "calibrationGlucoseLevels" + Arrays.toString(calibrationGlucoseLevels)) - aapsLogger.debug(LTag.BGSOURCE, "calibrationTimestamps" + Arrays.toString(calibrationTimestamps)) - aapsLogger.debug(LTag.BGSOURCE, "calibrationRecordNumbers" + Arrays.toString(calibrationRecordNumbers)) - } + aapsLogger.debug(LTag.BGSOURCE, "calibrationGlucoseLevels" + Arrays.toString(calibrationGlucoseLevels)) + aapsLogger.debug(LTag.BGSOURCE, "calibrationTimestamps" + Arrays.toString(calibrationTimestamps)) + aapsLogger.debug(LTag.BGSOURCE, "calibrationRecordNumbers" + Arrays.toString(calibrationRecordNumbers)) for (i in calibrationGlucoseLevels.indices) { try { if (MainApp.getDbHelper().getCareportalEventFromTimestamp(calibrationTimestamps[i]) == null) { diff --git a/app/src/main/java/info/nightscout/androidaps/utils/SntpClient.java b/app/src/main/java/info/nightscout/androidaps/utils/SntpClient.java index 2c28d3e212..38ef842f8d 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/SntpClient.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/SntpClient.java @@ -18,13 +18,12 @@ package info.nightscout.androidaps.utils; import android.os.SystemClock; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; -import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; /** @@ -40,7 +39,7 @@ import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; * */ public class SntpClient { - private static Logger log = StacktraceLoggerWrapper.getLogger(L.CORE); + private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.CORE); //private static final int REFERENCE_TIME_OFFSET = 16; private static final int ORIGINATE_TIME_OFFSET = 24; From 99907ed0291160fb2136484a6e792467e328ea1c Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 4 May 2020 00:33:27 +0200 Subject: [PATCH 06/16] SP -> core --- .../dependencyInjection/AppModule.kt | 8 -- .../info/nightscout/androidaps/utils/SP.java | 121 ------------------ .../core/dependencyInjection/CoreModule.kt | 9 ++ .../androidaps/utils/SafeParse.java | 20 ++- .../androidaps/utils/sharedPreferences/SP.kt | 0 .../sharedPreferences/SPImplementation.kt | 0 6 files changed, 17 insertions(+), 141 deletions(-) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/SafeParse.java (67%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/sharedPreferences/SP.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/sharedPreferences/SPImplementation.kt (100%) diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt index bb968938d5..9c78bd5642 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt @@ -1,7 +1,6 @@ package info.nightscout.androidaps.dependencyInjection import android.content.Context -import androidx.preference.PreferenceManager import dagger.Binds import dagger.Lazy import dagger.Module @@ -22,7 +21,6 @@ import info.nightscout.androidaps.queue.CommandQueue import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP -import info.nightscout.androidaps.utils.sharedPreferences.SPImplementation import info.nightscout.androidaps.utils.storage.FileStorage import info.nightscout.androidaps.utils.storage.Storage import javax.inject.Singleton @@ -30,12 +28,6 @@ import javax.inject.Singleton @Module(includes = [AppModule.AppBindings::class, PluginsModule::class]) open class AppModule { - @Provides - @Singleton - fun provideSharedPreferences(context: Context, resourceHelper: ResourceHelper): SP { - return SPImplementation(PreferenceManager.getDefaultSharedPreferences(context), resourceHelper) - } - @Provides @Singleton fun provideProfileFunction(injector: HasAndroidInjector, aapsLogger: AAPSLogger, sp: SP, resourceHelper: ResourceHelper, activePlugin: ActivePluginProvider, fabricPrivacy: FabricPrivacy): ProfileFunction { diff --git a/app/src/main/java/info/nightscout/androidaps/utils/SP.java b/app/src/main/java/info/nightscout/androidaps/utils/SP.java index 08ad3a8693..a6124acf10 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/SP.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/SP.java @@ -19,26 +19,6 @@ public class SP { return sharedPreferences.getAll(); } - @Deprecated - static public void clear() { - sharedPreferences.edit().clear().apply(); - } - - @Deprecated - static public boolean contains(String key) { - return sharedPreferences.contains(key); - } - - @Deprecated - static public boolean contains(int resourceId) { - return sharedPreferences.contains(MainApp.gs(resourceId)); - } - - @Deprecated - static public String getString(int resourceID, String defaultValue) { - return sharedPreferences.getString(MainApp.gs(resourceID), defaultValue); - } - @Deprecated static public String getString(String key, String defaultValue) { return sharedPreferences.getString(key, defaultValue); @@ -53,102 +33,6 @@ public class SP { } } - @Deprecated - static public boolean getBoolean(String key, Boolean defaultValue) { - try { - return sharedPreferences.getBoolean(key, defaultValue); - } catch (Exception e) { - return defaultValue; - } - } - - @Deprecated - static public Double getDouble(int resourceID, Double defaultValue) { - return SafeParse.stringToDouble(sharedPreferences.getString(MainApp.gs(resourceID), defaultValue.toString())); - } - - @Deprecated - static public Double getDouble(String key, Double defaultValue) { - return SafeParse.stringToDouble(sharedPreferences.getString(key, defaultValue.toString())); - } - - @Deprecated - static public int getInt(int resourceID, Integer defaultValue) { - try { - return sharedPreferences.getInt(MainApp.gs(resourceID), defaultValue); - } catch (Exception e) { - return SafeParse.stringToInt(sharedPreferences.getString(MainApp.gs(resourceID), defaultValue.toString())); - } - } - - @Deprecated - static public int getInt(String key, Integer defaultValue) { - try { - return sharedPreferences.getInt(key, defaultValue); - } catch (Exception e) { - return SafeParse.stringToInt(sharedPreferences.getString(key, defaultValue.toString())); - } - } - - @Deprecated - static public long getLong(int resourceID, Long defaultValue) { - try { - return sharedPreferences.getLong(MainApp.gs(resourceID), defaultValue); - } catch (Exception e) { - return SafeParse.stringToLong(sharedPreferences.getString(MainApp.gs(resourceID), defaultValue.toString())); - } - } - - @Deprecated - static public long getLong(String key, Long defaultValue) { - try { - return sharedPreferences.getLong(key, defaultValue); - } catch (Exception e) { - return SafeParse.stringToLong(sharedPreferences.getString(key, defaultValue.toString())); - } - } - - @Deprecated - static public void putBoolean(String key, boolean value) { - sharedPreferences.edit().putBoolean(key, value).apply(); - } - - @Deprecated - static public void putBoolean(int resourceID, boolean value) { - sharedPreferences.edit().putBoolean(MainApp.gs(resourceID), value).apply(); - } - - @Deprecated - static public void putDouble(String key, double value) { - sharedPreferences.edit().putString(key, Double.toString(value)).apply(); - } - - @Deprecated - static public void putLong(String key, long value) { - sharedPreferences.edit().putLong(key, value).apply(); - } - - @Deprecated - static public void putLong(int resourceID, long value) { - sharedPreferences.edit().putLong(MainApp.gs(resourceID), value).apply(); - } - - @Deprecated - static public void putInt(String key, int value) { - sharedPreferences.edit().putInt(key, value).apply(); - } - - @Deprecated - static public void putInt(int resourceID, int value) { - sharedPreferences.edit().putInt(MainApp.gs(resourceID), value).apply(); - } - - @Deprecated - static public void incInt(int resourceID) { - int value = getInt(resourceID, 0) + 1; - sharedPreferences.edit().putInt(MainApp.gs(resourceID), value).apply(); - } - @Deprecated static public void putString(int resourceID, String value) { sharedPreferences.edit().putString(MainApp.gs(resourceID), value).apply(); @@ -159,11 +43,6 @@ public class SP { sharedPreferences.edit().putString(key, value).apply(); } - @Deprecated - static public void remove(int resourceID) { - sharedPreferences.edit().remove(MainApp.gs(resourceID)).apply(); - } - @Deprecated static public void remove(String key) { sharedPreferences.edit().remove(key).apply(); diff --git a/core/src/main/java/info/nightscout/androidaps/core/dependencyInjection/CoreModule.kt b/core/src/main/java/info/nightscout/androidaps/core/dependencyInjection/CoreModule.kt index 3d022dfd6f..b7ec76d301 100644 --- a/core/src/main/java/info/nightscout/androidaps/core/dependencyInjection/CoreModule.kt +++ b/core/src/main/java/info/nightscout/androidaps/core/dependencyInjection/CoreModule.kt @@ -1,10 +1,13 @@ package info.nightscout.androidaps.core.dependencyInjection import android.content.Context +import android.preference.PreferenceManager import dagger.Module import dagger.Provides import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelperImplementation +import info.nightscout.androidaps.utils.sharedPreferences.SP +import info.nightscout.androidaps.utils.sharedPreferences.SPImplementation import javax.inject.Singleton @Module @@ -15,4 +18,10 @@ open class CoreModule { fun provideResources(context: Context): ResourceHelper { return ResourceHelperImplementation(context) } + + @Provides + @Singleton + fun provideSharedPreferences(context: Context, resourceHelper: ResourceHelper): SP { + return SPImplementation(PreferenceManager.getDefaultSharedPreferences(context), resourceHelper) + } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/utils/SafeParse.java b/core/src/main/java/info/nightscout/androidaps/utils/SafeParse.java similarity index 67% rename from app/src/main/java/info/nightscout/androidaps/utils/SafeParse.java rename to core/src/main/java/info/nightscout/androidaps/utils/SafeParse.java index 4e1ee5ceae..0ea68bd1eb 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/SafeParse.java +++ b/core/src/main/java/info/nightscout/androidaps/utils/SafeParse.java @@ -1,15 +1,11 @@ package info.nightscout.androidaps.utils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import info.nightscout.androidaps.logging.StacktraceLoggerWrapper; - /** * Created by mike on 23.06.2016. */ public class SafeParse { - private static Logger log = StacktraceLoggerWrapper.getLogger(SafeParse.class); + // TODO return logging with dagger +// private static Logger log = StacktraceLoggerWrapper.getLogger(SafeParse.class); public static Double stringToDouble(String input) { Double result = 0d; input = input.replace(",", "."); @@ -19,7 +15,7 @@ public class SafeParse { try { result = Double.parseDouble(input); } catch (Exception e) { - log.error("Error parsing " + input + " to double"); +// log.error("Error parsing " + input + " to double"); } return result; } @@ -33,21 +29,21 @@ public class SafeParse { try { result = Integer.parseInt(input); } catch (Exception e) { - log.error("Error parsing " + input + " to int"); +// log.error("Error parsing " + input + " to int"); } return result; } - public static Long stringToLong(String input) { + public static Long stringToLong(String input) { Long result = 0L; input = input.replace(",", "."); input = input.replace("−", "-"); - if (input.equals("")) - return 0L; + if (input.equals("")) + return 0L; try { result = Long.parseLong(input); } catch (Exception e) { - log.error("Error parsing " + input + " to long"); +// log.error("Error parsing " + input + " to long"); } return result; } diff --git a/app/src/main/java/info/nightscout/androidaps/utils/sharedPreferences/SP.kt b/core/src/main/java/info/nightscout/androidaps/utils/sharedPreferences/SP.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/sharedPreferences/SP.kt rename to core/src/main/java/info/nightscout/androidaps/utils/sharedPreferences/SP.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/sharedPreferences/SPImplementation.kt b/core/src/main/java/info/nightscout/androidaps/utils/sharedPreferences/SPImplementation.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/sharedPreferences/SPImplementation.kt rename to core/src/main/java/info/nightscout/androidaps/utils/sharedPreferences/SPImplementation.kt From 5be4a5dd9732323017c8a400caac6e6b588b58fd Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 4 May 2020 00:42:13 +0200 Subject: [PATCH 07/16] AAPSLogger -> core --- .../androidaps/dependencyInjection/AppModule.kt | 11 +---------- core/build.gradle | 2 ++ .../core/dependencyInjection/CoreModule.kt | 16 ++++++++++------ .../nightscout/androidaps/logging/AAPSLogger.kt | 0 .../androidaps/logging/AAPSLoggerProduction.kt | 0 .../androidaps/logging/AAPSLoggerTest.kt | 0 .../androidaps/logging/BundleLogger.java | 0 .../java/info/nightscout/androidaps/logging/L.kt | 2 -- .../info/nightscout/androidaps/logging/LTag.kt | 0 .../logging/StacktraceLoggerWrapper.kt | 0 10 files changed, 13 insertions(+), 18 deletions(-) rename {app => core}/src/main/java/info/nightscout/androidaps/logging/AAPSLogger.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerProduction.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerTest.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/logging/BundleLogger.java (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/logging/L.kt (95%) rename {app => core}/src/main/java/info/nightscout/androidaps/logging/LTag.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/logging/StacktraceLoggerWrapper.kt (100%) diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt index 9c78bd5642..548402341b 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt @@ -12,8 +12,6 @@ import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.logging.AAPSLogger -import info.nightscout.androidaps.logging.AAPSLoggerProduction -import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.plugins.configBuilder.PluginStore import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImplementation @@ -34,10 +32,6 @@ open class AppModule { return ProfileFunctionImplementation(injector, aapsLogger, sp, resourceHelper, activePlugin, fabricPrivacy) } - @Provides - @Singleton - fun provideAAPSLogger(l: L): AAPSLogger = AAPSLoggerProduction(l) - @Provides fun providesPlugins(@PluginsModule.AllConfigs allConfigs: Map<@JvmSuppressWildcards Int, @JvmSuppressWildcards PluginBase>, @PluginsModule.PumpDriver pumpDrivers: Lazy>, @@ -64,10 +58,7 @@ open class AppModule { @Binds fun bindContext(mainApp: MainApp): Context @Binds fun bindInjector(mainApp: MainApp): HasAndroidInjector - - @Binds - fun bindActivePluginProvider(pluginStore: PluginStore): ActivePluginProvider - + @Binds fun bindActivePluginProvider(pluginStore: PluginStore): ActivePluginProvider @Binds fun commandQueueProvider(commandQueue: CommandQueue): CommandQueueProvider } diff --git a/core/build.gradle b/core/build.gradle index 58ed7cbfb3..850732a959 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -51,6 +51,8 @@ dependencies { kapt "com.google.dagger:dagger-android-processor:$dagger_version" kapt "com.google.dagger:dagger-compiler:$dagger_version" + implementation 'org.slf4j:slf4j-api:1.7.30' + testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' diff --git a/core/src/main/java/info/nightscout/androidaps/core/dependencyInjection/CoreModule.kt b/core/src/main/java/info/nightscout/androidaps/core/dependencyInjection/CoreModule.kt index b7ec76d301..19e64742fc 100644 --- a/core/src/main/java/info/nightscout/androidaps/core/dependencyInjection/CoreModule.kt +++ b/core/src/main/java/info/nightscout/androidaps/core/dependencyInjection/CoreModule.kt @@ -4,6 +4,9 @@ import android.content.Context import android.preference.PreferenceManager import dagger.Module import dagger.Provides +import info.nightscout.androidaps.logging.AAPSLogger +import info.nightscout.androidaps.logging.AAPSLoggerProduction +import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelperImplementation import info.nightscout.androidaps.utils.sharedPreferences.SP @@ -15,13 +18,14 @@ open class CoreModule { @Provides @Singleton - fun provideResources(context: Context): ResourceHelper { - return ResourceHelperImplementation(context) - } + fun provideResources(context: Context): ResourceHelper = ResourceHelperImplementation(context) @Provides @Singleton - fun provideSharedPreferences(context: Context, resourceHelper: ResourceHelper): SP { - return SPImplementation(PreferenceManager.getDefaultSharedPreferences(context), resourceHelper) - } + fun provideSharedPreferences(context: Context, resourceHelper: ResourceHelper): SP = SPImplementation(PreferenceManager.getDefaultSharedPreferences(context), resourceHelper) + + @Provides + @Singleton + fun provideAAPSLogger(l: L): AAPSLogger = AAPSLoggerProduction(l) + } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/logging/AAPSLogger.kt b/core/src/main/java/info/nightscout/androidaps/logging/AAPSLogger.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/logging/AAPSLogger.kt rename to core/src/main/java/info/nightscout/androidaps/logging/AAPSLogger.kt diff --git a/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerProduction.kt b/core/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerProduction.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerProduction.kt rename to core/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerProduction.kt diff --git a/app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerTest.kt b/core/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerTest.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerTest.kt rename to core/src/main/java/info/nightscout/androidaps/logging/AAPSLoggerTest.kt diff --git a/app/src/main/java/info/nightscout/androidaps/logging/BundleLogger.java b/core/src/main/java/info/nightscout/androidaps/logging/BundleLogger.java similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/logging/BundleLogger.java rename to core/src/main/java/info/nightscout/androidaps/logging/BundleLogger.java diff --git a/app/src/main/java/info/nightscout/androidaps/logging/L.kt b/core/src/main/java/info/nightscout/androidaps/logging/L.kt similarity index 95% rename from app/src/main/java/info/nightscout/androidaps/logging/L.kt rename to core/src/main/java/info/nightscout/androidaps/logging/L.kt index 5decfceb53..b2156c4080 100644 --- a/app/src/main/java/info/nightscout/androidaps/logging/L.kt +++ b/core/src/main/java/info/nightscout/androidaps/logging/L.kt @@ -1,7 +1,5 @@ package info.nightscout.androidaps.logging -import androidx.preference.PreferenceManager -import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.utils.sharedPreferences.SP import java.util.* import javax.inject.Inject diff --git a/app/src/main/java/info/nightscout/androidaps/logging/LTag.kt b/core/src/main/java/info/nightscout/androidaps/logging/LTag.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/logging/LTag.kt rename to core/src/main/java/info/nightscout/androidaps/logging/LTag.kt diff --git a/app/src/main/java/info/nightscout/androidaps/logging/StacktraceLoggerWrapper.kt b/core/src/main/java/info/nightscout/androidaps/logging/StacktraceLoggerWrapper.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/logging/StacktraceLoggerWrapper.kt rename to core/src/main/java/info/nightscout/androidaps/logging/StacktraceLoggerWrapper.kt From e1ddde969777a4ba4766aaef67a74152e9a00740 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 4 May 2020 01:27:47 +0200 Subject: [PATCH 08/16] FabricPrivacy -> core --- .../nightscout/androidaps/MainActivity.kt | 38 +++++++++++++++- app/src/main/res/values/strings.xml | 1 - core/build.gradle | 4 ++ .../androidaps/utils/FabricPrivacy.kt | 44 ++----------------- core/src/main/res/values/strings.xml | 4 ++ 5 files changed, 49 insertions(+), 42 deletions(-) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/FabricPrivacy.kt (61%) create mode 100644 core/src/main/res/values/strings.xml diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt index adc325293c..4bcfd5611a 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt @@ -41,6 +41,8 @@ import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker +import info.nightscout.androidaps.plugins.constraints.signatureVerifier.SignatureVerifierPlugin import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerUtils import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin @@ -59,6 +61,7 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable import kotlinx.android.synthetic.main.activity_main.* +import java.util.* import javax.inject.Inject import kotlin.system.exitProcess @@ -79,6 +82,8 @@ class MainActivity : NoSplashAppCompatActivity() { @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var protectionCheck: ProtectionCheck @Inject lateinit var iconsProvider: IconsProvider + @Inject lateinit var constraintChecker: ConstraintChecker + @Inject lateinit var signatureVerifierPlugin: SignatureVerifierPlugin private lateinit var actionBarDrawerToggle: ActionBarDrawerToggle private var pluginPreferencesMenuItem: MenuItem? = null @@ -109,7 +114,7 @@ class MainActivity : NoSplashAppCompatActivity() { //Check here if loop plugin is disabled. Else check via constraints if (!loopPlugin.isEnabled(PluginType.LOOP)) versionCheckerUtils.triggerCheckVersion() - fabricPrivacy.setUserStats() + setUserStats() setupViews() disposable.add(rxBus .toObservable(EventRebuildTabs::class.java) @@ -325,4 +330,35 @@ class MainActivity : NoSplashAppCompatActivity() { } return actionBarDrawerToggle.onOptionsItemSelected(item) } + + // Correct place for calling setUserStats() would be probably MainApp + // but we need to have it called at least once a day. Thus this location + + private fun setUserStats() { + if (!fabricPrivacy.fabricEnabled()) return + val closedLoopEnabled = if (constraintChecker.isClosedLoopAllowed().value()) "CLOSED_LOOP_ENABLED" else "CLOSED_LOOP_DISABLED" + // Size is limited to 36 chars + val remote = BuildConfig.REMOTE.toLowerCase(Locale.getDefault()) + .replace("https://", "") + .replace("http://", "") + .replace(".git", "") + .replace(".com/", ":") + .replace(".org/", ":") + .replace(".net/", ":") + fabricPrivacy.firebaseAnalytics.setUserProperty("Mode", BuildConfig.APPLICATION_ID + "-" + closedLoopEnabled) + fabricPrivacy.firebaseAnalytics.setUserProperty("Language", sp.getString(R.string.key_language, Locale.getDefault().language)) + fabricPrivacy.firebaseAnalytics.setUserProperty("Version", BuildConfig.VERSION) + fabricPrivacy.firebaseAnalytics.setUserProperty("HEAD", BuildConfig.HEAD) + fabricPrivacy.firebaseAnalytics.setUserProperty("Remote", remote) + val hashes: List = signatureVerifierPlugin.shortHashes() + if (hashes.isNotEmpty()) fabricPrivacy.firebaseAnalytics.setUserProperty("Hash", hashes[0]) + activePlugin.activePump.let { fabricPrivacy.firebaseAnalytics.setUserProperty("Pump", it::class.java.simpleName) } + if (!Config.NSCLIENT && !Config.PUMPCONTROL) + activePlugin.activeAPS.let { fabricPrivacy.firebaseAnalytics.setUserProperty("Aps", it::class.java.simpleName) } + activePlugin.activeBgSource.let { fabricPrivacy.firebaseAnalytics.setUserProperty("BgSource", it::class.java.simpleName) } + fabricPrivacy.firebaseAnalytics.setUserProperty("Profile", activePlugin.activeProfileInterface.javaClass.simpleName) + activePlugin.activeSensitivity.let { fabricPrivacy.firebaseAnalytics.setUserProperty("Sensitivity", it::class.java.simpleName) } + activePlugin.activeInsulin.let { fabricPrivacy.firebaseAnalytics.setUserProperty("Insulin", it::class.java.simpleName) } + } + } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2a648432fe..10a39d41ae 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1769,7 +1769,6 @@ snoozedTo snooze_dst_in24h snooze_loopdisabled - enable_fabric ^\\d{6} Use of Extended bolus feature will stop closed loop mode for the time of running extended bolus. Do you really want it? Closed loop disabled because of running Extended bolus diff --git a/core/build.gradle b/core/build.gradle index 850732a959..e8c8867b8b 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -52,6 +52,10 @@ dependencies { kapt "com.google.dagger:dagger-compiler:$dagger_version" implementation 'org.slf4j:slf4j-api:1.7.30' + implementation 'com.google.firebase:firebase-core:17.3.0' + implementation('com.crashlytics.sdk.android:crashlytics:2.10.1@aar') { + transitive = true; + } testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' diff --git a/app/src/main/java/info/nightscout/androidaps/utils/FabricPrivacy.kt b/core/src/main/java/info/nightscout/androidaps/utils/FabricPrivacy.kt similarity index 61% rename from app/src/main/java/info/nightscout/androidaps/utils/FabricPrivacy.kt rename to core/src/main/java/info/nightscout/androidaps/utils/FabricPrivacy.kt index a87fd3fef9..9468f21bd4 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/FabricPrivacy.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/FabricPrivacy.kt @@ -4,17 +4,11 @@ import android.content.Context import android.os.Bundle import com.crashlytics.android.Crashlytics import com.google.firebase.analytics.FirebaseAnalytics -import info.nightscout.androidaps.BuildConfig -import info.nightscout.androidaps.Config -import info.nightscout.androidaps.R -import info.nightscout.androidaps.interfaces.ActivePluginProvider +import info.nightscout.androidaps.core.R import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag -import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker -import info.nightscout.androidaps.plugins.constraints.signatureVerifier.SignatureVerifierPlugin import info.nightscout.androidaps.utils.sharedPreferences.SP import io.fabric.sdk.android.Fabric -import java.util.* import javax.inject.Inject import javax.inject.Singleton @@ -27,13 +21,10 @@ import javax.inject.Singleton class FabricPrivacy @Inject constructor( context: Context, private val aapsLogger: AAPSLogger, - private val sp: SP, - private val constraintChecker: ConstraintChecker, - private val signatureVerifierPlugin: SignatureVerifierPlugin, - private val activePlugin: ActivePluginProvider + private val sp: SP ) { - private var firebaseAnalytics: FirebaseAnalytics + var firebaseAnalytics: FirebaseAnalytics init { instance = this @@ -49,7 +40,7 @@ class FabricPrivacy @Inject constructor( private lateinit var instance: FabricPrivacy @JvmStatic - @Deprecated("use dagger") + @Deprecated("Use Dagger") fun getInstance(): FabricPrivacy = instance } @@ -122,31 +113,4 @@ class FabricPrivacy @Inject constructor( fun fabricEnabled(): Boolean { return sp.getBoolean(R.string.key_enable_fabric, true) } - - fun setUserStats() { - if (!fabricEnabled()) return - val closedLoopEnabled = if (constraintChecker.isClosedLoopAllowed().value()) "CLOSED_LOOP_ENABLED" else "CLOSED_LOOP_DISABLED" - // Size is limited to 36 chars - val remote = BuildConfig.REMOTE.toLowerCase(Locale.getDefault()) - .replace("https://", "") - .replace("http://", "") - .replace(".git", "") - .replace(".com/", ":") - .replace(".org/", ":") - .replace(".net/", ":") - firebaseAnalytics.setUserProperty("Mode", BuildConfig.APPLICATION_ID + "-" + closedLoopEnabled) - firebaseAnalytics.setUserProperty("Language", sp.getString(R.string.key_language, Locale.getDefault().language)) - firebaseAnalytics.setUserProperty("Version", BuildConfig.VERSION) - firebaseAnalytics.setUserProperty("HEAD", BuildConfig.HEAD) - firebaseAnalytics.setUserProperty("Remote", remote) - val hashes: List = signatureVerifierPlugin.shortHashes() - if (hashes.isNotEmpty()) firebaseAnalytics.setUserProperty("Hash", hashes[0]) - activePlugin.activePump.let { firebaseAnalytics.setUserProperty("Pump", it::class.java.simpleName) } - if (!Config.NSCLIENT && !Config.PUMPCONTROL) - activePlugin.activeAPS.let { firebaseAnalytics.setUserProperty("Aps", it::class.java.simpleName) } - activePlugin.activeBgSource.let { firebaseAnalytics.setUserProperty("BgSource", it::class.java.simpleName) } - firebaseAnalytics.setUserProperty("Profile", activePlugin.activeProfileInterface.javaClass.simpleName) - activePlugin.activeSensitivity.let { firebaseAnalytics.setUserProperty("Sensitivity", it::class.java.simpleName) } - activePlugin.activeInsulin.let { firebaseAnalytics.setUserProperty("Insulin", it::class.java.simpleName) } - } } \ No newline at end of file diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml new file mode 100644 index 0000000000..38f3a9736c --- /dev/null +++ b/core/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + + enable_fabric + \ No newline at end of file From 2fb0198418ca078c39b0a6b0d4440cce14897764 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 4 May 2020 01:36:46 +0200 Subject: [PATCH 09/16] RxBus -> core --- core/build.gradle | 5 +++++ .../src/main/java/info/nightscout/androidaps/events/Event.kt | 0 .../java/info/nightscout/androidaps/plugins/bus/RxBus.kt | 0 .../info/nightscout/androidaps/plugins/bus/RxBusWrapper.kt | 0 4 files changed, 5 insertions(+) rename {app => core}/src/main/java/info/nightscout/androidaps/events/Event.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/plugins/bus/RxBus.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/plugins/bus/RxBusWrapper.kt (100%) diff --git a/core/build.gradle b/core/build.gradle index e8c8867b8b..c2c390f97a 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -51,11 +51,16 @@ dependencies { kapt "com.google.dagger:dagger-android-processor:$dagger_version" kapt "com.google.dagger:dagger-compiler:$dagger_version" + //Logger implementation 'org.slf4j:slf4j-api:1.7.30' + //Fabric implementation 'com.google.firebase:firebase-core:17.3.0' implementation('com.crashlytics.sdk.android:crashlytics:2.10.1@aar') { transitive = true; } + //RxBus + implementation "io.reactivex.rxjava2:rxandroid:2.1.1" + implementation "org.apache.commons:commons-lang3:3.9" testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' diff --git a/app/src/main/java/info/nightscout/androidaps/events/Event.kt b/core/src/main/java/info/nightscout/androidaps/events/Event.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/events/Event.kt rename to core/src/main/java/info/nightscout/androidaps/events/Event.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/bus/RxBus.kt b/core/src/main/java/info/nightscout/androidaps/plugins/bus/RxBus.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/bus/RxBus.kt rename to core/src/main/java/info/nightscout/androidaps/plugins/bus/RxBus.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/bus/RxBusWrapper.kt b/core/src/main/java/info/nightscout/androidaps/plugins/bus/RxBusWrapper.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/plugins/bus/RxBusWrapper.kt rename to core/src/main/java/info/nightscout/androidaps/plugins/bus/RxBusWrapper.kt From d44bc87d1b52e56b109cc56967ddb687d4d0ec7f Mon Sep 17 00:00:00 2001 From: Philoul Date: Mon, 4 May 2020 10:15:21 +0200 Subject: [PATCH 10/16] Fix Crash TemporyBasal Injector missing with extendedbolus --- .../main/java/info/nightscout/androidaps/db/TemporaryBasal.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java b/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java index c65732b932..aa902b0867 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java +++ b/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java @@ -110,6 +110,8 @@ public class TemporaryBasal implements Interval, DbObjectBase { } public TemporaryBasal(ExtendedBolus extendedBolus) { + injector = MainApp.instance(); + injector.androidInjector().inject(this); double basal = profileFunction.getProfile(extendedBolus.date).getBasal(extendedBolus.date); this.date = extendedBolus.date; this.isValid = extendedBolus.isValid; From 60b5c7366f03a313a3aebdf1631573b6ed203ff1 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 4 May 2020 10:27:48 +0200 Subject: [PATCH 11/16] Update Crowdin configuration file --- crowdin.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crowdin.yml b/crowdin.yml index a37dfd27e0..ace938f2a1 100644 --- a/crowdin.yml +++ b/crowdin.yml @@ -13,3 +13,5 @@ files: translation: /app/src/main/res/values-%android_code%/protection.xml - source: /app/src/main/res/values/validator.xml translation: /app/src/main/res/values-%android_code%/validator.xml + - source: /core/src/main/res/values/strings.xml + translation: /core/src/main/res/values-%android_code%/strings.xml From 3e63d32d60b900a258cbf05002214f58982644e7 Mon Sep 17 00:00:00 2001 From: Philoul Date: Mon, 4 May 2020 10:40:22 +0200 Subject: [PATCH 12/16] Add missing function in DatabaseHelper getExtendedBolusDataFromTime(long from, long to, boolean ascending) => I need it for autotune plugin... --- .../nightscout/androidaps/db/DatabaseHelper.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 616108669f..5759429d69 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -1250,6 +1250,22 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList(); } + public List getExtendedBolusDataFromTime(long from, long to, boolean ascending) { + try { + List extendedBoluses; + QueryBuilder queryBuilder = getDaoExtendedBolus().queryBuilder(); + queryBuilder.orderBy("date", ascending); + Where where = queryBuilder.where(); + where.between("date", from, to); + PreparedQuery preparedQuery = queryBuilder.prepare(); + extendedBoluses = getDaoExtendedBolus().query(preparedQuery); + return extendedBoluses; + } catch (SQLException e) { + log.error("Unhandled exception", e); + } + return new ArrayList(); + } + public void deleteExtendedBolusById(String _id) { ExtendedBolus stored = findExtendedBolusById(_id); if (stored != null) { From ab9da6e2b6e7ed8644436ef0840ffa21aa289eed Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 4 May 2020 10:49:19 +0200 Subject: [PATCH 13/16] AlertDialogs -> core --- app/src/main/res/values/colors.xml | 14 ----- app/src/main/res/values/strings.xml | 2 - app/src/main/res/values/styles.xml | 26 +------- .../events/EventDismissNotification.kt | 0 .../overview/events/EventNewNotification.kt | 0 .../overview/notifications/Notification.java | 0 .../info/nightscout/androidaps/utils/T.java | 0 .../androidaps/utils/ToastUtils.java | 2 +- .../utils/alertDialogs/AlertDialogHelper.kt | 60 +++++++++--------- .../androidaps/utils/alertDialogs/OKDialog.kt | 2 +- .../utils/alertDialogs/WarningDialog.kt | 2 +- .../androidaps/utils/extensions/UIUtils.kt | 0 .../main/res/drawable/ic_check_while_48dp.xml | 0 .../main/res/drawable/ic_header_warning.xml | 30 ++++----- .../src/main/res/drawable/ic_toast_check.xml | 0 .../res/drawable/ic_toast_delete_confirm.xml | 18 +++--- .../src/main/res/drawable/ic_toast_error.xml | 18 +++--- .../src/main/res/drawable/ic_toast_info.xml | 18 +++--- .../src/main/res/drawable/ic_toast_warn.xml | 18 +++--- .../main/res/layout/dialog_alert_custom.xml | 0 {app => core}/src/main/res/layout/toast.xml | 62 +++++++++---------- {app => core}/src/main/res/values/attrs.xml | 12 ++-- core/src/main/res/values/colors.xml | 18 ++++++ core/src/main/res/values/strings.xml | 6 ++ core/src/main/res/values/styles.xml | 38 ++++++++++++ 25 files changed, 184 insertions(+), 162 deletions(-) rename {app => core}/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissNotification.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventNewNotification.kt (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/Notification.java (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/T.java (100%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/ToastUtils.java (98%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/alertDialogs/AlertDialogHelper.kt (95%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/alertDialogs/OKDialog.kt (99%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/alertDialogs/WarningDialog.kt (97%) rename {app => core}/src/main/java/info/nightscout/androidaps/utils/extensions/UIUtils.kt (100%) rename {app => core}/src/main/res/drawable/ic_check_while_48dp.xml (100%) rename {app => core}/src/main/res/drawable/ic_header_warning.xml (97%) rename {app => core}/src/main/res/drawable/ic_toast_check.xml (100%) rename {app => core}/src/main/res/drawable/ic_toast_delete_confirm.xml (98%) rename {app => core}/src/main/res/drawable/ic_toast_error.xml (97%) rename {app => core}/src/main/res/drawable/ic_toast_info.xml (97%) rename {app => core}/src/main/res/drawable/ic_toast_warn.xml (97%) rename {app => core}/src/main/res/layout/dialog_alert_custom.xml (100%) rename {app => core}/src/main/res/layout/toast.xml (97%) rename {app => core}/src/main/res/values/attrs.xml (97%) create mode 100644 core/src/main/res/values/colors.xml create mode 100644 core/src/main/res/values/styles.xml diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index d30a19a76e..c1873d786f 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -39,17 +39,9 @@ #77dd77 - #212121 - #000000 - #40bbaa #40bbaa #00695c - #303030 - #121212 - #FFFFFF - #FFFFFF - #121212 #779ECB @@ -91,12 +83,6 @@ #2E2E2E - #FFFB8C00 - #FF000000 - - #FFFF5555 - #FF000000 - #666666 #ffffff #77dd77 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 10a39d41ae..710ee85e4e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -250,7 +250,6 @@ This value is called max basal in OpenAPS context Maximum basal IOB OpenAPS can deliver [U] This value is called Max IOB in OpenAPS context\nThis is maximal insulin in [U] APS can deliver at once. - DISMISS Language You will be asked for master password, which will be used to encrypt exported preferences. @@ -1761,7 +1760,6 @@ 24h Automation event Already set - Message Clear queue? All data in queue will be lost! xdripstatus_detailediob xdripstatus_showbgi diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index e68e414cf1..4914afa9fe 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -70,31 +70,7 @@ #ff0000 - - - - - - - - - + + + + + + + + + + + From ee913cffd8630ffb61f9f62afda4dd909566ccb1 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 4 May 2020 21:03:30 +0200 Subject: [PATCH 14/16] gradle tweaking --- app/build.gradle | 1 + build.gradle | 2 +- gradle.properties | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6f613d0f64..c9b6c4e16e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -160,6 +160,7 @@ android { } firebaseDisable { System.setProperty("disableFirebase", "true") + ext.enableCrashlytics = false } } productFlavors { diff --git a/build.gradle b/build.gradle index 23ca45ba11..44009604e3 100644 --- a/build.gradle +++ b/build.gradle @@ -38,7 +38,7 @@ allprojects { } ivy { url 'https://github.com/' - layout 'pattern', { + patternLayout { artifact '/[organisation]/[module]/archive/[revision].[ext]' } } diff --git a/gradle.properties b/gradle.properties index 1bc51c91af..43ad963b2f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,7 +15,7 @@ # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true +org.gradle.parallel=true org.gradle.jvmargs=-Xmx2g From 47fd4bd1fe4e8c8f2ad2e98f266aaf4c202d4742 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 4 May 2020 21:37:03 +0200 Subject: [PATCH 15/16] libraries update --- app/build.gradle | 38 +++++++++++++++++++------------------- build.gradle | 2 +- core/build.gradle | 6 +++--- wear/build.gradle | 10 +++++----- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c9b6c4e16e..f767cfc823 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -29,7 +29,7 @@ ext { powermockVersion = "1.7.3" dexmakerVersion = "1.2" retrofit2Version = '2.8.1' - okhttp3Version = '4.5.0' + okhttp3Version = '4.6.0' coroutinesVersion = '1.3.5' } @@ -248,9 +248,9 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.google.android.gms:play-services-wearable:17.0.0' implementation "com.google.android.gms:play-services-location:17.0.0" - implementation 'com.google.firebase:firebase-core:17.3.0' - implementation 'com.google.firebase:firebase-auth:19.3.0' - implementation 'com.google.firebase:firebase-database:19.2.1' + implementation 'com.google.firebase:firebase-core:17.4.0' + implementation 'com.google.firebase:firebase-auth:19.3.1' + implementation 'com.google.firebase:firebase-database:19.3.0' implementation('com.crashlytics.sdk.android:crashlytics:2.10.1@aar') { transitive = true; } @@ -263,7 +263,7 @@ dependencies { implementation 'androidx.recyclerview:recyclerview:1.1.0' implementation 'androidx.gridlayout:gridlayout:1.0.0' implementation 'androidx.percentlayout:percentlayout:1.0.0' - implementation "androidx.preference:preference-ktx:1.1.0" + implementation "androidx.preference:preference-ktx:1.1.1" implementation 'com.google.android.material:material:1.1.0' implementation 'com.wdullaer:materialdatetimepicker:4.2.3' @@ -274,7 +274,7 @@ dependencies { implementation("com.github.tony19:logback-android-classic:1.1.1-6") { exclude group: "com.google.android", module: "android" } - implementation "org.apache.commons:commons-lang3:3.9" + implementation 'org.apache.commons:commons-lang3:3.10' implementation 'org.slf4j:slf4j-api:1.7.30' // Graphview cannot be upgraded implementation "com.jjoe64:graphview:4.0.1" @@ -291,28 +291,28 @@ dependencies { exclude group: "org.json", module: "json" } implementation "com.google.code.gson:gson:2.8.6" - implementation ("com.google.guava:guava:24.1-jre") { + implementation('com.google.guava:guava:29.0-jre') { exclude group: "com.google.code.findbugs", module: "jsr305" } implementation 'com.google.code.findbugs:jsr305:3.0.2' - implementation "net.danlew:android.joda:2.10.3" + implementation 'net.danlew:android.joda:2.10.6' - implementation 'org.mozilla:rhino:1.7.11' + implementation 'org.mozilla:rhino:1.7.12' implementation 'com.github.DavidProdinger:weekdays-selector:1.1.0' implementation 'com.github.kenglxn.QRGen:android:2.6.0' implementation 'com.eatthepath:java-otp:0.2.0' - testImplementation "junit:junit:4.12" + testImplementation "junit:junit:4.13" testImplementation "org.json:json:20190722" testImplementation "org.mockito:mockito-core:2.8.47" testImplementation "org.powermock:powermock-api-mockito2:${powermockVersion}" testImplementation "org.powermock:powermock-module-junit4-rule-agent:${powermockVersion}" testImplementation "org.powermock:powermock-module-junit4-rule:${powermockVersion}" testImplementation "org.powermock:powermock-module-junit4:${powermockVersion}" - testImplementation "joda-time:joda-time:2.10.5" + testImplementation 'joda-time:joda-time:2.10.6' testImplementation('com.google.truth:truth:1.0.1') { exclude group: "com.google.guava", module: "guava" exclude group: "com.google.code.findbugs", module: "jsr305" @@ -333,24 +333,24 @@ dependencies { implementation "com.squareup.retrofit2:converter-gson:$retrofit2Version" // Phone checker - implementation 'com.scottyab:rootbeer-lib:0.0.7' + implementation 'com.scottyab:rootbeer-lib:0.0.8' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha03' androidTestImplementation 'androidx.test.ext:junit:1.1.1' - androidTestImplementation 'androidx.test:rules:1.3.0-alpha03' + androidTestImplementation 'androidx.test:rules:1.3.0-beta01' androidTestImplementation 'com.google.code.findbugs:jsr305:3.0.2' /* Dagger2 - We are going to use dagger.android which includes * support for Activity and fragment injection so we need to include * the following dependencies */ - implementation 'com.google.dagger:dagger-android:2.25.2' - implementation 'com.google.dagger:dagger-android-support:2.25.2' - annotationProcessor 'com.google.dagger:dagger-compiler:2.25.2' - annotationProcessor 'com.google.dagger:dagger-android-processor:2.25.2' - kapt 'com.google.dagger:dagger-android-processor:2.25.2' + implementation "com.google.dagger:dagger-android:$dagger_version" + implementation "com.google.dagger:dagger-android-support:$dagger_version" + annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version" + annotationProcessor "com.google.dagger:dagger-android-processor:$dagger_version" + kapt "com.google.dagger:dagger-android-processor:$dagger_version" /* Dagger2 - default dependency */ - kapt 'com.google.dagger:dagger-compiler:2.25.2' + kapt "com.google.dagger:dagger-compiler:$dagger_version" androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0' } diff --git a/build.gradle b/build.gradle index 44009604e3..9635afae0e 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ buildscript { ext { - kotlin_version = '1.3.71' + kotlin_version = '1.3.72' android_ktx_version = '1.2.0' rxjava_version = '2.2.19' rxandroid_version = '2.1.1' diff --git a/core/build.gradle b/core/build.gradle index c2c390f97a..0a6122fa64 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -54,15 +54,15 @@ dependencies { //Logger implementation 'org.slf4j:slf4j-api:1.7.30' //Fabric - implementation 'com.google.firebase:firebase-core:17.3.0' + implementation 'com.google.firebase:firebase-core:17.4.0' implementation('com.crashlytics.sdk.android:crashlytics:2.10.1@aar') { transitive = true; } //RxBus implementation "io.reactivex.rxjava2:rxandroid:2.1.1" - implementation "org.apache.commons:commons-lang3:3.9" + implementation 'org.apache.commons:commons-lang3:3.10' - testImplementation 'junit:junit:4.12' + testImplementation 'junit:junit:4.13' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' } diff --git a/wear/build.gradle b/wear/build.gradle index dc73e3c4f0..ffe7617086 100644 --- a/wear/build.gradle +++ b/wear/build.gradle @@ -122,9 +122,9 @@ dependencies { implementation 'androidx.wear:wear:1.0.0' implementation('me.denley.wearpreferenceactivity:wearpreferenceactivity:0.5.0') implementation('com.github.lecho:hellocharts-library:1.5.8@aar') - - testImplementation "junit:junit:4.12" - testImplementation "org.json:json:20140107" + + testImplementation 'junit:junit:4.13' + testImplementation 'org.json:json:20190722' testImplementation ("org.mockito:mockito-core:2.8.47") { exclude group: 'net.bytebuddy', module: 'byte-buddy' exclude group: 'net.bytebuddy', module: 'byte-buddy-android' @@ -139,8 +139,8 @@ dependencies { testImplementation "org.powermock:powermock-module-junit4-rule-agent:${powermockVersion}" testImplementation "org.powermock:powermock-module-junit4-rule:${powermockVersion}" testImplementation "org.powermock:powermock-module-junit4:${powermockVersion}" - testImplementation "joda-time:joda-time:2.9.9" - testImplementation("com.google.truth:truth:0.39") { + testImplementation 'joda-time:joda-time:2.10.6' + testImplementation('com.google.truth:truth:1.0.1') { exclude group: "com.google.guava", module: "guava" } testImplementation "org.skyscreamer:jsonassert:1.5.0" From d8f27c609c3c9f3b0015b5a5a2ffca0df2dca220 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 4 May 2020 23:40:39 +0200 Subject: [PATCH 16/16] BlePreCheck -> core --- app/src/main/res/values/strings.xml | 4 - core/build.gradle | 2 +- core/src/main/AndroidManifest.xml | 5 +- .../plugins/pump/common/ble/BlePreCheck.kt | 87 +++++++++++++++++++ core/src/main/res/values/strings.xml | 5 ++ 5 files changed, 97 insertions(+), 6 deletions(-) create mode 100644 core/src/main/java/info/nightscout/androidaps/plugins/pump/common/ble/BlePreCheck.kt diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 710ee85e4e..e09f297a7b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1549,10 +1549,6 @@ STOP Selected RileyLink Scan - Bluetooth Low Energy not supported. - Bluetooth not enabled. - Location Is Not Enabled - For Bluetooth discovery to work on newer devices, location must be enabled. AAPS does not track your location and it can be disabled after pairing is successful. Enable No Scanning diff --git a/core/build.gradle b/core/build.gradle index 0a6122fa64..55829c53d1 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -42,7 +42,7 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'androidx.core:core-ktx:1.2.0' + implementation "androidx.preference:preference-ktx:1.1.1" implementation "com.google.dagger:dagger-android:$dagger_version" implementation "com.google.dagger:dagger-android-support:$dagger_version" diff --git a/core/src/main/AndroidManifest.xml b/core/src/main/AndroidManifest.xml index 46d6d492d4..0ff2fcd7b8 100644 --- a/core/src/main/AndroidManifest.xml +++ b/core/src/main/AndroidManifest.xml @@ -1,2 +1,5 @@ + package="info.nightscout.androidaps.core" > + + + diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/ble/BlePreCheck.kt b/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/ble/BlePreCheck.kt new file mode 100644 index 0000000000..497ec61fbc --- /dev/null +++ b/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/ble/BlePreCheck.kt @@ -0,0 +1,87 @@ +package info.nightscout.androidaps.plugins.pump.common.ble + +import android.Manifest +import android.bluetooth.BluetoothAdapter +import android.content.Context +import android.content.Intent +import android.content.pm.PackageManager +import android.location.LocationManager +import android.provider.Settings +import androidx.appcompat.app.AppCompatActivity +import androidx.core.app.ActivityCompat +import androidx.core.content.ContextCompat +import info.nightscout.androidaps.core.R +import info.nightscout.androidaps.utils.alertDialogs.OKDialog +import info.nightscout.androidaps.utils.resources.ResourceHelper +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class BlePreCheck @Inject constructor( + val resourceHelper: ResourceHelper +) { + + companion object { + private const val PERMISSION_REQUEST_COARSE_LOCATION = 30241 // arbitrary. + } + + fun prerequisitesCheck(activity: AppCompatActivity): Boolean { + if (!activity.packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { + OKDialog.show(activity, resourceHelper.gs(R.string.message), resourceHelper.gs(R.string.rileylink_scanner_ble_not_supported)) + return false + } else { + // Use this check to determine whether BLE is supported on the device. Then + // you can selectively disable BLE-related features. + if (ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + // your code that requires permission + ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION), PERMISSION_REQUEST_COARSE_LOCATION) + } + + val bluetoothAdapter = BluetoothAdapter.getDefaultAdapter() + // Ensures Bluetooth is available on the device and it is enabled. If not, + // displays a dialog requesting user permission to enable Bluetooth. + if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled) { + OKDialog.show(activity, resourceHelper.gs(R.string.message), resourceHelper.gs(R.string.rileylink_scanner_ble_not_enabled)) + return false + } else { + // Will request that GPS be enabled for devices running Marshmallow or newer. + if (!isLocationEnabled(activity)) { + requestLocation(activity) + return false + } + } + } + return true + } + + /** + * Determine if GPS is currently enabled. + * + * + * On Android 6 (Marshmallow), location needs to be enabled for Bluetooth discovery to work. + * + * @param context The current app context. + * @return true if location is enabled, false otherwise. + */ + private fun isLocationEnabled(context: Context): Boolean { + val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager + return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || + locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) + } + + /** + * Prompt the user to enable GPS location if it isn't already on. + * + * @param activity The currently visible activity. + */ + private fun requestLocation(activity: AppCompatActivity) { + if (isLocationEnabled(activity)) { + return + } + + // Shamelessly borrowed from http://stackoverflow.com/a/10311877/868533 + OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.location_not_found_title), resourceHelper.gs(R.string.location_not_found_message), Runnable { + activity.startActivity(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)) + }) + } +} \ No newline at end of file diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index b89cf096bd..a0d615ea71 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -7,4 +7,9 @@ Cancel DISMISS + Bluetooth Low Energy not supported. + Bluetooth not enabled. + Location Is Not Enabled + For Bluetooth discovery to work on newer devices, location must be enabled. AAPS does not track your location and it can be disabled after pairing is successful. + \ No newline at end of file