mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Use constructor injection for controllers.
Also made some listeners volatile.
This commit is contained in:
@@ -6,6 +6,8 @@ public interface ConfigController {
|
||||
|
||||
String getEncryptedDatabaseKey();
|
||||
|
||||
void setEncryptedDatabaseKey(String hex);
|
||||
|
||||
void deleteAccount(Context ctx);
|
||||
|
||||
boolean accountExists();
|
||||
|
||||
@@ -12,13 +12,14 @@ public class ConfigControllerImpl implements ConfigController {
|
||||
|
||||
private static final String PREF_DB_KEY = "key";
|
||||
|
||||
@Inject
|
||||
protected SharedPreferences briarPrefs;
|
||||
@Inject
|
||||
protected volatile DatabaseConfig databaseConfig;
|
||||
private final SharedPreferences briarPrefs;
|
||||
protected final DatabaseConfig databaseConfig;
|
||||
|
||||
@Inject
|
||||
public ConfigControllerImpl() {
|
||||
ConfigControllerImpl(SharedPreferences briarPrefs,
|
||||
DatabaseConfig databaseConfig) {
|
||||
this.briarPrefs = briarPrefs;
|
||||
this.databaseConfig = databaseConfig;
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +28,13 @@ public class ConfigControllerImpl implements ConfigController {
|
||||
return briarPrefs.getString(PREF_DB_KEY, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEncryptedDatabaseKey(String hex) {
|
||||
SharedPreferences.Editor editor = briarPrefs.edit();
|
||||
editor.putString(PREF_DB_KEY, hex);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAccount(Context ctx) {
|
||||
SharedPreferences.Editor editor = briarPrefs.edit();
|
||||
|
||||
@@ -13,16 +13,14 @@ public class DbControllerImpl implements DbController {
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(DbControllerImpl.class.getName());
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject
|
||||
@DatabaseExecutor
|
||||
protected volatile Executor dbExecutor;
|
||||
@Inject
|
||||
protected volatile LifecycleManager lifecycleManager;
|
||||
private final Executor dbExecutor;
|
||||
private final LifecycleManager lifecycleManager;
|
||||
|
||||
@Inject
|
||||
public DbControllerImpl() {
|
||||
|
||||
public DbControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
||||
LifecycleManager lifecycleManager) {
|
||||
this.dbExecutor = dbExecutor;
|
||||
this.lifecycleManager = lifecycleManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.app.Activity;
|
||||
import org.briarproject.android.api.ReferenceManager;
|
||||
import org.briarproject.android.controller.handler.ResultHandler;
|
||||
import org.briarproject.api.TransportId;
|
||||
import org.briarproject.api.db.DatabaseExecutor;
|
||||
import org.briarproject.api.db.DbException;
|
||||
import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
@@ -13,9 +14,11 @@ import org.briarproject.api.event.TransportDisabledEvent;
|
||||
import org.briarproject.api.event.TransportEnabledEvent;
|
||||
import org.briarproject.api.identity.IdentityManager;
|
||||
import org.briarproject.api.identity.LocalAuthor;
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.api.plugins.Plugin;
|
||||
import org.briarproject.api.plugins.PluginManager;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -29,22 +32,23 @@ public class NavDrawerControllerImpl extends DbControllerImpl
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(NavDrawerControllerImpl.class.getName());
|
||||
|
||||
@Inject
|
||||
ReferenceManager referenceManager;
|
||||
@Inject
|
||||
PluginManager pluginManager;
|
||||
@Inject
|
||||
EventBus eventBus;
|
||||
private final ReferenceManager referenceManager;
|
||||
private final PluginManager pluginManager;
|
||||
private final EventBus eventBus;
|
||||
private final IdentityManager identityManager;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject
|
||||
protected volatile IdentityManager identityManager;
|
||||
|
||||
private TransportStateListener listener;
|
||||
private volatile TransportStateListener listener;
|
||||
|
||||
@Inject
|
||||
public NavDrawerControllerImpl() {
|
||||
|
||||
NavDrawerControllerImpl(@DatabaseExecutor Executor dbExecutor,
|
||||
LifecycleManager lifecycleManager,
|
||||
ReferenceManager referenceManager, PluginManager pluginManager,
|
||||
EventBus eventBus, IdentityManager identityManager) {
|
||||
super(dbExecutor, lifecycleManager);
|
||||
this.referenceManager = referenceManager;
|
||||
this.pluginManager = pluginManager;
|
||||
this.eventBus = eventBus;
|
||||
this.identityManager = identityManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package org.briarproject.android.controller;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import org.briarproject.android.controller.handler.ResultHandler;
|
||||
import org.briarproject.api.crypto.CryptoComponent;
|
||||
import org.briarproject.api.crypto.CryptoExecutor;
|
||||
import org.briarproject.api.crypto.SecretKey;
|
||||
import org.briarproject.api.identity.LocalAuthor;
|
||||
import org.briarproject.api.db.DatabaseConfig;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -23,21 +22,16 @@ public class PasswordControllerImpl extends ConfigControllerImpl
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(PasswordControllerImpl.class.getName());
|
||||
|
||||
private final static String PREF_DB_KEY = "key";
|
||||
protected final Executor cryptoExecutor;
|
||||
protected final CryptoComponent crypto;
|
||||
|
||||
@Inject
|
||||
@CryptoExecutor
|
||||
protected Executor cryptoExecutor;
|
||||
@Inject
|
||||
protected Activity activity;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject
|
||||
protected CryptoComponent crypto;
|
||||
|
||||
@Inject
|
||||
public PasswordControllerImpl() {
|
||||
|
||||
PasswordControllerImpl(SharedPreferences briarPrefs,
|
||||
DatabaseConfig databaseConfig,
|
||||
@CryptoExecutor Executor cryptoExecutor, CryptoComponent crypto) {
|
||||
super(briarPrefs, databaseConfig);
|
||||
this.cryptoExecutor = cryptoExecutor;
|
||||
this.crypto = crypto;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,7 +65,7 @@ public class PasswordControllerImpl extends ConfigControllerImpl
|
||||
} else {
|
||||
String hex =
|
||||
encryptDatabaseKey(new SecretKey(key), newPassword);
|
||||
storeEncryptedDatabaseKey(hex);
|
||||
setEncryptedDatabaseKey(hex);
|
||||
resultHandler.onResult(true);
|
||||
}
|
||||
}
|
||||
@@ -94,10 +88,4 @@ public class PasswordControllerImpl extends ConfigControllerImpl
|
||||
LOG.info("Key derivation took " + duration + " ms");
|
||||
return StringUtils.toHexString(encrypted);
|
||||
}
|
||||
|
||||
void storeEncryptedDatabaseKey(String hex) {
|
||||
SharedPreferences.Editor editor = briarPrefs.edit();
|
||||
editor.putString(PREF_DB_KEY, hex);
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.briarproject.android.controller;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import org.briarproject.android.api.ReferenceManager;
|
||||
@@ -13,7 +12,6 @@ import org.briarproject.api.crypto.SecretKey;
|
||||
import org.briarproject.api.db.DatabaseConfig;
|
||||
import org.briarproject.api.identity.AuthorFactory;
|
||||
import org.briarproject.api.identity.LocalAuthor;
|
||||
import org.briarproject.util.StringUtils;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
@@ -28,17 +26,20 @@ public class SetupControllerImpl extends PasswordControllerImpl
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(SetupControllerImpl.class.getName());
|
||||
|
||||
@Inject
|
||||
protected PasswordStrengthEstimator strengthEstimator;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject
|
||||
protected volatile AuthorFactory authorFactory;
|
||||
@Inject
|
||||
protected volatile ReferenceManager referenceManager;
|
||||
private final PasswordStrengthEstimator strengthEstimator;
|
||||
private final AuthorFactory authorFactory;
|
||||
private final ReferenceManager referenceManager;
|
||||
|
||||
@Inject
|
||||
public SetupControllerImpl() {
|
||||
SetupControllerImpl(SharedPreferences briarPrefs,
|
||||
DatabaseConfig databaseConfig,
|
||||
@CryptoExecutor Executor cryptoExecutor, CryptoComponent crypto,
|
||||
PasswordStrengthEstimator strengthEstimator,
|
||||
AuthorFactory authorFactory, ReferenceManager referenceManager) {
|
||||
super(briarPrefs, databaseConfig, cryptoExecutor, crypto);
|
||||
this.strengthEstimator = strengthEstimator;
|
||||
this.authorFactory = authorFactory;
|
||||
this.referenceManager = referenceManager;
|
||||
|
||||
}
|
||||
|
||||
@@ -69,7 +70,7 @@ public class SetupControllerImpl extends PasswordControllerImpl
|
||||
SecretKey key = crypto.generateSecretKey();
|
||||
databaseConfig.setEncryptionKey(key);
|
||||
String hex = encryptDatabaseKey(key, password);
|
||||
storeEncryptedDatabaseKey(hex);
|
||||
setEncryptedDatabaseKey(hex);
|
||||
LocalAuthor localAuthor = createLocalAuthor(nickname);
|
||||
long handle = referenceManager.putReference(localAuthor,
|
||||
LocalAuthor.class);
|
||||
|
||||
Reference in New Issue
Block a user