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 untrusted user: 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) { override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
if (volumeDatabase.isVolumeSaved(s.toString())){ if (volumeDatabase.isVolumeSaved(s.toString())){
checkboxRememberPath.isEnabled = false checkboxRememberPath.isEnabled = false
checkboxRememberPath.isChecked = false checkboxRememberPath.isChecked = true
binding.editOldPassword.apply { binding.editOldPassword.apply {
if (volumeDatabase.isHashSaved(s.toString())){ if (volumeDatabase.isHashSaved(s.toString())){
text = null text = null

View File

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

View File

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

View File

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