From 399dce19a6f407ac89102206cdfd09531f927f50 Mon Sep 17 00:00:00 2001 From: James Rich <2199651+jamesarich@users.noreply.github.com> Date: Fri, 9 Jan 2026 16:38:36 -0600 Subject: [PATCH] fix(meshlog): Change default retention to 30 days (#4177) Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com> --- .../geeksville/mesh/MeshUtilApplication.kt | 24 ------------------- .../core/prefs/meshlog/MeshLogPrefs.kt | 2 +- feature/settings/build.gradle.kts | 17 ------------- .../feature/settings/SettingsViewModel.kt | 6 +++++ .../settings/debugging/DebugViewModel.kt | 3 +++ 5 files changed, 10 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/MeshUtilApplication.kt b/app/src/main/java/com/geeksville/mesh/MeshUtilApplication.kt index ca39431c1..d0acadb65 100644 --- a/app/src/main/java/com/geeksville/mesh/MeshUtilApplication.kt +++ b/app/src/main/java/com/geeksville/mesh/MeshUtilApplication.kt @@ -20,8 +20,6 @@ import android.app.Application import androidx.hilt.work.HiltWorkerFactory import androidx.work.Configuration import androidx.work.ExistingPeriodicWorkPolicy -import androidx.work.ExistingWorkPolicy -import androidx.work.OneTimeWorkRequestBuilder import androidx.work.PeriodicWorkRequestBuilder import androidx.work.WorkManager import co.touchlab.kermit.Logger @@ -59,7 +57,6 @@ class MeshUtilApplication : // Schedule periodic MeshLog cleanup scheduleMeshLogCleanup() - enqueueImmediateCleanupIfNeeded() // Initialize DatabaseManager asynchronously with current device address so DAO consumers have an active DB val entryPoint = EntryPointAccessors.fromApplication(this, AppEntryPoint::class.java) @@ -84,27 +81,6 @@ class MeshUtilApplication : ) } - private fun enqueueImmediateCleanupIfNeeded() { - // Use entry point to access prefs outside of Hilt graph - val entryPoint = EntryPointAccessors.fromApplication(this, AppEntryPoint::class.java) - val meshLogPrefs = entryPoint.meshLogPrefs() - val retentionDays = meshLogPrefs.retentionDays - if (!meshLogPrefs.loggingEnabled || retentionDays == MeshLogPrefs.NEVER_CLEAR_RETENTION_DAYS) { - Logger.i { - "Skipping immediate MeshLog cleanup; " + - "loggingEnabled=${meshLogPrefs.loggingEnabled}, retention=$retentionDays" - } - return - } - Logger.i { "Enqueuing immediate MeshLog cleanup with retentionDays=$retentionDays" } - WorkManager.getInstance(this) - .enqueueUniqueWork( - "${MeshLogCleanupWorker.WORK_NAME}_immediate", - ExistingWorkPolicy.REPLACE, - OneTimeWorkRequestBuilder().build(), - ) - } - override val workManagerConfiguration: Configuration get() = Configuration.Builder().setWorkerFactory(workerFactory).build() } diff --git a/core/prefs/src/main/kotlin/org/meshtastic/core/prefs/meshlog/MeshLogPrefs.kt b/core/prefs/src/main/kotlin/org/meshtastic/core/prefs/meshlog/MeshLogPrefs.kt index 42dd6d8ac..f110cf6aa 100644 --- a/core/prefs/src/main/kotlin/org/meshtastic/core/prefs/meshlog/MeshLogPrefs.kt +++ b/core/prefs/src/main/kotlin/org/meshtastic/core/prefs/meshlog/MeshLogPrefs.kt @@ -29,7 +29,7 @@ interface MeshLogPrefs { companion object { const val RETENTION_DAYS_KEY = "meshlog_retention_days" const val LOGGING_ENABLED_KEY = "meshlog_logging_enabled" - const val DEFAULT_RETENTION_DAYS = 7 + const val DEFAULT_RETENTION_DAYS = 30 const val DEFAULT_LOGGING_ENABLED = true const val MIN_RETENTION_DAYS = -1 // -1 == keep last hour const val MAX_RETENTION_DAYS = 365 diff --git a/feature/settings/build.gradle.kts b/feature/settings/build.gradle.kts index 9fe391f99..9ee42331d 100644 --- a/feature/settings/build.gradle.kts +++ b/feature/settings/build.gradle.kts @@ -16,23 +16,6 @@ */ import com.android.build.api.dsl.LibraryExtension -/* - * Copyright (c) 2025 Meshtastic LLC - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - plugins { alias(libs.plugins.meshtastic.android.library) alias(libs.plugins.meshtastic.android.library.compose) diff --git a/feature/settings/src/main/kotlin/org/meshtastic/feature/settings/SettingsViewModel.kt b/feature/settings/src/main/kotlin/org/meshtastic/feature/settings/SettingsViewModel.kt index 9d1c2ecc8..308c64380 100644 --- a/feature/settings/src/main/kotlin/org/meshtastic/feature/settings/SettingsViewModel.kt +++ b/feature/settings/src/main/kotlin/org/meshtastic/feature/settings/SettingsViewModel.kt @@ -152,11 +152,17 @@ constructor( val clamped = days.coerceIn(MeshLogPrefs.MIN_RETENTION_DAYS, MeshLogPrefs.MAX_RETENTION_DAYS) meshLogPrefs.retentionDays = clamped _meshLogRetentionDays.value = clamped + viewModelScope.launch { meshLogRepository.deleteLogsOlderThan(clamped) } } fun setMeshLogLoggingEnabled(enabled: Boolean) { meshLogPrefs.loggingEnabled = enabled _meshLogLoggingEnabled.value = enabled + if (!enabled) { + viewModelScope.launch { meshLogRepository.deleteAll() } + } else { + viewModelScope.launch { meshLogRepository.deleteLogsOlderThan(meshLogPrefs.retentionDays) } + } } fun setProvideLocation(value: Boolean) { diff --git a/feature/settings/src/main/kotlin/org/meshtastic/feature/settings/debugging/DebugViewModel.kt b/feature/settings/src/main/kotlin/org/meshtastic/feature/settings/debugging/DebugViewModel.kt index 10846898e..f563dd42a 100644 --- a/feature/settings/src/main/kotlin/org/meshtastic/feature/settings/debugging/DebugViewModel.kt +++ b/feature/settings/src/main/kotlin/org/meshtastic/feature/settings/debugging/DebugViewModel.kt @@ -252,6 +252,7 @@ constructor( val clamped = days.coerceIn(MeshLogPrefs.MIN_RETENTION_DAYS, MeshLogPrefs.MAX_RETENTION_DAYS) meshLogPrefs.retentionDays = clamped _retentionDays.value = clamped + viewModelScope.launch { meshLogRepository.deleteLogsOlderThan(clamped) } } fun setLoggingEnabled(enabled: Boolean) { @@ -259,6 +260,8 @@ constructor( _loggingEnabled.value = enabled if (!enabled) { viewModelScope.launch { meshLogRepository.deleteAll() } + } else { + viewModelScope.launch { meshLogRepository.deleteLogsOlderThan(meshLogPrefs.retentionDays) } } }