fixed TODO tags

no runtime permission needed
fixed api level checks
added info when no password found in preferences and doesn't start listening unless input entered (for encryption)
This commit is contained in:
Hans Cappelle
2017-10-07 08:31:38 +02:00
parent 8ecdb5bbfd
commit 8e353b8172
3 changed files with 22 additions and 14 deletions

View File

@@ -19,6 +19,7 @@
*/
package com.keepassdroid;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
@@ -192,7 +193,11 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
prefs = PreferenceManager.getDefaultSharedPreferences(this);
mRememberKeyfile = prefs.getBoolean(getString(R.string.keyfile_key), getResources().getBoolean(R.bool.keyfile_default));
setContentView(R.layout.password);
confirmButton = (Button) findViewById(R.id.pass_ok);
fingerprintView = findViewById(R.id.fingerprint);
confirmationView = (TextView) findViewById(R.id.fingerprint_label);
passwordView = (EditText) findViewById(R.id.password);
new InitTask().execute(i);
@@ -256,13 +261,8 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
// fingerprint related code here
private void initForFingerprint() {
// TODO implement runtime permissions needed here?
// TODO double check on lower API levels
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (fingerPrintHelper.isFingerprintSupported()) {
fingerPrintHelper = new FingerPrintHelper(this, this);
fingerprintView = findViewById(R.id.fingerprint);
confirmationView = (TextView) findViewById(R.id.fingerprint_label);
passwordView = (EditText) findViewById(R.id.password);
// when text entered we can enable the logon/purchase button and if required update encryption/decryption mode
passwordView.addTextChangedListener(new TextWatcher() {
@@ -323,6 +323,7 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
if (mode == Cipher.ENCRYPT_MODE) {
// newly store the entered password in encrypted way
final String password = passwordView.getText().toString();
fingerPrintHelper.encryptData(password);
@@ -345,8 +346,8 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
}
private String getPreferenceKey() {
// TODO improve unique key per database generation, using complete path should be unique and seems to work
return PREF_KEY_PREFIX + mDbUri != null ? mDbUri.getPath() : "";//mDbUri.getLastPathSegment();
// makes it possible to store passwords uniqly per database
return PREF_KEY_PREFIX + mDbUri != null ? mDbUri.getPath() : "";
}
private int toggleMode(final int newMode) {
@@ -397,10 +398,18 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
fingerprintView.setAlpha(1f);
}
// fingerprint available but no stored password found yet for this DB so show info don't listen
if (prefs.getString(getPreferenceKey(), null) == null) {
confirmationView.setText(R.string.no_password_stored);
}
// all is set here so we can confirm to user and start listening for fingerprints
confirmationView.setText(R.string.scanning_fingerprint);
// listen for decryption by default
toggleMode(Cipher.DECRYPT_MODE);
else {
confirmationView.setText(R.string.scanning_fingerprint);
// listen for decryption by default
toggleMode(Cipher.DECRYPT_MODE);
}
}
}

View File

@@ -24,8 +24,6 @@ import javax.crypto.spec.IvParameterSpec;
public class FingerPrintHelper {
private int MINIMAL_REQUIRED_SDK_VERSION = Build.VERSION_CODES.M;
private static final String ALIAS_KEY = "example-key";
private static final String IV_FILE = "iv-file";
@@ -310,7 +308,7 @@ public class FingerPrintHelper {
}
public boolean isFingerprintSupported() {
return Build.VERSION.SDK_INT >= MINIMAL_REQUIRED_SDK_VERSION;
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
}
}

View File

@@ -200,6 +200,7 @@
<string name="fingerprint_invalid_key">Invalid Key problem</string>
<string name="fingerprint_error">Fingerprint problem</string>
<string name="store_with_fingerprint">Use fingerprint to store this password</string>
<string name="no_password_stored">No password stored yet for this database</string>
<string-array name="clipboard_timeout_options">
<item>30 seconds</item>