From 0e3ef0755e3049a0e111a43ac796e665bd6d4377 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Fri, 24 Mar 2023 05:41:25 +0530 Subject: [PATCH 01/24] isTelemetryEnabled() without application parameter --- .../foundation/e/lib/telemetry/Telemetry.kt | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) 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 5fc3639..c41fd1a 100644 --- a/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt +++ b/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt @@ -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) { -- GitLab From 17a7047a6e920d98fc66028c2bc3a360c5ecb863 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Fri, 24 Mar 2023 05:59:40 +0530 Subject: [PATCH 02/24] Make Utils objects --- .../java/foundation/e/lib/telemetry/Utils.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 lib/src/main/java/foundation/e/lib/telemetry/Utils.kt diff --git a/lib/src/main/java/foundation/e/lib/telemetry/Utils.kt b/lib/src/main/java/foundation/e/lib/telemetry/Utils.kt new file mode 100644 index 0000000..7465831 --- /dev/null +++ b/lib/src/main/java/foundation/e/lib/telemetry/Utils.kt @@ -0,0 +1,19 @@ +package foundation.e.lib.telemetry + +import android.annotation.SuppressLint + +object Utils { + + @SuppressLint("PrivateApi") + fun getSystemProperty(key: String?): String? { + var value: String? = null + try { + value = Class.forName("android.os.SystemProperties") + .getMethod("get", String::class.java).invoke(null, key) as String + } catch (e: Exception) { + e.printStackTrace() + } + return value + } + +} \ No newline at end of file -- GitLab From 98650971077e290a353783168e45e0cfda04004d Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Fri, 24 Mar 2023 06:00:22 +0530 Subject: [PATCH 03/24] add Constants for e version tag --- lib/src/main/java/foundation/e/lib/telemetry/Constants.kt | 2 ++ 1 file changed, 2 insertions(+) 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 54a85ce..02268fe 100644 --- a/lib/src/main/java/foundation/e/lib/telemetry/Constants.kt +++ b/lib/src/main/java/foundation/e/lib/telemetry/Constants.kt @@ -2,4 +2,6 @@ package foundation.e.lib.telemetry internal object Constants { const val SETTINGS_TELEMETRY_FIELD = "e_telemetry" + const val TAG_E_VERSION = "e_version" + const val PROPERTY_OS_VERSION = "ro.lineage.version" } \ No newline at end of file -- GitLab From 7d2eae57dc2af44af23c0b439298663928c6a0dc Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Fri, 24 Mar 2023 06:03:48 +0530 Subject: [PATCH 04/24] add e version tag while initializing --- .../java/foundation/e/lib/telemetry/Telemetry.kt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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 c41fd1a..61bb416 100644 --- a/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt +++ b/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt @@ -15,14 +15,25 @@ object Telemetry { * Call this function in `onCreate()` of custom Application class. * Telemetry will be enabled only if enabled from developer options. */ - fun init(identifier: String, application: Application) { + fun init( + identifier: String, + application: Application, + enableOsTag: Boolean = true, + ) { this.identifier = identifier this.application = application if (isTelemetryEnabled()) { SentryAndroid.init(application) { options -> options.dsn = identifier } - + } + Sentry.configureScope { + if (enableOsTag) { + val eVersion = Utils.getSystemProperty(Constants.PROPERTY_OS_VERSION) ?: "" + it.setTag(Constants.TAG_E_VERSION, eVersion) + } else { + it.removeTag(Constants.TAG_E_VERSION) + } } } -- GitLab From 32e4be0e53aee78c7bd5b908c8b5cd9a4e8c223c Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Fri, 24 Mar 2023 06:08:56 +0530 Subject: [PATCH 05/24] update version --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index c8131c9..b84964b 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -7,7 +7,7 @@ plugins { def versionMajor = 0 def versionMinor = 0 -def versionPatch = 4 +def versionPatch = 5 def releasePatch = "alpha" -- GitLab From 009b43d92f9991a5ea0b5245c1cf968f03dc3154 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Fri, 24 Mar 2023 06:09:13 +0530 Subject: [PATCH 06/24] update sentry version --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index b84964b..3ad99ab 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -86,5 +86,5 @@ publishing { } dependencies { - api 'io.sentry:sentry-android:6.10.0' + api 'io.sentry:sentry-android:6.15.0' } \ No newline at end of file -- GitLab From 3a9e3903013c27735f09744ea22abb7b51aa7434 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Fri, 24 Mar 2023 07:34:54 +0530 Subject: [PATCH 07/24] deprecate isTelemetryEnabled() for isReportingTelemetry() --- .../foundation/e/lib/telemetry/Telemetry.kt | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) 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 61bb416..0cf2d36 100644 --- a/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt +++ b/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt @@ -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) { -- GitLab From 2a3bc40ec2390f96c43a1d0cb1647118a862da34 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Fri, 24 Mar 2023 08:06:50 +0530 Subject: [PATCH 08/24] trackTelemetryOptionChange() --- .../foundation/e/lib/telemetry/Telemetry.kt | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) 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 0cf2d36..0af8537 100644 --- a/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt +++ b/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt @@ -1,6 +1,8 @@ package foundation.e.lib.telemetry import android.app.Application +import android.os.Handler +import android.os.Looper import android.provider.Settings import foundation.e.lib.telemetry.Constants.SETTINGS_TELEMETRY_FIELD import io.sentry.Sentry @@ -10,6 +12,7 @@ object Telemetry { private var identifier: String = "" private lateinit var application: Application + private var enableOsTag: Boolean = true private var isTelemetryEnabled: Boolean = false @@ -24,12 +27,15 @@ object Telemetry { ) { this.identifier = identifier this.application = application + this.enableOsTag = enableOsTag + this.isTelemetryEnabled = checkTelemetryDeveloperOption() if (isTelemetryEnabled) { SentryAndroid.init(application) { options -> options.dsn = identifier } } + Sentry.configureScope { if (enableOsTag) { val eVersion = Utils.getSystemProperty(Constants.PROPERTY_OS_VERSION) ?: "" @@ -40,6 +46,34 @@ object Telemetry { } } + /** + * Check if telemetry option is changed every 2 seconds. + * Or specify a different [interval]. + */ + fun trackTelemetryOptionChange(interval: Long = 2000) { + val handle = Handler(Looper.getMainLooper()) + val runnable = Runnable { + if (isTelemetryEnabled && !checkTelemetryDeveloperOption()) { + /* Indicates that telemetry reporting is going on but + * telemetry from developer options is turned off. + * In this case, disable telemetry. + */ + SentryAndroid.init(application) { options -> + options.dsn = null + } + isTelemetryEnabled = false + + } else if (!isTelemetryEnabled && checkTelemetryDeveloperOption()) { + /* + * Just the opposite of the above case. + * Re-initialise to auto enable. + */ + init(identifier, application, enableOsTag) + } + } + handle.postDelayed(runnable, interval) + } + /** * Send a simple string message. */ -- GitLab From 7cb3a6d234c9fd14a708aa2cb0a4db70c82b7758 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Fri, 24 Mar 2023 08:11:35 +0530 Subject: [PATCH 09/24] test with logging --- lib/build.gradle | 2 +- lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index 3ad99ab..e879f82 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -8,7 +8,7 @@ plugins { def versionMajor = 0 def versionMinor = 0 def versionPatch = 5 -def releasePatch = "alpha" +def releasePatch = "test" android { 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 0af8537..ad573ad 100644 --- a/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt +++ b/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt @@ -53,7 +53,9 @@ object Telemetry { fun trackTelemetryOptionChange(interval: Long = 2000) { val handle = Handler(Looper.getMainLooper()) val runnable = Runnable { + println("Testingggg: run") if (isTelemetryEnabled && !checkTelemetryDeveloperOption()) { + println("Testingggg: disable") /* Indicates that telemetry reporting is going on but * telemetry from developer options is turned off. * In this case, disable telemetry. @@ -64,6 +66,7 @@ object Telemetry { isTelemetryEnabled = false } else if (!isTelemetryEnabled && checkTelemetryDeveloperOption()) { + println("Testingggg: enable") /* * Just the opposite of the above case. * Re-initialise to auto enable. -- GitLab From 3a488aa9fda2c5e23c57384c1bbc8f44ef790f9a Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 27 Mar 2023 18:34:32 +0530 Subject: [PATCH 10/24] test contentObserver --- .../foundation/e/lib/telemetry/Telemetry.kt | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) 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 ad573ad..855a8b6 100644 --- a/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt +++ b/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt @@ -1,6 +1,7 @@ package foundation.e.lib.telemetry import android.app.Application +import android.database.ContentObserver import android.os.Handler import android.os.Looper import android.provider.Settings @@ -51,30 +52,34 @@ object Telemetry { * Or specify a different [interval]. */ fun trackTelemetryOptionChange(interval: Long = 2000) { - val handle = Handler(Looper.getMainLooper()) - val runnable = Runnable { - println("Testingggg: run") - if (isTelemetryEnabled && !checkTelemetryDeveloperOption()) { - println("Testingggg: disable") - /* Indicates that telemetry reporting is going on but - * telemetry from developer options is turned off. - * In this case, disable telemetry. - */ - SentryAndroid.init(application) { options -> - options.dsn = null + val handler = Handler(Looper.getMainLooper()) + val telemetryOptionObserver = object : ContentObserver(handler) { + override fun onChange(selfChange: Boolean) { + super.onChange(selfChange) + + println("Testingggg: run") + if (isTelemetryEnabled && !checkTelemetryDeveloperOption()) { + println("Testingggg: disable") + /* Indicates that telemetry reporting is going on but + * telemetry from developer options is turned off. + * In this case, disable telemetry. + */ + SentryAndroid.init(application) { options -> + options.dsn = null + } + isTelemetryEnabled = false + + } else if (!isTelemetryEnabled && checkTelemetryDeveloperOption()) { + println("Testingggg: enable") + /* + * Just the opposite of the above case. + * Re-initialise to auto enable. + */ + init(identifier, application, enableOsTag) } - isTelemetryEnabled = false - } else if (!isTelemetryEnabled && checkTelemetryDeveloperOption()) { - println("Testingggg: enable") - /* - * Just the opposite of the above case. - * Re-initialise to auto enable. - */ - init(identifier, application, enableOsTag) } } - handle.postDelayed(runnable, interval) } /** -- GitLab From cb4e4f49cc9626846e0235e406744ae4c85db307 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 27 Mar 2023 18:42:53 +0530 Subject: [PATCH 11/24] register with content resolver --- lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt | 7 +++++++ 1 file changed, 7 insertions(+) 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 855a8b6..44f5938 100644 --- a/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt +++ b/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt @@ -53,6 +53,7 @@ object Telemetry { */ fun trackTelemetryOptionChange(interval: Long = 2000) { val handler = Handler(Looper.getMainLooper()) + val contentResolver = application.contentResolver val telemetryOptionObserver = object : ContentObserver(handler) { override fun onChange(selfChange: Boolean) { super.onChange(selfChange) @@ -80,6 +81,12 @@ object Telemetry { } } + + contentResolver.registerContentObserver( + Settings.Global.getUriFor(SETTINGS_TELEMETRY_FIELD), + true, + telemetryOptionObserver + ) } /** -- GitLab From 6f1755723d2b72aeef283beb2862123fa6aa992d Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 27 Mar 2023 19:11:32 +0530 Subject: [PATCH 12/24] change uri --- lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 44f5938..75fc2e9 100644 --- a/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt +++ b/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt @@ -83,7 +83,7 @@ object Telemetry { } contentResolver.registerContentObserver( - Settings.Global.getUriFor(SETTINGS_TELEMETRY_FIELD), + Settings.System.getUriFor(SETTINGS_TELEMETRY_FIELD), true, telemetryOptionObserver ) -- GitLab From 38eca053d27acd69f87411efefe08250e2704b22 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 27 Mar 2023 19:32:08 +0530 Subject: [PATCH 13/24] Use empty dsn instead of null to disable --- lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 75fc2e9..ed7fc23 100644 --- a/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt +++ b/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt @@ -66,7 +66,7 @@ object Telemetry { * In this case, disable telemetry. */ SentryAndroid.init(application) { options -> - options.dsn = null + options.dsn = "" } isTelemetryEnabled = false -- GitLab From d6d763fd62920459b7b3dd5cec360a5c331309cf Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 27 Mar 2023 21:12:22 +0530 Subject: [PATCH 14/24] code restructure. End sentry session in trackTelemetryOptionChange() --- .../foundation/e/lib/telemetry/Telemetry.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) 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 ed7fc23..ef2b364 100644 --- a/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt +++ b/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt @@ -31,10 +31,12 @@ object Telemetry { this.enableOsTag = enableOsTag this.isTelemetryEnabled = checkTelemetryDeveloperOption() - if (isTelemetryEnabled) { - SentryAndroid.init(application) { options -> - options.dsn = identifier - } + val sentryDsn = + if (isTelemetryEnabled) identifier + else String() + + SentryAndroid.init(application) { options -> + options.dsn = sentryDsn } Sentry.configureScope { @@ -65,10 +67,8 @@ object Telemetry { * telemetry from developer options is turned off. * In this case, disable telemetry. */ - SentryAndroid.init(application) { options -> - options.dsn = "" - } - isTelemetryEnabled = false + Sentry.endSession() + init(identifier, application, enableOsTag) } else if (!isTelemetryEnabled && checkTelemetryDeveloperOption()) { println("Testingggg: enable") @@ -76,6 +76,7 @@ object Telemetry { * Just the opposite of the above case. * Re-initialise to auto enable. */ + Sentry.endSession() init(identifier, application, enableOsTag) } -- GitLab From ba1e432c7c52772581057058d0efd5bd078cf270 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 27 Mar 2023 21:22:53 +0530 Subject: [PATCH 15/24] remove interval in trackTelemetryOptionChange --- lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 ef2b364..08021ac 100644 --- a/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt +++ b/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt @@ -50,10 +50,9 @@ object Telemetry { } /** - * Check if telemetry option is changed every 2 seconds. - * Or specify a different [interval]. + * Check if telemetry option is changed using ContentObserver. */ - fun trackTelemetryOptionChange(interval: Long = 2000) { + fun trackTelemetryOptionChange() { val handler = Handler(Looper.getMainLooper()) val contentResolver = application.contentResolver val telemetryOptionObserver = object : ContentObserver(handler) { -- GitLab From 3c664a44129d1d25c1231f4892ffc9954ffc5b57 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 27 Mar 2023 21:24:19 +0530 Subject: [PATCH 16/24] remove logging, simplify code --- .../foundation/e/lib/telemetry/Telemetry.kt | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) 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 08021ac..c464b36 100644 --- a/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt +++ b/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt @@ -58,23 +58,7 @@ object Telemetry { val telemetryOptionObserver = object : ContentObserver(handler) { override fun onChange(selfChange: Boolean) { super.onChange(selfChange) - - println("Testingggg: run") - if (isTelemetryEnabled && !checkTelemetryDeveloperOption()) { - println("Testingggg: disable") - /* Indicates that telemetry reporting is going on but - * telemetry from developer options is turned off. - * In this case, disable telemetry. - */ - Sentry.endSession() - init(identifier, application, enableOsTag) - - } else if (!isTelemetryEnabled && checkTelemetryDeveloperOption()) { - println("Testingggg: enable") - /* - * Just the opposite of the above case. - * Re-initialise to auto enable. - */ + if (isTelemetryEnabled != checkTelemetryDeveloperOption()) { Sentry.endSession() init(identifier, application, enableOsTag) } -- GitLab From 9842b4d4e8a0fd016791dbb7a3a6826283beaea7 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 27 Mar 2023 23:05:12 +0530 Subject: [PATCH 17/24] update version 0.0.5-alpha --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index e879f82..3ad99ab 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -8,7 +8,7 @@ plugins { def versionMajor = 0 def versionMinor = 0 def versionPatch = 5 -def releasePatch = "test" +def releasePatch = "alpha" android { -- GitLab From 06d6d84da866190d7a548a132db9098734d7d56c Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 27 Mar 2023 23:31:29 +0530 Subject: [PATCH 18/24] update version 0.0.5-alpha2 to force build --- lib/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.gradle b/lib/build.gradle index 3ad99ab..12266f1 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -8,7 +8,7 @@ plugins { def versionMajor = 0 def versionMinor = 0 def versionPatch = 5 -def releasePatch = "alpha" +def releasePatch = "alpha2" android { -- GitLab From e93bc917fb088b581dd7e03f8256893d206050dd Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Tue, 28 Mar 2023 18:24:28 +0530 Subject: [PATCH 19/24] update gitlab ci rules --- .gitlab-ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f88da22..d6bb04a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -15,6 +15,12 @@ cache: lib: stage: lib + rules: + - if: '$CI_COMMIT_TAG !~ "/^$/"' + when: always + - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' + when: always + - when: manual script: - ./gradlew :lib:assembleRelease artifacts: @@ -23,5 +29,6 @@ lib: publish: stage: publish + needs: ["lib"] script: - ./gradlew :lib:publish -- GitLab From c1bfc28877f275368aaf04f61549c448633f4817 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Tue, 28 Mar 2023 19:19:24 +0530 Subject: [PATCH 20/24] move getSystemProperty() to Telemetry.kt and delete Utils.kt --- .../java/foundation/e/lib/telemetry/Telemetry.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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 b847050..c660319 100644 --- a/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt +++ b/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt @@ -1,5 +1,6 @@ package foundation.e.lib.telemetry +import android.annotation.SuppressLint import android.app.Application import android.database.ContentObserver import android.os.Handler @@ -53,7 +54,7 @@ object Telemetry { Sentry.configureScope { if (enableOsTag) { - val eVersion = Utils.getSystemProperty(Constants.PROPERTY_OS_VERSION) ?: "" + val eVersion = getSystemProperty(Constants.PROPERTY_OS_VERSION) ?: "" it.setTag(Constants.TAG_E_VERSION, eVersion) } else { it.removeTag(Constants.TAG_E_VERSION) @@ -147,4 +148,16 @@ object Telemetry { false } } + + @SuppressLint("PrivateApi") + private fun getSystemProperty(key: String?): String? { + var value: String? = null + try { + value = Class.forName("android.os.SystemProperties") + .getMethod("get", String::class.java).invoke(null, key) as String + } catch (e: Exception) { + e.printStackTrace() + } + return value + } } \ No newline at end of file -- GitLab From 2b8cf31aaef8d3e8b9524a5d0b77a58e2083537e Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Wed, 29 Mar 2023 15:41:01 +0530 Subject: [PATCH 21/24] fixup! move getSystemProperty() to Telemetry.kt and delete Utils.kt --- .../java/foundation/e/lib/telemetry/Utils.kt | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 lib/src/main/java/foundation/e/lib/telemetry/Utils.kt diff --git a/lib/src/main/java/foundation/e/lib/telemetry/Utils.kt b/lib/src/main/java/foundation/e/lib/telemetry/Utils.kt deleted file mode 100644 index 7465831..0000000 --- a/lib/src/main/java/foundation/e/lib/telemetry/Utils.kt +++ /dev/null @@ -1,19 +0,0 @@ -package foundation.e.lib.telemetry - -import android.annotation.SuppressLint - -object Utils { - - @SuppressLint("PrivateApi") - fun getSystemProperty(key: String?): String? { - var value: String? = null - try { - value = Class.forName("android.os.SystemProperties") - .getMethod("get", String::class.java).invoke(null, key) as String - } catch (e: Exception) { - e.printStackTrace() - } - return value - } - -} \ No newline at end of file -- GitLab From 85462f28404a5e482a340771e068303816e1f873 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Wed, 29 Mar 2023 15:41:26 +0530 Subject: [PATCH 22/24] apply style suggestion --- lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 c660319..b91b4b5 100644 --- a/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt +++ b/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt @@ -39,8 +39,12 @@ object Telemetry { this.isTelemetryEnabled = checkTelemetryDeveloperOption() val sentryDsn = - if (isTelemetryEnabled) identifier - else String() + if (isTelemetryEnabled) { + identifier + } else { + String() + } + SentryAndroid.init(application) { options -> options.dsn = sentryDsn -- GitLab From 5b9b9c62102a2d85fb8c6be37592d5596fcce876 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Wed, 29 Mar 2023 15:43:05 +0530 Subject: [PATCH 23/24] remove trackTelemetryOptionChange() --- .../foundation/e/lib/telemetry/Telemetry.kt | 27 ------------------- 1 file changed, 27 deletions(-) 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 b91b4b5..70bb00d 100644 --- a/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt +++ b/lib/src/main/java/foundation/e/lib/telemetry/Telemetry.kt @@ -2,9 +2,6 @@ package foundation.e.lib.telemetry import android.annotation.SuppressLint import android.app.Application -import android.database.ContentObserver -import android.os.Handler -import android.os.Looper import android.provider.Settings import foundation.e.lib.telemetry.Constants.SETTINGS_TELEMETRY_FIELD import io.sentry.Sentry @@ -66,30 +63,6 @@ object Telemetry { } } - /** - * Check if telemetry option is changed using ContentObserver. - */ - fun trackTelemetryOptionChange() { - val handler = Handler(Looper.getMainLooper()) - val contentResolver = application.contentResolver - val telemetryOptionObserver = object : ContentObserver(handler) { - override fun onChange(selfChange: Boolean) { - super.onChange(selfChange) - if (isTelemetryEnabled != checkTelemetryDeveloperOption()) { - Sentry.endSession() - init(identifier, application, enableOsTag) - } - - } - } - - contentResolver.registerContentObserver( - Settings.System.getUriFor(SETTINGS_TELEMETRY_FIELD), - true, - telemetryOptionObserver - ) - } - /** * Send a simple string message. * -- GitLab From 7ccffcbbbea6eb2c065b10cede85e2acf0d86cd6 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Wed, 29 Mar 2023 15:44:00 +0530 Subject: [PATCH 24/24] update version to 0.0.6-alpha --- lib/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index 55cb7fd..bc680ce 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -6,8 +6,8 @@ plugins { def versionMajor = 0 def versionMinor = 0 -def versionPatch = 5 -def releasePatch = "alpha2" +def versionPatch = 6 +def releasePatch = "alpha" android { namespace 'foundation.e.lib.telemetry' -- GitLab