Remove redundant locking.

This commit is contained in:
akwizgran
2018-07-27 14:18:31 +01:00
parent abaefacb69
commit adbfa26364
3 changed files with 20 additions and 20 deletions

View File

@@ -35,16 +35,15 @@ class AndroidAccountManager extends AccountManagerImpl
appContext = app.getApplicationContext();
}
// Locking: stateChangeLock
@Override
@Nullable
protected String loadEncryptedDatabaseKey() {
synchronized (stateChangeLock) {
String key = getDatabaseKeyFromPreferences();
if (key == null) key = super.loadEncryptedDatabaseKey();
else migrateDatabaseKeyToFile(key);
return key;
}
}
// Locking: stateChangeLock
@Nullable

View File

@@ -38,7 +38,7 @@ class AccountManagerImpl implements AccountManager {
private final CryptoComponent crypto;
private final File dbKeyFile, dbKeyBackupFile;
protected final Object stateChangeLock = new Object();
final Object stateChangeLock = new Object();
@Nullable
private volatile SecretKey databaseKey = null;
@@ -63,9 +63,9 @@ class AccountManagerImpl implements AccountManager {
return databaseKey;
}
// Locking: stateChangeLock
@Nullable
protected String loadEncryptedDatabaseKey() {
synchronized (stateChangeLock) {
String key = readDbKeyFromFile(dbKeyFile);
if (key == null) {
LOG.info("No database key in primary file");
@@ -77,7 +77,6 @@ class AccountManagerImpl implements AccountManager {
}
return key;
}
}
// Locking: stateChangeLock
@Nullable

View File

@@ -63,7 +63,8 @@ public class AccountManagerImplTest extends BrambleMockTestCase {
assertFalse(keyBackupFile.exists());
assertEquals(encryptedKeyHex, loadDatabaseKey(keyFile));
assertEquals(encryptedKeyHex, accountManager.loadEncryptedDatabaseKey());
assertEquals(encryptedKeyHex,
accountManager.loadEncryptedDatabaseKey());
assertTrue(keyFile.exists());
assertFalse(keyBackupFile.exists());
@@ -81,7 +82,8 @@ public class AccountManagerImplTest extends BrambleMockTestCase {
assertTrue(keyBackupFile.exists());
assertEquals(encryptedKeyHex, loadDatabaseKey(keyBackupFile));
assertEquals(encryptedKeyHex, accountManager.loadEncryptedDatabaseKey());
assertEquals(encryptedKeyHex,
accountManager.loadEncryptedDatabaseKey());
assertFalse(keyFile.exists());
assertTrue(keyBackupFile.exists());