Loading app/build.gradle +1 −1 Original line number Diff line number Diff line Loading @@ -17,5 +17,5 @@ android { } dependencies { implementation 'io.sentry:sentry-android:6.10.0' } No newline at end of file app/src/main/java/foundation/e/lib/telemetry/Constants.kt 0 → 100644 +5 −0 Original line number Diff line number Diff line package foundation.e.lib.telemetry internal object Constants { const val SETTINGS_TELEMETRY_FIELD = "e_telemetry" } No newline at end of file app/src/main/java/foundation/e/lib/telemetry/Telemetry.kt 0 → 100644 +47 −0 Original line number Diff line number Diff line package foundation.e.lib.telemetry import android.app.Application import android.provider.Settings import foundation.e.lib.telemetry.Constants.SETTINGS_TELEMETRY_FIELD import io.sentry.Sentry import io.sentry.android.core.SentryAndroid object Telemetry { private var identifier: String = "" /** * Call this function in `onCreate()` of custom Application class. * Telemetry will be enabled only if enabled from developer options. */ fun init(identifier: String, application: Application) { this.identifier = identifier if (shouldEnableSentry(application)) { SentryAndroid.init(application) { options -> options.dsn = identifier } } } /** * Send a simple string message. */ fun reportMessage(message: String) { Sentry.captureMessage(message) } /** * Read from OS developer options. * Pass false by default. */ private fun shouldEnableSentry(application: Application): Boolean { return try { Settings.System.getInt(application.contentResolver, SETTINGS_TELEMETRY_FIELD) == 1 } catch (e: Settings.SettingNotFoundException) { false } catch (_: Exception) { false } } } No newline at end of file Loading
app/build.gradle +1 −1 Original line number Diff line number Diff line Loading @@ -17,5 +17,5 @@ android { } dependencies { implementation 'io.sentry:sentry-android:6.10.0' } No newline at end of file
app/src/main/java/foundation/e/lib/telemetry/Constants.kt 0 → 100644 +5 −0 Original line number Diff line number Diff line package foundation.e.lib.telemetry internal object Constants { const val SETTINGS_TELEMETRY_FIELD = "e_telemetry" } No newline at end of file
app/src/main/java/foundation/e/lib/telemetry/Telemetry.kt 0 → 100644 +47 −0 Original line number Diff line number Diff line package foundation.e.lib.telemetry import android.app.Application import android.provider.Settings import foundation.e.lib.telemetry.Constants.SETTINGS_TELEMETRY_FIELD import io.sentry.Sentry import io.sentry.android.core.SentryAndroid object Telemetry { private var identifier: String = "" /** * Call this function in `onCreate()` of custom Application class. * Telemetry will be enabled only if enabled from developer options. */ fun init(identifier: String, application: Application) { this.identifier = identifier if (shouldEnableSentry(application)) { SentryAndroid.init(application) { options -> options.dsn = identifier } } } /** * Send a simple string message. */ fun reportMessage(message: String) { Sentry.captureMessage(message) } /** * Read from OS developer options. * Pass false by default. */ private fun shouldEnableSentry(application: Application): Boolean { return try { Settings.System.getInt(application.contentResolver, SETTINGS_TELEMETRY_FIELD) == 1 } catch (e: Settings.SettingNotFoundException) { false } catch (_: Exception) { false } } } No newline at end of file