Fix fingerprint checkbox behavior

This commit is contained in:
Matéo Duparc 2021-10-19 13:52:06 +02:00
parent b273fa828b
commit 6158b36c9f
Signed by: hardcoresushi
GPG Key ID: 007F84120107191E
4 changed files with 13 additions and 11 deletions

View File

@ -53,7 +53,7 @@ class ChangePasswordActivity : VolumeActionActivity() {
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
if (volumeDatabase.isVolumeSaved(s.toString())){
checkboxRememberPath.isEnabled = false
checkboxRememberPath.isChecked = false
checkboxRememberPath.isChecked = true
binding.editOldPassword.apply {
if (volumeDatabase.isHashSaved(s.toString())){
text = null

View File

@ -25,7 +25,7 @@ class CreateActivity : VolumeActionActivity() {
binding = ActivityCreateBinding.inflate(layoutInflater)
setContentView(binding.root)
setupLayout()
setupFingerprintStuff()
setupFingerprintStuff(mayDecrypt = false)
binding.editPasswordConfirm.setOnEditorActionListener { _, _, _ ->
createVolume()
true

View File

@ -73,10 +73,10 @@ class OpenActivity : VolumeActionActivity() {
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
if (volumeDatabase.isVolumeSaved(s.toString())){
checkboxRememberPath.isEnabled = false
checkboxRememberPath.isChecked = false
checkboxRememberPath.isChecked = true
if (volumeDatabase.isHashSaved(s.toString())){
checkboxSavePassword.isEnabled = false
checkboxSavePassword.isChecked = false
checkboxSavePassword.isChecked = true
} else {
checkboxSavePassword.isEnabled = true
}
@ -164,7 +164,7 @@ class OpenActivity : VolumeActionActivity() {
override fun doTask(activity: AppCompatActivity) {
val password = binding.editPassword.text.toString().toCharArray()
var returnedHash: ByteArray? = null
if (checkboxSavePassword.isChecked){
if (checkboxSavePassword.isChecked && usf_fingerprint) {
returnedHash = ByteArray(GocryptfsVolume.KeyLen)
}
sessionID = GocryptfsVolume.init(currentVolumePath, password, null, returnedHash)

View File

@ -43,7 +43,7 @@ abstract class VolumeActionActivity : BaseActivity() {
onDirectoryPicked(uri)
}
}
private var usf_fingerprint = false
protected var usf_fingerprint = false
private var biometricCanAuthenticateCode: Int = -1
private lateinit var biometricManager: BiometricManager
private lateinit var biometricPrompt: BiometricPrompt
@ -98,7 +98,7 @@ abstract class VolumeActionActivity : BaseActivity() {
checkboxSavePassword.setOnClickListener {
if (checkboxSavePassword.isChecked) {
if (biometricCanAuthenticateCode == 0) {
checkboxRememberPath.isChecked = checkboxRememberPath.isEnabled
checkboxRememberPath.isChecked = true
} else {
checkboxSavePassword.isChecked = false
printAuthenticateImpossibleError()
@ -151,13 +151,17 @@ abstract class VolumeActionActivity : BaseActivity() {
}
}
protected fun setupFingerprintStuff(){
protected fun setupFingerprintStuff(mayDecrypt: Boolean = true) {
originalHiddenVolumeSectionLayoutParams = hiddenVolumeSection.layoutParams as LinearLayout.LayoutParams
originalNormalVolumeSectionLayoutParams = normalVolumeSection.layoutParams as LinearLayout.LayoutParams
WidgetUtil.hide(hiddenVolumeSection)
volumeDatabase = VolumeDatabase(this)
usf_fingerprint = sharedPrefs.getBoolean("usf_fingerprint", false)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && usf_fingerprint) {
val marshmallow = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
if (!marshmallow || !usf_fingerprint) {
WidgetUtil.hideWithPadding(checkboxSavePassword)
}
if (marshmallow && (mayDecrypt || usf_fingerprint)) {
biometricManager = BiometricManager.from(this)
biometricCanAuthenticateCode = canAuthenticate()
if (biometricCanAuthenticateCode == 0){
@ -225,8 +229,6 @@ abstract class VolumeActionActivity : BaseActivity() {
}
biometricPrompt = BiometricPrompt(this, executor, callback)
}
} else {
WidgetUtil.hideWithPadding(checkboxSavePassword)
}
}