From e1ddde969777a4ba4766aaef67a74152e9a00740 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 4 May 2020 01:27:47 +0200 Subject: [PATCH] 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