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

Commit 1ed7bbac authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

telemetry: add function to get sentry user id

parent 6f04dc58
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -38,8 +38,21 @@ Telemetry.init(BuildConfig.SENTRY_DSN, this)
Telemetry.reportMessage("sample message")
```

- To get sentry user id, we need to add the following code:

```kotlin
Telemetry.getSentryUserId()
```

# How to force telemetry to be enabled without manual action in settings?

Use adb command:

`adb shell settings put system e_telemetry 1`

# How to get/change sentry user id?

Use adb command:

`adb shell settings get secure sentry_userid`
`adb shell settings put secure sentry_userid 2163681a-0980-41f6-8044-7db50c580986`
+1 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ package foundation.e.lib.telemetry

internal object Constants {
    const val SETTINGS_TELEMETRY_FIELD = "e_telemetry"
    const val SENTRY_USERID = "sentry_userid";
    const val TAG_E_VERSION = "e_version"
    const val PROPERTY_OS_VERSION = "ro.lineage.version"
}
+18 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ object Telemetry {
    private lateinit var application: Application
    private var enableOsTag: Boolean = true
    private var isTelemetryEnabled: Boolean = false
    private var userSentryId: String = ""

    /**
     * Call this function in `onCreate()` of custom Application class.
@@ -30,6 +31,7 @@ object Telemetry {
        this.application = application
        this.enableOsTag = enableOsTag
        this.isTelemetryEnabled = checkTelemetryDeveloperOption()
        this.userSentryId = getSentryUserId(application)

        val sentryDsn =
            if (isTelemetryEnabled) {
@@ -110,6 +112,16 @@ object Telemetry {
        }
    }

    private fun getSentryUserId(application: Application): String {
        return try {
            Settings.Secure.getString(application.contentResolver, Constants.SENTRY_USERID)
        } catch (e: Settings.SettingNotFoundException) {
            ""
        } catch (_: Exception) {
            ""
        }
    }

    /**
     * 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
@@ -122,6 +134,12 @@ object Telemetry {
    @JvmStatic
    fun isReportingTelemetry() = isTelemetryEnabled

    /**
     * Return a unique id for a device, that can be used for sentry.
     */
    @JvmStatic
    fun getSentryUserId() = userSentryId

    /**
     * Read from OS developer options.
     * Pass false by default.