From d771f6c94cdffdd73fd65e4da93860e20f4f325a Mon Sep 17 00:00:00 2001 From: akwizgran <akwizgran@users.sourceforge.net> Date: Fri, 29 Nov 2013 22:52:51 +0000 Subject: [PATCH] Merged HelloWorldModule into AndroidModule. --- briar-android/res/values/roboguice.xml | 1 - .../net/sf/briar/android/AndroidModule.java | 51 ++++++++++++++++ .../android/helloworld/HelloWorldModule.java | 61 ------------------- 3 files changed, 51 insertions(+), 62 deletions(-) delete mode 100644 briar-android/src/net/sf/briar/android/helloworld/HelloWorldModule.java diff --git a/briar-android/res/values/roboguice.xml b/briar-android/res/values/roboguice.xml index 55873674e6..5d317aeb97 100644 --- a/briar-android/res/values/roboguice.xml +++ b/briar-android/res/values/roboguice.xml @@ -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> diff --git a/briar-android/src/net/sf/briar/android/AndroidModule.java b/briar-android/src/net/sf/briar/android/AndroidModule.java index bcccfefd0c..1a584579a5 100644 --- a/briar-android/src/net/sf/briar/android/AndroidModule.java +++ b/briar-android/src/net/sf/briar/android/AndroidModule.java @@ -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; + } + }; + } } diff --git a/briar-android/src/net/sf/briar/android/helloworld/HelloWorldModule.java b/briar-android/src/net/sf/briar/android/helloworld/HelloWorldModule.java deleted file mode 100644 index 4a28987d2a..0000000000 --- a/briar-android/src/net/sf/briar/android/helloworld/HelloWorldModule.java +++ /dev/null @@ -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; - } - }; - } -} -- GitLab