mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-30 22:02:57 -08:00
Create timers to calculate Database opening
This commit is contained in:
1 parent
a42ec74723
commit
a792df2021
3 files changed
+40
-4
No files matched your search
@@ -19,6 +19,8 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.file.input
|
||||
|
||||
import android.util.Log
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseVersioned
|
||||
import com.kunzisoft.keepass.database.exception.LoadDatabaseException
|
||||
@@ -29,6 +31,9 @@ import java.io.InputStream
|
||||
abstract class DatabaseInput<PwDb : DatabaseVersioned<*, *, *, *>>
|
||||
(protected val cacheDirectory: File) {
|
||||
|
||||
private var startTimeKey = System.currentTimeMillis()
|
||||
private var startTimeContent = System.currentTimeMillis()
|
||||
|
||||
/**
|
||||
* Load a versioned database file, return contents in a new DatabaseVersioned.
|
||||
*
|
||||
@@ -54,4 +59,28 @@ abstract class DatabaseInput<PwDb : DatabaseVersioned<*, *, *, *>>
|
||||
loadedCipherKey: Database.LoadedKey,
|
||||
progressTaskUpdater: ProgressTaskUpdater?,
|
||||
fixDuplicateUUID: Boolean = false): PwDb
|
||||
|
||||
protected fun startKeyTimer(progressTaskUpdater: ProgressTaskUpdater?) {
|
||||
progressTaskUpdater?.updateMessage(R.string.retrieving_db_key)
|
||||
Log.d(TAG, "Start retrieving database key...")
|
||||
startTimeKey = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
protected fun stopKeyTimer() {
|
||||
Log.d(TAG, "Stop retrieving database key... ${System.currentTimeMillis() - startTimeKey} ms")
|
||||
}
|
||||
|
||||
protected fun startContentTimer(progressTaskUpdater: ProgressTaskUpdater?) {
|
||||
progressTaskUpdater?.updateMessage(R.string.decrypting_db)
|
||||
Log.d(TAG, "Start decrypting database content...")
|
||||
startTimeContent = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
protected fun stopContentTimer() {
|
||||
Log.d(TAG, "Stop retrieving database content... ${System.currentTimeMillis() - startTimeContent} ms")
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = DatabaseInput::class.java.name
|
||||
}
|
||||
}
|
||||
@@ -81,6 +81,7 @@ class DatabaseInputKDB(cacheDirectory: File)
|
||||
assignMasterKey: (() -> Unit)? = null): DatabaseKDB {
|
||||
|
||||
try {
|
||||
startKeyTimer(progressTaskUpdater)
|
||||
// Load entire file, most of it's encrypted.
|
||||
val fileSize = databaseInputStream.available()
|
||||
|
||||
@@ -103,7 +104,6 @@ class DatabaseInputKDB(cacheDirectory: File)
|
||||
throw VersionDatabaseException()
|
||||
}
|
||||
|
||||
progressTaskUpdater?.updateMessage(R.string.retrieving_db_key)
|
||||
mDatabase = DatabaseKDB()
|
||||
|
||||
mDatabase.changeDuplicateId = fixDuplicateUUID
|
||||
@@ -128,7 +128,8 @@ class DatabaseInputKDB(cacheDirectory: File)
|
||||
header.transformSeed,
|
||||
mDatabase.numberKeyEncryptionRounds)
|
||||
|
||||
progressTaskUpdater?.updateMessage(R.string.decrypting_db)
|
||||
stopKeyTimer()
|
||||
startContentTimer(progressTaskUpdater)
|
||||
|
||||
val cipher: Cipher = try {
|
||||
mDatabase.encryptionAlgorithm
|
||||
@@ -324,6 +325,8 @@ class DatabaseInputKDB(cacheDirectory: File)
|
||||
}
|
||||
constructTreeFromIndex()
|
||||
|
||||
stopContentTimer()
|
||||
|
||||
} catch (e: LoadDatabaseException) {
|
||||
mDatabase.clearCache()
|
||||
throw e
|
||||
|
||||
@@ -125,7 +125,7 @@ class DatabaseInputKDBX(cacheDirectory: File)
|
||||
fixDuplicateUUID: Boolean,
|
||||
assignMasterKey: (() -> Unit)? = null): DatabaseKDBX {
|
||||
try {
|
||||
progressTaskUpdater?.updateMessage(R.string.retrieving_db_key)
|
||||
startKeyTimer(progressTaskUpdater)
|
||||
mDatabase = DatabaseKDBX()
|
||||
|
||||
mDatabase.changeDuplicateId = fixDuplicateUUID
|
||||
@@ -141,7 +141,9 @@ class DatabaseInputKDBX(cacheDirectory: File)
|
||||
assignMasterKey?.invoke()
|
||||
mDatabase.makeFinalKey(header.masterSeed)
|
||||
|
||||
progressTaskUpdater?.updateMessage(R.string.decrypting_db)
|
||||
stopKeyTimer()
|
||||
startContentTimer(progressTaskUpdater)
|
||||
|
||||
val engine: CipherEngine
|
||||
val cipher: Cipher
|
||||
try {
|
||||
@@ -213,6 +215,8 @@ class DatabaseInputKDBX(cacheDirectory: File)
|
||||
|
||||
readDocumentStreamed(createPullParser(inputStreamXml))
|
||||
|
||||
stopContentTimer()
|
||||
|
||||
} catch (e: LoadDatabaseException) {
|
||||
throw e
|
||||
} catch (e: XmlPullParserException) {
|
||||
|
||||
Reference in new issue
Block a user