diff --git a/app/src/main/java/com/kunzisoft/keepass/biometric/AdvancedUnlockedViewManager.kt b/app/src/main/java/com/kunzisoft/keepass/biometric/AdvancedUnlockedViewManager.kt index d1274da9c..b9b833b3b 100644 --- a/app/src/main/java/com/kunzisoft/keepass/biometric/AdvancedUnlockedViewManager.kt +++ b/app/src/main/java/com/kunzisoft/keepass/biometric/AdvancedUnlockedViewManager.kt @@ -286,12 +286,10 @@ class AdvancedUnlockedViewManager(var context: FragmentActivity, } fun deleteEntryKey() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - biometricHelper?.deleteEntryKey() - removePrefsNoBackupKey() - biometricMode = Mode.NOT_CONFIGURED - checkBiometricAvailability() - } + biometricHelper?.deleteEntryKey() + removePrefsNoBackupKey() + biometricMode = Mode.NOT_CONFIGURED + checkBiometricAvailability() } enum class Mode { diff --git a/app/src/main/java/com/kunzisoft/keepass/biometric/BiometricHelper.kt b/app/src/main/java/com/kunzisoft/keepass/biometric/BiometricHelper.kt index 1fe7cf3d2..fec7c3169 100644 --- a/app/src/main/java/com/kunzisoft/keepass/biometric/BiometricHelper.kt +++ b/app/src/main/java/com/kunzisoft/keepass/biometric/BiometricHelper.kt @@ -57,7 +57,7 @@ class BiometricHelper(private val context: FragmentActivity, private val biometr private var keyguardManager: KeyguardManager? = null private var cryptoObject: BiometricPrompt.CryptoObject? = null - private var isFingerprintInit = false + private var isBiometricInit = false private var authenticationCallback: BiometricPrompt.AuthenticationCallback? = null private val promptInfoStoreCredential = BiometricPrompt.PromptInfo.Builder() @@ -73,13 +73,18 @@ class BiometricHelper(private val context: FragmentActivity, private val biometr .build() val isFingerprintInitialized: Boolean - get() = isFingerprintInitialized(true) + get() { + if (!isBiometricInit && biometricUnlockCallback != null) { + biometricUnlockCallback.onBiometricException(Exception("FingerPrint not initialized")) + } + return isBiometricInit + } init { if (BiometricManager.from(context).canAuthenticate() != BiometricManager.BIOMETRIC_SUCCESS) { // really not much to do when no fingerprint support found - isFingerprintInit = false + isBiometricInit = false } else { this.keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager @@ -93,23 +98,15 @@ class BiometricHelper(private val context: FragmentActivity, private val biometr + KeyProperties.BLOCK_MODE_CBC + "/" + KeyProperties.ENCRYPTION_PADDING_PKCS7) this.cryptoObject = BiometricPrompt.CryptoObject(cipher!!) - isFingerprintInit = true + isBiometricInit = true } catch (e: Exception) { Log.e(TAG, "Unable to initialize the keystore", e) - isFingerprintInit = false + isBiometricInit = false biometricUnlockCallback?.onBiometricException(e) } } } - private fun isFingerprintInitialized(throwException: Boolean): Boolean { - if (!isFingerprintInit && biometricUnlockCallback != null) { - if (throwException) - biometricUnlockCallback.onBiometricException(Exception("FingerPrint not initialized")) - } - return isFingerprintInit - } - fun initEncryptData(actionIfCypherInit : (biometricPrompt: BiometricPrompt?, cryptoObject: BiometricPrompt.CryptoObject?, @@ -118,7 +115,7 @@ class BiometricHelper(private val context: FragmentActivity, private val biometr return } try { - createNewKeyIfNeeded(false) // no need to keep deleting existing keys + createNewKeyIfNeeded() // no need to keep deleting existing keys keyStore?.load(null) val key = keyStore?.getKey(BIOMETRIC_KEYSTORE_KEY, null) as SecretKey cipher?.init(Cipher.ENCRYPT_MODE, key) @@ -169,7 +166,7 @@ class BiometricHelper(private val context: FragmentActivity, private val biometr return } try { - createNewKeyIfNeeded(false) + createNewKeyIfNeeded() keyStore?.load(null) val key = keyStore?.getKey(BIOMETRIC_KEYSTORE_KEY, null) as SecretKey @@ -216,16 +213,11 @@ class BiometricHelper(private val context: FragmentActivity, private val biometr } @SuppressLint("NewApi") - private fun createNewKeyIfNeeded(allowDeleteExisting: Boolean) { + private fun createNewKeyIfNeeded() { if (!isFingerprintInitialized) { return } try { - keyStore?.load(null) - if (allowDeleteExisting && keyStore != null && keyStore!!.containsAlias(BIOMETRIC_KEYSTORE_KEY)) { - keyStore?.deleteEntry(BIOMETRIC_KEYSTORE_KEY) - } - // Create new key if needed if (keyStore != null && !keyStore!!.containsAlias(BIOMETRIC_KEYSTORE_KEY)) { // Set the alias of the entry in Android KeyStore where the key will appear diff --git a/app/src/main/java/com/kunzisoft/keepass/view/AdvancedUnlockInfoView.kt b/app/src/main/java/com/kunzisoft/keepass/view/AdvancedUnlockInfoView.kt index 9d629d584..dcd89d124 100644 --- a/app/src/main/java/com/kunzisoft/keepass/view/AdvancedUnlockInfoView.kt +++ b/app/src/main/java/com/kunzisoft/keepass/view/AdvancedUnlockInfoView.kt @@ -25,7 +25,7 @@ class AdvancedUnlockInfoView @JvmOverloads constructor(context: Context, init { val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater - inflater.inflate(R.layout.fingerprint_show, this) + inflater.inflate(R.layout.view_advanced_unlock, this) unlockContainerView = findViewById(R.id.fingerprint_container) diff --git a/app/src/main/res/drawable-v23/lock_open.xml b/app/src/main/res/drawable-v23/lock_open.xml deleted file mode 100644 index d65cefb28..000000000 --- a/app/src/main/res/drawable-v23/lock_open.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/drawable/background_image.xml b/app/src/main/res/drawable/background_image.xml new file mode 100644 index 000000000..e098308d1 --- /dev/null +++ b/app/src/main/res/drawable/background_image.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/circle.xml b/app/src/main/res/drawable/circle.xml deleted file mode 100644 index bea663f9d..000000000 --- a/app/src/main/res/drawable/circle.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/app/src/main/res/layout-v23/fragment_fingerprint_explanation.xml b/app/src/main/res/layout-v23/fragment_fingerprint_explanation.xml index c50fbd0c1..27773b26d 100644 --- a/app/src/main/res/layout-v23/fragment_fingerprint_explanation.xml +++ b/app/src/main/res/layout-v23/fragment_fingerprint_explanation.xml @@ -20,6 +20,7 @@ @@ -130,6 +130,7 @@ @@ -208,9 +209,8 @@ android:elevation="4dp" android:layout_marginBottom="8dp" android:layout_gravity="center" - android:src="@drawable/lock_open" - android:background="@drawable/circle" - android:backgroundTint="?attr/colorPrimary" + android:src="@drawable/ic_settings_white_24dp" + android:background="@drawable/background_icon" tools:targetApi="lollipop" /> diff --git a/app/src/main/res/layout-v23/fingerprint_show.xml b/app/src/main/res/layout-v23/view_advanced_unlock.xml similarity index 96% rename from app/src/main/res/layout-v23/fingerprint_show.xml rename to app/src/main/res/layout-v23/view_advanced_unlock.xml index 50d1b0057..8592064d9 100644 --- a/app/src/main/res/layout-v23/fingerprint_show.xml +++ b/app/src/main/res/layout-v23/view_advanced_unlock.xml @@ -32,6 +32,6 @@ android:layout_alignParentEnd="true" android:elevation="8dp" android:src="@drawable/fingerprint" - android:background="@drawable/circle" + android:background="@drawable/background_image" android:backgroundTint="?attr/colorAccent" /> diff --git a/app/src/main/res/layout/fingerprint_show.xml b/app/src/main/res/layout/view_advanced_unlock.xml similarity index 100% rename from app/src/main/res/layout/fingerprint_show.xml rename to app/src/main/res/layout/view_advanced_unlock.xml