Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/logging/impl-legacy/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ kotlin {
sourceSets {
androidMain.dependencies {
implementation(libs.timber)
implementation(projects.core.logging.implComposite)
implementation(projects.core.logging.implFile)
}

commonMain.dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
package net.thunderbird.core.logging.legacy

import net.thunderbird.core.logging.composite.CompositeLogSink
import net.thunderbird.core.logging.file.FileLogSink
import timber.log.Timber
import timber.log.Timber.DebugTree

// TODO: Implementation https://github.com/thunderbird/thunderbird-android/issues/9573
class DebugLogConfigurator {

class DebugLogConfigurator(
private val syncDebugCompositeSink: CompositeLogSink,
private val syncDebugFileLogSink: FileLogSink,
) {
fun updateLoggingStatus(isDebugLoggingEnabled: Boolean) {
Timber.uprootAll()
if (isDebugLoggingEnabled) {
Timber.plant(Timber.DebugTree())
Timber.plant(DebugTree())
}
}

fun updateSyncLogging(isSyncLoggingEnabled: Boolean) {
if (isSyncLoggingEnabled) {
syncDebugCompositeSink.manager.add(syncDebugFileLogSink)
} else {
syncDebugCompositeSink.manager.remove(syncDebugFileLogSink)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package net.thunderbird.core.preference.debugging

const val DEBUGGING_SETTINGS_DEFAULT_IS_SYNC_LOGGING_ENABLED = false
val DEBUGGING_SETTINGS_DEFAULT_IS_DEBUGGING_LOGGING_ENABLED = isDebug

data class DebuggingSettings(
val isDebugLoggingEnabled: Boolean = DEBUGGING_SETTINGS_DEFAULT_IS_DEBUGGING_LOGGING_ENABLED,
val isSyncLoggingEnabled: Boolean = DEBUGGING_SETTINGS_DEFAULT_IS_SYNC_LOGGING_ENABLED,
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package net.thunderbird.core.preference.debugging
import net.thunderbird.core.preference.PreferenceManager

const val KEY_ENABLE_DEBUG_LOGGING = "enableDebugLogging"
const val KEY_ENABLE_SYNC_DEBUG_LOGGING = "enableSyncDebugLogging"

interface DebuggingSettingsPreferenceManager : PreferenceManager<DebuggingSettings>
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ class DefaultDebuggingSettingsPreferenceManager(
KEY_ENABLE_DEBUG_LOGGING,
DEBUGGING_SETTINGS_DEFAULT_IS_DEBUGGING_LOGGING_ENABLED,
),
isSyncLoggingEnabled = storage.getBoolean(
KEY_ENABLE_SYNC_DEBUG_LOGGING,
DEBUGGING_SETTINGS_DEFAULT_IS_SYNC_LOGGING_ENABLED,
),
)

private fun writeConfig(config: DebuggingSettings) {
logger.debug(TAG) { "writeConfig() called with: config = $config" }
scope.launch(ioDispatcher) {
mutex.withLock {
storageEditor.putBoolean(KEY_ENABLE_DEBUG_LOGGING, config.isDebugLoggingEnabled)
storageEditor.putBoolean(KEY_ENABLE_SYNC_DEBUG_LOGGING, config.isSyncLoggingEnabled)
storageEditor.commit().also { commited ->
logger.verbose(TAG) { "writeConfig: storageEditor.commit() resulted in: $commited" }
}
Expand Down
25 changes: 0 additions & 25 deletions legacy/core/src/main/java/com/fsck/k9/K9.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,18 @@ import net.thunderbird.core.common.action.SwipeAction
import net.thunderbird.core.common.action.SwipeActions
import net.thunderbird.core.featureflag.FeatureFlagProvider
import net.thunderbird.core.featureflag.toFeatureFlagKey
import net.thunderbird.core.logging.composite.CompositeLogSink
import net.thunderbird.core.logging.file.FileLogSink
import net.thunderbird.core.preference.storage.Storage
import net.thunderbird.core.preference.storage.StorageEditor
import net.thunderbird.core.preference.storage.getEnumOrDefault
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import org.koin.core.qualifier.named
import timber.log.Timber

// TODO "Use GeneralSettingsManager and GeneralSettings instead"
object K9 : KoinComponent {
private val generalSettingsManager: DefaultGeneralSettingsManager by inject()
private val telemetryManager: TelemetryManager by inject()
private val featureFlagProvider: FeatureFlagProvider by inject()
private val syncDebugCompositeSink: CompositeLogSink by inject(named("syncDebug"))
private val syncDebugFileLogSink: FileLogSink by inject(named("syncDebug"))

/**
* Name of the [SharedPreferences] file used to store the last known version of the
Expand Down Expand Up @@ -118,13 +113,6 @@ object K9 : KoinComponent {
}
}

@JvmStatic
var isSyncLoggingEnabled: Boolean = false
set(debug) {
field = debug
updateSyncLogging()
}

@JvmStatic
var isSensitiveDebugLoggingEnabled: Boolean = false

Expand Down Expand Up @@ -161,9 +149,6 @@ object K9 : KoinComponent {
@JvmStatic
var messageListPreviewLines = 2

@JvmStatic
var isShowContactName = false

@JvmStatic
var contactNameColor = 0xFF1093F5.toInt()

Expand Down Expand Up @@ -261,7 +246,6 @@ object K9 : KoinComponent {
@JvmStatic
@Suppress("LongMethod")
fun loadPrefs(storage: Storage) {
isSyncLoggingEnabled = storage.getBoolean("enableSyncDebugLogging", false)
isSensitiveDebugLoggingEnabled = storage.getBoolean("enableSensitiveLogging", false)
isUseVolumeKeysForNavigation = storage.getBoolean("useVolumeKeysForNavigation", false)
isShowAccountSelector = storage.getBoolean("showAccountSelector", true)
Expand Down Expand Up @@ -330,7 +314,6 @@ object K9 : KoinComponent {

@Suppress("LongMethod")
internal fun save(editor: StorageEditor) {
editor.putBoolean("enableSyncDebugLogging", isSyncLoggingEnabled)
editor.putBoolean("enableSensitiveLogging", isSensitiveDebugLoggingEnabled)
editor.putBoolean("useVolumeKeysForNavigation", isUseVolumeKeysForNavigation)
editor.putBoolean("notificationDuringQuietTimeEnabled", isNotificationDuringQuietTimeEnabled)
Expand Down Expand Up @@ -379,14 +362,6 @@ object K9 : KoinComponent {
fontSizes.save(editor)
}

private fun updateSyncLogging() {
if (isSyncLoggingEnabled) {
syncDebugCompositeSink.manager.add(syncDebugFileLogSink)
} else {
syncDebugCompositeSink.manager.remove(syncDebugFileLogSink)
}
}

@JvmStatic
fun saveSettingsAsync() {
generalSettingsManager.saveSettingsAsync()
Expand Down
3 changes: 2 additions & 1 deletion legacy/core/src/main/java/com/fsck/k9/job/KoinModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ val jobModule = module {
baseLogger = get<Logger>(),
fileLogSink = get<FileLogSink>(named("syncDebug")),
syncDebugCompositeSink = get<CompositeLogSink>(named("syncDebug")),
parameters,
generalSettingsManager = get(),
parameters = parameters,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ package com.fsck.k9.job
import android.content.Context
import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters
import com.fsck.k9.K9
import java.io.IOException
import net.thunderbird.core.logging.Logger
import net.thunderbird.core.logging.composite.CompositeLogSink
import net.thunderbird.core.logging.file.FileLogSink
import net.thunderbird.core.preference.GeneralSettingsManager
import net.thunderbird.core.preference.update

class SyncDebugWorker(
context: Context,
val baseLogger: Logger,
val fileLogSink: FileLogSink,
val syncDebugCompositeSink: CompositeLogSink,
parameters: WorkerParameters,
val generalSettingsManager: GeneralSettingsManager,
) : CoroutineWorker(context, parameters) {

override suspend fun doWork(): Result {
Expand All @@ -25,8 +27,9 @@ class SyncDebugWorker(
return Result.failure()
}
syncDebugCompositeSink.manager.remove(fileLogSink)
K9.isSyncLoggingEnabled = false
K9.saveSettingsAsync()
generalSettingsManager.update { settings ->
settings.copy(debugging = settings.debugging.copy(isSyncLoggingEnabled = false))
}
return Result.success()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ internal class DefaultGeneralSettingsManager(
debugging = debuggingSettings,
).also {
debugLogConfigurator.updateLoggingStatus(debuggingSettings.isDebugLoggingEnabled)
debugLogConfigurator.updateSyncLogging(debuggingSettings.isSyncLoggingEnabled)
}
}
.stateIn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ val preferencesModule = module {
)
}
single<DebugLogConfigurator> {
DebugLogConfigurator()
DebugLogConfigurator(
syncDebugCompositeSink = get(named("syncDebug")),
syncDebugFileLogSink = get(named("syncDebug")),
)
}
single {
DefaultGeneralSettingsManager(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class GeneralSettingsDataStore(
"privacy_hide_useragent" -> generalSettingsManager.getConfig().privacy.isHideUserAgent
"privacy_hide_timezone" -> generalSettingsManager.getConfig().privacy.isHideTimeZone
"debug_logging" -> generalSettingsManager.getConfig().debugging.isDebugLoggingEnabled
"sync_debug_logging" -> K9.isSyncLoggingEnabled
"sync_debug_logging" -> generalSettingsManager.getConfig().debugging.isSyncLoggingEnabled
"sensitive_logging" -> K9.isSensitiveDebugLoggingEnabled
"volume_navigation" -> K9.isUseVolumeKeysForNavigation
"enable_telemetry" -> K9.isTelemetryEnabled
Expand Down Expand Up @@ -111,7 +111,7 @@ class GeneralSettingsDataStore(
"privacy_hide_useragent" -> setIsHideUserAgent(isHideUserAgent = value)
"privacy_hide_timezone" -> setIsHideTimeZone(isHideTimeZone = value)
"debug_logging" -> setIsDebugLoggingEnabled(isDebugLoggingEnabled = value)
"sync_debug_logging" -> K9.isSyncLoggingEnabled = value
"sync_debug_logging" -> setIsSyncLoggingEnabled(isSyncLoggingEnabled = value)
"sensitive_logging" -> K9.isSensitiveDebugLoggingEnabled = value
"volume_navigation" -> K9.isUseVolumeKeysForNavigation = value
"enable_telemetry" -> setTelemetryEnabled(value)
Expand Down Expand Up @@ -479,6 +479,17 @@ class GeneralSettingsDataStore(
}
}

private fun setIsSyncLoggingEnabled(isSyncLoggingEnabled: Boolean) {
skipSaveSettings = true
generalSettingsManager.update { settings ->
settings.copy(
debugging = settings.debugging.copy(
isSyncLoggingEnabled = isSyncLoggingEnabled,
),
)
}
}

private fun setIsHideUserAgent(isHideUserAgent: Boolean) {
skipSaveSettings = true
generalSettingsManager.update { settings ->
Expand Down