feat: per device DB manager (#3641)

This commit is contained in:
Mac DeCourcy 2025-11-09 08:54:21 -08:00 committed by GitHub
parent f0b9a0ff75
commit cb8d1871c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 643 additions and 86 deletions

View file

@ -18,7 +18,16 @@
package com.geeksville.mesh
import android.app.Application
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn
import dagger.hilt.android.EntryPointAccessors
import dagger.hilt.android.HiltAndroidApp
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.meshtastic.core.database.DatabaseManager
import org.meshtastic.core.prefs.mesh.MeshPrefs
import timber.log.Timber
/**
@ -33,9 +42,22 @@ class MeshUtilApplication : Application() {
override fun onCreate() {
super.onCreate()
initializeMaps(this)
// Initialize DatabaseManager asynchronously with current device address so DAO consumers have an active DB
val entryPoint = EntryPointAccessors.fromApplication(this, AppEntryPoint::class.java)
CoroutineScope(Dispatchers.Default).launch {
entryPoint.databaseManager().init(entryPoint.meshPrefs().deviceAddress)
}
}
}
@EntryPoint
@InstallIn(SingletonComponent::class)
interface AppEntryPoint {
fun databaseManager(): DatabaseManager
fun meshPrefs(): MeshPrefs
}
fun logAssert(executeReliableWrite: Boolean) {
if (!executeReliableWrite) {
val ex = AssertionError("Assertion failed")