mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 06:09:55 +01:00
Remove redundant locking.
This commit is contained in:
@@ -35,15 +35,14 @@ class AndroidAccountManager extends AccountManagerImpl
|
|||||||
appContext = app.getApplicationContext();
|
appContext = app.getApplicationContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Locking: stateChangeLock
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
protected String loadEncryptedDatabaseKey() {
|
protected String loadEncryptedDatabaseKey() {
|
||||||
synchronized (stateChangeLock) {
|
String key = getDatabaseKeyFromPreferences();
|
||||||
String key = getDatabaseKeyFromPreferences();
|
if (key == null) key = super.loadEncryptedDatabaseKey();
|
||||||
if (key == null) key = super.loadEncryptedDatabaseKey();
|
else migrateDatabaseKeyToFile(key);
|
||||||
else migrateDatabaseKeyToFile(key);
|
return key;
|
||||||
return key;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Locking: stateChangeLock
|
// Locking: stateChangeLock
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ class AccountManagerImpl implements AccountManager {
|
|||||||
private final CryptoComponent crypto;
|
private final CryptoComponent crypto;
|
||||||
private final File dbKeyFile, dbKeyBackupFile;
|
private final File dbKeyFile, dbKeyBackupFile;
|
||||||
|
|
||||||
protected final Object stateChangeLock = new Object();
|
final Object stateChangeLock = new Object();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private volatile SecretKey databaseKey = null;
|
private volatile SecretKey databaseKey = null;
|
||||||
@@ -63,20 +63,19 @@ class AccountManagerImpl implements AccountManager {
|
|||||||
return databaseKey;
|
return databaseKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Locking: stateChangeLock
|
||||||
@Nullable
|
@Nullable
|
||||||
protected String loadEncryptedDatabaseKey() {
|
protected String loadEncryptedDatabaseKey() {
|
||||||
synchronized (stateChangeLock) {
|
String key = readDbKeyFromFile(dbKeyFile);
|
||||||
String key = readDbKeyFromFile(dbKeyFile);
|
if (key == null) {
|
||||||
if (key == null) {
|
LOG.info("No database key in primary file");
|
||||||
LOG.info("No database key in primary file");
|
key = readDbKeyFromFile(dbKeyBackupFile);
|
||||||
key = readDbKeyFromFile(dbKeyBackupFile);
|
if (key == null) LOG.info("No database key in backup file");
|
||||||
if (key == null) LOG.info("No database key in backup file");
|
else LOG.warning("Found database key in backup file");
|
||||||
else LOG.warning("Found database key in backup file");
|
} else {
|
||||||
} else {
|
LOG.info("Found database key in primary file");
|
||||||
LOG.info("Found database key in primary file");
|
|
||||||
}
|
|
||||||
return key;
|
|
||||||
}
|
}
|
||||||
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Locking: stateChangeLock
|
// Locking: stateChangeLock
|
||||||
|
|||||||
@@ -63,7 +63,8 @@ public class AccountManagerImplTest extends BrambleMockTestCase {
|
|||||||
assertFalse(keyBackupFile.exists());
|
assertFalse(keyBackupFile.exists());
|
||||||
assertEquals(encryptedKeyHex, loadDatabaseKey(keyFile));
|
assertEquals(encryptedKeyHex, loadDatabaseKey(keyFile));
|
||||||
|
|
||||||
assertEquals(encryptedKeyHex, accountManager.loadEncryptedDatabaseKey());
|
assertEquals(encryptedKeyHex,
|
||||||
|
accountManager.loadEncryptedDatabaseKey());
|
||||||
|
|
||||||
assertTrue(keyFile.exists());
|
assertTrue(keyFile.exists());
|
||||||
assertFalse(keyBackupFile.exists());
|
assertFalse(keyBackupFile.exists());
|
||||||
@@ -81,7 +82,8 @@ public class AccountManagerImplTest extends BrambleMockTestCase {
|
|||||||
assertTrue(keyBackupFile.exists());
|
assertTrue(keyBackupFile.exists());
|
||||||
assertEquals(encryptedKeyHex, loadDatabaseKey(keyBackupFile));
|
assertEquals(encryptedKeyHex, loadDatabaseKey(keyBackupFile));
|
||||||
|
|
||||||
assertEquals(encryptedKeyHex, accountManager.loadEncryptedDatabaseKey());
|
assertEquals(encryptedKeyHex,
|
||||||
|
accountManager.loadEncryptedDatabaseKey());
|
||||||
|
|
||||||
assertFalse(keyFile.exists());
|
assertFalse(keyFile.exists());
|
||||||
assertTrue(keyBackupFile.exists());
|
assertTrue(keyBackupFile.exists());
|
||||||
|
|||||||
Reference in New Issue
Block a user