From 1ed7bbac37dcb64d95df4252fc62a509579c8dd3 Mon Sep 17 00:00:00 2001 From: althafvly Date: Fri, 23 Jun 2023 14:01:25 +0530 Subject: [PATCH 1/2] telemetry: add function to get sentry user id --- README.md | 13 +++++++++++++ .../foundation/e/lib/telemetry/Constants.kt | 1 + .../foundation/e/lib/telemetry/Telemetry.kt | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/README.md b/README.md index e96b6ee..23fea24 100644 --- a/README.md +++ b/README.md @@ -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/src/main/java/foundation/e/lib/telemetry/Constants.kt b/lib/src/main/java/foundation/e/lib/telemetry/Constants.kt index 747ca3c..47dc5ec 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 3a31ec0..110fbf8 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. -- GitLab From fc24aec1dece821e479077c0dcab870bdb7bd8d1 Mon Sep 17 00:00:00 2001 From: althafvly Date: Fri, 23 Jun 2023 14:16:14 +0530 Subject: [PATCH 2/2] e-telemetry: Update to 0.0.10-alpha --- README.md | 2 +- lib/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 23fea24..c88802e 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`: diff --git a/lib/build.gradle b/lib/build.gradle index 7bd2508..f6423dc 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 { -- GitLab