fix: add detailed logging for unlock process to improve debugging and performance tracking

This commit is contained in:
2026-02-05 01:56:18 +05:00
parent e307e8d35d
commit 4dc7c6e9bc
13 changed files with 640 additions and 169 deletions

View File

@@ -73,34 +73,53 @@ private suspend fun performUnlock(
onError: (String) -> Unit,
onSuccess: (DecryptedAccount) -> Unit
) {
val TAG = "UnlockScreen"
val totalStart = System.currentTimeMillis()
if (selectedAccount == null) {
onError("Please select an account")
return
}
onUnlocking(true)
android.util.Log.d(TAG, "🔓 Starting unlock for account: ${selectedAccount.name}")
try {
val account = selectedAccount.encryptedAccount
// Try to decrypt
// Try to decrypt private key
val decryptStart = System.currentTimeMillis()
android.util.Log.d(TAG, "🔐 Decrypting private key (PBKDF2)...")
val decryptedPrivateKey = CryptoManager.decryptWithPassword(
account.encryptedPrivateKey,
password
)
val decryptPrivateKeyTime = System.currentTimeMillis() - decryptStart
android.util.Log.d(TAG, "🔐 Private key decrypted in ${decryptPrivateKeyTime}ms")
if (decryptedPrivateKey == null) {
android.util.Log.w(TAG, "❌ Decryption failed - incorrect password")
onError("Incorrect password")
onUnlocking(false)
return
}
// Decrypt seed phrase
val seedStart = System.currentTimeMillis()
android.util.Log.d(TAG, "🌱 Decrypting seed phrase...")
val decryptedSeedPhrase = CryptoManager.decryptWithPassword(
account.encryptedSeedPhrase,
password
)?.split(" ") ?: emptyList()
val seedTime = System.currentTimeMillis() - seedStart
android.util.Log.d(TAG, "🌱 Seed phrase decrypted in ${seedTime}ms")
// Generate private key hash
val hashStart = System.currentTimeMillis()
android.util.Log.d(TAG, "🔑 Generating private key hash...")
val privateKeyHash = CryptoManager.generatePrivateKeyHash(decryptedPrivateKey)
val hashTime = System.currentTimeMillis() - hashStart
android.util.Log.d(TAG, "🔑 Hash generated in ${hashTime}ms")
val decryptedAccount = DecryptedAccount(
publicKey = account.publicKey,
@@ -110,8 +129,9 @@ private suspend fun performUnlock(
name = account.name
)
// Connect to server and authenticate
// Connect to server
val connectStart = System.currentTimeMillis()
android.util.Log.d(TAG, "🌐 Connecting to server...")
ProtocolManager.connect()
// Wait for websocket connection
@@ -120,8 +140,11 @@ private suspend fun performUnlock(
kotlinx.coroutines.delay(100)
waitAttempts++
}
val connectTime = System.currentTimeMillis() - connectStart
android.util.Log.d(TAG, "🌐 Connected in ${connectTime}ms (attempts: $waitAttempts)")
if (ProtocolManager.state.value == ProtocolState.DISCONNECTED) {
android.util.Log.e(TAG, "❌ Connection failed after $waitAttempts attempts")
onError("Failed to connect to server")
onUnlocking(false)
return
@@ -129,12 +152,22 @@ private suspend fun performUnlock(
kotlinx.coroutines.delay(300)
// Authenticate
val authStart = System.currentTimeMillis()
android.util.Log.d(TAG, "🔒 Authenticating...")
ProtocolManager.authenticate(account.publicKey, privateKeyHash)
val authTime = System.currentTimeMillis() - authStart
android.util.Log.d(TAG, "🔒 Auth request sent in ${authTime}ms")
accountManager.setCurrentAccount(account.publicKey)
val totalTime = System.currentTimeMillis() - totalStart
android.util.Log.d(TAG, "✅ UNLOCK COMPLETE in ${totalTime}ms")
android.util.Log.d(TAG, " 📊 Breakdown: privateKey=${decryptPrivateKeyTime}ms, seed=${seedTime}ms, hash=${hashTime}ms, connect=${connectTime}ms, auth=${authTime}ms")
onSuccess(decryptedAccount)
} catch (e: Exception) {
android.util.Log.e(TAG, "❌ Unlock failed: ${e.message}", e)
onError("Failed to unlock: ${e.message}")
onUnlocking(false)
}