mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
1.8 KiB
1.8 KiB
Implementation Plan - Extract DatabaseManager to KMP
Phase 1: Multiplatform Database Abstraction
- Define
expect fun buildRoomDb(dbName: String): MeshtasticDatabaseincommonMain. - Implement
actual fun buildRoomDbfor Android (usingApplication.getDatabasePath). - Implement
actual fun buildRoomDbfor JVM/Desktop (using the established~/.meshtasticdata directory). - Implement
actual fun buildRoomDbfor iOS (usingNSDocumentDirectory). - Update
DatabaseConstantswith shared keys and default values.
Phase 2: KMP DataStore & File I/O
- Replace Android
SharedPreferencesinDatabaseManagerwith a KMP-readyDataStore<Preferences>instance namedDatabasePrefs. - Introduce an
expect fun deleteDatabase(dbName: String)or similar Okio-based deletion helper. - Refactor database file listing to use
okio.FileSystem.SYSTEMinstead ofjava.io.File.
Phase 3: Logic Extraction
- Move
DatabaseManager.ktfromcore:database/androidMaintocore:database/commonMain. - Refactor
DatabaseManagerto use the newbuildRoomDb,DataStore, andFileSystemabstractions. - Ensure
DatabaseManageris annotated with Koin@Singleand correctly binds toDatabaseProviderandSharedDatabaseManager(fromcore:common). - Remove
DesktopDatabaseManagerfromdesktopmodule. - Update the DI (Koin) graph in
appanddesktopto wire the new sharedDatabaseManager.
Phase 4: Verification
- Add unit tests in
core:database/commonTestto verify thatswitchActiveDatabasecorrectly swaps databases and that the LRU eviction limit is respected. - Perform manual verification on Desktop to ensure that connecting to different nodes creates separate
.dbfiles in~/.meshtastic/. - Verify that the
core:databasemodule still compiles for Android and iOS targets.