Meshtastic-Android/conductor/archive/extract_database_manager_kmp_20260320/plan.md

1.8 KiB

Implementation Plan - Extract DatabaseManager to KMP

Phase 1: Multiplatform Database Abstraction

  • Define expect fun buildRoomDb(dbName: String): MeshtasticDatabase in commonMain.
  • Implement actual fun buildRoomDb for Android (using Application.getDatabasePath).
  • Implement actual fun buildRoomDb for JVM/Desktop (using the established ~/.meshtastic data directory).
  • Implement actual fun buildRoomDb for iOS (using NSDocumentDirectory).
  • Update DatabaseConstants with shared keys and default values.

Phase 2: KMP DataStore & File I/O

  • Replace Android SharedPreferences in DatabaseManager with a KMP-ready DataStore<Preferences> instance named DatabasePrefs.
  • Introduce an expect fun deleteDatabase(dbName: String) or similar Okio-based deletion helper.
  • Refactor database file listing to use okio.FileSystem.SYSTEM instead of java.io.File.

Phase 3: Logic Extraction

  • Move DatabaseManager.kt from core:database/androidMain to core:database/commonMain.
  • Refactor DatabaseManager to use the new buildRoomDb, DataStore, and FileSystem abstractions.
  • Ensure DatabaseManager is annotated with Koin @Single and correctly binds to DatabaseProvider and SharedDatabaseManager (from core:common).
  • Remove DesktopDatabaseManager from desktop module.
  • Update the DI (Koin) graph in app and desktop to wire the new shared DatabaseManager.

Phase 4: Verification

  • Add unit tests in core:database/commonTest to verify that switchActiveDatabase correctly swaps databases and that the LRU eviction limit is respected.
  • Perform manual verification on Desktop to ensure that connecting to different nodes creates separate .db files in ~/.meshtastic/.
  • Verify that the core:database module still compiles for Android and iOS targets.