feat: add fdroid and google flavors

This commit is contained in:
andrekir 2023-01-19 11:24:42 -03:00 committed by Andre K
parent f0294a7955
commit 6e96a6b7c2
12 changed files with 267 additions and 22 deletions

View file

@ -0,0 +1,16 @@
package com.geeksville.mesh
import com.geeksville.mesh.android.GeeksvilleApplication
import com.geeksville.mesh.android.Logging
import dagger.hilt.android.HiltAndroidApp
@HiltAndroidApp
class MeshUtilApplication : GeeksvilleApplication() {
override fun onCreate() {
super.onCreate()
Logging.showLogs = BuildConfig.DEBUG
}
}

View file

@ -0,0 +1,42 @@
package com.geeksville.mesh.analytics
class DataPair(val name: String, valueIn: Any?) {
val value = valueIn ?: "null"
/// An accumulating firebase event - only one allowed per event
constructor(d: Double) : this("BOGUS", d)
constructor(d: Int) : this("BOGUS", d)
}
public interface AnalyticsProvider {
// Turn analytics logging on/off
fun setEnabled(on: Boolean)
/**
* Store an event
*/
fun track(event: String, vararg properties: DataPair)
/**
* Only track this event if using a cheap provider (like google)
*/
fun trackLowValue(event: String, vararg properties: DataPair)
fun endSession()
fun startSession()
/**
* 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()
}

View file

@ -0,0 +1,46 @@
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 {
init {
}
override fun setEnabled(on: Boolean) {
}
override fun endSession() {
}
override fun trackLowValue(event: String, vararg properties: DataPair) {
}
override fun track(event: String, vararg properties: DataPair) {
}
override fun startSession() {
}
override fun setUserInfo(vararg p: DataPair) {
}
override fun increment(name: String, amount: Double) {
}
/**
* Send a google analyics screen view event
*/
override fun sendScreenView(name: String) {
}
override fun endScreenView() {
}
}

View file

@ -0,0 +1,107 @@
package com.geeksville.mesh.android
import android.app.Activity
import android.app.Application
import android.content.Context
import android.content.SharedPreferences
import android.net.ConnectivityManager
import android.os.Bundle
import android.provider.Settings
import androidx.core.content.edit
import com.geeksville.mesh.analytics.AnalyticsProvider
fun isGooglePlayAvailable(context: Context): Boolean = false
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<Application>.onCreate()
val googleAnalytics = com.geeksville.mesh.analytics.GoogleAnalytics(this)
analytics = googleAnalytics
// Set analytics per prefs
isAnalyticsAllowed = isAnalyticsAllowed
registerActivityLifecycleCallbacks(lifecycleCallbacks)
}
fun isInternetConnected(): Boolean {
val cm = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetwork = cm.getActiveNetworkInfo();
val isConnected = activeNetwork != null &&
activeNetwork.isConnectedOrConnecting();
return isConnected
}
}
fun geeksvilleApp(context: Context) = context.applicationContext as GeeksvilleApplication
interface GeeksvilleApplicationClient {
fun getAnalytics() = GeeksvilleApplication.analytics
}