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

Commit 3a9e3903 authored by Sayantan Roychowdhury's avatar Sayantan Roychowdhury
Browse files

deprecate isTelemetryEnabled() for isReportingTelemetry()

parent 009b43d9
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -11,6 +11,8 @@ object Telemetry {
    private var identifier: String = ""
    private lateinit var application: Application

    private var isTelemetryEnabled: Boolean = false

    /**
     * Call this function in `onCreate()` of custom Application class.
     * Telemetry will be enabled only if enabled from developer options.
@@ -22,7 +24,8 @@ object Telemetry {
    ) {
        this.identifier = identifier
        this.application = application
        if (isTelemetryEnabled()) {
        this.isTelemetryEnabled = checkTelemetryDeveloperOption()
        if (isTelemetryEnabled) {
            SentryAndroid.init(application) { options ->
                options.dsn = identifier
            }
@@ -45,8 +48,8 @@ object Telemetry {
    }

    @Deprecated(
        "Use isTelemetryEnabled() without parameters.",
        ReplaceWith("isTelemetryEnabled()"),
        "Use isReportingTelemetry()",
        ReplaceWith("isReportingTelemetry()"),
    )
    fun isTelemetryEnabled(application: Application): Boolean {
        return try {
@@ -58,11 +61,24 @@ object Telemetry {
        }
    }

    /**
     * It is possible that the telemetry option in developer options is different from
     * the current state of the library. It is possible if the app is open and
     * e_telemetry system setting is (say) disabled via ADB command.
     *
     * This method reports the actual state of telemetry reporting, immaterial of the
     * developer options. This state is set when [init] has been called, usually
     * during app start up.
     */
    fun isReportingTelemetry(): Boolean {
        return isTelemetryEnabled
    }

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