From 51d028a47a24c6a84b22831ec8be6fb930a3d9df Mon Sep 17 00:00:00 2001 From: Cris Barreiro Date: Wed, 26 Nov 2025 11:59:23 +0100 Subject: [PATCH] Migrate PIR to DatabaseProvider --- .../secure/PirSecureStorageDatabaseFactory.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pir/pir-impl/src/main/java/com/duckduckgo/pir/impl/store/secure/PirSecureStorageDatabaseFactory.kt b/pir/pir-impl/src/main/java/com/duckduckgo/pir/impl/store/secure/PirSecureStorageDatabaseFactory.kt index a14e3bcf883b..0b6e2cb09ec9 100644 --- a/pir/pir-impl/src/main/java/com/duckduckgo/pir/impl/store/secure/PirSecureStorageDatabaseFactory.kt +++ b/pir/pir-impl/src/main/java/com/duckduckgo/pir/impl/store/secure/PirSecureStorageDatabaseFactory.kt @@ -17,7 +17,8 @@ package com.duckduckgo.pir.impl.store.secure import android.content.Context -import androidx.room.Room +import com.duckduckgo.data.store.api.DatabaseProvider +import com.duckduckgo.data.store.api.RoomDatabaseConfig import com.duckduckgo.di.scopes.AppScope import com.duckduckgo.library.loader.LibraryLoader import com.duckduckgo.pir.impl.store.PirDatabase @@ -43,6 +44,7 @@ interface PirSecureStorageDatabaseFactory { class RealPirSecureStorageDatabaseFactory @Inject constructor( private val context: Context, private val keyProvider: PirSecureStorageKeyProvider, + private val databaseProvider: DatabaseProvider, ) : PirSecureStorageDatabaseFactory { private var _database: PirDatabase? = null @@ -77,19 +79,17 @@ class RealPirSecureStorageDatabaseFactory @Inject constructor( // If we can't access the keystore, it means that L1Key will be null. We don't want to encrypt the db with a null key. if (keyProvider.canAccessKeyStore()) { // At this point, we are guaranteed that if L1key is null, it's because it hasn't been generated yet. Else, we always use the one stored. - _database = Room.databaseBuilder( - context, + _database = databaseProvider.buildRoomDatabase( PirDatabase::class.java, "pir_encrypted.db", - ) - .openHelperFactory( - SupportOpenHelperFactory( + RoomDatabaseConfig( + openHelperFactory = SupportOpenHelperFactory( keyProvider.getl1Key(), ), - ) - .enableMultiInstanceInvalidation() - .fallbackToDestructiveMigration() - .build() + enableMultiInstanceInvalidation = true, + fallbackToDestructiveMigration = true, + ), + ) logcat { "PIR-DB: Ready to use!" } _database } else {