mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 06:39:54 +01:00
WIP: FakeTestData proof-of-concept
This commit is contained in:
@@ -140,6 +140,9 @@ dependencies {
|
|||||||
androidTestAnnotationProcessor "com.google.dagger:dagger-compiler:2.0.2"
|
androidTestAnnotationProcessor "com.google.dagger:dagger-compiler:2.0.2"
|
||||||
androidTestCompileOnly 'javax.annotation:jsr250-api:1.0'
|
androidTestCompileOnly 'javax.annotation:jsr250-api:1.0'
|
||||||
androidTestImplementation 'junit:junit:4.12'
|
androidTestImplementation 'junit:junit:4.12'
|
||||||
|
|
||||||
|
androidTestScreenshotImplementation project(path: ':bramble-api', configuration: 'testOutput')
|
||||||
|
androidTestScreenshotImplementation project(path: ':bramble-core', configuration: 'testOutput')
|
||||||
androidTestScreenshotImplementation "tools.fastlane:screengrab:1.2.0"
|
androidTestScreenshotImplementation "tools.fastlane:screengrab:1.2.0"
|
||||||
androidTestScreenshotImplementation "com.android.support.test.uiautomator:uiautomator-v18:2.1.3"
|
androidTestScreenshotImplementation "com.android.support.test.uiautomator:uiautomator-v18:2.1.3"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,3 +28,5 @@
|
|||||||
|
|
||||||
# Emoji
|
# Emoji
|
||||||
-keep class com.vanniktech.emoji.**
|
-keep class com.vanniktech.emoji.**
|
||||||
|
|
||||||
|
-keepclasseswithmembers public class android.support.v7.widget.RecyclerView { *; }
|
||||||
|
|||||||
@@ -13,3 +13,4 @@
|
|||||||
-dontwarn junit.**
|
-dontwarn junit.**
|
||||||
|
|
||||||
-dontwarn org.briarproject.briar.android.**
|
-dontwarn org.briarproject.briar.android.**
|
||||||
|
-dontwarn org.briarproject.bramble.**
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public class BriarTestComponentApplication extends BriarApplicationImpl {
|
|||||||
@Override
|
@Override
|
||||||
protected AndroidComponent createApplicationComponent() {
|
protected AndroidComponent createApplicationComponent() {
|
||||||
AndroidComponent component = DaggerBriarUiTestComponent.builder()
|
AndroidComponent component = DaggerBriarUiTestComponent.builder()
|
||||||
.appModule(new AppModule(this)).build();
|
.testAppModule(new TestAppModule(this)).build();
|
||||||
// We need to load the eager singletons directly after making the
|
// We need to load the eager singletons directly after making the
|
||||||
// dependency graphs
|
// dependency graphs
|
||||||
BrambleCoreModule.initEagerSingletons(component);
|
BrambleCoreModule.initEagerSingletons(component);
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ public abstract class UiTest {
|
|||||||
getTargetContext().getString(R.string.screenshot_alice);
|
getTargetContext().getString(R.string.screenshot_alice);
|
||||||
protected static final String PASSWORD = "123456";
|
protected static final String PASSWORD = "123456";
|
||||||
|
|
||||||
|
protected final BriarUiTestComponent alice;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected AccountManager accountManager;
|
protected AccountManager accountManager;
|
||||||
@Inject
|
@Inject
|
||||||
@@ -30,7 +32,8 @@ public abstract class UiTest {
|
|||||||
BriarTestComponentApplication app =
|
BriarTestComponentApplication app =
|
||||||
(BriarTestComponentApplication) getTargetContext()
|
(BriarTestComponentApplication) getTargetContext()
|
||||||
.getApplicationContext();
|
.getApplicationContext();
|
||||||
inject((BriarUiTestComponent) app.getApplicationComponent());
|
alice = (BriarUiTestComponent) app.getApplicationComponent();
|
||||||
|
inject(alice);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void inject(BriarUiTestComponent component);
|
protected abstract void inject(BriarUiTestComponent component);
|
||||||
|
|||||||
@@ -13,13 +13,13 @@ import dagger.Component;
|
|||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@Component(modules = {
|
@Component(modules = {
|
||||||
AppModule.class,
|
TestAppModule.class,
|
||||||
BriarCoreModule.class,
|
BriarCoreModule.class,
|
||||||
BrambleAndroidModule.class,
|
BrambleAndroidModule.class,
|
||||||
BriarAccountModule.class,
|
BriarAccountModule.class,
|
||||||
BrambleCoreModule.class
|
BrambleCoreModule.class
|
||||||
})
|
})
|
||||||
public interface BriarUiTestComponent extends AndroidComponent {
|
public interface BriarUiTestComponent extends AndroidComponent, FakeDataTestComponent {
|
||||||
|
|
||||||
void inject(SetupDataTest test);
|
void inject(SetupDataTest test);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package org.briarproject.briar.android;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactManager;
|
||||||
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
|
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||||
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
|
import org.briarproject.bramble.api.sync.SyncSessionFactory;
|
||||||
|
import org.briarproject.bramble.api.transport.KeyManager;
|
||||||
|
import org.briarproject.bramble.api.transport.StreamReaderFactory;
|
||||||
|
import org.briarproject.bramble.api.transport.StreamWriterFactory;
|
||||||
|
import org.briarproject.bramble.client.ClientModule;
|
||||||
|
import org.briarproject.bramble.contact.ContactModule;
|
||||||
|
import org.briarproject.bramble.crypto.CryptoModule;
|
||||||
|
import org.briarproject.bramble.data.DataModule;
|
||||||
|
import org.briarproject.bramble.db.DatabaseModule;
|
||||||
|
import org.briarproject.bramble.event.EventModule;
|
||||||
|
import org.briarproject.bramble.identity.IdentityModule;
|
||||||
|
import org.briarproject.bramble.lifecycle.LifecycleModule;
|
||||||
|
import org.briarproject.bramble.record.RecordModule;
|
||||||
|
import org.briarproject.bramble.sync.SyncModule;
|
||||||
|
import org.briarproject.bramble.system.SystemModule;
|
||||||
|
import org.briarproject.bramble.test.TestCryptoExecutorModule;
|
||||||
|
import org.briarproject.bramble.test.TestDatabaseModule;
|
||||||
|
import org.briarproject.bramble.test.TestSecureRandomModule;
|
||||||
|
import org.briarproject.bramble.transport.TransportModule;
|
||||||
|
import org.briarproject.bramble.versioning.VersioningModule;
|
||||||
|
import org.briarproject.briar.api.messaging.MessagingManager;
|
||||||
|
import org.briarproject.briar.api.messaging.PrivateMessageFactory;
|
||||||
|
import org.briarproject.briar.client.BriarClientModule;
|
||||||
|
import org.briarproject.briar.messaging.MessagingModule;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import dagger.Component;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Component(modules = {
|
||||||
|
TestCryptoExecutorModule.class,
|
||||||
|
TestDatabaseModule.class,
|
||||||
|
TestPluginConfigModule.class,
|
||||||
|
TestSecureRandomModule.class,
|
||||||
|
BriarClientModule.class,
|
||||||
|
ClientModule.class,
|
||||||
|
ContactModule.class,
|
||||||
|
CryptoModule.class,
|
||||||
|
DataModule.class,
|
||||||
|
DatabaseModule.class,
|
||||||
|
EventModule.class,
|
||||||
|
IdentityModule.class,
|
||||||
|
LifecycleModule.class,
|
||||||
|
MessagingModule.class,
|
||||||
|
RecordModule.class,
|
||||||
|
SyncModule.class,
|
||||||
|
SystemModule.class,
|
||||||
|
TransportModule.class,
|
||||||
|
VersioningModule.class
|
||||||
|
})
|
||||||
|
interface FakeDataTestComponent {
|
||||||
|
|
||||||
|
void inject(ContactModule.EagerSingletons init);
|
||||||
|
|
||||||
|
void inject(IdentityModule.EagerSingletons init);
|
||||||
|
|
||||||
|
void inject(LifecycleModule.EagerSingletons init);
|
||||||
|
|
||||||
|
void inject(MessagingModule.EagerSingletons init);
|
||||||
|
|
||||||
|
void inject(SyncModule.EagerSingletons init);
|
||||||
|
|
||||||
|
void inject(SystemModule.EagerSingletons init);
|
||||||
|
|
||||||
|
void inject(TransportModule.EagerSingletons init);
|
||||||
|
|
||||||
|
void inject(VersioningModule.EagerSingletons init);
|
||||||
|
|
||||||
|
LifecycleManager getLifecycleManager();
|
||||||
|
|
||||||
|
IdentityManager getIdentityManager();
|
||||||
|
|
||||||
|
ContactManager getContactManager();
|
||||||
|
|
||||||
|
MessagingManager getMessagingManager();
|
||||||
|
|
||||||
|
KeyManager getKeyManager();
|
||||||
|
|
||||||
|
PrivateMessageFactory getPrivateMessageFactory();
|
||||||
|
|
||||||
|
EventBus getEventBus();
|
||||||
|
|
||||||
|
StreamWriterFactory getStreamWriterFactory();
|
||||||
|
|
||||||
|
StreamReaderFactory getStreamReaderFactory();
|
||||||
|
|
||||||
|
SyncSessionFactory getSyncSessionFactory();
|
||||||
|
}
|
||||||
@@ -5,23 +5,59 @@ import android.support.test.runner.AndroidJUnit4;
|
|||||||
import android.support.test.uiautomator.UiDevice;
|
import android.support.test.uiautomator.UiDevice;
|
||||||
import android.support.test.uiautomator.UiObject;
|
import android.support.test.uiautomator.UiObject;
|
||||||
import android.support.test.uiautomator.UiSelector;
|
import android.support.test.uiautomator.UiSelector;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.FormatException;
|
import org.briarproject.bramble.api.FormatException;
|
||||||
import org.briarproject.bramble.api.contact.Contact;
|
import org.briarproject.bramble.api.contact.Contact;
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.crypto.SecretKey;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||||
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
|
import org.briarproject.bramble.api.sync.GroupId;
|
||||||
|
import org.briarproject.bramble.api.sync.SyncSession;
|
||||||
|
import org.briarproject.bramble.api.sync.SyncSessionFactory;
|
||||||
|
import org.briarproject.bramble.api.transport.KeyManager;
|
||||||
|
import org.briarproject.bramble.api.transport.StreamContext;
|
||||||
|
import org.briarproject.bramble.api.transport.StreamReaderFactory;
|
||||||
|
import org.briarproject.bramble.api.transport.StreamWriter;
|
||||||
|
import org.briarproject.bramble.api.transport.StreamWriterFactory;
|
||||||
|
import org.briarproject.bramble.contact.ContactModule;
|
||||||
|
import org.briarproject.bramble.identity.IdentityModule;
|
||||||
|
import org.briarproject.bramble.lifecycle.LifecycleModule;
|
||||||
|
import org.briarproject.bramble.sync.SyncModule;
|
||||||
|
import org.briarproject.bramble.system.SystemModule;
|
||||||
|
import org.briarproject.bramble.test.TestDatabaseModule;
|
||||||
|
import org.briarproject.bramble.test.TestUtils;
|
||||||
|
import org.briarproject.bramble.transport.TransportModule;
|
||||||
|
import org.briarproject.bramble.versioning.VersioningModule;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.login.OpenDatabaseActivity;
|
import org.briarproject.briar.android.login.OpenDatabaseActivity;
|
||||||
import org.briarproject.briar.android.login.SetupActivity;
|
import org.briarproject.briar.android.login.SetupActivity;
|
||||||
|
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
|
||||||
|
import org.briarproject.briar.api.messaging.MessagingManager;
|
||||||
|
import org.briarproject.briar.api.messaging.PrivateMessage;
|
||||||
|
import org.briarproject.briar.api.messaging.PrivateMessageFactory;
|
||||||
|
import org.briarproject.briar.messaging.MessagingModule;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import static android.content.Context.MODE_PRIVATE;
|
||||||
import static android.support.test.InstrumentationRegistry.getInstrumentation;
|
import static android.support.test.InstrumentationRegistry.getInstrumentation;
|
||||||
import static android.support.test.InstrumentationRegistry.getTargetContext;
|
import static android.support.test.InstrumentationRegistry.getTargetContext;
|
||||||
import static android.support.test.espresso.Espresso.onView;
|
import static android.support.test.espresso.Espresso.onView;
|
||||||
import static android.support.test.espresso.action.ViewActions.click;
|
import static android.support.test.espresso.action.ViewActions.click;
|
||||||
import static android.support.test.espresso.action.ViewActions.typeText;
|
import static android.support.test.espresso.action.ViewActions.typeText;
|
||||||
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
||||||
|
import static android.support.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition;
|
||||||
import static android.support.test.espresso.intent.Intents.intended;
|
import static android.support.test.espresso.intent.Intents.intended;
|
||||||
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent;
|
import static android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent;
|
||||||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||||
@@ -30,9 +66,17 @@ import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
|||||||
import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
||||||
import static android.support.test.runner.lifecycle.Stage.PAUSED;
|
import static android.support.test.runner.lifecycle.Stage.PAUSED;
|
||||||
import static org.briarproject.bramble.api.plugin.LanTcpConstants.ID;
|
import static org.briarproject.bramble.api.plugin.LanTcpConstants.ID;
|
||||||
|
import static org.briarproject.bramble.api.transport.TransportConstants.TAG_LENGTH;
|
||||||
|
import static org.briarproject.bramble.test.TestUtils.getSecretKey;
|
||||||
|
import static org.briarproject.briar.android.TestPluginConfigModule.MAX_LATENCY;
|
||||||
|
import static org.briarproject.briar.android.TestPluginConfigModule.TRANSPORT_ID;
|
||||||
import static org.briarproject.briar.android.ViewActions.waitForActivity;
|
import static org.briarproject.briar.android.ViewActions.waitForActivity;
|
||||||
import static org.briarproject.briar.android.ViewActions.waitUntilMatches;
|
import static org.briarproject.briar.android.ViewActions.waitUntilMatches;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.needsDozeWhitelisting;
|
import static org.briarproject.briar.android.util.UiUtils.needsDozeWhitelisting;
|
||||||
|
import static org.hamcrest.Matchers.allOf;
|
||||||
|
import static org.hamcrest.Matchers.not;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
@@ -48,11 +92,49 @@ public class SetupDataTest extends ScreenshotTest {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private FakeDataTestComponent bob;
|
||||||
|
private final File testDir =
|
||||||
|
getTargetContext().getDir("test", MODE_PRIVATE);
|
||||||
|
private final File bobDir = new File(testDir, "bob");
|
||||||
|
private final SecretKey master = getSecretKey();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void inject(BriarUiTestComponent component) {
|
protected void inject(BriarUiTestComponent component) {
|
||||||
component.inject(this);
|
component.inject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
Log.e("TEST", testDir.getAbsolutePath());
|
||||||
|
Log.e("TEST", "exists: " + testDir.exists());
|
||||||
|
assertTrue(testDir.mkdirs());
|
||||||
|
bob = DaggerFakeDataTestComponent.builder()
|
||||||
|
.testDatabaseModule(new TestDatabaseModule(bobDir)).build();
|
||||||
|
injectEagerSingletons(bob);
|
||||||
|
Log.e("TEST", "built bob");
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
// Stop the lifecycle manager
|
||||||
|
LifecycleManager lifecycleManager = bob.getLifecycleManager();
|
||||||
|
lifecycleManager.stopServices();
|
||||||
|
lifecycleManager.waitForShutdown();
|
||||||
|
|
||||||
|
TestUtils.deleteTestDirectory(testDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void injectEagerSingletons(FakeDataTestComponent component) {
|
||||||
|
component.inject(new ContactModule.EagerSingletons());
|
||||||
|
component.inject(new IdentityModule.EagerSingletons());
|
||||||
|
component.inject(new LifecycleModule.EagerSingletons());
|
||||||
|
component.inject(new MessagingModule.EagerSingletons());
|
||||||
|
component.inject(new SyncModule.EagerSingletons());
|
||||||
|
component.inject(new SystemModule.EagerSingletons());
|
||||||
|
component.inject(new TransportModule.EagerSingletons());
|
||||||
|
component.inject(new VersioningModule.EagerSingletons());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createAccount() throws Exception {
|
public void createAccount() throws Exception {
|
||||||
// Enter username
|
// Enter username
|
||||||
@@ -103,26 +185,132 @@ public class SetupDataTest extends ScreenshotTest {
|
|||||||
|
|
||||||
assertTrue(accountManager.hasDatabaseKey());
|
assertTrue(accountManager.hasDatabaseKey());
|
||||||
|
|
||||||
|
// WIP below
|
||||||
|
|
||||||
|
// wait for OpenDatabaseActivity to go away
|
||||||
|
onView(isRoot())
|
||||||
|
.perform(waitUntilMatches(
|
||||||
|
allOf(withId(R.id.progressBar), not(isDisplayed()))));
|
||||||
lifecycleManager.waitForStartup();
|
lifecycleManager.waitForStartup();
|
||||||
createTestData();
|
intended(hasComponent(NavDrawerActivity.class.getName()));
|
||||||
|
|
||||||
// close expiry warning
|
// close expiry warning
|
||||||
onView(withId(R.id.expiryWarning))
|
|
||||||
.perform(waitUntilMatches(isDisplayed()));
|
|
||||||
onView(withId(R.id.expiryWarningClose))
|
onView(withId(R.id.expiryWarningClose))
|
||||||
.check(matches(isDisplayed()));
|
.check(matches(isDisplayed()));
|
||||||
onView(withId(R.id.expiryWarningClose))
|
onView(withId(R.id.expiryWarningClose))
|
||||||
.perform(click());
|
.perform(click());
|
||||||
|
|
||||||
|
LocalAuthor aliceAuthor = alice.identityManager().getLocalAuthor();
|
||||||
|
|
||||||
|
LocalAuthor bobAuthor = bob.getIdentityManager().createLocalAuthor(
|
||||||
|
getTargetContext().getString(R.string.screenshot_bob));
|
||||||
|
bob.getIdentityManager().registerLocalAuthor(bobAuthor);
|
||||||
|
// Start the lifecycle manager
|
||||||
|
bob.getLifecycleManager().startServices(getSecretKey());
|
||||||
|
bob.getLifecycleManager().waitForStartup();
|
||||||
|
long timestamp = clock.currentTimeMillis();
|
||||||
|
// Bob adds Alice as a contact
|
||||||
|
ContactId aliceContactId = bob.getContactManager()
|
||||||
|
.addContact(aliceAuthor, bobAuthor.getId(), master,
|
||||||
|
timestamp, true, true, true);
|
||||||
|
// Alice adds Bob as a contact
|
||||||
|
ContactId bobContactId = alice.contactManager()
|
||||||
|
.addContact(bobAuthor, aliceAuthor.getId(), master,
|
||||||
|
timestamp, false, true, true);
|
||||||
|
|
||||||
|
// TODO figure out how many messages
|
||||||
|
read(alice, bobContactId, write(bob, aliceContactId));
|
||||||
|
read(bob, aliceContactId, write(alice, bobContactId));
|
||||||
|
read(alice, bobContactId, write(bob, aliceContactId));
|
||||||
|
read(bob, aliceContactId, write(alice, bobContactId));
|
||||||
|
read(alice, bobContactId, write(bob, aliceContactId));
|
||||||
|
read(bob, aliceContactId, write(alice, bobContactId));
|
||||||
|
read(alice, bobContactId, write(bob, aliceContactId));
|
||||||
|
read(bob, aliceContactId, write(alice, bobContactId));
|
||||||
|
read(alice, bobContactId, write(bob, aliceContactId));
|
||||||
|
read(bob, aliceContactId, write(alice, bobContactId));
|
||||||
|
read(alice, bobContactId, write(bob, aliceContactId));
|
||||||
|
read(bob, aliceContactId, write(alice, bobContactId));
|
||||||
|
read(alice, bobContactId, write(bob, aliceContactId));
|
||||||
|
|
||||||
|
sendMessage(bob, aliceContactId);
|
||||||
|
read(alice, bobContactId, write(bob, aliceContactId));
|
||||||
|
|
||||||
|
onView(isRoot())
|
||||||
|
.perform(waitUntilMatches(withText(bobAuthor.getName())));
|
||||||
|
onView(withId(R.id.recyclerView))
|
||||||
|
.perform(actionOnItemAtPosition(0, click()));
|
||||||
|
onView(isRoot())
|
||||||
|
.perform(waitUntilMatches(withText(R.string.screenshot_message_2)));
|
||||||
|
|
||||||
|
assertEquals(1,
|
||||||
|
alice.conversationManager().getGroupCount(bobContactId).getMsgCount());
|
||||||
|
|
||||||
|
Thread.sleep(5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createTestData() {
|
private void sendMessage(FakeDataTestComponent device, ContactId contactId)
|
||||||
try {
|
throws Exception {
|
||||||
createTestDataExceptions();
|
// Send Bob a message
|
||||||
} catch (DbException | FormatException e) {
|
MessagingManager messagingManager = device.getMessagingManager();
|
||||||
throw new AssertionError(e);
|
GroupId groupId = messagingManager.getConversationId(contactId);
|
||||||
}
|
PrivateMessageFactory privateMessageFactory =
|
||||||
|
device.getPrivateMessageFactory();
|
||||||
|
PrivateMessage message = privateMessageFactory.createPrivateMessage(
|
||||||
|
groupId, getMinutesAgo(3),
|
||||||
|
getTargetContext().getString(R.string.screenshot_message_2));
|
||||||
|
messagingManager.addLocalMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void read(FakeDataTestComponent device,
|
||||||
|
ContactId contactId, byte[] stream) throws Exception {
|
||||||
|
// Read and recognise the tag
|
||||||
|
ByteArrayInputStream in = new ByteArrayInputStream(stream);
|
||||||
|
byte[] tag = new byte[TAG_LENGTH];
|
||||||
|
int read = in.read(tag);
|
||||||
|
assertEquals(tag.length, read);
|
||||||
|
KeyManager keyManager = device.getKeyManager();
|
||||||
|
StreamContext ctx = keyManager.getStreamContext(TRANSPORT_ID, tag);
|
||||||
|
assertNotNull(ctx);
|
||||||
|
// Create a stream reader
|
||||||
|
StreamReaderFactory streamReaderFactory =
|
||||||
|
device.getStreamReaderFactory();
|
||||||
|
InputStream streamReader = streamReaderFactory.createStreamReader(
|
||||||
|
in, ctx);
|
||||||
|
// Create an incoming sync session
|
||||||
|
SyncSessionFactory syncSessionFactory = device.getSyncSessionFactory();
|
||||||
|
SyncSession session = syncSessionFactory.createIncomingSession(
|
||||||
|
contactId, streamReader);
|
||||||
|
// Read whatever needs to be read
|
||||||
|
session.run();
|
||||||
|
streamReader.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] write(FakeDataTestComponent device,
|
||||||
|
ContactId contactId) throws Exception {
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
// Get a stream context
|
||||||
|
KeyManager keyManager = device.getKeyManager();
|
||||||
|
StreamContext ctx = keyManager.getStreamContext(contactId,
|
||||||
|
TRANSPORT_ID);
|
||||||
|
assertNotNull(ctx);
|
||||||
|
// Create a stream writer
|
||||||
|
StreamWriterFactory streamWriterFactory =
|
||||||
|
device.getStreamWriterFactory();
|
||||||
|
StreamWriter streamWriter =
|
||||||
|
streamWriterFactory.createStreamWriter(out, ctx);
|
||||||
|
// Create an outgoing sync session
|
||||||
|
SyncSessionFactory syncSessionFactory = device.getSyncSessionFactory();
|
||||||
|
SyncSession session = syncSessionFactory.createSimplexOutgoingSession(
|
||||||
|
contactId, MAX_LATENCY, streamWriter);
|
||||||
|
// Write whatever needs to be written
|
||||||
|
session.run();
|
||||||
|
streamWriter.sendEndOfStream();
|
||||||
|
// Return the contents of the stream
|
||||||
|
return out.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
private void createTestDataExceptions()
|
private void createTestDataExceptions()
|
||||||
throws DbException, FormatException {
|
throws DbException, FormatException {
|
||||||
String bobName =
|
String bobName =
|
||||||
|
|||||||
@@ -0,0 +1,161 @@
|
|||||||
|
package org.briarproject.briar.android;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.StrictMode;
|
||||||
|
|
||||||
|
import com.vanniktech.emoji.RecentEmoji;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.crypto.CryptoComponent;
|
||||||
|
import org.briarproject.bramble.api.crypto.PublicKey;
|
||||||
|
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||||
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.reporting.DevConfig;
|
||||||
|
import org.briarproject.bramble.util.AndroidUtils;
|
||||||
|
import org.briarproject.bramble.util.StringUtils;
|
||||||
|
import org.briarproject.briar.android.account.LockManagerImpl;
|
||||||
|
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||||
|
import org.briarproject.briar.api.android.DozeWatchdog;
|
||||||
|
import org.briarproject.briar.api.android.LockManager;
|
||||||
|
import org.briarproject.briar.api.android.ScreenFilterMonitor;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.security.GeneralSecurityException;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
import static android.content.Context.MODE_PRIVATE;
|
||||||
|
import static org.briarproject.bramble.api.reporting.ReportingConstants.DEV_ONION_ADDRESS;
|
||||||
|
import static org.briarproject.bramble.api.reporting.ReportingConstants.DEV_PUBLIC_KEY_HEX;
|
||||||
|
|
||||||
|
@Module(includes = TestPluginConfigModule.class)
|
||||||
|
public class TestAppModule {
|
||||||
|
|
||||||
|
static class EagerSingletons {
|
||||||
|
@Inject
|
||||||
|
AndroidNotificationManager androidNotificationManager;
|
||||||
|
@Inject
|
||||||
|
NetworkUsageLogger networkUsageLogger;
|
||||||
|
@Inject
|
||||||
|
DozeWatchdog dozeWatchdog;
|
||||||
|
@Inject
|
||||||
|
RecentEmoji recentEmoji;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Application application;
|
||||||
|
|
||||||
|
public TestAppModule(Application application) {
|
||||||
|
this.application = application;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
Application providesApplication() {
|
||||||
|
return application;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
DatabaseConfig provideDatabaseConfig(Application app) {
|
||||||
|
//FIXME: StrictMode
|
||||||
|
StrictMode.ThreadPolicy tp = StrictMode.allowThreadDiskReads();
|
||||||
|
StrictMode.allowThreadDiskWrites();
|
||||||
|
File dbDir = app.getApplicationContext().getDir("db", MODE_PRIVATE);
|
||||||
|
File keyDir = app.getApplicationContext().getDir("key", MODE_PRIVATE);
|
||||||
|
StrictMode.setThreadPolicy(tp);
|
||||||
|
return new AndroidDatabaseConfig(dbDir, keyDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
DevConfig provideDevConfig(Application app, CryptoComponent crypto) {
|
||||||
|
@NotNullByDefault
|
||||||
|
DevConfig devConfig = new DevConfig() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PublicKey getDevPublicKey() {
|
||||||
|
try {
|
||||||
|
return crypto.getMessageKeyParser().parsePublicKey(
|
||||||
|
StringUtils.fromHexString(DEV_PUBLIC_KEY_HEX));
|
||||||
|
} catch (GeneralSecurityException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDevOnionAddress() {
|
||||||
|
return DEV_ONION_ADDRESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getReportDir() {
|
||||||
|
return AndroidUtils.getReportDir(app.getApplicationContext());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return devConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
SharedPreferences provideSharedPreferences(Application app) {
|
||||||
|
// FIXME unify this with getDefaultSharedPreferences()
|
||||||
|
return app.getSharedPreferences("db", MODE_PRIVATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
AndroidNotificationManager provideAndroidNotificationManager(
|
||||||
|
LifecycleManager lifecycleManager, EventBus eventBus,
|
||||||
|
AndroidNotificationManagerImpl notificationManager) {
|
||||||
|
lifecycleManager.registerService(notificationManager);
|
||||||
|
eventBus.addListener(notificationManager);
|
||||||
|
return notificationManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
ScreenFilterMonitor provideScreenFilterMonitor(
|
||||||
|
LifecycleManager lifecycleManager,
|
||||||
|
ScreenFilterMonitorImpl screenFilterMonitor) {
|
||||||
|
lifecycleManager.registerService(screenFilterMonitor);
|
||||||
|
return screenFilterMonitor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
NetworkUsageLogger provideNetworkUsageLogger(
|
||||||
|
LifecycleManager lifecycleManager) {
|
||||||
|
NetworkUsageLogger networkUsageLogger = new NetworkUsageLogger();
|
||||||
|
lifecycleManager.registerService(networkUsageLogger);
|
||||||
|
return networkUsageLogger;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
DozeWatchdog provideDozeWatchdog(LifecycleManager lifecycleManager) {
|
||||||
|
DozeWatchdogImpl dozeWatchdog = new DozeWatchdogImpl(application);
|
||||||
|
lifecycleManager.registerService(dozeWatchdog);
|
||||||
|
return dozeWatchdog;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
LockManager provideLockManager(LifecycleManager lifecycleManager,
|
||||||
|
EventBus eventBus, LockManagerImpl lockManager) {
|
||||||
|
lifecycleManager.registerService(lockManager);
|
||||||
|
eventBus.addListener(lockManager);
|
||||||
|
return lockManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
RecentEmoji provideRecentEmoji(LifecycleManager lifecycleManager,
|
||||||
|
RecentEmojiImpl recentEmoji) {
|
||||||
|
lifecycleManager.registerClient(recentEmoji);
|
||||||
|
return recentEmoji;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package org.briarproject.briar.android;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.plugin.PluginConfig;
|
||||||
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
||||||
|
import org.briarproject.bramble.api.plugin.simplex.SimplexPlugin;
|
||||||
|
import org.briarproject.bramble.api.plugin.simplex.SimplexPluginCallback;
|
||||||
|
import org.briarproject.bramble.api.plugin.simplex.SimplexPluginFactory;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptyList;
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
|
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public class TestPluginConfigModule {
|
||||||
|
|
||||||
|
public static final TransportId TRANSPORT_ID = getTransportId();
|
||||||
|
public static final int MAX_LATENCY = 2 * 60 * 1000; // 2 minutes
|
||||||
|
|
||||||
|
@NotNullByDefault
|
||||||
|
private final SimplexPluginFactory simplex = new SimplexPluginFactory() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportId getId() {
|
||||||
|
return TRANSPORT_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxLatency() {
|
||||||
|
return MAX_LATENCY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public SimplexPlugin createPlugin(SimplexPluginCallback callback) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
PluginConfig providePluginConfig() {
|
||||||
|
@NotNullByDefault
|
||||||
|
PluginConfig pluginConfig = new PluginConfig() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<DuplexPluginFactory> getDuplexFactories() {
|
||||||
|
return emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<SimplexPluginFactory> getSimplexFactories() {
|
||||||
|
return singletonList(simplex);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldPoll() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return pluginConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package org.briarproject.briar.android;
|
package org.briarproject.briar.android;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.StrictMode;
|
import android.os.StrictMode;
|
||||||
|
|
||||||
@@ -11,24 +10,9 @@ import org.briarproject.bramble.api.crypto.CryptoComponent;
|
|||||||
import org.briarproject.bramble.api.crypto.PublicKey;
|
import org.briarproject.bramble.api.crypto.PublicKey;
|
||||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||||
import org.briarproject.bramble.api.event.EventBus;
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
|
||||||
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
|
||||||
import org.briarproject.bramble.api.network.NetworkManager;
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
|
||||||
import org.briarproject.bramble.api.plugin.PluginConfig;
|
|
||||||
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
|
||||||
import org.briarproject.bramble.api.plugin.simplex.SimplexPluginFactory;
|
|
||||||
import org.briarproject.bramble.api.reporting.DevConfig;
|
import org.briarproject.bramble.api.reporting.DevConfig;
|
||||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
|
||||||
import org.briarproject.bramble.api.system.Clock;
|
|
||||||
import org.briarproject.bramble.api.system.LocationUtils;
|
|
||||||
import org.briarproject.bramble.api.system.ResourceProvider;
|
|
||||||
import org.briarproject.bramble.api.system.Scheduler;
|
|
||||||
import org.briarproject.bramble.plugin.bluetooth.AndroidBluetoothPluginFactory;
|
|
||||||
import org.briarproject.bramble.plugin.tcp.AndroidLanTcpPluginFactory;
|
|
||||||
import org.briarproject.bramble.plugin.tor.AndroidTorPluginFactory;
|
|
||||||
import org.briarproject.bramble.plugin.tor.CircumventionProvider;
|
|
||||||
import org.briarproject.bramble.util.AndroidUtils;
|
import org.briarproject.bramble.util.AndroidUtils;
|
||||||
import org.briarproject.bramble.util.StringUtils;
|
import org.briarproject.bramble.util.StringUtils;
|
||||||
import org.briarproject.briar.android.account.LockManagerImpl;
|
import org.briarproject.briar.android.account.LockManagerImpl;
|
||||||
@@ -39,25 +23,18 @@ import org.briarproject.briar.api.android.ScreenFilterMonitor;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.net.SocketFactory;
|
|
||||||
|
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
|
|
||||||
import static android.content.Context.MODE_PRIVATE;
|
import static android.content.Context.MODE_PRIVATE;
|
||||||
import static java.util.Arrays.asList;
|
|
||||||
import static java.util.Collections.emptyList;
|
|
||||||
import static org.briarproject.bramble.api.reporting.ReportingConstants.DEV_ONION_ADDRESS;
|
import static org.briarproject.bramble.api.reporting.ReportingConstants.DEV_ONION_ADDRESS;
|
||||||
import static org.briarproject.bramble.api.reporting.ReportingConstants.DEV_PUBLIC_KEY_HEX;
|
import static org.briarproject.bramble.api.reporting.ReportingConstants.DEV_PUBLIC_KEY_HEX;
|
||||||
|
|
||||||
@Module
|
@Module(includes = PluginConfigModule.class)
|
||||||
public class AppModule {
|
public class AppModule {
|
||||||
|
|
||||||
static class EagerSingletons {
|
static class EagerSingletons {
|
||||||
@@ -95,47 +72,6 @@ public class AppModule {
|
|||||||
return new AndroidDatabaseConfig(dbDir, keyDir);
|
return new AndroidDatabaseConfig(dbDir, keyDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
|
||||||
PluginConfig providePluginConfig(@IoExecutor Executor ioExecutor,
|
|
||||||
@Scheduler ScheduledExecutorService scheduler,
|
|
||||||
AndroidExecutor androidExecutor, SecureRandom random,
|
|
||||||
SocketFactory torSocketFactory, BackoffFactory backoffFactory,
|
|
||||||
Application app, NetworkManager networkManager,
|
|
||||||
LocationUtils locationUtils, EventBus eventBus,
|
|
||||||
ResourceProvider resourceProvider,
|
|
||||||
CircumventionProvider circumventionProvider, Clock clock) {
|
|
||||||
Context appContext = app.getApplicationContext();
|
|
||||||
DuplexPluginFactory bluetooth =
|
|
||||||
new AndroidBluetoothPluginFactory(ioExecutor, androidExecutor,
|
|
||||||
appContext, random, eventBus, backoffFactory);
|
|
||||||
DuplexPluginFactory tor = new AndroidTorPluginFactory(ioExecutor,
|
|
||||||
scheduler, appContext, networkManager, locationUtils, eventBus,
|
|
||||||
torSocketFactory, backoffFactory, resourceProvider,
|
|
||||||
circumventionProvider, clock);
|
|
||||||
DuplexPluginFactory lan = new AndroidLanTcpPluginFactory(ioExecutor,
|
|
||||||
eventBus, backoffFactory, appContext);
|
|
||||||
Collection<DuplexPluginFactory> duplex = asList(bluetooth, tor, lan);
|
|
||||||
@NotNullByDefault
|
|
||||||
PluginConfig pluginConfig = new PluginConfig() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<DuplexPluginFactory> getDuplexFactories() {
|
|
||||||
return duplex;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<SimplexPluginFactory> getSimplexFactories() {
|
|
||||||
return emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldPoll() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return pluginConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
DevConfig provideDevConfig(Application app, CryptoComponent crypto) {
|
DevConfig provideDevConfig(Application app, CryptoComponent crypto) {
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
package org.briarproject.briar.android;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.event.EventBus;
|
||||||
|
import org.briarproject.bramble.api.lifecycle.IoExecutor;
|
||||||
|
import org.briarproject.bramble.api.network.NetworkManager;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.plugin.BackoffFactory;
|
||||||
|
import org.briarproject.bramble.api.plugin.PluginConfig;
|
||||||
|
import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
||||||
|
import org.briarproject.bramble.api.plugin.simplex.SimplexPluginFactory;
|
||||||
|
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||||
|
import org.briarproject.bramble.api.system.Clock;
|
||||||
|
import org.briarproject.bramble.api.system.LocationUtils;
|
||||||
|
import org.briarproject.bramble.api.system.ResourceProvider;
|
||||||
|
import org.briarproject.bramble.api.system.Scheduler;
|
||||||
|
import org.briarproject.bramble.plugin.bluetooth.AndroidBluetoothPluginFactory;
|
||||||
|
import org.briarproject.bramble.plugin.tcp.AndroidLanTcpPluginFactory;
|
||||||
|
import org.briarproject.bramble.plugin.tor.AndroidTorPluginFactory;
|
||||||
|
import org.briarproject.bramble.plugin.tor.CircumventionProvider;
|
||||||
|
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
|
||||||
|
import javax.net.SocketFactory;
|
||||||
|
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
|
||||||
|
import static java.util.Arrays.asList;
|
||||||
|
import static java.util.Collections.emptyList;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
public class PluginConfigModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
PluginConfig providePluginConfig(@IoExecutor Executor ioExecutor,
|
||||||
|
@Scheduler ScheduledExecutorService scheduler,
|
||||||
|
AndroidExecutor androidExecutor, SecureRandom random,
|
||||||
|
SocketFactory torSocketFactory, BackoffFactory backoffFactory,
|
||||||
|
Application app, NetworkManager networkManager,
|
||||||
|
LocationUtils locationUtils, EventBus eventBus,
|
||||||
|
ResourceProvider resourceProvider,
|
||||||
|
CircumventionProvider circumventionProvider, Clock clock) {
|
||||||
|
Context appContext = app.getApplicationContext();
|
||||||
|
DuplexPluginFactory bluetooth =
|
||||||
|
new AndroidBluetoothPluginFactory(ioExecutor, androidExecutor,
|
||||||
|
appContext, random, eventBus, backoffFactory);
|
||||||
|
DuplexPluginFactory tor = new AndroidTorPluginFactory(ioExecutor,
|
||||||
|
scheduler, appContext, networkManager, locationUtils, eventBus,
|
||||||
|
torSocketFactory, backoffFactory, resourceProvider,
|
||||||
|
circumventionProvider, clock);
|
||||||
|
DuplexPluginFactory lan = new AndroidLanTcpPluginFactory(ioExecutor,
|
||||||
|
eventBus, backoffFactory, appContext);
|
||||||
|
Collection<DuplexPluginFactory> duplex = asList(bluetooth, tor, lan);
|
||||||
|
@NotNullByDefault
|
||||||
|
PluginConfig pluginConfig = new PluginConfig() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<DuplexPluginFactory> getDuplexFactories() {
|
||||||
|
return duplex;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<SimplexPluginFactory> getSimplexFactories() {
|
||||||
|
return emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldPoll() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return pluginConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user