mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Semi-encapsulated the core/api dependency graphs and created a proper structure to load eager singletons
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package org.briarproject.android;
|
||||
|
||||
import org.briarproject.CoreComponent;
|
||||
import org.briarproject.android.contact.ContactListFragment;
|
||||
import org.briarproject.android.contact.ConversationActivity;
|
||||
import org.briarproject.android.forum.AvailableForumsActivity;
|
||||
@@ -14,38 +15,12 @@ import org.briarproject.android.identity.CreateIdentityActivity;
|
||||
import org.briarproject.android.invitation.AddContactActivity;
|
||||
import org.briarproject.android.panic.PanicPreferencesActivity;
|
||||
import org.briarproject.android.panic.PanicResponderActivity;
|
||||
import org.briarproject.clients.ClientsModule;
|
||||
import org.briarproject.contact.ContactModule;
|
||||
import org.briarproject.crypto.CryptoModule;
|
||||
import org.briarproject.data.DataModule;
|
||||
import org.briarproject.db.DatabaseModule;
|
||||
import org.briarproject.event.EventModule;
|
||||
import org.briarproject.forum.ForumModule;
|
||||
import org.briarproject.identity.IdentityModule;
|
||||
import org.briarproject.invitation.InvitationModule;
|
||||
import org.briarproject.lifecycle.LifecycleModule;
|
||||
import org.briarproject.messaging.MessagingModule;
|
||||
import org.briarproject.plugins.AndroidPluginsModule;
|
||||
import org.briarproject.properties.PropertiesModule;
|
||||
import org.briarproject.reliability.ReliabilityModule;
|
||||
import org.briarproject.settings.SettingsModule;
|
||||
import org.briarproject.sync.SyncModule;
|
||||
import org.briarproject.system.AndroidSystemModule;
|
||||
import org.briarproject.transport.TransportModule;
|
||||
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import dagger.Component;
|
||||
@Singleton
|
||||
@ApplicationScope
|
||||
@Component(
|
||||
modules = {AppModule.class, AndroidModule.class, DatabaseModule.class,
|
||||
CryptoModule.class, LifecycleModule.class,
|
||||
ReliabilityModule.class, MessagingModule.class,
|
||||
InvitationModule.class, ForumModule.class, IdentityModule.class,
|
||||
EventModule.class, DataModule.class, ContactModule.class,
|
||||
AndroidSystemModule.class, AndroidPluginsModule.class,
|
||||
PropertiesModule.class, TransportModule.class, SyncModule.class,
|
||||
SettingsModule.class, ClientsModule.class})
|
||||
dependencies = {CoreComponent.class},
|
||||
modules = {AppModule.class, AndroidModule.class})
|
||||
public interface AndroidComponent {
|
||||
void inject(SplashScreenActivity activity);
|
||||
void inject(SetupActivity activity);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.briarproject.android;
|
||||
|
||||
public class AndroidEagerSingletons {
|
||||
|
||||
public static void initEagerSingletons(AndroidComponent c) {
|
||||
c.inject(new AndroidModule.EagerSingletons());
|
||||
}
|
||||
}
|
||||
@@ -1,138 +1,37 @@
|
||||
package org.briarproject.android;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import org.briarproject.api.android.AndroidExecutor;
|
||||
import org.briarproject.api.android.AndroidNotificationManager;
|
||||
import org.briarproject.api.android.ReferenceManager;
|
||||
import org.briarproject.api.contact.ContactManager;
|
||||
import org.briarproject.api.crypto.SecretKey;
|
||||
import org.briarproject.api.db.DatabaseConfig;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.api.messaging.MessagingManager;
|
||||
import org.briarproject.api.plugins.PluginManager;
|
||||
import org.briarproject.api.properties.TransportPropertyManager;
|
||||
import org.briarproject.api.sync.ValidationManager;
|
||||
import org.briarproject.api.transport.KeyManager;
|
||||
import org.briarproject.api.ui.UiCallback;
|
||||
import org.briarproject.messaging.PrivateMessageValidator;
|
||||
import org.briarproject.properties.TransportPropertyValidator;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
|
||||
@Module
|
||||
public class AndroidModule {
|
||||
|
||||
static class EagerSingletons {
|
||||
// Load all relevant eager singletons and their references
|
||||
@Inject
|
||||
KeyManager keyManager;
|
||||
@Inject
|
||||
ValidationManager validationManager;
|
||||
@Inject
|
||||
PluginManager pluginManager;
|
||||
@Inject
|
||||
AndroidNotificationManager androidNotificationManager;
|
||||
@Inject
|
||||
TransportPropertyManager transportPropertyManager;
|
||||
@Inject
|
||||
MessagingManager messagingManager;
|
||||
@Inject
|
||||
PrivateMessageValidator privateMessageValidator;
|
||||
@Inject
|
||||
TransportPropertyValidator transportPropertyValidator;
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void injectEager(AndroidComponent c) {
|
||||
c.inject(new EagerSingletons());
|
||||
}
|
||||
|
||||
private final UiCallback uiCallback;
|
||||
|
||||
public AndroidModule() {
|
||||
// Use a dummy UI callback
|
||||
uiCallback = new UiCallback() {
|
||||
|
||||
public int showChoice(String[] options, String... message) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean showConfirmationMessage(String... message) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void showMessage(String... message) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Provides
|
||||
UiCallback provideUICallback() {
|
||||
return uiCallback;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@ApplicationScope
|
||||
ReferenceManager provideReferenceManager() {
|
||||
return new ReferenceManagerImpl();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
AndroidExecutor provideAndroidExecutor(
|
||||
AndroidExecutorImpl androidExecutor) {
|
||||
return androidExecutor;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
DatabaseConfig provideDatabaseConfig(final Application app) {
|
||||
final File dir = app.getApplicationContext().getDir("db", MODE_PRIVATE);
|
||||
return new DatabaseConfig() {
|
||||
|
||||
private volatile SecretKey key = null;
|
||||
|
||||
public boolean databaseExists() {
|
||||
return dir.isDirectory() && dir.listFiles().length > 0;
|
||||
}
|
||||
|
||||
public File getDatabaseDirectory() {
|
||||
return dir;
|
||||
}
|
||||
|
||||
public void setEncryptionKey(SecretKey key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public SecretKey getEncryptionKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public long getMaxSize() {
|
||||
return Long.MAX_VALUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@ApplicationScope
|
||||
AndroidNotificationManager provideAndroidNotificationManager(
|
||||
LifecycleManager lifecycleManager, EventBus eventBus,
|
||||
AndroidNotificationManagerImpl notificationManager) {
|
||||
lifecycleManager.register(notificationManager);
|
||||
eventBus.addListener(notificationManager);
|
||||
|
||||
return notificationManager;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import android.support.v4.app.TaskStackBuilder;
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.contact.ConversationActivity;
|
||||
import org.briarproject.android.forum.ForumActivity;
|
||||
import org.briarproject.api.android.AndroidExecutor;
|
||||
import org.briarproject.api.android.PlatformExecutor;
|
||||
import org.briarproject.api.android.AndroidNotificationManager;
|
||||
import org.briarproject.api.db.DatabaseExecutor;
|
||||
import org.briarproject.api.db.DbException;
|
||||
@@ -65,7 +65,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
private final SettingsManager settingsManager;
|
||||
private final MessagingManager messagingManager;
|
||||
private final ForumManager forumManager;
|
||||
private final AndroidExecutor androidExecutor;
|
||||
private final PlatformExecutor platformExecutor;
|
||||
private final Context appContext;
|
||||
|
||||
// The following must only be accessed on the main UI thread
|
||||
@@ -82,13 +82,13 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
@Inject
|
||||
public AndroidNotificationManagerImpl(@DatabaseExecutor Executor dbExecutor,
|
||||
SettingsManager settingsManager, MessagingManager messagingManager,
|
||||
ForumManager forumManager, AndroidExecutor androidExecutor,
|
||||
ForumManager forumManager, PlatformExecutor platformExecutor,
|
||||
Application app) {
|
||||
this.dbExecutor = dbExecutor;
|
||||
this.settingsManager = settingsManager;
|
||||
this.messagingManager = messagingManager;
|
||||
this.forumManager = forumManager;
|
||||
this.androidExecutor = androidExecutor;
|
||||
this.platformExecutor = platformExecutor;
|
||||
appContext = app.getApplicationContext();
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
}
|
||||
|
||||
private void clearNotifications() {
|
||||
androidExecutor.execute(new Runnable() {
|
||||
platformExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
clearPrivateMessageNotification();
|
||||
clearForumPostNotification();
|
||||
@@ -155,7 +155,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
}
|
||||
|
||||
public void showPrivateMessageNotification(final GroupId g) {
|
||||
androidExecutor.execute(new Runnable() {
|
||||
platformExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
Integer count = contactCounts.get(g);
|
||||
if (count == null) contactCounts.put(g, 1);
|
||||
@@ -168,7 +168,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
}
|
||||
|
||||
public void clearPrivateMessageNotification(final GroupId g) {
|
||||
androidExecutor.execute(new Runnable() {
|
||||
platformExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
Integer count = contactCounts.remove(g);
|
||||
if (count == null) return; // Already cleared
|
||||
@@ -239,7 +239,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
}
|
||||
|
||||
public void showForumPostNotification(final GroupId g) {
|
||||
androidExecutor.execute(new Runnable() {
|
||||
platformExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
Integer count = forumCounts.get(g);
|
||||
if (count == null) forumCounts.put(g, 1);
|
||||
@@ -252,7 +252,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
}
|
||||
|
||||
public void clearForumPostNotification(final GroupId g) {
|
||||
androidExecutor.execute(new Runnable() {
|
||||
platformExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
Integer count = forumCounts.remove(g);
|
||||
if (count == null) return; // Already cleared
|
||||
@@ -311,7 +311,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
}
|
||||
|
||||
public void blockNotification(final GroupId g) {
|
||||
androidExecutor.execute(new Runnable() {
|
||||
platformExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
visibleGroup = g;
|
||||
}
|
||||
@@ -319,7 +319,7 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
|
||||
}
|
||||
|
||||
public void unblockNotification(final GroupId g) {
|
||||
androidExecutor.execute(new Runnable() {
|
||||
platformExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
if (g.equals(visibleGroup)) visibleGroup = null;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package org.briarproject.android;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
@@ -18,7 +15,7 @@ public class AppModule {
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@ApplicationScope
|
||||
Application providesApplication() {
|
||||
return application;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.briarproject.android;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import javax.inject.Scope;
|
||||
|
||||
@Scope
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ApplicationScope {
|
||||
}
|
||||
@@ -6,6 +6,13 @@ import java.util.logging.Logger;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
import org.briarproject.CoreComponent;
|
||||
import org.briarproject.CoreEagerSingletons;
|
||||
import org.briarproject.DaggerCoreComponent;
|
||||
import org.briarproject.plugins.PluginsModuleExtension;
|
||||
import org.briarproject.system.PlatformModuleExtension;
|
||||
import org.briarproject.system.SystemModuleExtension;
|
||||
|
||||
public class BriarApplication extends Application {
|
||||
|
||||
private static final Logger LOG =
|
||||
@@ -23,14 +30,21 @@ public class BriarApplication extends Application {
|
||||
CrashHandler newHandler = new CrashHandler(ctx, oldHandler);
|
||||
Thread.setDefaultUncaughtExceptionHandler(newHandler);
|
||||
|
||||
CoreComponent coreComponent = DaggerCoreComponent.builder()
|
||||
.systemModule(new SystemModuleExtension(this))
|
||||
.platformModule(new PlatformModuleExtension(this))
|
||||
.pluginsModule(new PluginsModuleExtension(this))
|
||||
.build();
|
||||
|
||||
applicationComponent = DaggerAndroidComponent.builder()
|
||||
.appModule(new AppModule(this))
|
||||
.androidModule(new AndroidModule())
|
||||
.coreComponent(coreComponent)
|
||||
.build();
|
||||
// We need to load the eager singletons directly after making the
|
||||
// dependency graph
|
||||
AndroidModule.injectEager(applicationComponent);
|
||||
|
||||
// We need to load the eager singletons directly after making the
|
||||
// dependency graphs
|
||||
CoreEagerSingletons.initEagerSingletons(coreComponent);
|
||||
AndroidEagerSingletons.initEagerSingletons(applicationComponent);
|
||||
}
|
||||
|
||||
public AndroidComponent getApplicationComponent() {
|
||||
|
||||
@@ -12,7 +12,7 @@ import android.os.IBinder;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.api.android.AndroidExecutor;
|
||||
import org.briarproject.api.android.PlatformExecutor;
|
||||
import org.briarproject.api.db.DatabaseConfig;
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.api.lifecycle.LifecycleManager.StartResult;
|
||||
@@ -48,7 +48,7 @@ public class BriarService extends Service {
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject protected volatile LifecycleManager lifecycleManager;
|
||||
@Inject protected volatile AndroidExecutor androidExecutor;
|
||||
@Inject protected volatile PlatformExecutor platformExecutor;
|
||||
private volatile boolean started = false;
|
||||
|
||||
@Override
|
||||
@@ -106,7 +106,7 @@ public class BriarService extends Service {
|
||||
}
|
||||
|
||||
private void showStartupFailureNotification(final StartResult result) {
|
||||
androidExecutor.execute(new Runnable() {
|
||||
platformExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
NotificationCompat.Builder b =
|
||||
new NotificationCompat.Builder(BriarService.this);
|
||||
|
||||
@@ -4,14 +4,12 @@ import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
|
||||
import org.briarproject.api.android.AndroidExecutor;
|
||||
import org.briarproject.api.android.PlatformExecutor;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.api.plugins.BackoffFactory;
|
||||
import org.briarproject.api.plugins.duplex.DuplexPluginConfig;
|
||||
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
||||
import org.briarproject.api.plugins.simplex.SimplexPluginConfig;
|
||||
import org.briarproject.api.plugins.simplex.SimplexPluginFactory;
|
||||
import org.briarproject.api.system.LocationUtils;
|
||||
import org.briarproject.plugins.droidtooth.DroidtoothPluginFactory;
|
||||
import org.briarproject.plugins.tcp.AndroidLanTcpPluginFactory;
|
||||
@@ -20,32 +18,22 @@ import org.briarproject.plugins.tor.TorPluginFactory;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
@Module
|
||||
public class AndroidPluginsModule extends PluginsModule {
|
||||
public class AndroidPluginsModule {
|
||||
|
||||
@Provides
|
||||
SimplexPluginConfig getSimplexPluginConfig() {
|
||||
return new SimplexPluginConfig() {
|
||||
public Collection<SimplexPluginFactory> getFactories() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Provides
|
||||
DuplexPluginConfig getDuplexPluginConfig(@IoExecutor Executor ioExecutor,
|
||||
AndroidExecutor androidExecutor, Application app,
|
||||
DuplexPluginConfig provideDuplexPluginConfig(@IoExecutor Executor ioExecutor,
|
||||
PlatformExecutor platformExecutor, Application app,
|
||||
SecureRandom random, BackoffFactory backoffFactory,
|
||||
LocationUtils locationUtils, EventBus eventBus) {
|
||||
Context appContext = app.getApplicationContext();
|
||||
DuplexPluginFactory bluetooth = new DroidtoothPluginFactory(ioExecutor,
|
||||
androidExecutor, appContext, random, backoffFactory);
|
||||
platformExecutor, appContext, random, backoffFactory);
|
||||
DuplexPluginFactory tor = new TorPluginFactory(ioExecutor, appContext,
|
||||
locationUtils, eventBus);
|
||||
DuplexPluginFactory lan = new AndroidLanTcpPluginFactory(ioExecutor,
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package org.briarproject.plugins;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
import org.briarproject.api.android.PlatformExecutor;
|
||||
import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.api.plugins.BackoffFactory;
|
||||
import org.briarproject.api.plugins.duplex.DuplexPluginConfig;
|
||||
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
||||
import org.briarproject.api.system.LocationUtils;
|
||||
import org.briarproject.plugins.droidtooth.DroidtoothPluginFactory;
|
||||
import org.briarproject.plugins.tcp.AndroidLanTcpPluginFactory;
|
||||
import org.briarproject.plugins.tor.TorPluginFactory;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public class PluginsModuleExtension extends PluginsModule {
|
||||
|
||||
private final Application app;
|
||||
|
||||
public PluginsModuleExtension(Application app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DuplexPluginConfig provideDuplexPluginConfig(
|
||||
@IoExecutor Executor ioExecutor, PlatformExecutor platformExecutor,
|
||||
SecureRandom random, BackoffFactory backoffFactory,
|
||||
LocationUtils locationUtils, EventBus eventBus) {
|
||||
Context appContext = app.getApplicationContext();
|
||||
DuplexPluginFactory bluetooth = new DroidtoothPluginFactory(ioExecutor,
|
||||
platformExecutor, appContext, random, backoffFactory);
|
||||
DuplexPluginFactory tor = new TorPluginFactory(ioExecutor, appContext,
|
||||
locationUtils, eventBus);
|
||||
DuplexPluginFactory lan = new AndroidLanTcpPluginFactory(ioExecutor,
|
||||
backoffFactory, appContext);
|
||||
final Collection<DuplexPluginFactory> factories =
|
||||
Arrays.asList(bluetooth, tor, lan);
|
||||
return new DuplexPluginConfig() {
|
||||
public Collection<DuplexPluginFactory> getFactories() {
|
||||
return factories;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.briarproject.android;
|
||||
package org.briarproject.system;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
@@ -6,7 +6,7 @@ import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
|
||||
import org.briarproject.api.android.AndroidExecutor;
|
||||
import org.briarproject.api.android.PlatformExecutor;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
@@ -14,11 +14,10 @@ import java.util.concurrent.FutureTask;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
class AndroidExecutorImpl implements AndroidExecutor {
|
||||
class AndroidExecutorImpl implements PlatformExecutor {
|
||||
|
||||
private final Handler handler;
|
||||
|
||||
@Inject
|
||||
AndroidExecutorImpl(Application app) {
|
||||
Context ctx = app.getApplicationContext();
|
||||
handler = new FutureTaskHandler(ctx.getMainLooper());
|
||||
@@ -0,0 +1,78 @@
|
||||
package org.briarproject.system;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
import org.briarproject.PlatformModule;
|
||||
import org.briarproject.android.ApplicationScope;
|
||||
import org.briarproject.api.android.PlatformExecutor;
|
||||
import org.briarproject.api.crypto.SecretKey;
|
||||
import org.briarproject.api.db.DatabaseConfig;
|
||||
import org.briarproject.api.ui.UiCallback;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class PlatformModuleExtension extends PlatformModule {
|
||||
|
||||
private final UiCallback uiCallback;
|
||||
private final Application app;
|
||||
|
||||
public PlatformModuleExtension(Application app) {
|
||||
this.app = app;
|
||||
// Use a dummy UI callback
|
||||
uiCallback = new UiCallback() {
|
||||
|
||||
public int showChoice(String[] options, String... message) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean showConfirmationMessage(String... message) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void showMessage(String... message) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public UiCallback provideUICallback() {
|
||||
return uiCallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ApplicationScope
|
||||
public DatabaseConfig provideDatabaseConfig() {
|
||||
final File dir = app.getApplicationContext().getDir("db", Context.MODE_PRIVATE);
|
||||
return new DatabaseConfig() {
|
||||
|
||||
private volatile SecretKey key = null;
|
||||
|
||||
public boolean databaseExists() {
|
||||
return dir.isDirectory() && dir.listFiles().length > 0;
|
||||
}
|
||||
|
||||
public File getDatabaseDirectory() {
|
||||
return dir;
|
||||
}
|
||||
|
||||
public void setEncryptionKey(SecretKey key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public SecretKey getEncryptionKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public long getMaxSize() {
|
||||
return Long.MAX_VALUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformExecutor providePlatformExecutor() {
|
||||
return new AndroidExecutorImpl(app);
|
||||
}
|
||||
}
|
||||
@@ -11,26 +11,21 @@ import org.briarproject.api.system.Timer;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
@Module
|
||||
public class AndroidSystemModule {
|
||||
public class SystemModuleExtension extends SystemModule {
|
||||
|
||||
@Provides
|
||||
Clock provideClock() {
|
||||
return new SystemClock();
|
||||
private final Application app;
|
||||
|
||||
public SystemModuleExtension(final Application app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
@Provides
|
||||
Timer provideTimer() {
|
||||
return new SystemTimer();
|
||||
}
|
||||
|
||||
@Provides
|
||||
SeedProvider provideSeedProvider(final Application app) {
|
||||
@Override
|
||||
public SeedProvider provideSeedProvider() {
|
||||
return new AndroidSeedProvider(app);
|
||||
}
|
||||
|
||||
@Provides
|
||||
LocationUtils provideLocationUtils(final Application app) {
|
||||
@Override
|
||||
public LocationUtils provideLocationUtils() {
|
||||
return new AndroidLocationUtils(app);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user