mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Merge pull request #4602
* refactor(test): Introduce MeshTestApplication for robust testing
This commit is contained in:
parent
f75622002f
commit
ac5a1714e0
4 changed files with 77 additions and 2 deletions
|
|
@ -31,6 +31,7 @@ import dagger.hilt.android.HiltAndroidApp
|
|||
import dagger.hilt.components.SingletonComponent
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.launch
|
||||
import org.meshtastic.core.database.DatabaseManager
|
||||
import org.meshtastic.core.prefs.mesh.MeshPrefs
|
||||
|
|
@ -47,10 +48,12 @@ import kotlin.time.toJavaDuration
|
|||
* user preferences.
|
||||
*/
|
||||
@HiltAndroidApp
|
||||
class MeshUtilApplication :
|
||||
open class MeshUtilApplication :
|
||||
Application(),
|
||||
Configuration.Provider {
|
||||
@Inject lateinit var workerFactory: HiltWorkerFactory
|
||||
|
||||
private val applicationScope = CoroutineScope(Dispatchers.Default)
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
|
@ -61,11 +64,19 @@ class MeshUtilApplication :
|
|||
|
||||
// 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 {
|
||||
applicationScope.launch {
|
||||
entryPoint.databaseManager().init(entryPoint.meshPrefs().deviceAddress)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onTerminate() {
|
||||
// Shutdown managers (useful for Robolectric tests)
|
||||
val entryPoint = EntryPointAccessors.fromApplication(this, AppEntryPoint::class.java)
|
||||
entryPoint.databaseManager().close()
|
||||
applicationScope.cancel()
|
||||
super.onTerminate()
|
||||
}
|
||||
|
||||
private fun scheduleMeshLogCleanup() {
|
||||
val cleanupRequest =
|
||||
PeriodicWorkRequestBuilder<MeshLogCleanupWorker>(repeatInterval = 1.hours.toJavaDuration()).build()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue