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' 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..797783669 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_NO_HARDWARE } } } + 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 { 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_'