Loading lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt +34 −0 Original line number Diff line number Diff line package foundation.e.lib.telemetry import android.app.Application import android.os.Handler import android.os.Looper import android.provider.Settings import foundation.e.lib.telemetry.Constants.SETTINGS_TELEMETRY_FIELD import io.sentry.Sentry Loading @@ -10,6 +12,7 @@ object Telemetry { private var identifier: String = "" private lateinit var application: Application private var enableOsTag: Boolean = true private var isTelemetryEnabled: Boolean = false Loading @@ -24,12 +27,15 @@ object Telemetry { ) { this.identifier = identifier this.application = application this.enableOsTag = enableOsTag this.isTelemetryEnabled = checkTelemetryDeveloperOption() if (isTelemetryEnabled) { SentryAndroid.init(application) { options -> options.dsn = identifier } } Sentry.configureScope { if (enableOsTag) { val eVersion = Utils.getSystemProperty(Constants.PROPERTY_OS_VERSION) ?: "" Loading @@ -40,6 +46,34 @@ object Telemetry { } } /** * Check if telemetry option is changed every 2 seconds. * Or specify a different [interval]. */ fun trackTelemetryOptionChange(interval: Long = 2000) { val handle = Handler(Looper.getMainLooper()) val runnable = Runnable { if (isTelemetryEnabled && !checkTelemetryDeveloperOption()) { /* Indicates that telemetry reporting is going on but * telemetry from developer options is turned off. * In this case, disable telemetry. */ SentryAndroid.init(application) { options -> options.dsn = null } isTelemetryEnabled = false } else if (!isTelemetryEnabled && checkTelemetryDeveloperOption()) { /* * Just the opposite of the above case. * Re-initialise to auto enable. */ init(identifier, application, enableOsTag) } } handle.postDelayed(runnable, interval) } /** * Send a simple string message. */ Loading Loading
lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt +34 −0 Original line number Diff line number Diff line package foundation.e.lib.telemetry import android.app.Application import android.os.Handler import android.os.Looper import android.provider.Settings import foundation.e.lib.telemetry.Constants.SETTINGS_TELEMETRY_FIELD import io.sentry.Sentry Loading @@ -10,6 +12,7 @@ object Telemetry { private var identifier: String = "" private lateinit var application: Application private var enableOsTag: Boolean = true private var isTelemetryEnabled: Boolean = false Loading @@ -24,12 +27,15 @@ object Telemetry { ) { this.identifier = identifier this.application = application this.enableOsTag = enableOsTag this.isTelemetryEnabled = checkTelemetryDeveloperOption() if (isTelemetryEnabled) { SentryAndroid.init(application) { options -> options.dsn = identifier } } Sentry.configureScope { if (enableOsTag) { val eVersion = Utils.getSystemProperty(Constants.PROPERTY_OS_VERSION) ?: "" Loading @@ -40,6 +46,34 @@ object Telemetry { } } /** * Check if telemetry option is changed every 2 seconds. * Or specify a different [interval]. */ fun trackTelemetryOptionChange(interval: Long = 2000) { val handle = Handler(Looper.getMainLooper()) val runnable = Runnable { if (isTelemetryEnabled && !checkTelemetryDeveloperOption()) { /* Indicates that telemetry reporting is going on but * telemetry from developer options is turned off. * In this case, disable telemetry. */ SentryAndroid.init(application) { options -> options.dsn = null } isTelemetryEnabled = false } else if (!isTelemetryEnabled && checkTelemetryDeveloperOption()) { /* * Just the opposite of the above case. * Re-initialise to auto enable. */ init(identifier, application, enableOsTag) } } handle.postDelayed(runnable, interval) } /** * Send a simple string message. */ Loading