mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Better fingerprint version code
This commit is contained in:
@@ -154,7 +154,7 @@ class PasswordActivity : StylishActivity(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Init FingerPrint elements
|
// Init FingerPrint elements
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (PreferencesUtil.isFingerprintEnable(this) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
fingerPrintInfoView = findViewById(R.id.fingerprint_info)
|
fingerPrintInfoView = findViewById(R.id.fingerprint_info)
|
||||||
fingerPrintViewsManager = FingerPrintViewsManager(this,
|
fingerPrintViewsManager = FingerPrintViewsManager(this,
|
||||||
mDatabaseFileUri,
|
mDatabaseFileUri,
|
||||||
@@ -205,10 +205,11 @@ class PasswordActivity : StylishActivity(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
fingerPrintViewsManager?.initFingerprint()
|
if (PreferencesUtil.isFingerprintEnable(this)) {
|
||||||
|
fingerPrintViewsManager?.initFingerprint()
|
||||||
// Start the animation in all cases
|
} else {
|
||||||
fingerPrintInfoView?.startFingerPrintAnimation()
|
fingerPrintViewsManager?.destroy()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
checkboxPasswordView?.setOnCheckedChangeListener(enableButtonOnCheckedChangeListener)
|
checkboxPasswordView?.setOnCheckedChangeListener(enableButtonOnCheckedChangeListener)
|
||||||
}
|
}
|
||||||
@@ -326,12 +327,18 @@ class PasswordActivity : StylishActivity(),
|
|||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
fingerPrintInfoView?.stopFingerPrintAnimation()
|
fingerPrintViewsManager?.stopListening()
|
||||||
fingerPrintViewsManager?.pause()
|
|
||||||
}
|
}
|
||||||
super.onPause()
|
super.onPause()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
fingerPrintViewsManager?.destroy()
|
||||||
|
}
|
||||||
|
super.onDestroy()
|
||||||
|
}
|
||||||
|
|
||||||
private fun verifyCheckboxesAndLoadDatabase(password: String? = passwordView?.text?.toString(),
|
private fun verifyCheckboxesAndLoadDatabase(password: String? = passwordView?.text?.toString(),
|
||||||
keyFile: Uri? = UriUtil.parseUriFile(keyFileView?.text?.toString())) {
|
keyFile: Uri? = UriUtil.parseUriFile(keyFileView?.text?.toString())) {
|
||||||
val keyPassword = if (checkboxPasswordView?.isChecked != true) null else password
|
val keyPassword = if (checkboxPasswordView?.isChecked != true) null else password
|
||||||
@@ -440,8 +447,10 @@ class PasswordActivity : StylishActivity(),
|
|||||||
|
|
||||||
MenuUtil.defaultMenuInflater(inflater, menu)
|
MenuUtil.defaultMenuInflater(inflater, menu)
|
||||||
|
|
||||||
// Fingerprint menu
|
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
fingerPrintViewsManager?.inflateOptionsMenu(inflater, menu)
|
// Fingerprint menu
|
||||||
|
fingerPrintViewsManager?.inflateOptionsMenu(inflater, menu)
|
||||||
|
}
|
||||||
|
|
||||||
super.onCreateOptionsMenu(menu)
|
super.onCreateOptionsMenu(menu)
|
||||||
|
|
||||||
@@ -604,10 +613,10 @@ class PasswordActivity : StylishActivity(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* -------------------------
|
* -------------------------
|
||||||
* Standard Launch
|
* Standard Launch
|
||||||
* -------------------------
|
* -------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Throws(FileNotFoundException::class)
|
@Throws(FileNotFoundException::class)
|
||||||
fun launch(
|
fun launch(
|
||||||
@@ -619,10 +628,10 @@ class PasswordActivity : StylishActivity(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* -------------------------
|
* -------------------------
|
||||||
* Keyboard Launch
|
* Keyboard Launch
|
||||||
* -------------------------
|
* -------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Throws(FileNotFoundException::class)
|
@Throws(FileNotFoundException::class)
|
||||||
fun launchForKeyboardResult(
|
fun launchForKeyboardResult(
|
||||||
@@ -637,10 +646,10 @@ class PasswordActivity : StylishActivity(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* -------------------------
|
* -------------------------
|
||||||
* Autofill Launch
|
* Autofill Launch
|
||||||
* -------------------------
|
* -------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||||
@Throws(FileNotFoundException::class)
|
@Throws(FileNotFoundException::class)
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ class FingerPrintHelper(context: Context, private val fingerPrintCallback: Finge
|
|||||||
|
|
||||||
if (!isFingerprintSupported(fingerprintManager)) {
|
if (!isFingerprintSupported(fingerprintManager)) {
|
||||||
// really not much to do when no fingerprint support found
|
// really not much to do when no fingerprint support found
|
||||||
setInitOk(false)
|
initOk = false
|
||||||
} else {
|
} else {
|
||||||
this.keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
this.keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
||||||
|
|
||||||
@@ -108,10 +108,10 @@ class FingerPrintHelper(context: Context, private val fingerPrintCallback: Finge
|
|||||||
+ KeyProperties.BLOCK_MODE_CBC + "/"
|
+ KeyProperties.BLOCK_MODE_CBC + "/"
|
||||||
+ KeyProperties.ENCRYPTION_PADDING_PKCS7)
|
+ KeyProperties.ENCRYPTION_PADDING_PKCS7)
|
||||||
this.cryptoObject = FingerprintManager.CryptoObject(cipher!!)
|
this.cryptoObject = FingerprintManager.CryptoObject(cipher!!)
|
||||||
setInitOk(true)
|
initOk = true
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Unable to initialize the keystore", e)
|
Log.e(TAG, "Unable to initialize the keystore", e)
|
||||||
setInitOk(false)
|
initOk = false
|
||||||
fingerPrintCallback?.onFingerPrintException(e)
|
fingerPrintCallback?.onFingerPrintException(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,10 +294,6 @@ class FingerPrintHelper(context: Context, private val fingerPrintCallback: Finge
|
|||||||
&& keyguardManager != null && keyguardManager!!.isKeyguardSecure)
|
&& keyguardManager != null && keyguardManager!!.isKeyguardSecure)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setInitOk(initOk: Boolean) {
|
|
||||||
this.initOk = initOk
|
|
||||||
}
|
|
||||||
|
|
||||||
interface FingerPrintErrorCallback {
|
interface FingerPrintErrorCallback {
|
||||||
fun onInvalidKeyException(e: Exception)
|
fun onInvalidKeyException(e: Exception)
|
||||||
fun onFingerPrintException(e: Exception)
|
fun onFingerPrintException(e: Exception)
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import com.kunzisoft.keepass.R
|
|||||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||||
import com.kunzisoft.keepass.view.FingerPrintInfoView
|
import com.kunzisoft.keepass.view.FingerPrintInfoView
|
||||||
|
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||||
class FingerPrintViewsManager(var context: AppCompatActivity,
|
class FingerPrintViewsManager(var context: AppCompatActivity,
|
||||||
var databaseFileUri: Uri?,
|
var databaseFileUri: Uri?,
|
||||||
var fingerPrintInfoView: FingerPrintInfoView?,
|
var fingerPrintInfoView: FingerPrintInfoView?,
|
||||||
@@ -44,7 +45,6 @@ class FingerPrintViewsManager(var context: AppCompatActivity,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fingerprint related code here
|
// fingerprint related code here
|
||||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
|
||||||
fun initFingerprint() {
|
fun initFingerprint() {
|
||||||
|
|
||||||
// Check if fingerprint well init (be called the first time the fingerprint is configured
|
// Check if fingerprint well init (be called the first time the fingerprint is configured
|
||||||
@@ -53,7 +53,8 @@ class FingerPrintViewsManager(var context: AppCompatActivity,
|
|||||||
|
|
||||||
fingerPrintMode = FingerPrintHelper.Mode.NOT_CONFIGURED_MODE
|
fingerPrintMode = FingerPrintHelper.Mode.NOT_CONFIGURED_MODE
|
||||||
|
|
||||||
fingerPrintHelper = FingerPrintHelper(context, this)
|
// Start the animation
|
||||||
|
fingerPrintInfoView?.startFingerPrintAnimation()
|
||||||
|
|
||||||
checkboxPasswordView?.setOnCheckedChangeListener { compoundButton, checked ->
|
checkboxPasswordView?.setOnCheckedChangeListener { compoundButton, checked ->
|
||||||
if (!fingerprintMustBeConfigured) {
|
if (!fingerprintMustBeConfigured) {
|
||||||
@@ -74,6 +75,7 @@ class FingerPrintViewsManager(var context: AppCompatActivity,
|
|||||||
onCheckedPasswordChangeListener?.onCheckedChanged(compoundButton, checked)
|
onCheckedPasswordChangeListener?.onCheckedChanged(compoundButton, checked)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fingerPrintHelper = FingerPrintHelper(context, this)
|
||||||
// callback for fingerprint findings
|
// callback for fingerprint findings
|
||||||
fingerPrintHelper?.setAuthenticationCallback(object : FingerprintManager.AuthenticationCallback() {
|
fingerPrintHelper?.setAuthenticationCallback(object : FingerprintManager.AuthenticationCallback() {
|
||||||
override fun onAuthenticationError(
|
override fun onAuthenticationError(
|
||||||
@@ -114,22 +116,20 @@ class FingerPrintViewsManager(var context: AppCompatActivity,
|
|||||||
fingerPrintHelper?.decryptData(it)
|
fingerPrintHelper?.decryptData(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FingerPrintHelper.Mode.NOT_CONFIGURED_MODE -> TODO()
|
FingerPrintHelper.Mode.NOT_CONFIGURED_MODE -> {}
|
||||||
FingerPrintHelper.Mode.WAITING_PASSWORD_MODE -> TODO()
|
FingerPrintHelper.Mode.WAITING_PASSWORD_MODE -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
|
||||||
private fun initEncryptData() {
|
private fun initEncryptData() {
|
||||||
setFingerPrintView(R.string.store_with_fingerprint)
|
setFingerPrintView(R.string.store_with_fingerprint)
|
||||||
fingerPrintMode = FingerPrintHelper.Mode.STORE_MODE
|
fingerPrintMode = FingerPrintHelper.Mode.STORE_MODE
|
||||||
fingerPrintHelper?.initEncryptData()
|
fingerPrintHelper?.initEncryptData()
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
|
||||||
private fun initDecryptData() {
|
private fun initDecryptData() {
|
||||||
setFingerPrintView(R.string.scanning_fingerprint)
|
setFingerPrintView(R.string.scanning_fingerprint)
|
||||||
fingerPrintMode = FingerPrintHelper.Mode.OPEN_MODE
|
fingerPrintMode = FingerPrintHelper.Mode.OPEN_MODE
|
||||||
@@ -140,13 +140,11 @@ class FingerPrintViewsManager(var context: AppCompatActivity,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
|
||||||
private fun initWaitData() {
|
private fun initWaitData() {
|
||||||
setFingerPrintView(R.string.no_password_stored, true)
|
setFingerPrintView(R.string.no_password_stored, true)
|
||||||
fingerPrintMode = FingerPrintHelper.Mode.WAITING_PASSWORD_MODE
|
fingerPrintMode = FingerPrintHelper.Mode.WAITING_PASSWORD_MODE
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun toggleFingerprintMode(newMode: FingerPrintHelper.Mode) {
|
private fun toggleFingerprintMode(newMode: FingerPrintHelper.Mode) {
|
||||||
when (newMode) {
|
when (newMode) {
|
||||||
@@ -161,7 +159,6 @@ class FingerPrintViewsManager(var context: AppCompatActivity,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun reInitWithFingerprintMode() {
|
fun reInitWithFingerprintMode() {
|
||||||
when (fingerPrintMode) {
|
when (fingerPrintMode) {
|
||||||
@@ -174,13 +171,18 @@ class FingerPrintViewsManager(var context: AppCompatActivity,
|
|||||||
context.invalidateOptionsMenu()
|
context.invalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
fun stopListening() {
|
||||||
fun pause() {
|
|
||||||
// stop listening when we go in background
|
// stop listening when we go in background
|
||||||
|
fingerPrintInfoView?.stopFingerPrintAnimation()
|
||||||
fingerPrintMode = FingerPrintHelper.Mode.NOT_CONFIGURED_MODE
|
fingerPrintMode = FingerPrintHelper.Mode.NOT_CONFIGURED_MODE
|
||||||
fingerPrintHelper?.stopListening()
|
fingerPrintHelper?.stopListening()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun destroy() {
|
||||||
|
stopListening()
|
||||||
|
// TODO destroy
|
||||||
|
}
|
||||||
|
|
||||||
fun inflateOptionsMenu(menuInflater: MenuInflater, menu: Menu) {
|
fun inflateOptionsMenu(menuInflater: MenuInflater, menu: Menu) {
|
||||||
if (!fingerprintMustBeConfigured && prefsNoBackup?.contains(preferenceKeyValue) == true)
|
if (!fingerprintMustBeConfigured && prefsNoBackup?.contains(preferenceKeyValue) == true)
|
||||||
menuInflater.inflate(R.menu.fingerprint, menu)
|
menuInflater.inflate(R.menu.fingerprint, menu)
|
||||||
@@ -202,7 +204,6 @@ class FingerPrintViewsManager(var context: AppCompatActivity,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun checkFingerprintAvailability() {
|
fun checkFingerprintAvailability() {
|
||||||
// fingerprint not supported (by API level or hardware) so keep option hidden
|
// fingerprint not supported (by API level or hardware) so keep option hidden
|
||||||
@@ -243,7 +244,6 @@ class FingerPrintViewsManager(var context: AppCompatActivity,
|
|||||||
context.invalidateOptionsMenu()
|
context.invalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun removePrefsNoBackupKey() {
|
private fun removePrefsNoBackupKey() {
|
||||||
prefsNoBackup?.edit()
|
prefsNoBackup?.edit()
|
||||||
?.remove(preferenceKeyValue)
|
?.remove(preferenceKeyValue)
|
||||||
@@ -267,13 +267,11 @@ class FingerPrintViewsManager(var context: AppCompatActivity,
|
|||||||
loadDatabase.invoke(value)
|
loadDatabase.invoke(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
|
||||||
override fun onInvalidKeyException(e: Exception) {
|
override fun onInvalidKeyException(e: Exception) {
|
||||||
showError(context.getString(R.string.fingerprint_invalid_key))
|
showError(context.getString(R.string.fingerprint_invalid_key))
|
||||||
deleteEntryKey()
|
deleteEntryKey()
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
|
||||||
override fun onFingerPrintException(e: Exception) {
|
override fun onFingerPrintException(e: Exception) {
|
||||||
// Don't show error here;
|
// Don't show error here;
|
||||||
// showError(getString(R.string.fingerprint_error, e.getMessage()));
|
// showError(getString(R.string.fingerprint_error, e.getMessage()));
|
||||||
@@ -281,12 +279,13 @@ class FingerPrintViewsManager(var context: AppCompatActivity,
|
|||||||
setFingerPrintView(e.localizedMessage, true)
|
setFingerPrintView(e.localizedMessage, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
|
||||||
fun deleteEntryKey() {
|
fun deleteEntryKey() {
|
||||||
fingerPrintHelper?.deleteEntryKey()
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
removePrefsNoBackupKey()
|
fingerPrintHelper?.deleteEntryKey()
|
||||||
fingerPrintMode = FingerPrintHelper.Mode.NOT_CONFIGURED_MODE
|
removePrefsNoBackupKey()
|
||||||
checkFingerprintAvailability()
|
fingerPrintMode = FingerPrintHelper.Mode.NOT_CONFIGURED_MODE
|
||||||
|
checkFingerprintAvailability()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showError(messageId: Int) {
|
private fun showError(messageId: Int) {
|
||||||
|
|||||||
Reference in New Issue
Block a user