mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Merged HelloWorldModule into AndroidModule.
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
<resources>
|
||||
<string-array name="roboguice_modules">
|
||||
<item>net.sf.briar.android.AndroidModule</item>
|
||||
<item>net.sf.briar.android.helloworld.HelloWorldModule</item>
|
||||
<item>net.sf.briar.clock.ClockModule</item>
|
||||
<item>net.sf.briar.crypto.CryptoModule</item>
|
||||
<item>net.sf.briar.db.DatabaseModule</item>
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package net.sf.briar.android;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -18,6 +20,7 @@ import net.sf.briar.api.android.AndroidExecutor;
|
||||
import net.sf.briar.api.android.DatabaseUiExecutor;
|
||||
import net.sf.briar.api.android.ReferenceManager;
|
||||
import net.sf.briar.api.crypto.CryptoComponent;
|
||||
import net.sf.briar.api.db.DatabaseConfig;
|
||||
import net.sf.briar.api.lifecycle.LifecycleManager;
|
||||
import net.sf.briar.api.lifecycle.ShutdownManager;
|
||||
import net.sf.briar.api.os.FileUtils;
|
||||
@@ -26,10 +29,12 @@ import net.sf.briar.api.plugins.duplex.DuplexPluginConfig;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
|
||||
import net.sf.briar.api.plugins.simplex.SimplexPluginConfig;
|
||||
import net.sf.briar.api.plugins.simplex.SimplexPluginFactory;
|
||||
import net.sf.briar.api.ui.UiCallback;
|
||||
import net.sf.briar.plugins.droidtooth.DroidtoothPluginFactory;
|
||||
import net.sf.briar.plugins.tcp.DroidLanTcpPluginFactory;
|
||||
import net.sf.briar.plugins.tcp.WanTcpPluginFactory;
|
||||
import net.sf.briar.plugins.tor.TorPluginFactory;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
@@ -38,6 +43,7 @@ import com.google.inject.Provides;
|
||||
public class AndroidModule extends AbstractModule {
|
||||
|
||||
private final ExecutorService databaseUiExecutor;
|
||||
private final UiCallback uiCallback;
|
||||
|
||||
public AndroidModule() {
|
||||
// The queue is unbounded, so tasks can be dependent
|
||||
@@ -48,6 +54,21 @@ public class AndroidModule extends AbstractModule {
|
||||
// Use a single thread so DB accesses from the UI don't overlap
|
||||
databaseUiExecutor = new ThreadPoolExecutor(1, 1, 60, SECONDS, queue,
|
||||
policy);
|
||||
// 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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected void configure() {
|
||||
@@ -55,6 +76,7 @@ public class AndroidModule extends AbstractModule {
|
||||
bind(ReferenceManager.class).to(
|
||||
ReferenceManagerImpl.class).in(Singleton.class);
|
||||
bind(FileUtils.class).to(AndroidFileUtils.class);
|
||||
bind(UiCallback.class).toInstance(uiCallback);
|
||||
}
|
||||
|
||||
@Provides @Singleton @DatabaseUiExecutor
|
||||
@@ -94,4 +116,33 @@ public class AndroidModule extends AbstractModule {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Provides @Singleton
|
||||
DatabaseConfig getDatabaseConfig(final Application app) {
|
||||
final File dir = app.getApplicationContext().getDir("db", MODE_PRIVATE);
|
||||
return new DatabaseConfig() {
|
||||
|
||||
private volatile byte[] key = null;
|
||||
|
||||
public boolean databaseExists() {
|
||||
return dir.isDirectory() && dir.listFiles().length > 0;
|
||||
}
|
||||
|
||||
public File getDatabaseDirectory() {
|
||||
return dir;
|
||||
}
|
||||
|
||||
public void setEncryptionKey(byte[] key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public byte[] getEncryptionKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public long getMaxSize() {
|
||||
return Long.MAX_VALUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
package net.sf.briar.android.helloworld;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import net.sf.briar.api.db.DatabaseConfig;
|
||||
import net.sf.briar.api.ui.UiCallback;
|
||||
import android.app.Application;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
public class HelloWorldModule extends AbstractModule {
|
||||
|
||||
protected void configure() {
|
||||
bind(UiCallback.class).toInstance(new UiCallback() {
|
||||
|
||||
public int showChoice(String[] options, String... message) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public boolean showConfirmationMessage(String... message) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void showMessage(String... message) {}
|
||||
});
|
||||
}
|
||||
|
||||
@Provides @Singleton
|
||||
DatabaseConfig getDatabaseConfig(final Application app) {
|
||||
final File dir = app.getApplicationContext().getDir("db", MODE_PRIVATE);
|
||||
return new DatabaseConfig() {
|
||||
|
||||
private volatile byte[] key = null;
|
||||
|
||||
public boolean databaseExists() {
|
||||
return dir.isDirectory() && dir.listFiles().length > 0;
|
||||
}
|
||||
|
||||
public File getDatabaseDirectory() {
|
||||
return dir;
|
||||
}
|
||||
|
||||
public void setEncryptionKey(byte[] key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public byte[] getEncryptionKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public long getMaxSize() {
|
||||
return Long.MAX_VALUE;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user