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),
|
deviceUnlockError(error, this@MainCredentialActivity),
|
||||||
Snackbar.LENGTH_LONG
|
Snackbar.LENGTH_LONG
|
||||||
).asError().show()
|
).asError().show()
|
||||||
|
mDeviceUnlockViewModel.exceptionShown()
|
||||||
}
|
}
|
||||||
mDeviceUnlockViewModel.exceptionShown()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -266,11 +266,6 @@ class MainCredentialActivity : DatabaseModeActivity() {
|
|||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.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
|
// Init Biometric elements only if allowed
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
||||||
&& PreferencesUtil.isAdvancedUnlockEnable(this)) {
|
&& PreferencesUtil.isAdvancedUnlockEnable(this)) {
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ import androidx.lifecycle.Lifecycle
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.lifecycle.repeatOnLifecycle
|
import androidx.lifecycle.repeatOnLifecycle
|
||||||
import com.kunzisoft.keepass.R
|
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.DeviceUnlockView
|
||||||
import com.kunzisoft.keepass.view.hideByFading
|
import com.kunzisoft.keepass.view.hideByFading
|
||||||
import com.kunzisoft.keepass.view.showByFading
|
import com.kunzisoft.keepass.view.showByFading
|
||||||
@@ -148,6 +149,12 @@ class DeviceUnlockFragment: Fragment() {
|
|||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.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()
|
mDeviceUnlockViewModel.checkUnlockAvailability()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,6 +377,11 @@ class DeviceUnlockFragment: Fragment() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
mDeviceUnlockViewModel.allowAutoOpenBiometricPrompt = true
|
||||||
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
mDeviceUnlockView = null
|
mDeviceUnlockView = null
|
||||||
super.onDestroyView()
|
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 ->
|
_uiState.update { currentState ->
|
||||||
currentState.copy(
|
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() {
|
fun showPrompt() {
|
||||||
_uiState.update { currentState ->
|
_uiState.update { currentState ->
|
||||||
currentState.copy(
|
currentState.copy(
|
||||||
@@ -321,6 +320,7 @@ class DeviceUnlockViewModel(application: Application): AndroidViewModel(applicat
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun promptShown() {
|
fun promptShown() {
|
||||||
|
allowAutoOpenBiometricPrompt = false
|
||||||
_uiState.update { currentState ->
|
_uiState.update { currentState ->
|
||||||
currentState.copy(
|
currentState.copy(
|
||||||
cryptoPromptState = DeviceUnlockPromptMode.IDLE
|
cryptoPromptState = DeviceUnlockPromptMode.IDLE
|
||||||
@@ -362,8 +362,7 @@ class DeviceUnlockViewModel(application: Application): AndroidViewModel(applicat
|
|||||||
cipherDatabase?.let {
|
cipherDatabase?.let {
|
||||||
try {
|
try {
|
||||||
deviceUnlockManager?.initDecryptData(cipherDatabase.specParameters) { cryptoPrompt ->
|
deviceUnlockManager?.initDecryptData(cipherDatabase.specParameters) { cryptoPrompt ->
|
||||||
onPromptRequested(cryptoPrompt)
|
onPromptRequested(cryptoPrompt, autoOpen = allowAutoOpenBiometricPrompt)
|
||||||
checkAutoOpenPrompt()
|
|
||||||
} ?: setException(Exception("AdvancedUnlockManager not initialized"))
|
} ?: setException(Exception("AdvancedUnlockManager not initialized"))
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
setException(e)
|
setException(e)
|
||||||
@@ -445,5 +444,6 @@ data class DeviceUnlockState(
|
|||||||
val cipherDecryptDatabase: CipherDecryptDatabase? = null,
|
val cipherDecryptDatabase: CipherDecryptDatabase? = null,
|
||||||
val cryptoPrompt: DeviceUnlockCryptoPrompt? = null,
|
val cryptoPrompt: DeviceUnlockCryptoPrompt? = null,
|
||||||
val cryptoPromptState: DeviceUnlockPromptMode = DeviceUnlockPromptMode.IDLE,
|
val cryptoPromptState: DeviceUnlockPromptMode = DeviceUnlockPromptMode.IDLE,
|
||||||
|
val autoOpenPrompt: Boolean = false,
|
||||||
val exception: Exception? = null
|
val exception: Exception? = null
|
||||||
)
|
)
|
||||||
Reference in New Issue
Block a user