diff --git a/briar-android/src/org/briarproject/android/AppModule.java b/briar-android/src/org/briarproject/android/AppModule.java index 8f80ce0395841c0d5d1a5e81eb2d0c7f14a77831..5060b5f31bfd05c8ad89d1bf3e685fd9823a28d4 100644 --- a/briar-android/src/org/briarproject/android/AppModule.java +++ b/briar-android/src/org/briarproject/android/AppModule.java @@ -42,14 +42,17 @@ public class AppModule { this.application = application; uiCallback = new UiCallback() { + @Override public int showChoice(String[] options, String... message) { throw new UnsupportedOperationException(); } + @Override public boolean showConfirmationMessage(String... message) { throw new UnsupportedOperationException(); } + @Override public void showMessage(String... message) { throw new UnsupportedOperationException(); } @@ -75,24 +78,29 @@ public class AppModule { private volatile SecretKey key = null; + @Override public boolean databaseExists() { if (!dir.isDirectory()) return false; File[] files = dir.listFiles(); return files != null && files.length > 0; } + @Override public File getDatabaseDirectory() { return dir; } + @Override public void setEncryptionKey(SecretKey key) { this.key = key; } + @Override public SecretKey getEncryptionKey() { return key; } + @Override public long getMaxSize() { return Long.MAX_VALUE; } diff --git a/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java b/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java index 3347c2477ee47bdce74ad69ac7b005e39dce8044..e66e0a6583e9ca7acfff0a018e5411d621ea9422 100644 --- a/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java +++ b/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java @@ -248,17 +248,17 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener { // Unzip the Tor binary to the filesystem in = getTorInputStream(); out = new FileOutputStream(torFile); - IoUtils.copy(in, out); + IoUtils.copyAndClose(in, out); // Make the Tor binary executable if (!torFile.setExecutable(true, true)) throw new IOException(); // Unzip the GeoIP database to the filesystem in = getGeoIpInputStream(); out = new FileOutputStream(geoIpFile); - IoUtils.copy(in, out); + IoUtils.copyAndClose(in, out); // Copy the config file to the filesystem in = getConfigInputStream(); out = new FileOutputStream(configFile); - IoUtils.copy(in, out); + IoUtils.copyAndClose(in, out); doneFile.createNewFile(); } catch (IOException e) { tryToClose(in); @@ -306,8 +306,12 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener { } private void listFiles(File f) { - if (f.isDirectory()) for (File child : f.listFiles()) listFiles(child); - else LOG.info(f.getAbsolutePath()); + if (f.isDirectory()) { + File[] children = f.listFiles(); + if (children != null) for (File child : children) listFiles(child); + } else { + LOG.info(f.getAbsolutePath()); + } } private byte[] read(File f) throws IOException { @@ -322,7 +326,7 @@ class TorPlugin implements DuplexPlugin, EventHandler, EventListener { } return b; } finally { - in.close(); + tryToClose(in); } } diff --git a/briar-core/src/org/briarproject/db/H2Database.java b/briar-core/src/org/briarproject/db/H2Database.java index f671530857d1d83a4b66b7bba3c6676ea45d5726..5c062120d419cb850bb3b89598db1a0624ae535a 100644 --- a/briar-core/src/org/briarproject/db/H2Database.java +++ b/briar-core/src/org/briarproject/db/H2Database.java @@ -35,6 +35,7 @@ class H2Database extends JdbcDatabase { + ";WRITE_DELAY=0;DB_CLOSE_ON_EXIT=false"; } + @Override public boolean open() throws DbException { boolean reopen = config.databaseExists(); if (!reopen) config.getDatabaseDirectory().mkdirs(); @@ -42,6 +43,7 @@ class H2Database extends JdbcDatabase { return reopen; } + @Override public void close() throws DbException { // H2 will close the database when the last connection closes try { @@ -51,6 +53,7 @@ class H2Database extends JdbcDatabase { } } + @Override public long getFreeSpace() throws DbException { File dir = config.getDatabaseDirectory(); long maxSize = config.getMaxSize(); @@ -63,7 +66,9 @@ class H2Database extends JdbcDatabase { private long getDiskSpace(File f) { if (f.isDirectory()) { long total = 0; - for (File child : f.listFiles()) total += getDiskSpace(child); + File[] children = f.listFiles(); + if (children != null) + for (File child : children) total += getDiskSpace(child); return total; } else if (f.isFile()) { return f.length(); diff --git a/briar-core/src/org/briarproject/reporting/DevReporterImpl.java b/briar-core/src/org/briarproject/reporting/DevReporterImpl.java index 7d7415fb018dcd74e87a0930469bc0dbde296721..e9df7058280cb951a5f1e429a55a3b0b3d195408 100644 --- a/briar-core/src/org/briarproject/reporting/DevReporterImpl.java +++ b/briar-core/src/org/briarproject/reporting/DevReporterImpl.java @@ -35,7 +35,7 @@ class DevReporterImpl implements DevReporter { private final DevConfig devConfig; private final SocketFactory torSocketFactory; - public DevReporterImpl(CryptoComponent crypto, DevConfig devConfig, + DevReporterImpl(CryptoComponent crypto, DevConfig devConfig, SocketFactory torSocketFactory) { this.crypto = crypto; this.devConfig = devConfig; @@ -90,7 +90,7 @@ class DevReporterImpl implements DevReporter { Socket s = connectToDevelopers(); out = s.getOutputStream(); in = new FileInputStream(f); - IoUtils.copy(in, out); + IoUtils.copyAndClose(in, out); f.delete(); } catch (IOException e) { LOG.log(WARNING, "Failed to send reports", e); diff --git a/briar-core/src/org/briarproject/util/IoUtils.java b/briar-core/src/org/briarproject/util/IoUtils.java index 494c3a854be4c68386b6ed080e84eec4df051428..cb76c9d5fe838b0557e3761fc826eac969f5c2f7 100644 --- a/briar-core/src/org/briarproject/util/IoUtils.java +++ b/briar-core/src/org/briarproject/util/IoUtils.java @@ -20,7 +20,7 @@ public class IoUtils { } } - public static void copy(InputStream in, OutputStream out) + public static void copyAndClose(InputStream in, OutputStream out) throws IOException { byte[] buf = new byte[4096]; try { diff --git a/briar-tests/src/org/briarproject/TestDatabaseConfig.java b/briar-tests/src/org/briarproject/TestDatabaseConfig.java index 4066b149e24f369b0051a2257b1c4853666b13b0..03bfb4b1e9d783d2e3654d2e8b23ced15e764e4f 100644 --- a/briar-tests/src/org/briarproject/TestDatabaseConfig.java +++ b/briar-tests/src/org/briarproject/TestDatabaseConfig.java @@ -16,24 +16,29 @@ public class TestDatabaseConfig implements DatabaseConfig { this.maxSize = maxSize; } + @Override public boolean databaseExists() { if (!dir.isDirectory()) return false; File[] files = dir.listFiles(); return files != null && files.length > 0; } + @Override public File getDatabaseDirectory() { return dir; } + @Override public void setEncryptionKey(SecretKey key) { this.key = key; } + @Override public SecretKey getEncryptionKey() { return key; } + @Override public long getMaxSize() { return maxSize; }