biometric update
This commit is contained in:
parent
a2702fbc12
commit
c8dd373c37
3 changed files with 24 additions and 24 deletions
|
@ -7,7 +7,7 @@ android {
|
||||||
compileSdkVersion 28
|
compileSdkVersion 28
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
minSdkVersion 24
|
minSdkVersion 26
|
||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.0"
|
versionName "1.0"
|
||||||
|
|
|
@ -10,7 +10,7 @@ dependencies {
|
||||||
api 'androidx.legacy:legacy-support-v4:1.0.0'
|
api 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||||
api "androidx.appcompat:appcompat:$appcompat_verison"
|
api "androidx.appcompat:appcompat:$appcompat_verison"
|
||||||
api "androidx.preference:preference-ktx:$preferencektx_version"
|
api "androidx.preference:preference-ktx:$preferencektx_version"
|
||||||
api 'androidx.biometric:biometric:1.0.1'
|
api 'androidx.biometric:biometric:1.1.0'
|
||||||
api "androidx.browser:browser:1.3.0"
|
api "androidx.browser:browser:1.3.0"
|
||||||
api "androidx.activity:activity-ktx:${activityVersion}"
|
api "androidx.activity:activity-ktx:${activityVersion}"
|
||||||
api "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"
|
api "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package info.nightscout.androidaps.utils.protection
|
package info.nightscout.androidaps.utils.protection
|
||||||
|
|
||||||
import androidx.biometric.BiometricConstants
|
|
||||||
import androidx.biometric.BiometricPrompt
|
import androidx.biometric.BiometricPrompt
|
||||||
|
import androidx.biometric.BiometricPrompt.*
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import info.nightscout.androidaps.core.R
|
import info.nightscout.androidaps.core.R
|
||||||
import info.nightscout.androidaps.utils.ToastUtils
|
import info.nightscout.androidaps.utils.ToastUtils
|
||||||
|
@ -16,43 +16,43 @@ object BiometricCheck {
|
||||||
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
|
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
|
||||||
super.onAuthenticationError(errorCode, errString)
|
super.onAuthenticationError(errorCode, errString)
|
||||||
when (errorCode) {
|
when (errorCode) {
|
||||||
BiometricConstants.ERROR_UNABLE_TO_PROCESS,
|
ERROR_UNABLE_TO_PROCESS,
|
||||||
BiometricConstants.ERROR_TIMEOUT,
|
ERROR_TIMEOUT,
|
||||||
BiometricConstants.ERROR_CANCELED,
|
ERROR_CANCELED,
|
||||||
BiometricConstants.ERROR_LOCKOUT,
|
ERROR_LOCKOUT,
|
||||||
BiometricConstants.ERROR_VENDOR,
|
ERROR_VENDOR,
|
||||||
BiometricConstants.ERROR_LOCKOUT_PERMANENT,
|
ERROR_LOCKOUT_PERMANENT,
|
||||||
BiometricConstants.ERROR_USER_CANCELED -> {
|
ERROR_USER_CANCELED -> {
|
||||||
ToastUtils.showToastInUiThread(activity.baseContext, errString.toString())
|
ToastUtils.showToastInUiThread(activity.baseContext, errString.toString())
|
||||||
// fallback to master password
|
// fallback to master password
|
||||||
runOnUiThread(Runnable {
|
runOnUiThread {
|
||||||
passwordCheck.queryPassword(activity, R.string.master_password, R.string.key_master_password, { ok?.run() }, { cancel?.run() }, { fail?.run() })
|
passwordCheck.queryPassword(activity, R.string.master_password, R.string.key_master_password, { ok?.run() }, { cancel?.run() }, { fail?.run() })
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BiometricConstants.ERROR_NEGATIVE_BUTTON ->
|
ERROR_NEGATIVE_BUTTON ->
|
||||||
cancel?.run()
|
cancel?.run()
|
||||||
|
|
||||||
BiometricConstants.ERROR_NO_DEVICE_CREDENTIAL -> {
|
ERROR_NO_DEVICE_CREDENTIAL -> {
|
||||||
ToastUtils.showToastInUiThread(activity.baseContext, errString.toString())
|
ToastUtils.showToastInUiThread(activity.baseContext, errString.toString())
|
||||||
// no pin set
|
// no pin set
|
||||||
// fallback to master password
|
// fallback to master password
|
||||||
runOnUiThread(Runnable {
|
runOnUiThread {
|
||||||
passwordCheck.queryPassword(activity, R.string.master_password, R.string.key_master_password, { ok?.run() }, { cancel?.run() }, { fail?.run() })
|
passwordCheck.queryPassword(activity, R.string.master_password, R.string.key_master_password, { ok?.run() }, { cancel?.run() }, { fail?.run() })
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BiometricConstants.ERROR_NO_SPACE,
|
ERROR_NO_SPACE,
|
||||||
BiometricConstants.ERROR_HW_UNAVAILABLE,
|
ERROR_HW_UNAVAILABLE,
|
||||||
BiometricConstants.ERROR_HW_NOT_PRESENT,
|
ERROR_HW_NOT_PRESENT,
|
||||||
BiometricConstants.ERROR_NO_BIOMETRICS ->
|
ERROR_NO_BIOMETRICS ->
|
||||||
runOnUiThread(Runnable {
|
runOnUiThread {
|
||||||
passwordCheck.queryPassword(activity, R.string.master_password, R.string.key_master_password, { ok?.run() }, { cancel?.run() }, { fail?.run() })
|
passwordCheck.queryPassword(activity, R.string.master_password, R.string.key_master_password, { ok?.run() }, { cancel?.run() }, { fail?.run() })
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
|
override fun onAuthenticationSucceeded(result: AuthenticationResult) {
|
||||||
super.onAuthenticationSucceeded(result)
|
super.onAuthenticationSucceeded(result)
|
||||||
// Called when a biometric is recognized.
|
// Called when a biometric is recognized.
|
||||||
ok?.run()
|
ok?.run()
|
||||||
|
@ -65,7 +65,7 @@ object BiometricCheck {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
val promptInfo = BiometricPrompt.PromptInfo.Builder()
|
val promptInfo = PromptInfo.Builder()
|
||||||
.setTitle(activity.getString(title))
|
.setTitle(activity.getString(title))
|
||||||
.setDescription(activity.getString(R.string.biometric_title))
|
.setDescription(activity.getString(R.string.biometric_title))
|
||||||
.setNegativeButtonText(activity.getString(R.string.cancel)) // not possible with setDeviceCredentialAllowed
|
.setNegativeButtonText(activity.getString(R.string.cancel)) // not possible with setDeviceCredentialAllowed
|
||||||
|
|
Loading…
Add table
Reference in a new issue