mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 20:29:52 +01:00
Add Android implementation of RemovableDrivePlugin.
This commit is contained in:
@@ -0,0 +1,42 @@
|
|||||||
|
package org.briarproject.bramble.plugin.file;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
import android.net.Uri;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.properties.TransportProperties;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
import static org.briarproject.bramble.api.plugin.RemovableDriveConstants.PROP_URI;
|
||||||
|
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
class AndroidRemovableDrivePlugin extends RemovableDrivePlugin {
|
||||||
|
|
||||||
|
private final Application app;
|
||||||
|
|
||||||
|
AndroidRemovableDrivePlugin(Application app, int maxLatency) {
|
||||||
|
super(maxLatency);
|
||||||
|
this.app = app;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
InputStream openInputStream(TransportProperties p) throws IOException {
|
||||||
|
String uri = p.get(PROP_URI);
|
||||||
|
if (isNullOrEmpty(uri)) throw new IllegalArgumentException();
|
||||||
|
return app.getContentResolver().openInputStream(Uri.parse(uri));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
OutputStream openOutputStream(TransportProperties p) throws IOException {
|
||||||
|
String uri = p.get(PROP_URI);
|
||||||
|
if (isNullOrEmpty(uri)) throw new IllegalArgumentException();
|
||||||
|
return app.getContentResolver().openOutputStream(Uri.parse(uri));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package org.briarproject.bramble.plugin.file;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.plugin.PluginCallback;
|
||||||
|
import org.briarproject.bramble.api.plugin.TransportId;
|
||||||
|
import org.briarproject.bramble.api.plugin.simplex.SimplexPlugin;
|
||||||
|
import org.briarproject.bramble.api.plugin.simplex.SimplexPluginFactory;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static java.util.concurrent.TimeUnit.DAYS;
|
||||||
|
import static org.briarproject.bramble.api.plugin.RemovableDriveConstants.ID;
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public class AndroidRemovableDrivePluginFactory implements
|
||||||
|
SimplexPluginFactory {
|
||||||
|
|
||||||
|
private static final int MAX_LATENCY = (int) DAYS.toMillis(14);
|
||||||
|
|
||||||
|
private final Application app;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
AndroidRemovableDrivePluginFactory(Application app) {
|
||||||
|
this.app = app;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TransportId getId() {
|
||||||
|
return ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxLatency() {
|
||||||
|
return MAX_LATENCY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public SimplexPlugin createPlugin(PluginCallback callback) {
|
||||||
|
return new AndroidRemovableDrivePlugin(app, MAX_LATENCY);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,4 +5,5 @@ public interface RemovableDriveConstants {
|
|||||||
TransportId ID = new TransportId("org.briarproject.bramble.drive");
|
TransportId ID = new TransportId("org.briarproject.bramble.drive");
|
||||||
|
|
||||||
String PROP_PATH = "path";
|
String PROP_PATH = "path";
|
||||||
|
String PROP_URI = "uri";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import static org.briarproject.bramble.api.plugin.RemovableDriveConstants.ID;
|
|||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class RemovableDrivePluginFactory implements SimplexPluginFactory {
|
public class RemovableDrivePluginFactory implements SimplexPluginFactory {
|
||||||
|
|
||||||
private final int MAX_LATENCY = (int) DAYS.toMillis(14);
|
private static final int MAX_LATENCY = (int) DAYS.toMillis(14);
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
RemovableDrivePluginFactory() {
|
RemovableDrivePluginFactory() {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import org.briarproject.bramble.api.plugin.duplex.DuplexPluginFactory;
|
|||||||
import org.briarproject.bramble.api.plugin.simplex.SimplexPluginFactory;
|
import org.briarproject.bramble.api.plugin.simplex.SimplexPluginFactory;
|
||||||
import org.briarproject.bramble.api.reporting.DevConfig;
|
import org.briarproject.bramble.api.reporting.DevConfig;
|
||||||
import org.briarproject.bramble.plugin.bluetooth.AndroidBluetoothPluginFactory;
|
import org.briarproject.bramble.plugin.bluetooth.AndroidBluetoothPluginFactory;
|
||||||
|
import org.briarproject.bramble.plugin.file.AndroidRemovableDrivePluginFactory;
|
||||||
import org.briarproject.bramble.plugin.tcp.AndroidLanTcpPluginFactory;
|
import org.briarproject.bramble.plugin.tcp.AndroidLanTcpPluginFactory;
|
||||||
import org.briarproject.bramble.plugin.tor.AndroidTorPluginFactory;
|
import org.briarproject.bramble.plugin.tor.AndroidTorPluginFactory;
|
||||||
import org.briarproject.bramble.util.AndroidUtils;
|
import org.briarproject.bramble.util.AndroidUtils;
|
||||||
@@ -67,7 +68,6 @@ import dagger.Provides;
|
|||||||
import static android.content.Context.MODE_PRIVATE;
|
import static android.content.Context.MODE_PRIVATE;
|
||||||
import static android.os.Build.VERSION.SDK_INT;
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
import static java.util.Collections.emptyList;
|
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
import static java.util.Collections.singletonMap;
|
import static java.util.Collections.singletonMap;
|
||||||
import static org.briarproject.bramble.api.reporting.ReportingConstants.DEV_ONION_ADDRESS;
|
import static org.briarproject.bramble.api.reporting.ReportingConstants.DEV_ONION_ADDRESS;
|
||||||
@@ -151,7 +151,8 @@ public class AppModule {
|
|||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
PluginConfig providePluginConfig(AndroidBluetoothPluginFactory bluetooth,
|
PluginConfig providePluginConfig(AndroidBluetoothPluginFactory bluetooth,
|
||||||
AndroidTorPluginFactory tor, AndroidLanTcpPluginFactory lan) {
|
AndroidTorPluginFactory tor, AndroidLanTcpPluginFactory lan,
|
||||||
|
AndroidRemovableDrivePluginFactory drive) {
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
PluginConfig pluginConfig = new PluginConfig() {
|
PluginConfig pluginConfig = new PluginConfig() {
|
||||||
|
|
||||||
@@ -162,7 +163,7 @@ public class AppModule {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<SimplexPluginFactory> getSimplexFactories() {
|
public Collection<SimplexPluginFactory> getSimplexFactories() {
|
||||||
return emptyList();
|
return singletonList(drive);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user