Update rust sdk to 0.1.42 (changes in tracing and sync apis) (#1055)
* Update rust sdk to 0.1.42 (changes in tracing and sync apis) * Fix sample compilation --------- Co-authored-by: ganfra <francoisg@element.io>
This commit is contained in:
parent
08a0f710d7
commit
a911134636
10 changed files with 42 additions and 19 deletions
|
|
@ -141,7 +141,9 @@ class LoggedInFlowNode @AssistedInject constructor(
|
|||
},
|
||||
onStop = {
|
||||
//Counterpart startSync is done in observeSyncStateAndNetworkStatus method.
|
||||
syncService.stopSync()
|
||||
coroutineScope.launch {
|
||||
syncService.stopSync()
|
||||
}
|
||||
},
|
||||
onDestroy = {
|
||||
plugins<LifecycleCallback>().forEach { it.onFlowReleased(id, inputs.matrixClient) }
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ jsoup = { module = "org.jsoup:jsoup", version.ref = "jsoup" }
|
|||
appyx_core = { module = "com.bumble.appyx:core", version.ref = "appyx" }
|
||||
molecule-runtime = { module = "app.cash.molecule:molecule-runtime", version.ref = "molecule" }
|
||||
timber = "com.jakewharton.timber:timber:5.0.1"
|
||||
matrix_sdk = "org.matrix.rustcomponents:sdk-android:0.1.41"
|
||||
matrix_sdk = "org.matrix.rustcomponents:sdk-android:0.1.42"
|
||||
sqldelight-driver-android = { module = "com.squareup.sqldelight:android-driver", version.ref = "sqldelight" }
|
||||
sqldelight-driver-jvm = { module = "com.squareup.sqldelight:sqlite-driver", version.ref = "sqldelight" }
|
||||
sqldelight-coroutines = { module = "com.squareup.sqldelight:coroutines-extensions", version.ref = "sqldelight" }
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ interface SyncService {
|
|||
/**
|
||||
* Tries to stop the sync. If service is not syncing it has no effect.
|
||||
*/
|
||||
fun stopSync(): Result<Unit>
|
||||
suspend fun stopSync(): Result<Unit>
|
||||
|
||||
/**
|
||||
* Flow of [SyncState]. Will be updated as soon as the current [SyncState] changes.
|
||||
|
|
|
|||
|
|
@ -41,9 +41,9 @@ class RustSyncService(
|
|||
Timber.d("Start sync failed: $it")
|
||||
}
|
||||
|
||||
override fun stopSync() = runCatching {
|
||||
override suspend fun stopSync() = runCatching {
|
||||
Timber.i("Stop sync")
|
||||
innerSyncService.pause()
|
||||
innerSyncService.stop()
|
||||
}.onFailure {
|
||||
Timber.d("Stop sync failed: $it")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,8 +22,7 @@ package io.element.android.libraries.matrix.impl.tracing
|
|||
*/
|
||||
data class LogEventLocation(
|
||||
val file: String,
|
||||
val line: UInt,
|
||||
val column: UInt,
|
||||
val line: UInt?,
|
||||
) {
|
||||
|
||||
companion object {
|
||||
|
|
@ -32,9 +31,8 @@ data class LogEventLocation(
|
|||
*/
|
||||
fun from(stackTraceElement: StackTraceElement): LogEventLocation {
|
||||
return LogEventLocation(
|
||||
file = stackTraceElement.fileName,
|
||||
line = stackTraceElement.lineNumber.toUInt(),
|
||||
column = 0u,
|
||||
file = stackTraceElement.fileName ?: "",
|
||||
line = stackTraceElement.lineNumber.takeIf { it >= 0 }?.toUInt()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package io.element.android.libraries.matrix.impl.tracing
|
||||
|
||||
import com.squareup.anvil.annotations.ContributesBinding
|
||||
import io.element.android.libraries.core.meta.BuildMeta
|
||||
import io.element.android.libraries.di.AppScope
|
||||
import io.element.android.libraries.matrix.api.tracing.TracingConfiguration
|
||||
import io.element.android.libraries.matrix.api.tracing.TracingService
|
||||
|
|
@ -26,13 +27,13 @@ import timber.log.Timber
|
|||
import javax.inject.Inject
|
||||
|
||||
@ContributesBinding(AppScope::class)
|
||||
class RustTracingService @Inject constructor() : TracingService {
|
||||
class RustTracingService @Inject constructor(private val buildMeta: BuildMeta) : TracingService {
|
||||
|
||||
override fun setupTracing(tracingConfiguration: TracingConfiguration) {
|
||||
val filter = tracingConfiguration.filterConfiguration
|
||||
val rustTracingConfiguration = org.matrix.rustcomponents.sdk.TracingConfiguration(
|
||||
filter = tracingConfiguration.filterConfiguration.filter,
|
||||
writeToStdoutOrSystem = tracingConfiguration.writesToLogcat,
|
||||
writeToStdoutOrSystem = tracingConfiguration.writesToLogcat,
|
||||
writeToFiles = when (val writeToFilesConfiguration = tracingConfiguration.writesToFilesConfiguration) {
|
||||
is WriteToFilesConfiguration.Disabled -> null
|
||||
is WriteToFilesConfiguration.Enabled -> TracingFileConfiguration(
|
||||
|
|
@ -46,6 +47,6 @@ class RustTracingService @Inject constructor() : TracingService {
|
|||
}
|
||||
|
||||
override fun createTimberTree(): Timber.Tree {
|
||||
return RustTracingTree()
|
||||
return RustTracingTree(retrieveFromStackTrace = buildMeta.isDebuggable)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,15 +35,18 @@ private val fqcnIgnore = listOf(
|
|||
/**
|
||||
* A Timber tree that passes logs to the Rust SDK.
|
||||
*/
|
||||
internal class RustTracingTree : Timber.Tree() {
|
||||
internal class RustTracingTree(private val retrieveFromStackTrace: Boolean) : Timber.Tree() {
|
||||
|
||||
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
|
||||
val location = getLogEventLocationFromStackTrace()
|
||||
val location = if (retrieveFromStackTrace) {
|
||||
getLogEventLocationFromStackTrace()
|
||||
} else {
|
||||
LogEventLocation("", null)
|
||||
}
|
||||
val logLevel = priority.toLogLevel()
|
||||
logEvent(
|
||||
file = location.file,
|
||||
line = location.line,
|
||||
column = location.column,
|
||||
level = logLevel,
|
||||
target = Target.ELEMENT.filter,
|
||||
message = message,
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class FakeSyncService : SyncService {
|
|||
return Result.success(Unit)
|
||||
}
|
||||
|
||||
override fun stopSync(): Result<Unit> {
|
||||
override suspend fun stopSync(): Result<Unit> {
|
||||
syncStateFlow.value = SyncState.Terminated
|
||||
return Result.success(Unit)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,7 +113,9 @@ class RoomListScreen(
|
|||
}
|
||||
onDispose {
|
||||
Timber.w("Stop sync!")
|
||||
matrixClient.syncService().stopSync()
|
||||
runBlocking {
|
||||
matrixClient.syncService().stopSync()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@
|
|||
package io.element.android.samples.minimal
|
||||
|
||||
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
||||
import io.element.android.libraries.core.meta.BuildMeta
|
||||
import io.element.android.libraries.core.meta.BuildType
|
||||
import io.element.android.libraries.matrix.api.tracing.TracingConfiguration
|
||||
import io.element.android.libraries.matrix.api.tracing.TracingFilterConfigurations
|
||||
import io.element.android.libraries.matrix.api.tracing.WriteToFilesConfiguration
|
||||
|
|
@ -28,13 +30,28 @@ import kotlinx.coroutines.plus
|
|||
|
||||
object Singleton {
|
||||
|
||||
private val buildMeta = BuildMeta(
|
||||
isDebuggable = true,
|
||||
buildType = BuildType.DEBUG,
|
||||
applicationName = "EAX-Minimal",
|
||||
applicationId = "io.element.android.samples.minimal",
|
||||
lowPrivacyLoggingEnabled = false,
|
||||
versionName = "0.1.0",
|
||||
versionCode = 1,
|
||||
gitRevision = "TODO", // BuildConfig.GIT_REVISION,
|
||||
gitRevisionDate = "TODO", // BuildConfig.GIT_REVISION_DATE,
|
||||
gitBranchName = "TODO", // BuildConfig.GIT_BRANCH_NAME,
|
||||
flavorDescription = "TODO", // BuildConfig.FLAVOR_DESCRIPTION,
|
||||
flavorShortDescription = "TODO", // BuildConfig.SHORT_FLAVOR_DESCRIPTION,
|
||||
)
|
||||
|
||||
init {
|
||||
val tracingConfiguration = TracingConfiguration(
|
||||
filterConfiguration = TracingFilterConfigurations.debug,
|
||||
writesToLogcat = true,
|
||||
writesToFilesConfiguration = WriteToFilesConfiguration.Disabled
|
||||
)
|
||||
RustTracingService().setupTracing(tracingConfiguration)
|
||||
RustTracingService(buildMeta).setupTracing(tracingConfiguration)
|
||||
}
|
||||
|
||||
val appScope = MainScope() + CoroutineName("Minimal Scope")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue