Add preference to auto open biometric prompt

This commit is contained in:
J-Jamet committed 2019-09-02 14:47:03 +02:00
1 parent 027d581dcc
commit 186ca30be8
6 files changed
+38 -13

No files matched your search

@@ -280,7 +280,7 @@ class PasswordActivity : StylishActivity() {
// Init FingerPrint elements
var fingerPrintInit = false
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (PreferencesUtil.isBiometricPromptEnable(this)) {
if (PreferencesUtil.isBiometricUnlockEnable(this)) {
advancedUnlockInfoView?.setOnClickListener {
FingerPrintExplanationDialog().show(supportFragmentManager, "fingerPrintExplanationDialog")
@@ -432,7 +432,7 @@ class PasswordActivity : StylishActivity() {
runOnUiThread {
// Recheck fingerprint if error
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (PreferencesUtil.isBiometricPromptEnable(this@PasswordActivity)) {
if (PreferencesUtil.isBiometricUnlockEnable(this@PasswordActivity)) {
// Stay with the same mode and init it
advancedUnlockedViewManager?.initBiometricMode()
}
@@ -529,7 +529,7 @@ class PasswordActivity : StylishActivity() {
val biometricCanAuthenticate = BiometricManager.from(this).canAuthenticate()
// fingerprintEducationPerformed
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& PreferencesUtil.isBiometricPromptEnable(applicationContext)
&& PreferencesUtil.isBiometricUnlockEnable(applicationContext)
&& (biometricCanAuthenticate == BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED || biometricCanAuthenticate == BiometricManager.BIOMETRIC_SUCCESS)
&& advancedUnlockInfoView != null && advancedUnlockInfoView?.unlockIconImageView != null
&& passwordActivityEducation.checkAndPerformedFingerprintEducation(advancedUnlockInfoView?.unlockIconImageView!!)
@@ -30,6 +30,8 @@ class AdvancedUnlockedViewManager(var context: FragmentActivity,
private var biometricHelper: BiometricHelper? = null
private var biometricMode: Mode = Mode.NOT_CONFIGURED
private var isBiometricPromptAutoOpenEnable = PreferencesUtil.isBiometricPromptAutoOpenEnable(context)
// makes it possible to store passwords per database
private val preferenceKeyValue: String
get() = PREF_KEY_VALUE_PREFIX + (databaseFileUri?.path ?: "")
@@ -70,7 +72,7 @@ class AdvancedUnlockedViewManager(var context: FragmentActivity,
// or manually disable
val biometricCanAuthenticate = BiometricManager.from(context).canAuthenticate()
val newBiometricMode: Mode = if (!PreferencesUtil.isBiometricPromptEnable(context)
val newBiometricMode: Mode = if (!PreferencesUtil.isBiometricUnlockEnable(context)
|| biometricCanAuthenticate == BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE
|| biometricCanAuthenticate == BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE) {
@@ -148,8 +150,6 @@ class AdvancedUnlockedViewManager(var context: FragmentActivity,
}
private fun initPause() {
showFingerPrintViews(true)
advancedUnlockInfoView?.setIconViewClickListener(null)
}
@@ -172,12 +172,14 @@ class AdvancedUnlockedViewManager(var context: FragmentActivity,
setAdvancedUnlockedView(R.string.open_biometric_prompt_store_credential)
biometricHelper?.initEncryptData { biometricPrompt, cryptoObject, promptInfo ->
// Set listener to open the biometric dialog and save credential
advancedUnlockInfoView?.setIconViewClickListener { _ ->
cryptoObject?.let { crypto ->
cryptoObject?.let { crypto ->
// Set listener to open the biometric dialog and save credential
advancedUnlockInfoView?.setIconViewClickListener { _ ->
biometricPrompt?.authenticate(promptInfo, crypto)
}
}
}
}
@@ -188,12 +190,20 @@ class AdvancedUnlockedViewManager(var context: FragmentActivity,
if (biometricHelper != null) {
prefsNoBackup.getString(preferenceKeyIvSpec, null)?.let {
biometricHelper?.initDecryptData(it) { biometricPrompt, cryptoObject, promptInfo ->
// Set listener to open the biometric dialog and check credential
advancedUnlockInfoView?.setIconViewClickListener { _ ->
cryptoObject?.let { crypto ->
cryptoObject?.let { crypto ->
// Set listener to open the biometric dialog and check credential
advancedUnlockInfoView?.setIconViewClickListener { _ ->
biometricPrompt?.authenticate(promptInfo, crypto)
}
// Auto open the biometric prompt
if (isBiometricPromptAutoOpenEnable) {
isBiometricPromptAutoOpenEnable = false
biometricPrompt?.authenticate(promptInfo, crypto)
}
}
}
}
}
@@ -128,12 +128,18 @@ object PreferencesUtil {
context.resources.getBoolean(R.bool.lock_database_back_root_default))
}
fun isBiometricPromptEnable(context: Context): Boolean {
fun isBiometricUnlockEnable(context: Context): Boolean {
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.biometric_unlock_enable_key),
context.resources.getBoolean(R.bool.biometric_unlock_enable_default))
}
fun isBiometricPromptAutoOpenEnable(context: Context): Boolean {
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.biometric_auto_open_prompt_key),
context.resources.getBoolean(R.bool.biometric_auto_open_prompt_default))
}
fun isFullFilePathEnable(context: Context): Boolean {
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.full_file_path_enable_key),