Skip to content
Merged
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
@@ -1,7 +1,5 @@
package com.simprints.infra.enrolment.records.repository.local

import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteException
import androidx.room.withTransaction
import com.simprints.core.DispatcherIO
import com.simprints.core.domain.face.FaceSample
Expand All @@ -17,6 +15,7 @@ import com.simprints.infra.enrolment.records.repository.domain.models.SubjectAct
import com.simprints.infra.enrolment.records.repository.domain.models.SubjectQuery
import com.simprints.infra.enrolment.records.repository.local.models.toDomain
import com.simprints.infra.enrolment.records.repository.local.models.toRoomDb
import com.simprints.infra.enrolment.records.room.store.BuildConfig.DB_ENCRYPTION
import com.simprints.infra.enrolment.records.room.store.SubjectDao
import com.simprints.infra.enrolment.records.room.store.SubjectsDatabase
import com.simprints.infra.enrolment.records.room.store.SubjectsDatabaseFactory
Expand Down Expand Up @@ -229,7 +228,7 @@ internal class RoomEnrolmentRecordLocalDataSource @Inject constructor(
val dbVersion = database.openHelper.readableDatabase.version
val dbPath = database.openHelper.readableDatabase.path
val dbSize = getTotalRoomDbSizeBytes(dbPath!!)
val isDBEncrypted = isDBEncrypted(dbPath)
val isDBEncrypted = DB_ENCRYPTION
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely a simpler option :D

val subjectCount = subjectDao.countSubjects(queryBuilder.buildCountQuery(SubjectQuery()))
"Room DB Info:\n" +
"Database Name: ${database.openHelper.databaseName}\n" +
Expand All @@ -241,19 +240,6 @@ internal class RoomEnrolmentRecordLocalDataSource @Inject constructor(
}
}

private fun isDBEncrypted(fullDbPath: String): Boolean = try {
SQLiteDatabase.openDatabase(fullDbPath, null, SQLiteDatabase.OPEN_READONLY).use { db ->
db.rawQuery("PRAGMA schema_version;", null).use { cursor ->
cursor.moveToFirst()
// If we can read the schema version, it's not encrypted
false
}
}
} catch (_: SQLiteException) {
// Exception likely means the DB is encrypted
true
}

private fun getTotalRoomDbSizeBytes(fullDbPath: String): Long {
val baseFile = File(fullDbPath)
val walFile = File("$fullDbPath-wal")
Expand Down