Browse Source

Avoid hardcoded dispatchers.

Fix issue detected by sonar.
feature/jme/update_rust_sdk
Benoit Marty 2 years ago
parent
commit
f0721e484d
  1. 4
      features/rageshake/src/main/kotlin/io/element/android/features/rageshake/logs/VectorFileLogger.kt
  2. 7
      features/rageshake/src/main/kotlin/io/element/android/features/rageshake/reporter/BugReporter.kt

4
features/rageshake/src/main/kotlin/io/element/android/features/rageshake/logs/VectorFileLogger.kt

@ -20,6 +20,7 @@ import android.content.Context @@ -20,6 +20,7 @@ import android.content.Context
import android.util.Log
import io.element.android.libraries.androidutils.file.safeDelete
import io.element.android.libraries.core.data.tryOrNull
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
@ -38,6 +39,7 @@ import java.util.logging.Logger @@ -38,6 +39,7 @@ import java.util.logging.Logger
class VectorFileLogger(
context: Context,
// private val vectorPreferences: VectorPreferences
private val dispatcher: CoroutineDispatcher = Dispatchers.IO,
) : Timber.Tree() {
companion object {
@ -109,7 +111,7 @@ class VectorFileLogger( @@ -109,7 +111,7 @@ class VectorFileLogger(
@OptIn(DelicateCoroutinesApi::class)
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
fileHandler ?: return
GlobalScope.launch(Dispatchers.IO) {
GlobalScope.launch(dispatcher) {
if (skipLog(priority)) return@launch
if (t != null) {
logToFile(t)

7
features/rageshake/src/main/kotlin/io/element/android/features/rageshake/reporter/BugReporter.kt

@ -24,11 +24,11 @@ import io.element.android.features.rageshake.logs.VectorFileLogger @@ -24,11 +24,11 @@ import io.element.android.features.rageshake.logs.VectorFileLogger
import io.element.android.features.rageshake.screenshot.ScreenshotHolder
import io.element.android.libraries.androidutils.file.compressFile
import io.element.android.libraries.androidutils.file.safeDelete
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
import io.element.android.libraries.core.extensions.toOnOff
import io.element.android.libraries.core.mimetype.MimeTypes
import io.element.android.libraries.di.ApplicationContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@ -55,6 +55,7 @@ class BugReporter @Inject constructor( @@ -55,6 +55,7 @@ class BugReporter @Inject constructor(
@ApplicationContext private val context: Context,
private val screenshotHolder: ScreenshotHolder,
private val crashDataStore: CrashDataStore,
private val coroutineDispatchers: CoroutineDispatchers,
/*
private val activeSessionHolder: ActiveSessionHolder,
private val versionProvider: VersionProvider,
@ -169,7 +170,7 @@ class BugReporter @Inject constructor( @@ -169,7 +170,7 @@ class BugReporter @Inject constructor(
coroutineScope.launch {
var serverError: String? = null
var reportURL: String? = null
withContext(Dispatchers.IO) {
withContext(coroutineDispatchers.io) {
var bugDescription = theBugDescription
val crashCallStack = crashDataStore.crashInfo().first()
@ -419,7 +420,7 @@ class BugReporter @Inject constructor( @@ -419,7 +420,7 @@ class BugReporter @Inject constructor(
}
}
withContext(Dispatchers.Main) {
withContext(coroutineDispatchers.main) {
mBugReportCall = null
// delete when the bug report has been successfully sent

Loading…
Cancel
Save