feat: add retention period to meshLog. Defaults to 7 days, with a settings dropdown to change (#4078)

This commit is contained in:
Mac DeCourcy 2026-01-02 10:14:16 -08:00 committed by GitHub
parent dc9e51f18f
commit 6f338c4cde
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 396 additions and 8 deletions

View file

@ -37,6 +37,8 @@ import org.meshtastic.core.prefs.map.MapTileProviderPrefs
import org.meshtastic.core.prefs.map.MapTileProviderPrefsImpl
import org.meshtastic.core.prefs.mesh.MeshPrefs
import org.meshtastic.core.prefs.mesh.MeshPrefsImpl
import org.meshtastic.core.prefs.meshlog.MeshLogPrefs
import org.meshtastic.core.prefs.meshlog.MeshLogPrefsImpl
import org.meshtastic.core.prefs.radio.RadioPrefs
import org.meshtastic.core.prefs.radio.RadioPrefsImpl
import org.meshtastic.core.prefs.ui.UiPrefs
@ -83,6 +85,10 @@ internal annotation class RadioSharedPreferences
@Retention(AnnotationRetention.BINARY)
internal annotation class UiSharedPreferences
@Qualifier
@Retention(AnnotationRetention.BINARY)
internal annotation class MeshLogSharedPreferences
@Suppress("TooManyFunctions")
@InstallIn(SingletonComponent::class)
@Module
@ -100,6 +106,8 @@ interface PrefsModule {
@Binds fun bindMeshPrefs(meshPrefsImpl: MeshPrefsImpl): MeshPrefs
@Binds fun bindMeshLogPrefs(meshLogPrefsImpl: MeshLogPrefsImpl): MeshLogPrefs
@Binds fun bindRadioPrefs(radioPrefsImpl: RadioPrefsImpl): RadioPrefs
@Binds fun bindUiPrefs(uiPrefsImpl: UiPrefsImpl): UiPrefs
@ -159,5 +167,11 @@ interface PrefsModule {
@UiSharedPreferences
fun provideUiSharedPreferences(@ApplicationContext context: Context): SharedPreferences =
context.getSharedPreferences("ui-prefs", Context.MODE_PRIVATE)
@Provides
@Singleton
@MeshLogSharedPreferences
fun provideMeshLogSharedPreferences(@ApplicationContext context: Context): SharedPreferences =
context.getSharedPreferences("meshlog-prefs", Context.MODE_PRIVATE)
}
}

View file

@ -0,0 +1,57 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package org.meshtastic.core.prefs.meshlog
import android.content.SharedPreferences
import org.meshtastic.core.prefs.PrefDelegate
import org.meshtastic.core.prefs.di.MeshLogSharedPreferences
import javax.inject.Inject
import javax.inject.Singleton
interface MeshLogPrefs {
var retentionDays: Int
var loggingEnabled: Boolean
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_LOGGING_ENABLED = true
const val MIN_RETENTION_DAYS = -1 // -1 == keep last hour
const val MAX_RETENTION_DAYS = 365
const val NEVER_CLEAR_RETENTION_DAYS = 0
const val ONE_HOUR_RETENTION_DAYS = -1
}
}
@Singleton
class MeshLogPrefsImpl @Inject constructor(@MeshLogSharedPreferences private val prefs: SharedPreferences) :
MeshLogPrefs {
override var retentionDays: Int by
PrefDelegate(
prefs = prefs,
key = MeshLogPrefs.RETENTION_DAYS_KEY,
defaultValue = MeshLogPrefs.DEFAULT_RETENTION_DAYS,
)
override var loggingEnabled: Boolean by
PrefDelegate(
prefs = prefs,
key = MeshLogPrefs.LOGGING_ENABLED_KEY,
defaultValue = MeshLogPrefs.DEFAULT_LOGGING_ENABLED,
)
}