Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,41 @@ class RealSecureStorageDatabaseFactory @Inject constructor(
private val context: Context,
private val keyProvider: SecureStorageKeyProvider,
private val autofillFeature: AutofillFeature,
) : SecureStorageDatabaseFactory {
) : SecureStorageDatabaseFactory, LibraryLoader.LibraryLoaderListener {
private var _database: SecureStorageDatabase? = null

private val mutex = Mutex()

init {
logcat { "Loading the sqlcipher native library" }
try {
LibraryLoader.loadLibrary(context, "sqlcipher")
logcat { "sqlcipher native library loaded ok" }
LibraryLoader.loadLibrary(context, "sqlcipher", this)
} catch (t: Throwable) {
// error loading the library
logcat(ERROR) { "Error loading sqlcipher library: ${t.asLog()}" }
logcat(ERROR) { "Error when calling LibraryLoader.loadLibrary for sqlcipher: ${t.asLog()}" }
}
}

override suspend fun getDatabase(): SecureStorageDatabase? {
return if (autofillFeature.createAsyncPreferences().isEnabled()) {
getAsyncDatabase()
} else {
getDatabaseSynchronized()
return try {
if (autofillFeature.createAsyncPreferences().isEnabled()) {
getAsyncDatabase()
} else {
getDatabaseSynchronized()
}
} catch (e: Exception) {
logcat(ERROR) { "Error getting secure storage database instance: ${e.asLog()}" }
null
}
}

override fun success() {
logcat { "sqlcipher native library loaded ok" }
}

override fun failure(throwable: Throwable) {
logcat(ERROR) { "Error loading sqlcipher library: ${throwable.asLog()}" }
}

@Synchronized
private fun getDatabaseSynchronized(): SecureStorageDatabase? {
return runBlocking {
Expand Down
Loading