Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 50c231be authored by Sayantan Roychowdhury's avatar Sayantan Roychowdhury
Browse files

basic sentry setup

parent bf7a3bc6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -17,5 +17,5 @@ android {
}

dependencies {

    implementation 'io.sentry:sentry-android:6.10.0'
}
 No newline at end of file
+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
+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