FabricPrivacy -> core
This commit is contained in:
parent
5be4a5dd97
commit
e1ddde9697
5 changed files with 49 additions and 42 deletions
|
@ -41,6 +41,8 @@ import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
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.constraints.versionChecker.VersionCheckerUtils
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus
|
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus
|
||||||
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin
|
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.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
|
@ -79,6 +82,8 @@ class MainActivity : NoSplashAppCompatActivity() {
|
||||||
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
||||||
@Inject lateinit var protectionCheck: ProtectionCheck
|
@Inject lateinit var protectionCheck: ProtectionCheck
|
||||||
@Inject lateinit var iconsProvider: IconsProvider
|
@Inject lateinit var iconsProvider: IconsProvider
|
||||||
|
@Inject lateinit var constraintChecker: ConstraintChecker
|
||||||
|
@Inject lateinit var signatureVerifierPlugin: SignatureVerifierPlugin
|
||||||
|
|
||||||
private lateinit var actionBarDrawerToggle: ActionBarDrawerToggle
|
private lateinit var actionBarDrawerToggle: ActionBarDrawerToggle
|
||||||
private var pluginPreferencesMenuItem: MenuItem? = null
|
private var pluginPreferencesMenuItem: MenuItem? = null
|
||||||
|
@ -109,7 +114,7 @@ class MainActivity : NoSplashAppCompatActivity() {
|
||||||
|
|
||||||
//Check here if loop plugin is disabled. Else check via constraints
|
//Check here if loop plugin is disabled. Else check via constraints
|
||||||
if (!loopPlugin.isEnabled(PluginType.LOOP)) versionCheckerUtils.triggerCheckVersion()
|
if (!loopPlugin.isEnabled(PluginType.LOOP)) versionCheckerUtils.triggerCheckVersion()
|
||||||
fabricPrivacy.setUserStats()
|
setUserStats()
|
||||||
setupViews()
|
setupViews()
|
||||||
disposable.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventRebuildTabs::class.java)
|
.toObservable(EventRebuildTabs::class.java)
|
||||||
|
@ -325,4 +330,35 @@ class MainActivity : NoSplashAppCompatActivity() {
|
||||||
}
|
}
|
||||||
return actionBarDrawerToggle.onOptionsItemSelected(item)
|
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<String> = 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) }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1769,7 +1769,6 @@
|
||||||
<string name="key_snoozedTo" translatable="false">snoozedTo</string>
|
<string name="key_snoozedTo" translatable="false">snoozedTo</string>
|
||||||
<string name="key_snooze_dst_in24h" translatable="false">snooze_dst_in24h</string>
|
<string name="key_snooze_dst_in24h" translatable="false">snooze_dst_in24h</string>
|
||||||
<string name="key_snooze_loopdisabled" translatable="false">snooze_loopdisabled</string>
|
<string name="key_snooze_loopdisabled" translatable="false">snooze_loopdisabled</string>
|
||||||
<string name="key_enable_fabric" translatable="false">enable_fabric</string>
|
|
||||||
<string name="sixdigitnumber" translatable="false">^\\d{6}</string>
|
<string name="sixdigitnumber" translatable="false">^\\d{6}</string>
|
||||||
<string name="ebstopsloop">Use of Extended bolus feature will stop closed loop mode for the time of running extended bolus. Do you really want it?</string>
|
<string name="ebstopsloop">Use of Extended bolus feature will stop closed loop mode for the time of running extended bolus. Do you really want it?</string>
|
||||||
<string name="closed_loop_disabled_with_eb">Closed loop disabled because of running Extended bolus</string>
|
<string name="closed_loop_disabled_with_eb">Closed loop disabled because of running Extended bolus</string>
|
||||||
|
|
|
@ -52,6 +52,10 @@ dependencies {
|
||||||
kapt "com.google.dagger:dagger-compiler:$dagger_version"
|
kapt "com.google.dagger:dagger-compiler:$dagger_version"
|
||||||
|
|
||||||
implementation 'org.slf4j:slf4j-api:1.7.30'
|
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'
|
testImplementation 'junit:junit:4.12'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||||
|
|
|
@ -4,17 +4,11 @@ import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import com.crashlytics.android.Crashlytics
|
import com.crashlytics.android.Crashlytics
|
||||||
import com.google.firebase.analytics.FirebaseAnalytics
|
import com.google.firebase.analytics.FirebaseAnalytics
|
||||||
import info.nightscout.androidaps.BuildConfig
|
import info.nightscout.androidaps.core.R
|
||||||
import info.nightscout.androidaps.Config
|
|
||||||
import info.nightscout.androidaps.R
|
|
||||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
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 info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
import io.fabric.sdk.android.Fabric
|
import io.fabric.sdk.android.Fabric
|
||||||
import java.util.*
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@ -27,13 +21,10 @@ import javax.inject.Singleton
|
||||||
class FabricPrivacy @Inject constructor(
|
class FabricPrivacy @Inject constructor(
|
||||||
context: Context,
|
context: Context,
|
||||||
private val aapsLogger: AAPSLogger,
|
private val aapsLogger: AAPSLogger,
|
||||||
private val sp: SP,
|
private val sp: SP
|
||||||
private val constraintChecker: ConstraintChecker,
|
|
||||||
private val signatureVerifierPlugin: SignatureVerifierPlugin,
|
|
||||||
private val activePlugin: ActivePluginProvider
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private var firebaseAnalytics: FirebaseAnalytics
|
var firebaseAnalytics: FirebaseAnalytics
|
||||||
|
|
||||||
init {
|
init {
|
||||||
instance = this
|
instance = this
|
||||||
|
@ -49,7 +40,7 @@ class FabricPrivacy @Inject constructor(
|
||||||
private lateinit var instance: FabricPrivacy
|
private lateinit var instance: FabricPrivacy
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@Deprecated("use dagger")
|
@Deprecated("Use Dagger")
|
||||||
fun getInstance(): FabricPrivacy = instance
|
fun getInstance(): FabricPrivacy = instance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,31 +113,4 @@ class FabricPrivacy @Inject constructor(
|
||||||
fun fabricEnabled(): Boolean {
|
fun fabricEnabled(): Boolean {
|
||||||
return sp.getBoolean(R.string.key_enable_fabric, true)
|
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<String> = 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) }
|
|
||||||
}
|
|
||||||
}
|
}
|
4
core/src/main/res/values/strings.xml
Normal file
4
core/src/main/res/values/strings.xml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="key_enable_fabric" translatable="false">enable_fabric</string>
|
||||||
|
</resources>
|
Loading…
Reference in a new issue