mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
fix: auto open prompt #2105
This commit is contained in:
@@ -256,8 +256,8 @@ class MainCredentialActivity : DatabaseModeActivity() {
|
||||
deviceUnlockError(error, this@MainCredentialActivity),
|
||||
Snackbar.LENGTH_LONG
|
||||
).asError().show()
|
||||
mDeviceUnlockViewModel.exceptionShown()
|
||||
}
|
||||
mDeviceUnlockViewModel.exceptionShown()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -266,11 +266,6 @@ class MainCredentialActivity : DatabaseModeActivity() {
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
// Don't allow auto open prompt if lock become when UI visible
|
||||
if (UI_VISIBLE_DURING_LOCK) {
|
||||
mDeviceUnlockViewModel.allowAutoOpenBiometricPrompt = false
|
||||
}
|
||||
|
||||
// Init Biometric elements only if allowed
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
||||
&& PreferencesUtil.isAdvancedUnlockEnable(this)) {
|
||||
|
||||
@@ -45,6 +45,7 @@ import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.activities.legacy.DatabaseLockActivity.Companion.UI_VISIBLE_DURING_LOCK
|
||||
import com.kunzisoft.keepass.view.DeviceUnlockView
|
||||
import com.kunzisoft.keepass.view.hideByFading
|
||||
import com.kunzisoft.keepass.view.showByFading
|
||||
@@ -148,6 +149,12 @@ class DeviceUnlockFragment: Fragment() {
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
// Don't allow auto open prompt if lock become when UI visible
|
||||
if (UI_VISIBLE_DURING_LOCK) {
|
||||
mDeviceUnlockViewModel.allowAutoOpenBiometricPrompt = false
|
||||
}
|
||||
|
||||
mDeviceUnlockViewModel.checkUnlockAvailability()
|
||||
}
|
||||
|
||||
@@ -370,6 +377,11 @@ class DeviceUnlockFragment: Fragment() {
|
||||
)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
mDeviceUnlockViewModel.allowAutoOpenBiometricPrompt = true
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
mDeviceUnlockView = null
|
||||
super.onDestroyView()
|
||||
|
||||
@@ -295,23 +295,22 @@ class DeviceUnlockViewModel(application: Application): AndroidViewModel(applicat
|
||||
}
|
||||
}
|
||||
|
||||
fun onPromptRequested(cryptoPrompt: DeviceUnlockCryptoPrompt) {
|
||||
fun onPromptRequested(
|
||||
cryptoPrompt: DeviceUnlockCryptoPrompt,
|
||||
autoOpen: Boolean = false
|
||||
) {
|
||||
_uiState.update { currentState ->
|
||||
currentState.copy(
|
||||
cryptoPrompt = cryptoPrompt
|
||||
cryptoPrompt = cryptoPrompt,
|
||||
cryptoPromptState = if (
|
||||
autoOpen
|
||||
&& PreferencesUtil.isAdvancedUnlockPromptAutoOpenEnable(getApplication()))
|
||||
DeviceUnlockPromptMode.SHOW
|
||||
else uiState.value.cryptoPromptState
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun checkAutoOpenPrompt() {
|
||||
// Auto open the biometric prompt
|
||||
if (allowAutoOpenBiometricPrompt
|
||||
&& PreferencesUtil.isAdvancedUnlockPromptAutoOpenEnable(getApplication())
|
||||
) {
|
||||
showPrompt()
|
||||
}
|
||||
}
|
||||
|
||||
fun showPrompt() {
|
||||
_uiState.update { currentState ->
|
||||
currentState.copy(
|
||||
@@ -321,6 +320,7 @@ class DeviceUnlockViewModel(application: Application): AndroidViewModel(applicat
|
||||
}
|
||||
|
||||
fun promptShown() {
|
||||
allowAutoOpenBiometricPrompt = false
|
||||
_uiState.update { currentState ->
|
||||
currentState.copy(
|
||||
cryptoPromptState = DeviceUnlockPromptMode.IDLE
|
||||
@@ -362,8 +362,7 @@ class DeviceUnlockViewModel(application: Application): AndroidViewModel(applicat
|
||||
cipherDatabase?.let {
|
||||
try {
|
||||
deviceUnlockManager?.initDecryptData(cipherDatabase.specParameters) { cryptoPrompt ->
|
||||
onPromptRequested(cryptoPrompt)
|
||||
checkAutoOpenPrompt()
|
||||
onPromptRequested(cryptoPrompt, autoOpen = allowAutoOpenBiometricPrompt)
|
||||
} ?: setException(Exception("AdvancedUnlockManager not initialized"))
|
||||
} catch (e: Exception) {
|
||||
setException(e)
|
||||
@@ -445,5 +444,6 @@ data class DeviceUnlockState(
|
||||
val cipherDecryptDatabase: CipherDecryptDatabase? = null,
|
||||
val cryptoPrompt: DeviceUnlockCryptoPrompt? = null,
|
||||
val cryptoPromptState: DeviceUnlockPromptMode = DeviceUnlockPromptMode.IDLE,
|
||||
val autoOpenPrompt: Boolean = false,
|
||||
val exception: Exception? = null
|
||||
)
|
||||
Reference in New Issue
Block a user