Small enhancements

This commit is contained in:
J-Jamet
2019-09-02 14:04:05 +02:00
parent adcc1c745a
commit 027d581dcc
9 changed files with 36 additions and 52 deletions

View File

@@ -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 {

View File

@@ -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

View File

@@ -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)

View File

@@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/circle"
/>
<item
android:drawable="@drawable/ic_lock_open_white_24dp"
android:bottom="12dp"
android:left="12dp"
android:right="12dp"
android:top="12dp"/>
</layer-list>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="@color/white"
tools:targetApi="lollipop">
<item>
<shape
android:shape="oval">
<solid android:color="?attr/colorAccent"/>
</shape>
</item>
</ripple>

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="@color/green"/>
</shape>

View File

@@ -20,6 +20,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:orientation="horizontal">
<TextView
android:layout_width="20dp"
@@ -103,8 +104,7 @@
android:layout_height="48dp"
android:elevation="4dp"
android:src="@drawable/fingerprint"
android:background="@drawable/circle"
android:backgroundTint="?attr/colorAccent"
android:background="@drawable/background_image"
tools:targetApi="lollipop" />
</LinearLayout>
@@ -130,6 +130,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
style="@style/KeepassDXStyle.TextAppearance.Title"
android:text="@string/usage" />
@@ -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" />
</LinearLayout>

View File

@@ -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" />
</RelativeLayout>