diff --git a/README.md b/README.md index e96b6ee676b56c80bce6d4e1174e000ee2ef9b6d..c88802ea46ce6cf7d0a51f753035bab63dc3d9b2 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ maven("https://gitlab.e.foundation/api/v4/groups/1391/-/packages/maven") - Then, we need to add dependency to `build.gradle`: ```groovy -implementation 'foundation.e.lib:telemetry:0.0.6-alpha' +implementation 'foundation.e.lib:telemetry:0.0.10-alpha' ``` - Get the Sentry DSN from the sentry dashboard and add the following to `build.gradle`: @@ -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` diff --git a/lib/build.gradle b/lib/build.gradle index 7bd2508824497faab8eaaedc7d8b1db27f14ca77..f6423dc3ab77819e759cfc2908232f8e4287470e 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -6,7 +6,7 @@ plugins { def versionMajor = 0 def versionMinor = 0 -def versionPatch = 9 +def versionPatch = 10 def releasePatch = "alpha" android { diff --git a/lib/src/main/java/foundation/e/lib/telemetry/Constants.kt b/lib/src/main/java/foundation/e/lib/telemetry/Constants.kt index 747ca3c2a26da1dd9ad252377f5f104f9499bf6e..47dc5ec74cd21c2d5ef292f8432965b07d9473af 100644 --- a/lib/src/main/java/foundation/e/lib/telemetry/Constants.kt +++ b/lib/src/main/java/foundation/e/lib/telemetry/Constants.kt @@ -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" } diff --git a/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt b/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt index 3a31ec0069fde83fb18ac1855e2abd839545b5d1..110fbf8fd550208ad4645c764d9f75e9a73fa869 100644 --- a/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt +++ b/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt @@ -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.