From 932880497dcd786e01ab103ff76d7536ac9c6cca Mon Sep 17 00:00:00 2001 From: Cris Barreiro Date: Tue, 25 Nov 2025 14:09:29 +0100 Subject: [PATCH 1/2] Migrate app database to databaseProvider --- .../com/duckduckgo/app/di/DatabaseModule.kt | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/duckduckgo/app/di/DatabaseModule.kt b/app/src/main/java/com/duckduckgo/app/di/DatabaseModule.kt index 300b0a996fee..44089c71e89f 100644 --- a/app/src/main/java/com/duckduckgo/app/di/DatabaseModule.kt +++ b/app/src/main/java/com/duckduckgo/app/di/DatabaseModule.kt @@ -17,8 +17,7 @@ package com.duckduckgo.app.di import android.content.Context -import androidx.room.Room -import androidx.room.RoomDatabase +import androidx.room.RoomDatabase.JournalMode.TRUNCATE import com.duckduckgo.app.bookmarks.migration.AppDatabaseBookmarksMigrationCallbackProvider import com.duckduckgo.app.browser.DefaultWebViewDatabaseProvider import com.duckduckgo.app.browser.WebViewDatabaseProvider @@ -26,6 +25,8 @@ import com.duckduckgo.app.global.db.AppDatabase import com.duckduckgo.app.global.db.MigrationsProvider import com.duckduckgo.app.settings.db.SettingsDataStore import com.duckduckgo.appbuildconfig.api.* +import com.duckduckgo.data.store.api.DatabaseProvider +import com.duckduckgo.data.store.api.RoomDatabaseConfig import com.duckduckgo.di.scopes.AppScope import dagger.Lazy import dagger.Module @@ -52,17 +53,23 @@ object DatabaseModule { @Provides @SingleInstanceIn(AppScope::class) fun provideAppDatabase( - context: Context, migrationsProvider: MigrationsProvider, databaseBookmarksMigrationCallbackProvider: AppDatabaseBookmarksMigrationCallbackProvider, + databaseProvider: DatabaseProvider, ): AppDatabase { - return Room.databaseBuilder(context, AppDatabase::class.java, "app.db") - .addMigrations(*migrationsProvider.ALL_MIGRATIONS.toTypedArray()) - .addCallback(migrationsProvider.BOOKMARKS_DB_ON_CREATE) - .addCallback(migrationsProvider.CHANGE_JOURNAL_ON_OPEN) - .addCallback(databaseBookmarksMigrationCallbackProvider.provideCallbacks()) - .setJournalMode(RoomDatabase.JournalMode.TRUNCATE) - .build() + return databaseProvider.buildRoomDatabase( + AppDatabase::class.java, + "app.db", + config = RoomDatabaseConfig( + callbacks = listOf( + migrationsProvider.BOOKMARKS_DB_ON_CREATE, + migrationsProvider.CHANGE_JOURNAL_ON_OPEN, + databaseBookmarksMigrationCallbackProvider.provideCallbacks(), + ), + journalMode = TRUNCATE, + migrations = migrationsProvider.ALL_MIGRATIONS, + ), + ) } @Provides From 4d428b6afbe512fedb28aacd6ab20b6a69cd552f Mon Sep 17 00:00:00 2001 From: Cris Barreiro Date: Tue, 25 Nov 2025 16:03:59 +0100 Subject: [PATCH 2/2] Break circular dependency --- .../java/com/duckduckgo/app/statistics/api/RxPixelSender.kt | 4 +++- .../com/duckduckgo/app/statistics/api/RxPixelSenderTest.kt | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/statistics/statistics-impl/src/main/java/com/duckduckgo/app/statistics/api/RxPixelSender.kt b/statistics/statistics-impl/src/main/java/com/duckduckgo/app/statistics/api/RxPixelSender.kt index 9a3d7af217eb..9a16913ce2b8 100644 --- a/statistics/statistics-impl/src/main/java/com/duckduckgo/app/statistics/api/RxPixelSender.kt +++ b/statistics/statistics-impl/src/main/java/com/duckduckgo/app/statistics/api/RxPixelSender.kt @@ -43,6 +43,7 @@ import logcat.LogPriority.WARN import logcat.asLog import logcat.logcat import javax.inject.Inject +import javax.inject.Provider @ContributesBinding( scope = AppScope::class, @@ -55,13 +56,14 @@ import javax.inject.Inject @SingleInstanceIn(AppScope::class) class RxPixelSender @Inject constructor( private val api: PixelService, - private val pendingPixelDao: PendingPixelDao, + private val pendingPixelDaoProvider: Provider, private val statisticsDataStore: StatisticsDataStore, private val deviceInfo: DeviceInfo, private val statisticsLibraryConfig: StatisticsLibraryConfig?, private val pixelFiredRepository: PixelFiredRepository, ) : PixelSender, MainProcessLifecycleObserver { + private val pendingPixelDao by lazy { pendingPixelDaoProvider.get() } private val compositeDisposable = CompositeDisposable() private val shouldFirePixelsAsDev: Int? by lazy { diff --git a/statistics/statistics-impl/src/test/java/com/duckduckgo/app/statistics/api/RxPixelSenderTest.kt b/statistics/statistics-impl/src/test/java/com/duckduckgo/app/statistics/api/RxPixelSenderTest.kt index 3d7b0172a4d4..57bd2926ff6d 100644 --- a/statistics/statistics-impl/src/test/java/com/duckduckgo/app/statistics/api/RxPixelSenderTest.kt +++ b/statistics/statistics-impl/src/test/java/com/duckduckgo/app/statistics/api/RxPixelSenderTest.kt @@ -91,7 +91,7 @@ class RxPixelSenderTest { testee = RxPixelSender( api, - pendingPixelDao, + { pendingPixelDao }, mockStatisticsDataStore, mockDeviceInfo, object : StatisticsLibraryConfig {