mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat: add fdroid and google flavors
This commit is contained in:
parent
f0294a7955
commit
6e96a6b7c2
12 changed files with 267 additions and 22 deletions
|
|
@ -1,54 +0,0 @@
|
|||
package com.geeksville.mesh
|
||||
|
||||
import android.os.Debug
|
||||
import com.geeksville.mesh.android.AppPrefs
|
||||
import com.geeksville.mesh.android.BuildUtils.isEmulator
|
||||
import com.geeksville.mesh.android.GeeksvilleApplication
|
||||
import com.geeksville.mesh.android.Logging
|
||||
import com.geeksville.mesh.util.Exceptions
|
||||
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
|
||||
@HiltAndroidApp
|
||||
class MeshUtilApplication : GeeksvilleApplication() {
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
Logging.showLogs = BuildConfig.DEBUG
|
||||
|
||||
// We default to off in the manifest - we turn on here if the user approves
|
||||
// leave off when running in the debugger
|
||||
if (!isEmulator && (!BuildConfig.DEBUG || !Debug.isDebuggerConnected())) {
|
||||
val crashlytics = FirebaseCrashlytics.getInstance()
|
||||
crashlytics.setCrashlyticsCollectionEnabled(isAnalyticsAllowed)
|
||||
crashlytics.setCustomKey("debug_build", BuildConfig.DEBUG)
|
||||
|
||||
val pref = AppPrefs(this)
|
||||
crashlytics.setUserId(pref.getInstallId()) // be able to group all bugs per anonymous user
|
||||
|
||||
// We always send our log messages to the crashlytics lib, but they only get sent to the server if we report an exception
|
||||
// This makes log messages work properly if someone turns on analytics just before they click report bug.
|
||||
// send all log messages through crashyltics, so if we do crash we'll have those in the report
|
||||
val standardLogger = Logging.printlog
|
||||
Logging.printlog = { level, tag, message ->
|
||||
crashlytics.log("$tag: $message")
|
||||
standardLogger(level, tag, message)
|
||||
}
|
||||
|
||||
fun sendCrashReports() {
|
||||
if (isAnalyticsAllowed)
|
||||
crashlytics.sendUnsentReports()
|
||||
}
|
||||
|
||||
// Send any old reports if user approves
|
||||
sendCrashReports()
|
||||
|
||||
// Attach to our exception wrapper
|
||||
Exceptions.reporter = { exception, _, _ ->
|
||||
crashlytics.recordException(exception)
|
||||
sendCrashReports() // Send the new report
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
package com.geeksville.mesh.analytics
|
||||
|
||||
import com.google.firebase.analytics.FirebaseAnalytics
|
||||
|
||||
/**
|
||||
* Created by kevinh on 12/24/14.
|
||||
*/
|
||||
class DataPair(val name: String, valueIn: Any?) {
|
||||
val value = valueIn ?: "null"
|
||||
|
||||
/// An accumulating firebase event - only one allowed per event
|
||||
constructor(d: Double) : this(FirebaseAnalytics.Param.VALUE, d)
|
||||
constructor(d: Int) : this(FirebaseAnalytics.Param.VALUE, d)
|
||||
}
|
||||
|
||||
public interface AnalyticsProvider {
|
||||
|
||||
// Turn analytics logging on/off
|
||||
fun setEnabled(on: Boolean)
|
||||
|
||||
/**
|
||||
* Store an event
|
||||
*/
|
||||
fun track(event: String, vararg properties: DataPair): Unit
|
||||
|
||||
/**
|
||||
* Only track this event if using a cheap provider (like google)
|
||||
*/
|
||||
fun trackLowValue(event: String, vararg properties: DataPair): Unit
|
||||
|
||||
fun endSession(): Unit
|
||||
fun startSession(): Unit
|
||||
|
||||
/**
|
||||
* Set persistent ID info about this user, as a key value pair
|
||||
*/
|
||||
fun setUserInfo(vararg p: DataPair)
|
||||
|
||||
/**
|
||||
* Increment some sort of anyalytics counter
|
||||
*/
|
||||
fun increment(name: String, amount: Double = 1.0)
|
||||
|
||||
fun sendScreenView(name: String)
|
||||
fun endScreenView()
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
package com.geeksville.mesh.analytics
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import com.geeksville.mesh.android.AppPrefs
|
||||
import com.geeksville.mesh.android.GeeksvilleApplication
|
||||
import com.geeksville.mesh.android.Logging
|
||||
|
||||
/**
|
||||
* Implement our analytics API using firebase analtics
|
||||
*/
|
||||
class GoogleAnalytics(context: Context) : AnalyticsProvider, Logging {
|
||||
|
||||
val t = com.google.firebase.analytics.FirebaseAnalytics.getInstance(context)
|
||||
|
||||
init {
|
||||
val pref = AppPrefs(context)
|
||||
t.setUserId(pref.getInstallId())
|
||||
}
|
||||
|
||||
override fun setEnabled(on: Boolean) {
|
||||
t.setAnalyticsCollectionEnabled(on)
|
||||
}
|
||||
|
||||
override fun endSession() {
|
||||
track("End Session")
|
||||
// Mint.flush() // Send results now
|
||||
}
|
||||
|
||||
override fun trackLowValue(event: String, vararg properties: DataPair) {
|
||||
track(event, *properties)
|
||||
}
|
||||
|
||||
override fun track(event: String, vararg properties: DataPair) {
|
||||
debug("Analytics: track $event")
|
||||
|
||||
val bundle = Bundle()
|
||||
properties.forEach {
|
||||
when (it.value) {
|
||||
is Double -> bundle.putDouble(it.name, it.value)
|
||||
is Int -> bundle.putLong(it.name, it.value.toLong())
|
||||
is Long -> bundle.putLong(it.name, it.value)
|
||||
is Float -> bundle.putDouble(it.name, it.value.toDouble())
|
||||
else -> bundle.putString(it.name, it.value.toString())
|
||||
}
|
||||
}
|
||||
t.logEvent(event, bundle)
|
||||
}
|
||||
|
||||
override fun startSession() {
|
||||
debug("Analytics: start session")
|
||||
// automatic with firebase
|
||||
}
|
||||
|
||||
override fun setUserInfo(vararg p: DataPair) {
|
||||
p.forEach { t.setUserProperty(it.name, it.value.toString()) }
|
||||
}
|
||||
|
||||
override fun increment(name: String, amount: Double) {
|
||||
//Mint.logEvent("$name increment")
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a google analyics screen view event
|
||||
*/
|
||||
override fun sendScreenView(name: String) {
|
||||
debug("Analytics: start screen $name")
|
||||
GeeksvilleApplication.currentActivity?.let {
|
||||
t.setCurrentScreen(
|
||||
it, name, null
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun endScreenView() {
|
||||
// debug("Analytics: end screen")
|
||||
}
|
||||
}
|
||||
|
|
@ -1,96 +0,0 @@
|
|||
package com.geeksville.mesh.android
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import androidx.core.content.edit
|
||||
import com.geeksville.mesh.analytics.AnalyticsProvider
|
||||
import com.google.android.gms.common.ConnectionResult
|
||||
import com.google.android.gms.common.GoogleApiAvailabilityLight
|
||||
|
||||
|
||||
fun isGooglePlayAvailable(context: Context): Boolean {
|
||||
val a = GoogleApiAvailabilityLight.getInstance()
|
||||
val r = a.isGooglePlayServicesAvailable(context)
|
||||
return r != ConnectionResult.SERVICE_MISSING && r != ConnectionResult.SERVICE_INVALID
|
||||
}
|
||||
|
||||
/**
|
||||
* Created by kevinh on 1/4/15.
|
||||
*/
|
||||
|
||||
open class GeeksvilleApplication : Application(), Logging {
|
||||
|
||||
companion object {
|
||||
lateinit var analytics: AnalyticsProvider
|
||||
var currentActivity: Activity? = null
|
||||
private val backstack = mutableListOf<Activity>()
|
||||
}
|
||||
|
||||
private val lifecycleCallbacks = object : ActivityLifecycleCallbacks {
|
||||
override fun onActivityPaused(activity: Activity) {
|
||||
}
|
||||
|
||||
override fun onActivityStarted(activity: Activity) {
|
||||
}
|
||||
|
||||
override fun onActivityDestroyed(activity: Activity) {
|
||||
if (backstack.contains(activity)) backstack.remove(activity)
|
||||
currentActivity = backstack.lastOrNull()
|
||||
}
|
||||
|
||||
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
|
||||
}
|
||||
|
||||
override fun onActivityStopped(activity: Activity) {
|
||||
}
|
||||
|
||||
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
|
||||
backstack.add(activity)
|
||||
currentActivity = backstack.lastOrNull()
|
||||
}
|
||||
|
||||
override fun onActivityResumed(activity: Activity) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Are we running inside the testlab?
|
||||
val isInTestLab: Boolean
|
||||
get() {
|
||||
val testLabSetting =
|
||||
Settings.System.getString(contentResolver, "firebase.test.lab") ?: null
|
||||
if(testLabSetting != null)
|
||||
info("Testlab is $testLabSetting")
|
||||
return "true" == testLabSetting
|
||||
}
|
||||
|
||||
private val analyticsPrefs: SharedPreferences by lazy {
|
||||
getSharedPreferences("analytics-prefs", Context.MODE_PRIVATE)
|
||||
}
|
||||
|
||||
var isAnalyticsAllowed: Boolean
|
||||
get() = analyticsPrefs.getBoolean("allowed", true)
|
||||
set(value) {
|
||||
analyticsPrefs.edit {
|
||||
putBoolean("allowed", value)
|
||||
}
|
||||
|
||||
// Change the flag with the providers
|
||||
analytics.setEnabled(value && !isInTestLab) // Never do analytics in the test lab
|
||||
}
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
val googleAnalytics = com.geeksville.mesh.analytics.GoogleAnalytics(this)
|
||||
analytics = googleAnalytics
|
||||
|
||||
// Set analytics per prefs
|
||||
isAnalyticsAllowed = isAnalyticsAllowed
|
||||
|
||||
registerActivityLifecycleCallbacks(lifecycleCallbacks)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue