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
a04cb2963c
commit
c15483828d
10 changed files with 42 additions and 19 deletions
|
|
@ -141,7 +141,9 @@ class LoggedInFlowNode @AssistedInject constructor(
|
||||||
},
|
},
|
||||||
onStop = {
|
onStop = {
|
||||||
//Counterpart startSync is done in observeSyncStateAndNetworkStatus method.
|
//Counterpart startSync is done in observeSyncStateAndNetworkStatus method.
|
||||||
syncService.stopSync()
|
coroutineScope.launch {
|
||||||
|
syncService.stopSync()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onDestroy = {
|
onDestroy = {
|
||||||
plugins<LifecycleCallback>().forEach { it.onFlowReleased(id, inputs.matrixClient) }
|
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" }
|
appyx_core = { module = "com.bumble.appyx:core", version.ref = "appyx" }
|
||||||
molecule-runtime = { module = "app.cash.molecule:molecule-runtime", version.ref = "molecule" }
|
molecule-runtime = { module = "app.cash.molecule:molecule-runtime", version.ref = "molecule" }
|
||||||
timber = "com.jakewharton.timber:timber:5.0.1"
|
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-android = { module = "com.squareup.sqldelight:android-driver", version.ref = "sqldelight" }
|
||||||
sqldelight-driver-jvm = { module = "com.squareup.sqldelight:sqlite-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" }
|
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.
|
* 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.
|
* 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")
|
Timber.d("Start sync failed: $it")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun stopSync() = runCatching {
|
override suspend fun stopSync() = runCatching {
|
||||||
Timber.i("Stop sync")
|
Timber.i("Stop sync")
|
||||||
innerSyncService.pause()
|
innerSyncService.stop()
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
Timber.d("Stop sync failed: $it")
|
Timber.d("Stop sync failed: $it")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,7 @@ package io.element.android.libraries.matrix.impl.tracing
|
||||||
*/
|
*/
|
||||||
data class LogEventLocation(
|
data class LogEventLocation(
|
||||||
val file: String,
|
val file: String,
|
||||||
val line: UInt,
|
val line: UInt?,
|
||||||
val column: UInt,
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
@ -32,9 +31,8 @@ data class LogEventLocation(
|
||||||
*/
|
*/
|
||||||
fun from(stackTraceElement: StackTraceElement): LogEventLocation {
|
fun from(stackTraceElement: StackTraceElement): LogEventLocation {
|
||||||
return LogEventLocation(
|
return LogEventLocation(
|
||||||
file = stackTraceElement.fileName,
|
file = stackTraceElement.fileName ?: "",
|
||||||
line = stackTraceElement.lineNumber.toUInt(),
|
line = stackTraceElement.lineNumber.takeIf { it >= 0 }?.toUInt()
|
||||||
column = 0u,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package io.element.android.libraries.matrix.impl.tracing
|
package io.element.android.libraries.matrix.impl.tracing
|
||||||
|
|
||||||
import com.squareup.anvil.annotations.ContributesBinding
|
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.di.AppScope
|
||||||
import io.element.android.libraries.matrix.api.tracing.TracingConfiguration
|
import io.element.android.libraries.matrix.api.tracing.TracingConfiguration
|
||||||
import io.element.android.libraries.matrix.api.tracing.TracingService
|
import io.element.android.libraries.matrix.api.tracing.TracingService
|
||||||
|
|
@ -26,13 +27,13 @@ import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@ContributesBinding(AppScope::class)
|
@ContributesBinding(AppScope::class)
|
||||||
class RustTracingService @Inject constructor() : TracingService {
|
class RustTracingService @Inject constructor(private val buildMeta: BuildMeta) : TracingService {
|
||||||
|
|
||||||
override fun setupTracing(tracingConfiguration: TracingConfiguration) {
|
override fun setupTracing(tracingConfiguration: TracingConfiguration) {
|
||||||
val filter = tracingConfiguration.filterConfiguration
|
val filter = tracingConfiguration.filterConfiguration
|
||||||
val rustTracingConfiguration = org.matrix.rustcomponents.sdk.TracingConfiguration(
|
val rustTracingConfiguration = org.matrix.rustcomponents.sdk.TracingConfiguration(
|
||||||
filter = tracingConfiguration.filterConfiguration.filter,
|
filter = tracingConfiguration.filterConfiguration.filter,
|
||||||
writeToStdoutOrSystem = tracingConfiguration.writesToLogcat,
|
writeToStdoutOrSystem = tracingConfiguration.writesToLogcat,
|
||||||
writeToFiles = when (val writeToFilesConfiguration = tracingConfiguration.writesToFilesConfiguration) {
|
writeToFiles = when (val writeToFilesConfiguration = tracingConfiguration.writesToFilesConfiguration) {
|
||||||
is WriteToFilesConfiguration.Disabled -> null
|
is WriteToFilesConfiguration.Disabled -> null
|
||||||
is WriteToFilesConfiguration.Enabled -> TracingFileConfiguration(
|
is WriteToFilesConfiguration.Enabled -> TracingFileConfiguration(
|
||||||
|
|
@ -46,6 +47,6 @@ class RustTracingService @Inject constructor() : TracingService {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createTimberTree(): Timber.Tree {
|
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.
|
* 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?) {
|
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()
|
val logLevel = priority.toLogLevel()
|
||||||
logEvent(
|
logEvent(
|
||||||
file = location.file,
|
file = location.file,
|
||||||
line = location.line,
|
line = location.line,
|
||||||
column = location.column,
|
|
||||||
level = logLevel,
|
level = logLevel,
|
||||||
target = Target.ELEMENT.filter,
|
target = Target.ELEMENT.filter,
|
||||||
message = message,
|
message = message,
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ class FakeSyncService : SyncService {
|
||||||
return Result.success(Unit)
|
return Result.success(Unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun stopSync(): Result<Unit> {
|
override suspend fun stopSync(): Result<Unit> {
|
||||||
syncStateFlow.value = SyncState.Terminated
|
syncStateFlow.value = SyncState.Terminated
|
||||||
return Result.success(Unit)
|
return Result.success(Unit)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,9 @@ class RoomListScreen(
|
||||||
}
|
}
|
||||||
onDispose {
|
onDispose {
|
||||||
Timber.w("Stop sync!")
|
Timber.w("Stop sync!")
|
||||||
matrixClient.syncService().stopSync()
|
runBlocking {
|
||||||
|
matrixClient.syncService().stopSync()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
package io.element.android.samples.minimal
|
package io.element.android.samples.minimal
|
||||||
|
|
||||||
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
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.TracingConfiguration
|
||||||
import io.element.android.libraries.matrix.api.tracing.TracingFilterConfigurations
|
import io.element.android.libraries.matrix.api.tracing.TracingFilterConfigurations
|
||||||
import io.element.android.libraries.matrix.api.tracing.WriteToFilesConfiguration
|
import io.element.android.libraries.matrix.api.tracing.WriteToFilesConfiguration
|
||||||
|
|
@ -28,13 +30,28 @@ import kotlinx.coroutines.plus
|
||||||
|
|
||||||
object Singleton {
|
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 {
|
init {
|
||||||
val tracingConfiguration = TracingConfiguration(
|
val tracingConfiguration = TracingConfiguration(
|
||||||
filterConfiguration = TracingFilterConfigurations.debug,
|
filterConfiguration = TracingFilterConfigurations.debug,
|
||||||
writesToLogcat = true,
|
writesToLogcat = true,
|
||||||
writesToFilesConfiguration = WriteToFilesConfiguration.Disabled
|
writesToFilesConfiguration = WriteToFilesConfiguration.Disabled
|
||||||
)
|
)
|
||||||
RustTracingService().setupTracing(tracingConfiguration)
|
RustTracingService(buildMeta).setupTracing(tracingConfiguration)
|
||||||
}
|
}
|
||||||
|
|
||||||
val appScope = MainScope() + CoroutineName("Minimal Scope")
|
val appScope = MainScope() + CoroutineName("Minimal Scope")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue