change(tracing) : change how tracing is configured (ui and logic)
This commit is contained in:
parent
fd3b99765d
commit
7d27e6581b
38 changed files with 220 additions and 886 deletions
|
|
@ -9,50 +9,34 @@ package io.element.android.x.initializer
|
|||
|
||||
import android.content.Context
|
||||
import android.system.Os
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.startup.Initializer
|
||||
import io.element.android.features.preferences.impl.developer.tracing.SharedPreferencesTracingConfigurationStore
|
||||
import io.element.android.features.preferences.impl.developer.tracing.TargetLogLevelMapBuilder
|
||||
import io.element.android.features.rageshake.api.reporter.BugReporter
|
||||
import io.element.android.libraries.architecture.bindings
|
||||
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
|
||||
import io.element.android.x.BuildConfig
|
||||
import io.element.android.x.di.AppBindings
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import timber.log.Timber
|
||||
|
||||
private const val ELEMENT_X_TARGET = "elementx"
|
||||
|
||||
class TracingInitializer : Initializer<Unit> {
|
||||
override fun create(context: Context) {
|
||||
val appBindings = context.bindings<AppBindings>()
|
||||
val tracingService = appBindings.tracingService()
|
||||
val bugReporter = appBindings.bugReporter()
|
||||
Timber.plant(tracingService.createTimberTree())
|
||||
val tracingConfiguration = if (BuildConfig.BUILD_TYPE == BuildType.RELEASE.name) {
|
||||
TracingConfiguration(
|
||||
filterConfiguration = TracingFilterConfigurations.release,
|
||||
writesToLogcat = false,
|
||||
writesToFilesConfiguration = defaultWriteToDiskConfiguration(bugReporter),
|
||||
)
|
||||
} else {
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
val store = SharedPreferencesTracingConfigurationStore(prefs)
|
||||
val builder = TargetLogLevelMapBuilder(
|
||||
tracingConfigurationStore = store,
|
||||
defaultConfig = if (BuildConfig.BUILD_TYPE == BuildType.NIGHTLY.name) {
|
||||
TracingFilterConfigurations.nightly
|
||||
} else {
|
||||
TracingFilterConfigurations.debug
|
||||
}
|
||||
)
|
||||
TracingConfiguration(
|
||||
filterConfiguration = TracingFilterConfigurations.custom(builder.getCurrentMap()),
|
||||
writesToLogcat = BuildConfig.DEBUG,
|
||||
writesToFilesConfiguration = defaultWriteToDiskConfiguration(bugReporter),
|
||||
)
|
||||
}
|
||||
bugReporter.setCurrentTracingFilter(tracingConfiguration.filterConfiguration.filter)
|
||||
Timber.plant(tracingService.createTimberTree(ELEMENT_X_TARGET))
|
||||
val preferencesStore = appBindings.preferencesStore()
|
||||
val logLevel = runBlocking { preferencesStore.getTracingLogLevelFlow().first() }
|
||||
val tracingConfiguration = TracingConfiguration(
|
||||
writesToLogcat = BuildConfig.DEBUG,
|
||||
writesToFilesConfiguration = defaultWriteToDiskConfiguration(bugReporter),
|
||||
logLevel = logLevel,
|
||||
extraTargets = listOf(ELEMENT_X_TARGET),
|
||||
)
|
||||
bugReporter.setCurrentTracingLogLevel(logLevel.name)
|
||||
tracingService.setupTracing(tracingConfiguration)
|
||||
// Also set env variable for rust back trace
|
||||
Os.setenv("RUST_BACKTRACE", "1", true)
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
/*
|
||||
* Copyright 2023, 2024 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.preferences.api
|
||||
|
||||
import io.element.android.libraries.architecture.SimpleFeatureEntryPoint
|
||||
|
||||
interface ConfigureTracingEntryPoint : SimpleFeatureEntryPoint
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Copyright 2023, 2024 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.preferences.impl
|
||||
|
||||
import com.bumble.appyx.core.modality.BuildContext
|
||||
import com.bumble.appyx.core.node.Node
|
||||
import com.squareup.anvil.annotations.ContributesBinding
|
||||
import io.element.android.features.preferences.api.ConfigureTracingEntryPoint
|
||||
import io.element.android.features.preferences.impl.developer.tracing.ConfigureTracingNode
|
||||
import io.element.android.libraries.architecture.createNode
|
||||
import io.element.android.libraries.di.AppScope
|
||||
import javax.inject.Inject
|
||||
|
||||
@ContributesBinding(AppScope::class)
|
||||
class DefaultConfigureTracingEntryPoint @Inject constructor() : ConfigureTracingEntryPoint {
|
||||
override fun createNode(parentNode: Node, buildContext: BuildContext): Node {
|
||||
return parentNode.createNode<ConfigureTracingNode>(buildContext)
|
||||
}
|
||||
}
|
||||
|
|
@ -30,7 +30,6 @@ import io.element.android.features.preferences.impl.advanced.AdvancedSettingsNod
|
|||
import io.element.android.features.preferences.impl.analytics.AnalyticsSettingsNode
|
||||
import io.element.android.features.preferences.impl.blockedusers.BlockedUsersNode
|
||||
import io.element.android.features.preferences.impl.developer.DeveloperSettingsNode
|
||||
import io.element.android.features.preferences.impl.developer.tracing.ConfigureTracingNode
|
||||
import io.element.android.features.preferences.impl.notifications.NotificationSettingsNode
|
||||
import io.element.android.features.preferences.impl.notifications.edit.EditDefaultNotificationSettingNode
|
||||
import io.element.android.features.preferences.impl.root.PreferencesRootNode
|
||||
|
|
@ -72,9 +71,6 @@ class PreferencesFlowNode @AssistedInject constructor(
|
|||
@Parcelize
|
||||
data object AdvancedSettings : NavTarget
|
||||
|
||||
@Parcelize
|
||||
data object ConfigureTracing : NavTarget
|
||||
|
||||
@Parcelize
|
||||
data object AnalyticsSettings : NavTarget
|
||||
|
||||
|
|
@ -164,15 +160,7 @@ class PreferencesFlowNode @AssistedInject constructor(
|
|||
createNode<PreferencesRootNode>(buildContext, plugins = listOf(callback))
|
||||
}
|
||||
NavTarget.DeveloperSettings -> {
|
||||
val callback = object : DeveloperSettingsNode.Callback {
|
||||
override fun openConfigureTracing() {
|
||||
backstack.push(NavTarget.ConfigureTracing)
|
||||
}
|
||||
}
|
||||
createNode<DeveloperSettingsNode>(buildContext, listOf(callback))
|
||||
}
|
||||
NavTarget.ConfigureTracing -> {
|
||||
createNode<ConfigureTracingNode>(buildContext)
|
||||
createNode<DeveloperSettingsNode>(buildContext)
|
||||
}
|
||||
NavTarget.About -> {
|
||||
val callback = object : AboutNode.Callback {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
package io.element.android.features.preferences.impl.developer
|
||||
|
||||
import io.element.android.features.preferences.impl.developer.tracing.LogLevelItem
|
||||
import io.element.android.libraries.featureflag.ui.model.FeatureUiModel
|
||||
|
||||
sealed interface DeveloperSettingsEvents {
|
||||
|
|
@ -14,5 +15,6 @@ sealed interface DeveloperSettingsEvents {
|
|||
data class SetCustomElementCallBaseUrl(val baseUrl: String?) : DeveloperSettingsEvents
|
||||
data class SetSimplifiedSlidingSyncEnabled(val isEnabled: Boolean) : DeveloperSettingsEvents
|
||||
data class SetHideImagesAndVideos(val value: Boolean) : DeveloperSettingsEvents
|
||||
data class SetTracingLogLevel(val logLevel: LogLevelItem) : DeveloperSettingsEvents
|
||||
data object ClearCache : DeveloperSettingsEvents
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import com.airbnb.android.showkase.models.Showkase
|
|||
import com.bumble.appyx.core.modality.BuildContext
|
||||
import com.bumble.appyx.core.node.Node
|
||||
import com.bumble.appyx.core.plugin.Plugin
|
||||
import com.bumble.appyx.core.plugin.plugins
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedInject
|
||||
import io.element.android.anvilannotations.ContributesNode
|
||||
|
|
@ -28,14 +27,6 @@ class DeveloperSettingsNode @AssistedInject constructor(
|
|||
@Assisted plugins: List<Plugin>,
|
||||
private val presenter: DeveloperSettingsPresenter,
|
||||
) : Node(buildContext, plugins = plugins) {
|
||||
interface Callback : Plugin {
|
||||
fun openConfigureTracing()
|
||||
}
|
||||
|
||||
private fun onOpenConfigureTracing() {
|
||||
plugins<Callback>().forEach { it.openConfigureTracing() }
|
||||
}
|
||||
|
||||
@Composable
|
||||
override fun View(modifier: Modifier) {
|
||||
val activity = LocalContext.current as Activity
|
||||
|
|
@ -49,7 +40,6 @@ class DeveloperSettingsNode @AssistedInject constructor(
|
|||
state = state,
|
||||
modifier = modifier,
|
||||
onOpenShowkase = ::openShowkase,
|
||||
onOpenConfigureTracing = ::onOpenConfigureTracing,
|
||||
onBackClick = ::navigateUp
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ import androidx.compose.runtime.rememberCoroutineScope
|
|||
import androidx.compose.runtime.snapshots.SnapshotStateMap
|
||||
import io.element.android.appconfig.ElementCallConfig
|
||||
import io.element.android.features.logout.api.LogoutUseCase
|
||||
import io.element.android.features.preferences.impl.developer.tracing.toLogLevel
|
||||
import io.element.android.features.preferences.impl.developer.tracing.toLogLevelItem
|
||||
import io.element.android.features.preferences.impl.tasks.ClearCacheUseCase
|
||||
import io.element.android.features.preferences.impl.tasks.ComputeCacheSizeUseCase
|
||||
import io.element.android.features.rageshake.api.preferences.RageshakePreferencesState
|
||||
|
|
@ -37,6 +39,7 @@ import io.element.android.libraries.featureflag.ui.model.FeatureUiModel
|
|||
import io.element.android.libraries.preferences.api.store.AppPreferencesStore
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
import java.net.URL
|
||||
import javax.inject.Inject
|
||||
|
|
@ -76,6 +79,11 @@ class DeveloperSettingsPresenter @Inject constructor(
|
|||
.doesHideImagesAndVideosFlow()
|
||||
.collectAsState(initial = false)
|
||||
|
||||
val tracingLogLevel by appPreferencesStore
|
||||
.getTracingLogLevelFlow()
|
||||
.map { AsyncData.Success(it.toLogLevelItem()) }
|
||||
.collectAsState(initial = AsyncData.Uninitialized)
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
FeatureFlags.entries
|
||||
.filter { it.isFinished.not() }
|
||||
|
|
@ -123,6 +131,9 @@ class DeveloperSettingsPresenter @Inject constructor(
|
|||
is DeveloperSettingsEvents.SetHideImagesAndVideos -> coroutineScope.launch {
|
||||
appPreferencesStore.setHideImagesAndVideos(event.value)
|
||||
}
|
||||
is DeveloperSettingsEvents.SetTracingLogLevel -> coroutineScope.launch {
|
||||
appPreferencesStore.setTracingLogLevel(event.logLevel.toLogLevel())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -138,6 +149,7 @@ class DeveloperSettingsPresenter @Inject constructor(
|
|||
),
|
||||
isSimpleSlidingSyncEnabled = isSimplifiedSlidingSyncEnabled,
|
||||
hideImagesAndVideos = hideImagesAndVideos,
|
||||
tracingLogLevel = tracingLogLevel,
|
||||
eventSink = ::handleEvents
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
package io.element.android.features.preferences.impl.developer
|
||||
|
||||
import io.element.android.features.preferences.impl.developer.tracing.LogLevelItem
|
||||
import io.element.android.features.rageshake.api.preferences.RageshakePreferencesState
|
||||
import io.element.android.libraries.architecture.AsyncAction
|
||||
import io.element.android.libraries.architecture.AsyncData
|
||||
|
|
@ -21,6 +22,7 @@ data class DeveloperSettingsState(
|
|||
val customElementCallBaseUrlState: CustomElementCallBaseUrlState,
|
||||
val isSimpleSlidingSyncEnabled: Boolean,
|
||||
val hideImagesAndVideos: Boolean,
|
||||
val tracingLogLevel: AsyncData<LogLevelItem>,
|
||||
val eventSink: (DeveloperSettingsEvents) -> Unit
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
package io.element.android.features.preferences.impl.developer
|
||||
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||
import io.element.android.features.preferences.impl.developer.tracing.LogLevelItem
|
||||
import io.element.android.features.rageshake.api.preferences.aRageshakePreferencesState
|
||||
import io.element.android.libraries.architecture.AsyncAction
|
||||
import io.element.android.libraries.architecture.AsyncData
|
||||
|
|
@ -42,6 +43,7 @@ fun aDeveloperSettingsState(
|
|||
customElementCallBaseUrlState = customElementCallBaseUrlState,
|
||||
isSimpleSlidingSyncEnabled = isSimplifiedSlidingSyncEnabled,
|
||||
hideImagesAndVideos = hideImagesAndVideos,
|
||||
tracingLogLevel = AsyncData.Success(LogLevelItem.INFO),
|
||||
eventSink = eventSink,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -14,8 +14,10 @@ import androidx.compose.ui.res.stringResource
|
|||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import io.element.android.features.preferences.impl.R
|
||||
import io.element.android.features.preferences.impl.developer.tracing.LogLevelItem
|
||||
import io.element.android.features.rageshake.api.preferences.RageshakePreferencesView
|
||||
import io.element.android.libraries.designsystem.components.preferences.PreferenceCategory
|
||||
import io.element.android.libraries.designsystem.components.preferences.PreferenceDropdown
|
||||
import io.element.android.libraries.designsystem.components.preferences.PreferencePage
|
||||
import io.element.android.libraries.designsystem.components.preferences.PreferenceSwitch
|
||||
import io.element.android.libraries.designsystem.components.preferences.PreferenceText
|
||||
|
|
@ -25,12 +27,12 @@ import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
|||
import io.element.android.libraries.featureflag.ui.FeatureListView
|
||||
import io.element.android.libraries.featureflag.ui.model.FeatureUiModel
|
||||
import io.element.android.libraries.ui.strings.CommonStrings
|
||||
import kotlinx.collections.immutable.toPersistentList
|
||||
|
||||
@Composable
|
||||
fun DeveloperSettingsView(
|
||||
state: DeveloperSettingsState,
|
||||
onOpenShowkase: () -> Unit,
|
||||
onOpenConfigureTracing: () -> Unit,
|
||||
onBackClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
|
|
@ -49,9 +51,14 @@ fun DeveloperSettingsView(
|
|||
}
|
||||
ElementCallCategory(state = state)
|
||||
PreferenceCategory(title = "Rust SDK") {
|
||||
PreferenceText(
|
||||
title = "Configure tracing",
|
||||
onClick = onOpenConfigureTracing,
|
||||
PreferenceDropdown(
|
||||
title = "Tracing log level",
|
||||
supportingText = "Requires app reboot",
|
||||
selectedOption = state.tracingLogLevel.dataOrNull(),
|
||||
options = LogLevelItem.entries.toPersistentList(),
|
||||
onSelectOption = { logLevel ->
|
||||
state.eventSink(DeveloperSettingsEvents.SetTracingLogLevel(logLevel))
|
||||
}
|
||||
)
|
||||
PreferenceSwitch(
|
||||
title = "Enable Simplified Sliding Sync",
|
||||
|
|
@ -157,7 +164,6 @@ internal fun DeveloperSettingsViewPreview(@PreviewParameter(DeveloperSettingsSta
|
|||
DeveloperSettingsView(
|
||||
state = state,
|
||||
onOpenShowkase = {},
|
||||
onOpenConfigureTracing = {},
|
||||
onBackClick = {}
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
/*
|
||||
* Copyright 2023, 2024 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.preferences.impl.developer.tracing
|
||||
|
||||
import io.element.android.libraries.matrix.api.tracing.LogLevel
|
||||
import io.element.android.libraries.matrix.api.tracing.Target
|
||||
|
||||
sealed interface ConfigureTracingEvents {
|
||||
data class UpdateFilter(val target: Target, val logLevel: LogLevel) : ConfigureTracingEvents
|
||||
data object ResetFilters : ConfigureTracingEvents
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright 2023, 2024 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.preferences.impl.developer.tracing
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import com.bumble.appyx.core.modality.BuildContext
|
||||
import com.bumble.appyx.core.node.Node
|
||||
import com.bumble.appyx.core.plugin.Plugin
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedInject
|
||||
import io.element.android.anvilannotations.ContributesNode
|
||||
import io.element.android.libraries.di.AppScope
|
||||
|
||||
@ContributesNode(AppScope::class)
|
||||
class ConfigureTracingNode @AssistedInject constructor(
|
||||
@Assisted buildContext: BuildContext,
|
||||
@Assisted plugins: List<Plugin>,
|
||||
private val presenter: ConfigureTracingPresenter,
|
||||
) : Node(buildContext, plugins = plugins) {
|
||||
@Composable
|
||||
override fun View(modifier: Modifier) {
|
||||
val state = presenter.present()
|
||||
ConfigureTracingView(
|
||||
state = state,
|
||||
onBackClick = ::navigateUp,
|
||||
modifier = modifier
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* Copyright 2023, 2024 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.preferences.impl.developer.tracing
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import io.element.android.libraries.architecture.Presenter
|
||||
import kotlinx.collections.immutable.toImmutableMap
|
||||
import javax.inject.Inject
|
||||
|
||||
class ConfigureTracingPresenter @Inject constructor(
|
||||
private val tracingConfigurationStore: TracingConfigurationStore,
|
||||
private val targetLogLevelMapBuilder: TargetLogLevelMapBuilder,
|
||||
) : Presenter<ConfigureTracingState> {
|
||||
@Composable
|
||||
override fun present(): ConfigureTracingState {
|
||||
val modifiedMap = remember { mutableStateOf(targetLogLevelMapBuilder.getCurrentMap()) }
|
||||
|
||||
fun handleEvents(event: ConfigureTracingEvents) {
|
||||
when (event) {
|
||||
is ConfigureTracingEvents.UpdateFilter -> {
|
||||
modifiedMap.value = modifiedMap.value.toMutableMap()
|
||||
.apply { this[event.target] = event.logLevel }
|
||||
tracingConfigurationStore.storeLogLevel(event.target, event.logLevel)
|
||||
}
|
||||
ConfigureTracingEvents.ResetFilters -> {
|
||||
modifiedMap.value = targetLogLevelMapBuilder.getDefaultMap()
|
||||
tracingConfigurationStore.reset()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ConfigureTracingState(
|
||||
targetsToLogLevel = modifiedMap.value.toImmutableMap(),
|
||||
eventSink = ::handleEvents
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
/*
|
||||
* Copyright 2023, 2024 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.preferences.impl.developer.tracing
|
||||
|
||||
import io.element.android.libraries.matrix.api.tracing.LogLevel
|
||||
import io.element.android.libraries.matrix.api.tracing.Target
|
||||
import kotlinx.collections.immutable.ImmutableMap
|
||||
|
||||
data class ConfigureTracingState(
|
||||
val targetsToLogLevel: ImmutableMap<Target, LogLevel>,
|
||||
val eventSink: (ConfigureTracingEvents) -> Unit
|
||||
)
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* Copyright 2023, 2024 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.preferences.impl.developer.tracing
|
||||
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||
import io.element.android.libraries.matrix.api.tracing.LogLevel
|
||||
import io.element.android.libraries.matrix.api.tracing.Target
|
||||
import kotlinx.collections.immutable.persistentMapOf
|
||||
|
||||
open class ConfigureTracingStateProvider : PreviewParameterProvider<ConfigureTracingState> {
|
||||
override val values: Sequence<ConfigureTracingState>
|
||||
get() = sequenceOf(
|
||||
aConfigureTracingState(),
|
||||
)
|
||||
}
|
||||
|
||||
fun aConfigureTracingState() = ConfigureTracingState(
|
||||
targetsToLogLevel = persistentMapOf(
|
||||
Target.ELEMENT to LogLevel.INFO,
|
||||
Target.MATRIX_SDK_FFI to LogLevel.WARN,
|
||||
Target.MATRIX_SDK_BASE_SLIDING_SYNC to LogLevel.ERROR,
|
||||
),
|
||||
eventSink = {}
|
||||
)
|
||||
|
|
@ -1,234 +0,0 @@
|
|||
/*
|
||||
* Copyright 2023, 2024 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.preferences.impl.developer.tracing
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.consumeWindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.imePadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.statusBars
|
||||
import androidx.compose.foundation.layout.systemBarsPadding
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.rotate
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.unit.dp
|
||||
import io.element.android.compound.theme.ElementTheme
|
||||
import io.element.android.compound.tokens.generated.CompoundIcons
|
||||
import io.element.android.libraries.designsystem.components.button.BackButton
|
||||
import io.element.android.libraries.designsystem.components.list.ListItemContent
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||
import io.element.android.libraries.designsystem.theme.aliasScreenTitle
|
||||
import io.element.android.libraries.designsystem.theme.components.DropdownMenu
|
||||
import io.element.android.libraries.designsystem.theme.components.DropdownMenuItem
|
||||
import io.element.android.libraries.designsystem.theme.components.HorizontalDivider
|
||||
import io.element.android.libraries.designsystem.theme.components.Icon
|
||||
import io.element.android.libraries.designsystem.theme.components.IconButton
|
||||
import io.element.android.libraries.designsystem.theme.components.ListItem
|
||||
import io.element.android.libraries.designsystem.theme.components.Scaffold
|
||||
import io.element.android.libraries.designsystem.theme.components.Text
|
||||
import io.element.android.libraries.designsystem.theme.components.TopAppBar
|
||||
import io.element.android.libraries.matrix.api.tracing.LogLevel
|
||||
import io.element.android.libraries.matrix.api.tracing.Target
|
||||
import kotlinx.collections.immutable.ImmutableMap
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun ConfigureTracingView(
|
||||
state: ConfigureTracingState,
|
||||
onBackClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
var showMenu by remember { mutableStateOf(false) }
|
||||
Scaffold(
|
||||
modifier = modifier
|
||||
.fillMaxSize()
|
||||
.systemBarsPadding()
|
||||
.imePadding(),
|
||||
contentWindowInsets = WindowInsets.statusBars,
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
navigationIcon = {
|
||||
BackButton(onClick = onBackClick)
|
||||
},
|
||||
title = {
|
||||
Text(
|
||||
text = "Configure tracing",
|
||||
style = ElementTheme.typography.aliasScreenTitle,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
},
|
||||
actions = {
|
||||
IconButton(
|
||||
onClick = { showMenu = !showMenu }
|
||||
) {
|
||||
Icon(
|
||||
imageVector = CompoundIcons.OverflowVertical(),
|
||||
tint = ElementTheme.materialColors.secondary,
|
||||
contentDescription = null,
|
||||
)
|
||||
}
|
||||
DropdownMenu(
|
||||
expanded = showMenu,
|
||||
onDismissRequest = { showMenu = false }
|
||||
) {
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
showMenu = false
|
||||
state.eventSink.invoke(ConfigureTracingEvents.ResetFilters)
|
||||
},
|
||||
text = { Text("Reset to default") },
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
imageVector = CompoundIcons.Delete(),
|
||||
tint = ElementTheme.materialColors.secondary,
|
||||
contentDescription = null,
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
content = {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(it)
|
||||
.consumeWindowInsets(it)
|
||||
.verticalScroll(state = rememberScrollState())
|
||||
) {
|
||||
ListItem(
|
||||
headlineContent = {
|
||||
Text(
|
||||
modifier = Modifier.clickable { Runtime.getRuntime().exit(0) },
|
||||
text = "Tap here to kill the app and apply the changes. You'll have to re-open the app manually.",
|
||||
style = ElementTheme.typography.fontHeadingSmMedium,
|
||||
)
|
||||
},
|
||||
)
|
||||
HorizontalDivider()
|
||||
CrateListContent(state)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CrateListContent(
|
||||
state: ConfigureTracingState,
|
||||
) {
|
||||
fun onLogLevelChange(target: Target, logLevel: LogLevel) {
|
||||
state.eventSink(ConfigureTracingEvents.UpdateFilter(target, logLevel))
|
||||
}
|
||||
|
||||
TargetAndLogLevelListView(
|
||||
data = state.targetsToLogLevel,
|
||||
onLogLevelChange = ::onLogLevelChange,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TargetAndLogLevelListView(
|
||||
data: ImmutableMap<Target, LogLevel>,
|
||||
onLogLevelChange: (Target, LogLevel) -> Unit,
|
||||
) {
|
||||
Column {
|
||||
data.forEach { item ->
|
||||
fun onLogLevelChange(logLevel: LogLevel) {
|
||||
onLogLevelChange(item.key, logLevel)
|
||||
}
|
||||
|
||||
TargetAndLogLevelView(
|
||||
target = item.key,
|
||||
logLevel = item.value,
|
||||
onLogLevelChange = ::onLogLevelChange
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TargetAndLogLevelView(
|
||||
target: Target,
|
||||
logLevel: LogLevel,
|
||||
onLogLevelChange: (LogLevel) -> Unit,
|
||||
) {
|
||||
ListItem(
|
||||
headlineContent = { Text(text = target.filter.takeIf { it.isNotEmpty() } ?: "(common)") },
|
||||
trailingContent = ListItemContent.Custom {
|
||||
LogLevelDropdownMenu(
|
||||
logLevel = logLevel,
|
||||
onLogLevelChange = onLogLevelChange,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LogLevelDropdownMenu(
|
||||
logLevel: LogLevel,
|
||||
onLogLevelChange: (LogLevel) -> Unit,
|
||||
) {
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
Box {
|
||||
DropdownMenuItem(
|
||||
modifier = Modifier.widthIn(max = 120.dp),
|
||||
text = { Text(text = logLevel.filter) },
|
||||
onClick = { expanded = !expanded },
|
||||
trailingIcon = {
|
||||
Icon(
|
||||
modifier = Modifier.rotate(if (expanded) 180f else 0f),
|
||||
imageVector = CompoundIcons.ChevronDown(),
|
||||
contentDescription = null,
|
||||
)
|
||||
},
|
||||
)
|
||||
DropdownMenu(
|
||||
expanded = expanded,
|
||||
onDismissRequest = { expanded = false },
|
||||
) {
|
||||
LogLevel.values().forEach { logLevel ->
|
||||
DropdownMenuItem(
|
||||
text = {
|
||||
Text(text = logLevel.filter)
|
||||
},
|
||||
onClick = {
|
||||
expanded = false
|
||||
onLogLevelChange(logLevel)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@PreviewsDayNight
|
||||
@Composable
|
||||
internal fun ConfigureTracingViewPreview(
|
||||
@PreviewParameter(ConfigureTracingStateProvider::class) state: ConfigureTracingState
|
||||
) = ElementPreview {
|
||||
ConfigureTracingView(
|
||||
state = state,
|
||||
onBackClick = {},
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.preferences.impl.developer.tracing
|
||||
|
||||
import io.element.android.libraries.designsystem.components.preferences.DropdownOption
|
||||
|
||||
enum class LogLevelItem : DropdownOption {
|
||||
ERROR {
|
||||
override val text: String = "Error"
|
||||
},
|
||||
WARN {
|
||||
override val text: String = "Warn"
|
||||
},
|
||||
INFO {
|
||||
override val text: String = "Info"
|
||||
},
|
||||
DEBUG {
|
||||
override val text: String = "Debug"
|
||||
},
|
||||
TRACE {
|
||||
override val text: String = "Trace"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.preferences.impl.developer.tracing
|
||||
|
||||
import io.element.android.libraries.matrix.api.tracing.LogLevel
|
||||
|
||||
fun LogLevelItem.toLogLevel(): LogLevel {
|
||||
return when (this) {
|
||||
LogLevelItem.ERROR -> io.element.android.libraries.matrix.api.tracing.LogLevel.ERROR
|
||||
LogLevelItem.WARN -> io.element.android.libraries.matrix.api.tracing.LogLevel.WARN
|
||||
LogLevelItem.INFO -> io.element.android.libraries.matrix.api.tracing.LogLevel.INFO
|
||||
LogLevelItem.DEBUG -> io.element.android.libraries.matrix.api.tracing.LogLevel.DEBUG
|
||||
LogLevelItem.TRACE -> io.element.android.libraries.matrix.api.tracing.LogLevel.TRACE
|
||||
}
|
||||
}
|
||||
|
||||
fun LogLevel.toLogLevelItem(): LogLevelItem {
|
||||
return when (this) {
|
||||
LogLevel.ERROR -> LogLevelItem.ERROR
|
||||
LogLevel.WARN -> LogLevelItem.WARN
|
||||
LogLevel.INFO -> LogLevelItem.INFO
|
||||
LogLevel.DEBUG -> LogLevelItem.DEBUG
|
||||
LogLevel.TRACE -> LogLevelItem.TRACE
|
||||
}
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* Copyright 2023, 2024 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.preferences.impl.developer.tracing
|
||||
|
||||
import io.element.android.libraries.matrix.api.tracing.LogLevel
|
||||
import io.element.android.libraries.matrix.api.tracing.Target
|
||||
import io.element.android.libraries.matrix.api.tracing.TracingFilterConfiguration
|
||||
import javax.inject.Inject
|
||||
|
||||
class TargetLogLevelMapBuilder @Inject constructor(
|
||||
private val tracingConfigurationStore: TracingConfigurationStore,
|
||||
private val defaultConfig: TracingFilterConfiguration,
|
||||
) {
|
||||
fun getDefaultMap(): Map<Target, LogLevel> {
|
||||
return Target.entries.associateWith { target ->
|
||||
defaultConfig.getLogLevel(target)
|
||||
}
|
||||
}
|
||||
|
||||
fun getCurrentMap(): Map<Target, LogLevel> {
|
||||
return Target.entries.associateWith { target ->
|
||||
tracingConfigurationStore.getLogLevel(target)
|
||||
?: defaultConfig.getLogLevel(target)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* Copyright 2023, 2024 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.preferences.impl.developer.tracing
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
import com.squareup.anvil.annotations.ContributesBinding
|
||||
import io.element.android.libraries.di.AppScope
|
||||
import io.element.android.libraries.matrix.api.tracing.LogLevel
|
||||
import io.element.android.libraries.matrix.api.tracing.Target
|
||||
import javax.inject.Inject
|
||||
|
||||
interface TracingConfigurationStore {
|
||||
fun getLogLevel(target: Target): LogLevel?
|
||||
fun storeLogLevel(target: Target, logLevel: LogLevel)
|
||||
fun reset()
|
||||
}
|
||||
|
||||
@ContributesBinding(AppScope::class)
|
||||
class SharedPreferencesTracingConfigurationStore @Inject constructor(
|
||||
private val sharedPreferences: SharedPreferences
|
||||
) : TracingConfigurationStore {
|
||||
override fun getLogLevel(target: Target): LogLevel? {
|
||||
return sharedPreferences.getString("$KEY_PREFIX${target.name}", null)
|
||||
?.let { LogLevel.valueOf(it) }
|
||||
}
|
||||
|
||||
override fun storeLogLevel(target: Target, logLevel: LogLevel) {
|
||||
sharedPreferences.edit {
|
||||
putString("$KEY_PREFIX${target.name}", logLevel.name)
|
||||
}
|
||||
}
|
||||
|
||||
override fun reset() {
|
||||
sharedPreferences.edit {
|
||||
sharedPreferences.all.keys.filter { it.startsWith(KEY_PREFIX) }.forEach {
|
||||
remove(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val KEY_PREFIX = "tracing_log_level_"
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ package io.element.android.features.preferences.impl.developer
|
|||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.appconfig.ElementCallConfig
|
||||
import io.element.android.features.logout.test.FakeLogoutUseCase
|
||||
import io.element.android.features.preferences.impl.developer.tracing.LogLevelItem
|
||||
import io.element.android.features.preferences.impl.tasks.FakeClearCacheUseCase
|
||||
import io.element.android.features.preferences.impl.tasks.FakeComputeCacheSizeUseCase
|
||||
import io.element.android.features.rageshake.api.preferences.aRageshakePreferencesState
|
||||
|
|
@ -52,11 +53,13 @@ class DeveloperSettingsPresenterTest {
|
|||
assertThat(state.rageshakeState.isEnabled).isFalse()
|
||||
assertThat(state.rageshakeState.isSupported).isTrue()
|
||||
assertThat(state.rageshakeState.sensitivity).isEqualTo(0.3f)
|
||||
assertThat(state.tracingLogLevel).isEqualTo(AsyncData.Uninitialized)
|
||||
}
|
||||
awaitItem().also { state ->
|
||||
assertThat(state.features).isNotEmpty()
|
||||
val numberOfModifiableFeatureFlags = FeatureFlags.entries.count { it.isFinished.not() }
|
||||
assertThat(state.features).hasSize(numberOfModifiableFeatureFlags)
|
||||
assertThat(state.tracingLogLevel.dataOrNull()).isEqualTo(LogLevelItem.INFO)
|
||||
}
|
||||
awaitItem().also { state ->
|
||||
assertThat(state.cacheSize).isInstanceOf(AsyncData.Success::class.java)
|
||||
|
|
@ -200,6 +203,22 @@ class DeveloperSettingsPresenterTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `present - changing tracing log level`() = runTest {
|
||||
val preferences = InMemoryAppPreferencesStore()
|
||||
val presenter = createDeveloperSettingsPresenter(preferencesStore = preferences)
|
||||
presenter.test {
|
||||
skipItems(2)
|
||||
awaitItem().also { state ->
|
||||
assertThat(state.tracingLogLevel.dataOrNull()).isEqualTo(LogLevelItem.INFO)
|
||||
state.eventSink(DeveloperSettingsEvents.SetTracingLogLevel(LogLevelItem.TRACE))
|
||||
}
|
||||
awaitItem().also { state ->
|
||||
assertThat(state.tracingLogLevel.dataOrNull()).isEqualTo(LogLevelItem.TRACE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun createDeveloperSettingsPresenter(
|
||||
featureFlagService: FakeFeatureFlagService = FakeFeatureFlagService(),
|
||||
cacheSizeUseCase: FakeComputeCacheSizeUseCase = FakeComputeCacheSizeUseCase(),
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import androidx.compose.ui.test.onNodeWithText
|
|||
import androidx.compose.ui.test.performClick
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import io.element.android.features.preferences.impl.R
|
||||
import io.element.android.features.preferences.impl.developer.tracing.LogLevelItem
|
||||
import io.element.android.libraries.ui.strings.CommonStrings
|
||||
import io.element.android.tests.testutils.EnsureNeverCalled
|
||||
import io.element.android.tests.testutils.EventsRecorder
|
||||
|
|
@ -76,17 +77,16 @@ class DeveloperSettingsViewTest {
|
|||
|
||||
@Config(qualifiers = "h1024dp")
|
||||
@Test
|
||||
fun `clicking on configure tracing invokes the expected callback`() {
|
||||
val eventsRecorder = EventsRecorder<DeveloperSettingsEvents>(expectEvents = false)
|
||||
ensureCalledOnce {
|
||||
rule.setDeveloperSettingsView(
|
||||
state = aDeveloperSettingsState(
|
||||
eventSink = eventsRecorder
|
||||
),
|
||||
onOpenConfigureTracing = it
|
||||
)
|
||||
rule.onNodeWithText("Configure tracing").performClick()
|
||||
}
|
||||
fun `clicking on log level emits the expected event`() {
|
||||
val eventsRecorder = EventsRecorder<DeveloperSettingsEvents>()
|
||||
rule.setDeveloperSettingsView(
|
||||
state = aDeveloperSettingsState(
|
||||
eventSink = eventsRecorder
|
||||
),
|
||||
)
|
||||
rule.onNodeWithText("Tracing log level").performClick()
|
||||
rule.onNodeWithText("Debug").performClick()
|
||||
eventsRecorder.assertSingle(DeveloperSettingsEvents.SetTracingLogLevel(LogLevelItem.DEBUG))
|
||||
}
|
||||
|
||||
@Config(qualifiers = "h1500dp")
|
||||
|
|
@ -131,14 +131,12 @@ class DeveloperSettingsViewTest {
|
|||
private fun <R : TestRule> AndroidComposeTestRule<R, ComponentActivity>.setDeveloperSettingsView(
|
||||
state: DeveloperSettingsState,
|
||||
onOpenShowkase: () -> Unit = EnsureNeverCalled(),
|
||||
onOpenConfigureTracing: () -> Unit = EnsureNeverCalled(),
|
||||
onBackClick: () -> Unit = EnsureNeverCalled()
|
||||
) {
|
||||
setContent {
|
||||
DeveloperSettingsView(
|
||||
state = state,
|
||||
onOpenShowkase = onOpenShowkase,
|
||||
onOpenConfigureTracing = onOpenConfigureTracing,
|
||||
onBackClick = onBackClick,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,101 +0,0 @@
|
|||
/*
|
||||
* Copyright 2023, 2024 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.preferences.impl.developer.tracing
|
||||
|
||||
import app.cash.molecule.RecompositionMode
|
||||
import app.cash.molecule.moleculeFlow
|
||||
import app.cash.turbine.test
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.libraries.matrix.api.tracing.LogLevel
|
||||
import io.element.android.libraries.matrix.api.tracing.Target
|
||||
import io.element.android.libraries.matrix.api.tracing.TracingFilterConfigurations
|
||||
import io.element.android.tests.testutils.WarmUpRule
|
||||
import io.element.android.tests.testutils.waitForPredicate
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
class ConfigureTracingPresenterTest {
|
||||
@get:Rule
|
||||
val warmUpRule = WarmUpRule()
|
||||
|
||||
@Test
|
||||
fun `present - initial state`() = runTest {
|
||||
val store = InMemoryTracingConfigurationStore()
|
||||
val presenter = ConfigureTracingPresenter(
|
||||
store,
|
||||
TargetLogLevelMapBuilder(store, TracingFilterConfigurations.debug),
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
val initialState = awaitItem()
|
||||
assertThat(initialState.targetsToLogLevel).isNotEmpty()
|
||||
assertThat(initialState.targetsToLogLevel[Target.MATRIX_SDK_CRYPTO]).isEqualTo(LogLevel.DEBUG)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `present - store is taken into account`() = runTest {
|
||||
val store = InMemoryTracingConfigurationStore()
|
||||
store.givenLogLevel(LogLevel.ERROR)
|
||||
val presenter = ConfigureTracingPresenter(
|
||||
store,
|
||||
TargetLogLevelMapBuilder(store, TracingFilterConfigurations.debug),
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
val initialState = awaitItem()
|
||||
assertThat(initialState.targetsToLogLevel).isNotEmpty()
|
||||
assertThat(initialState.targetsToLogLevel[Target.MATRIX_SDK_CRYPTO]).isEqualTo(LogLevel.ERROR)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `present - change a value`() = runTest {
|
||||
val store = InMemoryTracingConfigurationStore()
|
||||
val presenter = ConfigureTracingPresenter(
|
||||
store,
|
||||
TargetLogLevelMapBuilder(store, TracingFilterConfigurations.debug),
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
val initialState = awaitItem()
|
||||
assertThat(initialState.targetsToLogLevel[Target.MATRIX_SDK_CRYPTO]).isEqualTo(LogLevel.DEBUG)
|
||||
initialState.eventSink.invoke(ConfigureTracingEvents.UpdateFilter(Target.MATRIX_SDK_CRYPTO, LogLevel.WARN))
|
||||
val finalState = awaitItem()
|
||||
assertThat(finalState.targetsToLogLevel[Target.MATRIX_SDK_CRYPTO]).isEqualTo(LogLevel.WARN)
|
||||
waitForPredicate { store.hasStoreLogLevelBeenCalled }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `present - reset`() = runTest {
|
||||
val store = InMemoryTracingConfigurationStore()
|
||||
val presenter = ConfigureTracingPresenter(
|
||||
store,
|
||||
TargetLogLevelMapBuilder(store, TracingFilterConfigurations.debug),
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
presenter.present()
|
||||
}.test {
|
||||
val initialState = awaitItem()
|
||||
assertThat(initialState.targetsToLogLevel[Target.MATRIX_SDK_CRYPTO]).isEqualTo(LogLevel.DEBUG)
|
||||
initialState.eventSink.invoke(ConfigureTracingEvents.UpdateFilter(Target.MATRIX_SDK_CRYPTO, LogLevel.WARN))
|
||||
val finalState = awaitItem()
|
||||
assertThat(finalState.targetsToLogLevel[Target.MATRIX_SDK_CRYPTO]).isEqualTo(LogLevel.WARN)
|
||||
waitForPredicate { store.hasStoreLogLevelBeenCalled }
|
||||
finalState.eventSink.invoke(ConfigureTracingEvents.ResetFilters)
|
||||
val resetState = awaitItem()
|
||||
assertThat(resetState.targetsToLogLevel[Target.MATRIX_SDK_CRYPTO]).isEqualTo(LogLevel.DEBUG)
|
||||
waitForPredicate { store.hasResetBeenCalled }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright 2023, 2024 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.preferences.impl.developer.tracing
|
||||
|
||||
import io.element.android.libraries.matrix.api.tracing.LogLevel
|
||||
import io.element.android.libraries.matrix.api.tracing.Target
|
||||
|
||||
class InMemoryTracingConfigurationStore : TracingConfigurationStore {
|
||||
var hasResetBeenCalled = false
|
||||
private set
|
||||
var hasStoreLogLevelBeenCalled = false
|
||||
private set
|
||||
private var logLevel: LogLevel? = null
|
||||
|
||||
fun givenLogLevel(logLevel: LogLevel?) {
|
||||
this.logLevel = logLevel
|
||||
}
|
||||
|
||||
override fun getLogLevel(target: Target): LogLevel? {
|
||||
return logLevel
|
||||
}
|
||||
|
||||
override fun storeLogLevel(target: Target, logLevel: LogLevel) {
|
||||
hasStoreLogLevelBeenCalled = true
|
||||
}
|
||||
|
||||
override fun reset() {
|
||||
hasResetBeenCalled = true
|
||||
}
|
||||
}
|
||||
|
|
@ -35,9 +35,9 @@ interface BugReporter {
|
|||
fun logDirectory(): File
|
||||
|
||||
/**
|
||||
* Set the current tracing filter.
|
||||
* Set the current tracing log level.
|
||||
*/
|
||||
fun setCurrentTracingFilter(tracingFilter: String)
|
||||
fun setCurrentTracingLogLevel(logLevel: String)
|
||||
|
||||
/**
|
||||
* Save the logcat.
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ class DefaultBugReporter @Inject constructor(
|
|||
}
|
||||
|
||||
private val logcatCommandDebug = arrayOf("logcat", "-d", "-v", "threadtime", "*:*")
|
||||
private var currentTracingFilter: String? = null
|
||||
private var currentTracingLogLevel: String? = null
|
||||
|
||||
private val logCatErrFile = File(logDirectory().absolutePath, LOG_CAT_FILENAME)
|
||||
|
||||
|
|
@ -156,7 +156,7 @@ class DefaultBugReporter @Inject constructor(
|
|||
if (crashCallStack.isNotEmpty() && withCrashLogs) {
|
||||
builder.addFormDataPart("label", "crash")
|
||||
}
|
||||
currentTracingFilter?.let {
|
||||
currentTracingLogLevel?.let {
|
||||
builder.addFormDataPart("tracing_filter", it)
|
||||
}
|
||||
if (buildMeta.isEnterpriseBuild) {
|
||||
|
|
@ -299,8 +299,8 @@ class DefaultBugReporter @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun setCurrentTracingFilter(tracingFilter: String) {
|
||||
currentTracingFilter = tracingFilter
|
||||
override fun setCurrentTracingLogLevel(logLevel: String) {
|
||||
currentTracingLogLevel = logLevel
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ class FakeBugReporter(val mode: Mode = Mode.Success) : BugReporter {
|
|||
return File("fake")
|
||||
}
|
||||
|
||||
override fun setCurrentTracingFilter(tracingFilter: String) {
|
||||
override fun setCurrentTracingLogLevel(logLevel: String) {
|
||||
// No op
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* Copyright 2022-2024 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.matrix.api.tracing
|
||||
|
||||
/**
|
||||
* Log levels for tracing in the SDK.
|
||||
*/
|
||||
enum class LogLevel {
|
||||
ERROR,
|
||||
WARN,
|
||||
INFO,
|
||||
DEBUG,
|
||||
TRACE,
|
||||
}
|
||||
|
|
@ -8,7 +8,8 @@
|
|||
package io.element.android.libraries.matrix.api.tracing
|
||||
|
||||
data class TracingConfiguration(
|
||||
val filterConfiguration: TracingFilterConfiguration,
|
||||
val logLevel: LogLevel,
|
||||
val extraTargets: List<String>,
|
||||
val writesToLogcat: Boolean,
|
||||
val writesToFilesConfiguration: WriteToFilesConfiguration,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,102 +0,0 @@
|
|||
/*
|
||||
* Copyright 2022-2024 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.matrix.api.tracing
|
||||
|
||||
data class TracingFilterConfiguration(
|
||||
val overrides: Map<Target, LogLevel> = emptyMap(),
|
||||
) {
|
||||
private val defaultLogLevel = LogLevel.INFO
|
||||
|
||||
// Order should matters
|
||||
private val targetsToLogLevel: Map<Target, LogLevel> = mapOf(
|
||||
Target.HYPER to LogLevel.WARN,
|
||||
Target.MATRIX_SDK_CRYPTO to LogLevel.DEBUG,
|
||||
Target.MATRIX_SDK_CRYPTO_ACCOUNT to LogLevel.TRACE,
|
||||
Target.MATRIX_SDK_HTTP_CLIENT to LogLevel.DEBUG,
|
||||
Target.MATRIX_SDK_SLIDING_SYNC to LogLevel.INFO,
|
||||
Target.MATRIX_SDK_BASE_SLIDING_SYNC to LogLevel.INFO,
|
||||
Target.MATRIX_SDK_UI_TIMELINE to LogLevel.INFO,
|
||||
Target.MATRIX_SDK_BASE_CLIENT to LogLevel.TRACE,
|
||||
// To debug OIDC logouts
|
||||
Target.MATRIX_SDK_OIDC to LogLevel.TRACE,
|
||||
)
|
||||
|
||||
fun getLogLevel(target: Target): LogLevel {
|
||||
return overrides[target] ?: targetsToLogLevel[target] ?: defaultLogLevel
|
||||
}
|
||||
|
||||
val filter: String
|
||||
get() {
|
||||
val fullMap = Target.entries.associateWith {
|
||||
overrides[it] ?: targetsToLogLevel[it] ?: defaultLogLevel
|
||||
}
|
||||
return fullMap.map {
|
||||
if (it.key.filter.isEmpty()) {
|
||||
it.value.filter
|
||||
} else {
|
||||
"${it.key.filter}=${it.value.filter}"
|
||||
}
|
||||
}.joinToString(separator = ",")
|
||||
}
|
||||
}
|
||||
|
||||
enum class Target(open val filter: String) {
|
||||
// COMMON(""),
|
||||
ELEMENT("elementx"),
|
||||
HYPER("hyper"),
|
||||
MATRIX_SDK_FFI("matrix_sdk_ffi"),
|
||||
MATRIX_SDK_UNIFFI_API("matrix_sdk_ffi::uniffi_api"),
|
||||
MATRIX_SDK_CRYPTO("matrix_sdk_crypto"),
|
||||
MATRIX_SDK_CRYPTO_ACCOUNT("matrix_sdk_crypto::olm::account"),
|
||||
MATRIX_SDK("matrix_sdk"),
|
||||
MATRIX_SDK_HTTP_CLIENT("matrix_sdk::http_client"),
|
||||
MATRIX_SDK_CLIENT("matrix_sdk::client"),
|
||||
MATRIX_SDK_OIDC("matrix_sdk::oidc"),
|
||||
MATRIX_SDK_SEND_QUEUE("matrix_sdk::send_queue"),
|
||||
MATRIX_SDK_SLIDING_SYNC("matrix_sdk::sliding_sync"),
|
||||
MATRIX_SDK_BASE_SLIDING_SYNC("matrix_sdk_base::sliding_sync"),
|
||||
MATRIX_SDK_UI_TIMELINE("matrix_sdk_ui::timeline"),
|
||||
MATRIX_SDK_BASE_READ_RECEIPTS("matrix_sdk_base::read_receipts"),
|
||||
MATRIX_SDK_BASE_CLIENT("matrix_sdk_base"),
|
||||
}
|
||||
|
||||
enum class LogLevel(open val filter: String) {
|
||||
ERROR("error"),
|
||||
WARN("warn"),
|
||||
INFO("info"),
|
||||
DEBUG("debug"),
|
||||
TRACE("trace"),
|
||||
}
|
||||
|
||||
object TracingFilterConfigurations {
|
||||
val release = TracingFilterConfiguration(
|
||||
overrides = mapOf(
|
||||
Target.ELEMENT to LogLevel.DEBUG
|
||||
),
|
||||
)
|
||||
val nightly = TracingFilterConfiguration(
|
||||
overrides = mapOf(
|
||||
Target.ELEMENT to LogLevel.TRACE,
|
||||
),
|
||||
)
|
||||
val debug = TracingFilterConfiguration(
|
||||
overrides = mapOf(
|
||||
Target.ELEMENT to LogLevel.TRACE
|
||||
)
|
||||
)
|
||||
|
||||
/**
|
||||
* Use this method to create a custom configuration where all targets will have the same log level.
|
||||
*/
|
||||
fun custom(logLevel: LogLevel) = TracingFilterConfiguration(overrides = Target.entries.associateWith { logLevel })
|
||||
|
||||
/**
|
||||
* Use this method to override the log level of specific targets.
|
||||
*/
|
||||
fun custom(overrides: Map<Target, LogLevel>) = TracingFilterConfiguration(overrides)
|
||||
}
|
||||
|
|
@ -11,5 +11,5 @@ import timber.log.Timber
|
|||
|
||||
interface TracingService {
|
||||
fun setupTracing(tracingConfiguration: TracingConfiguration)
|
||||
fun createTimberTree(): Timber.Tree
|
||||
fun createTimberTree(target: String): Timber.Tree
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
/*
|
||||
* Copyright 2024 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.matrix.impl.di
|
||||
|
||||
import com.squareup.anvil.annotations.ContributesTo
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import io.element.android.libraries.core.meta.BuildMeta
|
||||
import io.element.android.libraries.core.meta.BuildType
|
||||
import io.element.android.libraries.di.AppScope
|
||||
import io.element.android.libraries.matrix.api.tracing.TracingFilterConfiguration
|
||||
import io.element.android.libraries.matrix.api.tracing.TracingFilterConfigurations
|
||||
|
||||
@Module
|
||||
@ContributesTo(AppScope::class)
|
||||
object TracingMatrixModule {
|
||||
@Provides
|
||||
fun providesTracingFilterConfiguration(buildMeta: BuildMeta): TracingFilterConfiguration {
|
||||
return when (buildMeta.buildType) {
|
||||
BuildType.DEBUG -> TracingFilterConfigurations.debug
|
||||
BuildType.NIGHTLY -> TracingFilterConfigurations.nightly
|
||||
BuildType.RELEASE -> TracingFilterConfigurations.release
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,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.LogLevel
|
||||
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.WriteToFilesConfiguration
|
||||
|
|
@ -20,21 +21,28 @@ import javax.inject.Inject
|
|||
@ContributesBinding(AppScope::class)
|
||||
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,
|
||||
logLevel = tracingConfiguration.logLevel.toRustLogLevel(),
|
||||
extraTargets = tracingConfiguration.extraTargets,
|
||||
writeToFiles = tracingConfiguration.writesToFilesConfiguration.toTracingFileConfiguration(),
|
||||
)
|
||||
org.matrix.rustcomponents.sdk.setupTracing(rustTracingConfiguration)
|
||||
Timber.v("Tracing config filter = $filter: ${filter.filter}")
|
||||
|
||||
*/
|
||||
Timber.d("setupTracing: $rustTracingConfiguration")
|
||||
}
|
||||
|
||||
override fun createTimberTree(): Timber.Tree {
|
||||
return RustTracingTree(retrieveFromStackTrace = buildMeta.isDebuggable)
|
||||
override fun createTimberTree(target: String): Timber.Tree {
|
||||
return RustTracingTree(target = target, retrieveFromStackTrace = buildMeta.isDebuggable)
|
||||
}
|
||||
}
|
||||
|
||||
private fun LogLevel.toRustLogLevel(): org.matrix.rustcomponents.sdk.LogLevel {
|
||||
return when (this) {
|
||||
LogLevel.ERROR -> org.matrix.rustcomponents.sdk.LogLevel.ERROR
|
||||
LogLevel.WARN -> org.matrix.rustcomponents.sdk.LogLevel.WARN
|
||||
LogLevel.INFO -> org.matrix.rustcomponents.sdk.LogLevel.INFO
|
||||
LogLevel.DEBUG -> org.matrix.rustcomponents.sdk.LogLevel.DEBUG
|
||||
LogLevel.TRACE -> org.matrix.rustcomponents.sdk.LogLevel.TRACE
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
package io.element.android.libraries.matrix.impl.tracing
|
||||
|
||||
import android.util.Log
|
||||
import io.element.android.libraries.matrix.api.tracing.Target
|
||||
import org.matrix.rustcomponents.sdk.LogLevel
|
||||
import org.matrix.rustcomponents.sdk.logEvent
|
||||
import timber.log.Timber
|
||||
|
|
@ -26,7 +25,10 @@ private val fqcnIgnore = listOf(
|
|||
/**
|
||||
* A Timber tree that passes logs to the Rust SDK.
|
||||
*/
|
||||
internal class RustTracingTree(private val retrieveFromStackTrace: Boolean) : Timber.Tree() {
|
||||
internal class RustTracingTree(
|
||||
private val target: String,
|
||||
private val retrieveFromStackTrace: Boolean,
|
||||
) : Timber.Tree() {
|
||||
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) {
|
||||
val location = if (retrieveFromStackTrace) {
|
||||
getLogEventLocationFromStackTrace()
|
||||
|
|
@ -38,7 +40,7 @@ internal class RustTracingTree(private val retrieveFromStackTrace: Boolean) : Ti
|
|||
file = location.file,
|
||||
line = location.line,
|
||||
level = logLevel,
|
||||
target = Target.ELEMENT.filter,
|
||||
target = target,
|
||||
message = if (tag != null) "[$tag] $message" else message,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* Copyright 2024 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.matrix.impl.di
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.libraries.core.meta.BuildType
|
||||
import io.element.android.libraries.matrix.api.tracing.TracingFilterConfigurations
|
||||
import io.element.android.libraries.matrix.test.core.aBuildMeta
|
||||
import org.junit.Test
|
||||
|
||||
class TracingMatrixModuleTest {
|
||||
@Test
|
||||
fun `providesTracingFilterConfiguration returns debug config for debug build`() {
|
||||
assertThat(TracingMatrixModule.providesTracingFilterConfiguration(aBuildMeta(BuildType.DEBUG)))
|
||||
.isEqualTo(TracingFilterConfigurations.debug)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `providesTracingFilterConfiguration returns nightly config for nightly build`() {
|
||||
assertThat(TracingMatrixModule.providesTracingFilterConfiguration(aBuildMeta(BuildType.NIGHTLY)))
|
||||
.isEqualTo(TracingFilterConfigurations.nightly)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `providesTracingFilterConfiguration returns release config for release build`() {
|
||||
assertThat(TracingMatrixModule.providesTracingFilterConfiguration(aBuildMeta(BuildType.RELEASE)))
|
||||
.isEqualTo(TracingFilterConfigurations.release)
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
package io.element.android.libraries.preferences.api.store
|
||||
|
||||
import io.element.android.libraries.matrix.api.tracing.LogLevel
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface AppPreferencesStore {
|
||||
|
|
@ -25,5 +26,8 @@ interface AppPreferencesStore {
|
|||
suspend fun setHideImagesAndVideos(value: Boolean)
|
||||
fun doesHideImagesAndVideosFlow(): Flow<Boolean>
|
||||
|
||||
suspend fun setTracingLogLevel(logLevel: LogLevel)
|
||||
fun getTracingLogLevelFlow(): Flow<LogLevel>
|
||||
|
||||
suspend fun reset()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import io.element.android.libraries.core.meta.BuildMeta
|
|||
import io.element.android.libraries.core.meta.BuildType
|
||||
import io.element.android.libraries.di.AppScope
|
||||
import io.element.android.libraries.di.ApplicationContext
|
||||
import io.element.android.libraries.matrix.api.tracing.LogLevel
|
||||
import io.element.android.libraries.preferences.api.store.AppPreferencesStore
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
|
@ -31,6 +32,7 @@ private val customElementCallBaseUrlKey = stringPreferencesKey("elementCallBaseU
|
|||
private val themeKey = stringPreferencesKey("theme")
|
||||
private val simplifiedSlidingSyncKey = booleanPreferencesKey("useSimplifiedSlidingSync")
|
||||
private val hideImagesAndVideosKey = booleanPreferencesKey("hideImagesAndVideos")
|
||||
private val logLevelKey = stringPreferencesKey("logLevel")
|
||||
|
||||
@ContributesBinding(AppScope::class)
|
||||
class DefaultAppPreferencesStore @Inject constructor(
|
||||
|
|
@ -104,7 +106,27 @@ class DefaultAppPreferencesStore @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun setTracingLogLevel(logLevel: LogLevel) {
|
||||
store.edit { prefs ->
|
||||
prefs[logLevelKey] = logLevel.name
|
||||
}
|
||||
}
|
||||
|
||||
override fun getTracingLogLevelFlow(): Flow<LogLevel> {
|
||||
return store.data.map { prefs ->
|
||||
prefs[logLevelKey]?.let { LogLevel.valueOf(it) } ?: buildMeta.defaultLogLevel()
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun reset() {
|
||||
store.edit { it.clear() }
|
||||
}
|
||||
}
|
||||
|
||||
private fun BuildMeta.defaultLogLevel(): LogLevel {
|
||||
return when (buildType) {
|
||||
BuildType.DEBUG -> LogLevel.TRACE
|
||||
BuildType.NIGHTLY -> LogLevel.DEBUG
|
||||
BuildType.RELEASE -> LogLevel.INFO
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
package io.element.android.libraries.preferences.test
|
||||
|
||||
import io.element.android.libraries.matrix.api.tracing.LogLevel
|
||||
import io.element.android.libraries.preferences.api.store.AppPreferencesStore
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
|
|
@ -16,13 +17,15 @@ class InMemoryAppPreferencesStore(
|
|||
hideImagesAndVideos: Boolean = false,
|
||||
customElementCallBaseUrl: String? = null,
|
||||
theme: String? = null,
|
||||
simplifiedSlidingSyncEnabled: Boolean = false
|
||||
simplifiedSlidingSyncEnabled: Boolean = false,
|
||||
logLevel: LogLevel = LogLevel.INFO,
|
||||
) : AppPreferencesStore {
|
||||
private val isDeveloperModeEnabled = MutableStateFlow(isDeveloperModeEnabled)
|
||||
private val hideImagesAndVideos = MutableStateFlow(hideImagesAndVideos)
|
||||
private val customElementCallBaseUrl = MutableStateFlow(customElementCallBaseUrl)
|
||||
private val theme = MutableStateFlow(theme)
|
||||
private val simplifiedSlidingSyncEnabled = MutableStateFlow(simplifiedSlidingSyncEnabled)
|
||||
private val logLevel = MutableStateFlow(logLevel)
|
||||
|
||||
override suspend fun setDeveloperModeEnabled(enabled: Boolean) {
|
||||
isDeveloperModeEnabled.value = enabled
|
||||
|
|
@ -64,6 +67,14 @@ class InMemoryAppPreferencesStore(
|
|||
return hideImagesAndVideos
|
||||
}
|
||||
|
||||
override suspend fun setTracingLogLevel(logLevel: LogLevel) {
|
||||
this.logLevel.value = logLevel
|
||||
}
|
||||
|
||||
override fun getTracingLogLevelFlow(): Flow<LogLevel> {
|
||||
return logLevel
|
||||
}
|
||||
|
||||
override suspend fun reset() {
|
||||
// No op
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue