From 7d5c37ec337d18a05d70e54917e770f2fe811ea1 Mon Sep 17 00:00:00 2001 From: hbiel Date: Thu, 8 Oct 2020 21:16:10 +0200 Subject: [PATCH 1/4] upgrade icon packs to API 30 --- icon-pack-classic/build.gradle | 6 +++--- icon-pack-material/build.gradle | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/icon-pack-classic/build.gradle b/icon-pack-classic/build.gradle index d69bda28a..925a05d19 100644 --- a/icon-pack-classic/build.gradle +++ b/icon-pack-classic/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 29 - buildToolsVersion '29.0.3' + compileSdkVersion 30 + buildToolsVersion '30.0.2' defaultConfig { minSdkVersion 14 - targetSdkVersion 29 + targetSdkVersion 30 } resourcePrefix 'classic_' diff --git a/icon-pack-material/build.gradle b/icon-pack-material/build.gradle index 2c2a7b9fd..e78944c36 100644 --- a/icon-pack-material/build.gradle +++ b/icon-pack-material/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 29 - buildToolsVersion '29.0.3' + compileSdkVersion 30 + buildToolsVersion '30.0.2' defaultConfig { minSdkVersion 14 - targetSdkVersion 29 + targetSdkVersion 30 } resourcePrefix 'material_' From f1e675d662dfd9863f0835aaf20d70459dc94015 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Thu, 8 Oct 2020 22:28:20 +0200 Subject: [PATCH 2/4] Upgrade biometric lib to 1.1.0-beta01 #724 --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index fec2b9613..1fe75573f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -101,7 +101,7 @@ dependencies { // WARNING: Bug with extra field implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.documentfile:documentfile:1.0.1' - implementation 'androidx.biometric:biometric:1.1.0-alpha02' + implementation 'androidx.biometric:biometric:1.1.0-beta01' // Lifecycle - LiveData - ViewModel - Coroutines implementation "androidx.core:core-ktx:1.3.1" implementation 'androidx.fragment:fragment-ktx:1.2.5' From 267f4273ee357c7a56a1da6f1746d4ae9d4b0700 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Thu, 8 Oct 2020 23:10:28 +0200 Subject: [PATCH 3/4] Try to add new biometric states from the doc #724 --- .../biometric/AdvancedUnlockedManager.kt | 5 ++-- .../BiometricUnlockDatabaseHelper.kt | 29 ++++++++++++++----- .../settings/NestedAppSettingsFragment.kt | 14 +++------ 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/kunzisoft/keepass/biometric/AdvancedUnlockedManager.kt b/app/src/main/java/com/kunzisoft/keepass/biometric/AdvancedUnlockedManager.kt index 82ab8e5f5..52212d8e5 100644 --- a/app/src/main/java/com/kunzisoft/keepass/biometric/AdvancedUnlockedManager.kt +++ b/app/src/main/java/com/kunzisoft/keepass/biometric/AdvancedUnlockedManager.kt @@ -30,7 +30,6 @@ import android.view.View import android.widget.CompoundButton import android.widget.TextView import androidx.annotation.RequiresApi -import androidx.biometric.BiometricConstants import androidx.biometric.BiometricManager import androidx.biometric.BiometricPrompt import androidx.fragment.app.FragmentActivity @@ -229,8 +228,8 @@ class AdvancedUnlockedManager(var context: FragmentActivity, setAdvancedUnlockedMessageView("") advancedUnlockInfoView?.setIconViewClickListener(false) { - biometricAuthenticationCallback.onAuthenticationError( - BiometricConstants.ERROR_UNABLE_TO_PROCESS, context.getString(R.string.credential_before_click_biometric_button)) + biometricAuthenticationCallback.onAuthenticationError(BiometricPrompt.ERROR_UNABLE_TO_PROCESS, + context.getString(R.string.credential_before_click_biometric_button)) } } diff --git a/app/src/main/java/com/kunzisoft/keepass/biometric/BiometricUnlockDatabaseHelper.kt b/app/src/main/java/com/kunzisoft/keepass/biometric/BiometricUnlockDatabaseHelper.kt index 81f057c0f..a45b2711d 100644 --- a/app/src/main/java/com/kunzisoft/keepass/biometric/BiometricUnlockDatabaseHelper.kt +++ b/app/src/main/java/com/kunzisoft/keepass/biometric/BiometricUnlockDatabaseHelper.kt @@ -31,7 +31,6 @@ import androidx.annotation.RequiresApi import androidx.biometric.BiometricManager import androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG import androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_WEAK -import androidx.biometric.BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE import androidx.biometric.BiometricPrompt import androidx.fragment.app.FragmentActivity import com.kunzisoft.keepass.R @@ -94,12 +93,8 @@ class BiometricUnlockDatabaseHelper(private val context: FragmentActivity) { } init { - if (canAuthenticate(context) != BiometricManager.BIOMETRIC_SUCCESS) { - // really not much to do when no fingerprint support found - isKeyManagerInit = false - } else { + if (allowInitKeyStore(context)) { this.keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager? - try { this.keyStore = KeyStore.getInstance(BIOMETRIC_KEYSTORE) this.keyGenerator = KeyGenerator.getInstance(BIOMETRIC_KEY_ALGORITHM, BIOMETRIC_KEYSTORE) @@ -116,6 +111,9 @@ class BiometricUnlockDatabaseHelper(private val context: FragmentActivity) { isKeyManagerInit = false biometricUnlockCallback?.onBiometricException(e) } + } else { + // really not much to do when no fingerprint support found + isKeyManagerInit = false } } @@ -307,11 +305,28 @@ class BiometricUnlockDatabaseHelper(private val context: FragmentActivity) { BiometricManager.from(context).canAuthenticate(BIOMETRIC_WEAK) } catch (e: Exception) { Log.e(TAG, "Unable to authenticate with weak biometric.", e) - BIOMETRIC_ERROR_HW_UNAVAILABLE + BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE } } } + fun allowInitKeyStore(context: Context): Boolean { + val biometricCanAuthenticate = canAuthenticate(context) + return ( biometricCanAuthenticate == BiometricManager.BIOMETRIC_SUCCESS + || biometricCanAuthenticate == BiometricManager.BIOMETRIC_STATUS_UNKNOWN + ) + } + + fun unlockSupported(context: Context): Boolean { + val biometricCanAuthenticate = canAuthenticate(context) + return ( biometricCanAuthenticate == BiometricManager.BIOMETRIC_SUCCESS + || biometricCanAuthenticate == BiometricManager.BIOMETRIC_STATUS_UNKNOWN + || biometricCanAuthenticate == BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE + || biometricCanAuthenticate == BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED + || biometricCanAuthenticate == BiometricManager.BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED + ) + } + /** * Remove entry key in keystore */ diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/NestedAppSettingsFragment.kt b/app/src/main/java/com/kunzisoft/keepass/settings/NestedAppSettingsFragment.kt index 2a66f31b5..d2dc148fb 100644 --- a/app/src/main/java/com/kunzisoft/keepass/settings/NestedAppSettingsFragment.kt +++ b/app/src/main/java/com/kunzisoft/keepass/settings/NestedAppSettingsFragment.kt @@ -209,13 +209,11 @@ class NestedAppSettingsFragment : NestedSettingsFragment() { activity?.let { activity -> val biometricUnlockEnablePreference: SwitchPreference? = findPreference(getString(R.string.biometric_unlock_enable_key)) + val deleteKeysFingerprints: Preference? = findPreference(getString(R.string.biometric_delete_all_key_key)) // < M solve verifyError exception - var biometricUnlockSupported = false - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - val biometricCanAuthenticate = BiometricUnlockDatabaseHelper.canAuthenticate(activity) - biometricUnlockSupported = biometricCanAuthenticate == BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED - || biometricCanAuthenticate == BiometricManager.BIOMETRIC_SUCCESS - } + val biometricUnlockSupported = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + BiometricUnlockDatabaseHelper.unlockSupported(activity) + } else false if (!biometricUnlockSupported) { // False if under Marshmallow biometricUnlockEnablePreference?.apply { @@ -227,10 +225,6 @@ class NestedAppSettingsFragment : NestedSettingsFragment() { false } } - } - - val deleteKeysFingerprints: Preference? = findPreference(getString(R.string.biometric_delete_all_key_key)) - if (!biometricUnlockSupported) { deleteKeysFingerprints?.isEnabled = false } else { deleteKeysFingerprints?.setOnPreferenceClickListener { From 9173bcc742345f047970cb1495e12f5bba200386 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Thu, 8 Oct 2020 23:17:36 +0200 Subject: [PATCH 4/4] Fix biometric authentication when weak security is not present --- .../keepass/biometric/BiometricUnlockDatabaseHelper.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/kunzisoft/keepass/biometric/BiometricUnlockDatabaseHelper.kt b/app/src/main/java/com/kunzisoft/keepass/biometric/BiometricUnlockDatabaseHelper.kt index a45b2711d..797783669 100644 --- a/app/src/main/java/com/kunzisoft/keepass/biometric/BiometricUnlockDatabaseHelper.kt +++ b/app/src/main/java/com/kunzisoft/keepass/biometric/BiometricUnlockDatabaseHelper.kt @@ -305,7 +305,7 @@ class BiometricUnlockDatabaseHelper(private val context: FragmentActivity) { BiometricManager.from(context).canAuthenticate(BIOMETRIC_WEAK) } catch (e: Exception) { Log.e(TAG, "Unable to authenticate with weak biometric.", e) - BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE + BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE } } }