feat: Add logging for screen initialization and data loading in UnlockScreen

This commit is contained in:
k1ngsterr1
2026-01-24 23:07:43 +05:00
parent a239486860
commit 0bb8bee2e2

View File

@@ -180,6 +180,8 @@ fun UnlockScreen(
val biometricManager = remember { BiometricAuthManager(context) } val biometricManager = remember { BiometricAuthManager(context) }
val biometricPrefs = remember { BiometricPreferences(context) } val biometricPrefs = remember { BiometricPreferences(context) }
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
android.util.Log.d("UnlockScreen", "🎬 SCREEN INITIALIZED - Activity: $activity")
var password by remember { mutableStateOf("") } var password by remember { mutableStateOf("") }
var passwordVisible by remember { mutableStateOf(false) } var passwordVisible by remember { mutableStateOf(false) }
@@ -191,6 +193,7 @@ fun UnlockScreen(
var isBiometricEnabled by remember { mutableStateOf(false) } var isBiometricEnabled by remember { mutableStateOf(false) }
var savedPasswordsMap by remember { mutableStateOf<Map<String, String>>(emptyMap()) } var savedPasswordsMap by remember { mutableStateOf<Map<String, String>>(emptyMap()) }
var dataLoaded by remember { mutableStateOf(false) } var dataLoaded by remember { mutableStateOf(false) }
var biometricAttempted by remember { mutableStateOf(false) } // Отслеживаем попытку биометрии
// Account selection state // Account selection state
var accounts by remember { mutableStateOf<List<AccountItem>>(emptyList()) } var accounts by remember { mutableStateOf<List<AccountItem>>(emptyList()) }
@@ -201,6 +204,7 @@ fun UnlockScreen(
// Load accounts and pre-select last used account // Load accounts and pre-select last used account
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
android.util.Log.d("UnlockScreen", "📦 LOADING DATA...")
// ⚡ СИНХРОННОЕ чтение последнего аккаунта ДО загрузки списка // ⚡ СИНХРОННОЕ чтение последнего аккаунта ДО загрузки списка
val lastLoggedKey = accountManager.getLastLoggedPublicKey() val lastLoggedKey = accountManager.getLastLoggedPublicKey()
@@ -248,60 +252,86 @@ fun UnlockScreen(
android.util.Log.d("UnlockScreen", "🔐 Has password for selected: ${selectedAccount?.let { passwords.containsKey(it.publicKey) }}") android.util.Log.d("UnlockScreen", "🔐 Has password for selected: ${selectedAccount?.let { passwords.containsKey(it.publicKey) }}")
dataLoaded = true dataLoaded = true
android.util.Log.d("UnlockScreen", "✅ DATA LOADED")
} }
// Автоматически пытаемся разблокировать через биометрию при выборе аккаунта // Функция для запуска биометрической разблокировки
LaunchedEffect(selectedAccount, isBiometricEnabled, savedPasswordsMap, dataLoaded) { fun tryBiometricUnlock() {
android.util.Log.d("UnlockScreen", "🚀 LaunchedEffect triggered") if (selectedAccount == null || activity == null) {
android.util.Log.d("UnlockScreen", "🚀 dataLoaded: $dataLoaded") android.util.Log.d("UnlockScreen", "❌ Cannot start biometric: no account or activity")
android.util.Log.d("UnlockScreen", "🚀 selectedAccount: ${selectedAccount?.publicKey}") return
android.util.Log.d("UnlockScreen", "🚀 isBiometricEnabled: $isBiometricEnabled") }
android.util.Log.d("UnlockScreen", "🚀 biometricAvailable: $biometricAvailable")
android.util.Log.d("UnlockScreen", "🚀 activity: $activity") val encryptedPassword = savedPasswordsMap[selectedAccount!!.publicKey]
if (encryptedPassword == null) {
android.util.Log.d("UnlockScreen", "❌ No saved password for account")
return
}
android.util.Log.d("UnlockScreen", "🔐 Starting biometric unlock...")
biometricAttempted = true
biometricManager.decryptPassword(
activity = activity,
encryptedData = encryptedPassword,
onSuccess = { decryptedPassword ->
android.util.Log.d("UnlockScreen", "✅ Biometric success, unlocking...")
scope.launch {
performUnlock(
selectedAccount = selectedAccount,
password = decryptedPassword,
accountManager = accountManager,
onUnlocking = { isUnlocking = it },
onError = { error = it },
onSuccess = { decryptedAccount ->
onUnlocked(decryptedAccount)
}
)
}
},
onError = { errorMessage ->
android.util.Log.e("UnlockScreen", "❌ Biometric error: $errorMessage")
error = errorMessage
},
onCancel = {
android.util.Log.d("UnlockScreen", "🚫 Biometric cancelled")
}
)
}
// Автоматически запускаем биометрию при загрузке данных
LaunchedEffect(dataLoaded, selectedAccount, isBiometricEnabled, savedPasswordsMap) {
android.util.Log.d("UnlockScreen", "🚀 Auto-biometric LaunchedEffect")
android.util.Log.d("UnlockScreen", " dataLoaded: $dataLoaded")
android.util.Log.d("UnlockScreen", " selectedAccount: ${selectedAccount?.publicKey}")
android.util.Log.d("UnlockScreen", " isBiometricEnabled: $isBiometricEnabled")
android.util.Log.d("UnlockScreen", " biometricAvailable: $biometricAvailable")
android.util.Log.d("UnlockScreen", " activity: $activity")
android.util.Log.d("UnlockScreen", " biometricAttempted: $biometricAttempted")
if (!dataLoaded) { if (!dataLoaded) {
android.util.Log.d("UnlockScreen", "⏸️ Data not loaded yet, waiting...") android.util.Log.d("UnlockScreen", "⏸️ Data not loaded yet")
return@LaunchedEffect return@LaunchedEffect
} }
if (selectedAccount != null && isBiometricEnabled && activity != null && if (biometricAttempted) {
android.util.Log.d("UnlockScreen", "⏸️ Biometric already attempted")
return@LaunchedEffect
}
if (selectedAccount != null &&
isBiometricEnabled &&
activity != null &&
biometricAvailable is BiometricAvailability.Available) { biometricAvailable is BiometricAvailability.Available) {
val encryptedPassword = savedPasswordsMap[selectedAccount!!.publicKey] val encryptedPassword = savedPasswordsMap[selectedAccount!!.publicKey]
android.util.Log.d("UnlockScreen", "🔑 Encrypted password found: ${encryptedPassword != null}") android.util.Log.d("UnlockScreen", "🔑 Has password: ${encryptedPassword != null}")
if (encryptedPassword != null) { if (encryptedPassword != null) {
// Небольшая задержка для анимации UI // Небольшая задержка для анимации UI
delay(500) delay(300)
tryBiometricUnlock()
// Запускаем биометрическую аутентификацию
biometricManager.decryptPassword(
activity = activity,
encryptedData = encryptedPassword,
onSuccess = { decryptedPassword ->
password = decryptedPassword
// Автоматически разблокируем
scope.launch {
performUnlock(
selectedAccount = selectedAccount,
password = decryptedPassword,
accountManager = accountManager,
onUnlocking = { isUnlocking = it },
onError = { error = it },
onSuccess = { decryptedAccount ->
onUnlocked(decryptedAccount)
}
)
}
},
onError = { errorMessage ->
// Если биометрия не сработала, пользователь может ввести пароль вручную
android.util.Log.e("UnlockScreen", "Biometric error: $errorMessage")
},
onCancel = {
// Пользователь отменил биометрию, покажем поле для ввода пароля
}
)
} }
} }
} }
@@ -813,35 +843,7 @@ fun UnlockScreen(
if (showBiometricButton) { if (showBiometricButton) {
Button( Button(
onClick = { onClick = {
if (selectedAccount == null || activity == null) return@Button tryBiometricUnlock()
val encryptedPassword = savedPasswordsMap[selectedAccount!!.publicKey]
if (encryptedPassword != null) {
biometricManager.decryptPassword(
activity = activity,
encryptedData = encryptedPassword,
onSuccess = { decryptedPassword ->
scope.launch {
performUnlock(
selectedAccount = selectedAccount,
password = decryptedPassword,
accountManager = accountManager,
onUnlocking = { isUnlocking = it },
onError = { error = it },
onSuccess = { decryptedAccount ->
onUnlocked(decryptedAccount)
}
)
}
},
onError = { errorMessage ->
error = errorMessage
},
onCancel = {
// User cancelled
}
)
}
}, },
enabled = !isUnlocking, enabled = !isUnlocking,
modifier = Modifier modifier = Modifier