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
4 changes: 4 additions & 0 deletions core/logging/impl-legacy/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ android {

kotlin {
sourceSets {
androidMain.dependencies {
implementation(libs.timber)
}

commonMain.dependencies {
api(projects.core.logging.api)
api(libs.androidx.annotation)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.thunderbird.core.logging.legacy

import timber.log.Timber

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

fun updateLoggingStatus(isDebugLoggingEnabled: Boolean) {
Timber.uprootAll()
if (isDebugLoggingEnabled) {
Timber.plant(Timber.DebugTree())
}
}
}
3 changes: 3 additions & 0 deletions core/preference/api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ plugins {

android {
namespace = "net.thunderbird.core.preference"
buildFeatures {
buildConfig = true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package net.thunderbird.core.preference.debugging

import net.thunderbird.core.preference.BuildConfig

actual val isDebug: Boolean = BuildConfig.DEBUG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.thunderbird.core.preference

import net.thunderbird.core.preference.debugging.DebuggingSettings
import net.thunderbird.core.preference.display.DisplaySettings
import net.thunderbird.core.preference.network.NetworkSettings
import net.thunderbird.core.preference.notification.NotificationPreference
Expand All @@ -18,6 +19,7 @@ data class GeneralSettings(
val notification: NotificationPreference = NotificationPreference(),
val display: DisplaySettings = DisplaySettings(),
val privacy: PrivacySettings = PrivacySettings(),
val debugging: DebuggingSettings = DebuggingSettings(),
)

enum class BackgroundSync {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package net.thunderbird.core.preference.debugging

expect val isDebug: Boolean
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.thunderbird.core.preference.debugging

val DEBUGGING_SETTINGS_DEFAULT_IS_DEBUGGING_LOGGING_ENABLED = isDebug

data class DebuggingSettings(
val isDebugLoggingEnabled: Boolean = DEBUGGING_SETTINGS_DEFAULT_IS_DEBUGGING_LOGGING_ENABLED,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.thunderbird.core.preference.debugging

import net.thunderbird.core.preference.PreferenceManager

const val KEY_ENABLE_DEBUG_LOGGING = "enableDebugLogging"

interface DebuggingSettingsPreferenceManager : PreferenceManager<DebuggingSettings>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package net.thunderbird.core.preference.debugging

actual val isDebug: Boolean = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package net.thunderbird.core.preference.debugging

import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import net.thunderbird.core.logging.Logger
import net.thunderbird.core.preference.storage.Storage
import net.thunderbird.core.preference.storage.StorageEditor

private const val TAG = "DefaultDebuggingSettingsPreferenceManager"

class DefaultDebuggingSettingsPreferenceManager(
private val logger: Logger,
private val storage: Storage,
private val storageEditor: StorageEditor,
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO,
private var scope: CoroutineScope = CoroutineScope(SupervisorJob()),
) : DebuggingSettingsPreferenceManager {
private val configState: MutableStateFlow<DebuggingSettings> = MutableStateFlow(value = loadConfig())
private val mutex = Mutex()

override fun getConfig(): DebuggingSettings = configState.value
override fun getConfigFlow(): Flow<DebuggingSettings> = configState

override fun save(config: DebuggingSettings) {
logger.debug(TAG) { "save() called with: config = $config" }
writeConfig(config)
configState.update { config }
}

private fun loadConfig(): DebuggingSettings = DebuggingSettings(
isDebugLoggingEnabled = storage.getBoolean(
KEY_ENABLE_DEBUG_LOGGING,
DEBUGGING_SETTINGS_DEFAULT_IS_DEBUGGING_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.commit().also { commited ->
logger.verbose(TAG) { "writeConfig: storageEditor.commit() resulted in: $commited" }
}
}
}
}
}
3 changes: 2 additions & 1 deletion legacy/core/src/main/java/com/fsck/k9/Core.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.fsck.k9
import android.content.ComponentName
import android.content.Context
import android.content.pm.PackageManager
import com.fsck.k9.core.BuildConfig
import com.fsck.k9.job.K9JobManager
import com.fsck.k9.mail.internet.BinaryTempFileBody
import com.fsck.k9.notification.NotificationController
Expand All @@ -27,7 +28,7 @@ object Core : KoinComponent {
* injection library.
*/
fun earlyInit() {
if (K9.DEVELOPER_MODE) {
if (BuildConfig.DEBUG) {
enableStrictMode()
}
}
Expand Down
26 changes: 1 addition & 25 deletions legacy/core/src/main/java/com/fsck/k9/K9.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.fsck.k9.K9.DATABASE_VERSION_CACHE
import com.fsck.k9.K9.areDatabasesUpToDate
import com.fsck.k9.K9.checkCachedDatabaseVersion
import com.fsck.k9.K9.setDatabasesUpToDate
import com.fsck.k9.core.BuildConfig
import com.fsck.k9.mail.K9MailLib
import com.fsck.k9.mailstore.LocalStore
import com.fsck.k9.preferences.DefaultGeneralSettingsManager
Expand All @@ -26,7 +25,6 @@ import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import org.koin.core.qualifier.named
import timber.log.Timber
import timber.log.Timber.DebugTree

// TODO "Use GeneralSettingsManager and GeneralSettings instead"
object K9 : KoinComponent {
Expand All @@ -36,12 +34,6 @@ object K9 : KoinComponent {
private val syncDebugCompositeSink: CompositeLogSink by inject(named("syncDebug"))
private val syncDebugFileLogSink: FileLogSink by inject(named("syncDebug"))

/**
* If this is `true`, various development settings will be enabled.
*/
@JvmField
val DEVELOPER_MODE = BuildConfig.DEBUG

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

@JvmStatic
var isDebugLoggingEnabled: Boolean = DEVELOPER_MODE
set(debug) {
field = debug
updateLoggingStatus()
}

@JvmStatic
var isSyncLoggingEnabled: Boolean = false
set(debug) {
Expand Down Expand Up @@ -262,7 +247,7 @@ object K9 : KoinComponent {
fun init(context: Context) {
K9MailLib.setDebugStatus(
object : K9MailLib.DebugStatus {
override fun enabled(): Boolean = isDebugLoggingEnabled
override fun enabled(): Boolean = generalSettingsManager.getConfig().debugging.isDebugLoggingEnabled

override fun debugSensitive(): Boolean = isSensitiveDebugLoggingEnabled
},
Expand All @@ -276,7 +261,6 @@ object K9 : KoinComponent {
@JvmStatic
@Suppress("LongMethod")
fun loadPrefs(storage: Storage) {
isDebugLoggingEnabled = storage.getBoolean("enableDebugLogging", DEVELOPER_MODE)
isSyncLoggingEnabled = storage.getBoolean("enableSyncDebugLogging", false)
isSensitiveDebugLoggingEnabled = storage.getBoolean("enableSensitiveLogging", false)
isUseVolumeKeysForNavigation = storage.getBoolean("useVolumeKeysForNavigation", false)
Expand Down Expand Up @@ -346,7 +330,6 @@ object K9 : KoinComponent {

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

private fun updateLoggingStatus() {
Timber.uprootAll()
if (isDebugLoggingEnabled) {
Timber.plant(DebugTree())
}
}

private fun updateSyncLogging() {
if (isSyncLoggingEnabled) {
syncDebugCompositeSink.manager.add(syncDebugFileLogSink)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import app.k9mail.legacy.di.DI;
import app.k9mail.legacy.mailstore.FolderDetailsAccessor;
import app.k9mail.legacy.mailstore.MessageStore;
import app.k9mail.legacy.mailstore.MessageStoreManager;
import app.k9mail.legacy.mailstore.SaveMessageData;
import app.k9mail.legacy.message.controller.MessageReference;
import app.k9mail.legacy.message.controller.MessagingControllerMailChecker;
import app.k9mail.legacy.message.controller.MessagingControllerRegistry;
Expand Down Expand Up @@ -66,17 +70,13 @@
import com.fsck.k9.mail.ServerSettings;
import com.fsck.k9.mail.power.PowerManager;
import com.fsck.k9.mail.power.WakeLock;
import app.k9mail.legacy.mailstore.FolderDetailsAccessor;
import com.fsck.k9.mailstore.LocalFolder;
import com.fsck.k9.mailstore.LocalMessage;
import com.fsck.k9.mailstore.LocalStore;
import com.fsck.k9.mailstore.LocalStoreProvider;
import com.fsck.k9.mailstore.MessageListCache;
import app.k9mail.legacy.mailstore.MessageStore;
import app.k9mail.legacy.mailstore.MessageStoreManager;
import com.fsck.k9.mailstore.OutboxState;
import com.fsck.k9.mailstore.OutboxStateRepository;
import app.k9mail.legacy.mailstore.SaveMessageData;
import com.fsck.k9.mailstore.SaveMessageDataCreator;
import com.fsck.k9.mailstore.SendState;
import com.fsck.k9.mailstore.SpecialLocalFoldersCreator;
Expand All @@ -85,11 +85,11 @@
import net.thunderbird.core.android.account.DeletePolicy;
import net.thunderbird.core.android.account.LegacyAccount;
import net.thunderbird.core.featureflag.FeatureFlagProvider;
import net.thunderbird.feature.search.legacy.LocalMessageSearch;
import net.thunderbird.core.logging.Logger;
import net.thunderbird.core.logging.legacy.Log;
import net.thunderbird.feature.search.legacy.LocalMessageSearch;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import net.thunderbird.core.logging.legacy.Log;

import static com.fsck.k9.K9.MAX_SEND_ATTEMPTS;
import static com.fsck.k9.controller.Preconditions.requireNotNull;
Expand Down Expand Up @@ -765,7 +765,7 @@ public void processPendingCommandsSynchronous(LegacyAccount account) throws Mess
Log.e(e, "Unexpected exception with command '%s', removing command from queue", commandName);
localStore.removePendingCommand(processingCommand);

if (K9.DEVELOPER_MODE) {
if (BuildConfig.DEBUG) {
throw new AssertionError("Unexpected exception while processing pending command", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.fsck.k9.message.extractors.AttachmentInfoExtractor;

import net.thunderbird.core.android.account.LegacyAccount;
import net.thunderbird.core.preference.GeneralSettingsManager;
import org.apache.commons.io.IOUtils;
import org.apache.james.mime4j.util.MimeUtil;

Expand Down Expand Up @@ -62,6 +63,7 @@ public class LocalFolder {

private final LocalStore localStore;
private final AttachmentInfoExtractor attachmentInfoExtractor;
private GeneralSettingsManager generalSettingsManager;


private String status = null;
Expand All @@ -83,23 +85,24 @@ public class LocalFolder {
private boolean localOnly = false;


public LocalFolder(LocalStore localStore, String serverId) {
this(localStore, serverId, null);
public LocalFolder(LocalStore localStore, String serverId, GeneralSettingsManager generalSettingsManager) {
this(localStore, serverId, null, generalSettingsManager);
}

public LocalFolder(LocalStore localStore, String serverId, String name) {
this(localStore, serverId, name, FolderType.REGULAR);
public LocalFolder(LocalStore localStore, String serverId, String name, GeneralSettingsManager generalSettingsManager) {
this(localStore, serverId, name, FolderType.REGULAR, generalSettingsManager);
}

public LocalFolder(LocalStore localStore, String serverId, String name, FolderType type) {
public LocalFolder(LocalStore localStore, String serverId, String name, FolderType type, GeneralSettingsManager generalSettingsManager) {
this.localStore = localStore;
this.serverId = serverId;
this.name = name;
this.type = type;
this.generalSettingsManager = generalSettingsManager;
attachmentInfoExtractor = localStore.getAttachmentInfoExtractor();
}

public LocalFolder(LocalStore localStore, long databaseId) {
public LocalFolder(LocalStore localStore, long databaseId, GeneralSettingsManager generalSettingsManager) {
super();
this.localStore = localStore;
this.databaseId = databaseId;
Expand Down Expand Up @@ -476,7 +479,7 @@ public LocalMessage getMessage(final String uid) throws MessagingException {
@Override
public LocalMessage doDbWork(final SQLiteDatabase db) throws MessagingException {
open();
LocalMessage message = new LocalMessage(LocalFolder.this.localStore, uid, LocalFolder.this);
LocalMessage message = new LocalMessage(LocalFolder.this.localStore, uid, LocalFolder.this, generalSettingsManager);
Cursor cursor = null;

try {
Expand Down Expand Up @@ -505,7 +508,7 @@ public LocalMessage doDbWork(final SQLiteDatabase db) throws MessagingException
public LocalMessage getMessage(long messageId) throws MessagingException {
return localStore.getDatabase().execute(false, db -> {
open();
LocalMessage message = new LocalMessage(localStore, messageId, LocalFolder.this);
LocalMessage message = new LocalMessage(localStore, messageId, LocalFolder.this, generalSettingsManager);

Cursor cursor = db.rawQuery(
"SELECT " +
Expand Down Expand Up @@ -1107,7 +1110,7 @@ private void deleteMessagePartsFromDisk(SQLiteDatabase db, long rootMessagePartI
String messagePartId = cursor.getString(0);
File file = localStore.getAttachmentFile(messagePartId);
if (file.exists()) {
if (!file.delete() && K9.isDebugLoggingEnabled()) {
if (!file.delete() && generalSettingsManager.getConfig().getDebugging().isDebugLoggingEnabled()) {
Log.d("Couldn't delete message part file: %s", file.getAbsolutePath());
}
}
Expand Down
Loading