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

Commit 0e3ef075 authored by Sayantan Roychowdhury's avatar Sayantan Roychowdhury
Browse files

isTelemetryEnabled() without application parameter

parent cb12a6ec
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ import io.sentry.android.core.SentryAndroid
object Telemetry {

    private var identifier: String = ""
    private lateinit var application: Application

    /**
     * Call this function in `onCreate()` of custom Application class.
@@ -16,7 +17,8 @@ object Telemetry {
     */
    fun init(identifier: String, application: Application) {
        this.identifier = identifier
        if (isTelemetryEnabled(application)) {
        this.application = application
        if (isTelemetryEnabled()) {
            SentryAndroid.init(application) { options ->
                options.dsn = identifier
            }
@@ -31,11 +33,25 @@ object Telemetry {
        Sentry.captureMessage(message)
    }

    @Deprecated(
        "Use isTelemetryEnabled() without parameters.",
        ReplaceWith("isTelemetryEnabled()"),
    )
    fun isTelemetryEnabled(application: Application): Boolean {
        return try {
            Settings.System.getInt(application.contentResolver, SETTINGS_TELEMETRY_FIELD) == 1
        } catch (e: Settings.SettingNotFoundException) {
            false
        } catch (_: Exception) {
            false
        }
    }

    /**
     * Read from OS developer options.
     * Pass false by default.
     */
    fun isTelemetryEnabled(application: Application): Boolean {
    fun isTelemetryEnabled(): Boolean {
        return try {
            Settings.System.getInt(application.contentResolver, SETTINGS_TELEMETRY_FIELD) == 1
        } catch (e: Settings.SettingNotFoundException) {