Separate FileUtils implementations for Android and desktop builds.

The method used by Commons IO to get the available disk space fails on
Android devices that lack a df binary - use the Android API instead.
This commit is contained in:
akwizgran
2013-07-27 20:50:05 +01:00
parent 0941697922
commit c868764244
23 changed files with 116 additions and 295 deletions

View File

@@ -0,0 +1,13 @@
package net.sf.briar.os;
import net.sf.briar.api.os.FileUtils;
import com.google.inject.AbstractModule;
public class DesktopOsModule extends AbstractModule {
@Override
protected void configure() {
bind(FileUtils.class).to(FileUtilsImpl.class);
}
}

View File

@@ -0,0 +1,15 @@
package net.sf.briar.os;
import java.io.File;
import java.io.IOException;
import net.sf.briar.api.os.FileUtils;
import org.apache.commons.io.FileSystemUtils;
class FileUtilsImpl implements FileUtils {
public long getFreeSpace(File f) throws IOException {
return FileSystemUtils.freeSpaceKb(f.getAbsolutePath()) * 1024;
}
}

View File

@@ -6,6 +6,7 @@ import java.util.concurrent.Executor;
import net.sf.briar.api.crypto.CryptoComponent;
import net.sf.briar.api.lifecycle.ShutdownManager;
import net.sf.briar.api.os.FileUtils;
import net.sf.briar.api.plugins.PluginExecutor;
import net.sf.briar.api.plugins.duplex.DuplexPluginConfig;
import net.sf.briar.api.plugins.duplex.DuplexPluginFactory;
@@ -27,9 +28,9 @@ public class DesktopPluginsModule extends AbstractModule {
@Provides
SimplexPluginConfig getSimplexPluginConfig(
@PluginExecutor Executor pluginExecutor) {
@PluginExecutor Executor pluginExecutor, FileUtils fileUtils) {
SimplexPluginFactory removable =
new RemovableDrivePluginFactory(pluginExecutor);
new RemovableDrivePluginFactory(pluginExecutor, fileUtils);
final Collection<SimplexPluginFactory> factories =
Arrays.asList(removable);
return new SimplexPluginConfig() {

View File

@@ -13,6 +13,7 @@ import java.util.logging.Logger;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.TransportId;
import net.sf.briar.api.os.FileUtils;
import net.sf.briar.api.plugins.simplex.SimplexPluginCallback;
import net.sf.briar.util.StringUtils;
@@ -31,11 +32,11 @@ implements RemovableDriveMonitor.Callback {
private final RemovableDriveFinder finder;
private final RemovableDriveMonitor monitor;
RemovableDrivePlugin(Executor pluginExecutor,
RemovableDrivePlugin(Executor pluginExecutor, FileUtils fileUtils,
SimplexPluginCallback callback, RemovableDriveFinder finder,
RemovableDriveMonitor monitor, int maxFrameLength,
long maxLatency) {
super(pluginExecutor, callback, maxFrameLength, maxLatency);
super(pluginExecutor, fileUtils, callback, maxFrameLength, maxLatency);
this.finder = finder;
this.monitor = monitor;
}

View File

@@ -5,6 +5,7 @@ import static net.sf.briar.api.transport.TransportConstants.MAX_FRAME_LENGTH;
import java.util.concurrent.Executor;
import net.sf.briar.api.TransportId;
import net.sf.briar.api.os.FileUtils;
import net.sf.briar.api.plugins.simplex.SimplexPlugin;
import net.sf.briar.api.plugins.simplex.SimplexPluginCallback;
import net.sf.briar.api.plugins.simplex.SimplexPluginFactory;
@@ -17,9 +18,12 @@ public class RemovableDrivePluginFactory implements SimplexPluginFactory {
private static final long POLLING_INTERVAL = 10 * 1000; // 10 seconds
private final Executor pluginExecutor;
private final FileUtils fileUtils;
public RemovableDrivePluginFactory(Executor pluginExecutor) {
public RemovableDrivePluginFactory(Executor pluginExecutor,
FileUtils fileUtils) {
this.pluginExecutor = pluginExecutor;
this.fileUtils = fileUtils;
}
public TransportId getId() {
@@ -47,7 +51,7 @@ public class RemovableDrivePluginFactory implements SimplexPluginFactory {
} else {
return null;
}
return new RemovableDrivePlugin(pluginExecutor, callback, finder,
monitor, MAX_FRAME_LENGTH, MAX_LATENCY);
return new RemovableDrivePlugin(pluginExecutor, fileUtils, callback,
finder, monitor, MAX_FRAME_LENGTH, MAX_LATENCY);
}
}