From d0e850888c9893ccfc8d501b8b803572fa3a1aeb Mon Sep 17 00:00:00 2001 From: Nino van Hooff Date: Wed, 22 Jun 2022 14:16:59 +0200 Subject: [PATCH] BUGFIX update coroutines to 1.6.3 Fixes a DiskRead policy violation (really this time) --- build.gradle | 2 +- .../java/com/q42/q42stats/library/Q42Stats.kt | 29 ++++--------------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/build.gradle b/build.gradle index 666fec1..e4eec94 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ buildscript { ext { kotlin_version = "1.6.10" - version_kotlinx_coroutines = "1.6.0" + version_kotlinx_coroutines = "1.6.3" gradle_version = '7.1.2' jvm_target = "11" version_androidx_annotation = "1.2.0" diff --git a/q42stats/src/main/java/com/q42/q42stats/library/Q42Stats.kt b/q42stats/src/main/java/com/q42/q42stats/library/Q42Stats.kt index 7d14414..05973c1 100644 --- a/q42stats/src/main/java/com/q42/q42stats/library/Q42Stats.kt +++ b/q42stats/src/main/java/com/q42/q42stats/library/Q42Stats.kt @@ -21,31 +21,14 @@ internal const val DATA_MODEL_VERSION = 3 class Q42Stats(private val config: Q42StatsConfig) { /** - * Collects stats and sends it to the server. This method is safe to be called from anywhere - * in your app and will do nothing if it is running or has already run before + * Collects stats and sends it to the server. This method is safe to be called from anywhere + * in your app and will do nothing if it is running or has already run before */ - @OptIn(DelicateCoroutinesApi::class) @AnyThread - fun runAsync(context: Context) { - // Creating MainScope on the main thread would trigger a diskRead violation, so go to IO - CoroutineScope(Dispatchers.IO + coroutineExceptionHandler).launch { - runAsync(context, MainScope() + coroutineExceptionHandler) - } - } - - /** - * Collects stats and sends it to the server. This method can be called from anywhere - * in your app and will do nothing if it is running or has already run before. - * - * Although this overload is generally safe; - * Consider using [runAsync] instead for maximum error handling safety - * - * @param coroutineScope should be configured with an CoroutineExceptionHandler - * - */ - @AnyThread - @DelicateCoroutinesApi - fun runAsync(context: Context, coroutineScope: CoroutineScope) { + fun runAsync( + context: Context, + coroutineScope: CoroutineScope = MainScope() + coroutineExceptionHandler + ) { Q42StatsLogger.d(TAG, "Q42Stats: Checking Preconditions") // check preconditions on the main thread to prevent concurrency issues coroutineScope.launch(Dispatchers.Main) {