mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Move identity creation into AccountManager.
This commit is contained in:
@@ -5,6 +5,7 @@ import android.content.SharedPreferences;
|
||||
|
||||
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.Localizer;
|
||||
import org.briarproject.briar.android.util.UiUtils;
|
||||
@@ -15,8 +16,9 @@ class BriarAccountManager extends AndroidAccountManager {
|
||||
|
||||
@Inject
|
||||
BriarAccountManager(DatabaseConfig databaseConfig, CryptoComponent crypto,
|
||||
SharedPreferences prefs, Application app) {
|
||||
super(databaseConfig, crypto, prefs, app);
|
||||
IdentityManager identityManager, SharedPreferences prefs,
|
||||
Application app) {
|
||||
super(databaseConfig, crypto, identityManager, prefs, app);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,8 +4,6 @@ import android.support.annotation.Nullable;
|
||||
|
||||
import org.briarproject.bramble.api.account.AccountManager;
|
||||
import org.briarproject.bramble.api.crypto.PasswordStrengthEstimator;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.briar.android.controller.handler.ResultHandler;
|
||||
@@ -23,18 +21,14 @@ public class SetupControllerImpl extends PasswordControllerImpl
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(SetupControllerImpl.class.getName());
|
||||
|
||||
private final IdentityManager identityManager;
|
||||
|
||||
@Nullable
|
||||
private volatile SetupActivity setupActivity;
|
||||
|
||||
@Inject
|
||||
SetupControllerImpl(AccountManager accountManager,
|
||||
@IoExecutor Executor ioExecutor,
|
||||
PasswordStrengthEstimator strengthEstimator,
|
||||
IdentityManager identityManager) {
|
||||
PasswordStrengthEstimator strengthEstimator) {
|
||||
super(accountManager, ioExecutor, strengthEstimator);
|
||||
this.identityManager = identityManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,10 +98,8 @@ public class SetupControllerImpl extends PasswordControllerImpl
|
||||
if (password == null) throw new IllegalStateException();
|
||||
ioExecutor.execute(() -> {
|
||||
LOG.info("Creating account");
|
||||
LocalAuthor localAuthor =
|
||||
identityManager.createLocalAuthor(authorName);
|
||||
identityManager.registerLocalAuthor(localAuthor);
|
||||
resultHandler.onResult(accountManager.createAccount(password));
|
||||
resultHandler.onResult(accountManager.createAccount(authorName,
|
||||
password));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@ package org.briarproject.briar.android.login;
|
||||
|
||||
import org.briarproject.bramble.api.account.AccountManager;
|
||||
import org.briarproject.bramble.api.crypto.PasswordStrengthEstimator;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.test.BrambleMockTestCase;
|
||||
import org.briarproject.bramble.test.ImmediateExecutor;
|
||||
import org.jmock.Expectations;
|
||||
@@ -15,7 +13,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||
import static org.briarproject.bramble.test.TestUtils.getLocalAuthor;
|
||||
import static org.briarproject.bramble.util.StringUtils.getRandomString;
|
||||
|
||||
public class SetupControllerImplTest extends BrambleMockTestCase {
|
||||
@@ -24,15 +21,12 @@ public class SetupControllerImplTest extends BrambleMockTestCase {
|
||||
context.mock(AccountManager.class);
|
||||
private final PasswordStrengthEstimator estimator =
|
||||
context.mock(PasswordStrengthEstimator.class);
|
||||
private final IdentityManager identityManager =
|
||||
context.mock(IdentityManager.class);
|
||||
private final SetupActivity setupActivity;
|
||||
|
||||
private final Executor ioExecutor = new ImmediateExecutor();
|
||||
|
||||
private final String authorName = getRandomString(MAX_AUTHOR_NAME_LENGTH);
|
||||
private final String password = getRandomString(10);
|
||||
private final LocalAuthor localAuthor = getLocalAuthor();
|
||||
|
||||
public SetupControllerImplTest() {
|
||||
context.setImposteriser(ClassImposteriser.INSTANCE);
|
||||
@@ -51,17 +45,13 @@ public class SetupControllerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(authorName));
|
||||
oneOf(setupActivity).getPassword();
|
||||
will(returnValue(password));
|
||||
// Create and register the local author
|
||||
oneOf(identityManager).createLocalAuthor(authorName);
|
||||
will(returnValue(localAuthor));
|
||||
oneOf(identityManager).registerLocalAuthor(localAuthor);
|
||||
// Create the account
|
||||
oneOf(accountManager).createAccount(password);
|
||||
oneOf(accountManager).createAccount(authorName, password);
|
||||
will(returnValue(true));
|
||||
}});
|
||||
|
||||
SetupControllerImpl s = new SetupControllerImpl(accountManager,
|
||||
ioExecutor, estimator, identityManager);
|
||||
ioExecutor, estimator);
|
||||
s.setSetupActivity(setupActivity);
|
||||
|
||||
AtomicBoolean called = new AtomicBoolean(false);
|
||||
|
||||
Reference in New Issue
Block a user