Support Tor on Android x86 (thanks to n8fr8).

This commit is contained in:
akwizgran
2015-04-16 08:02:57 +01:00
parent 92d26f7867
commit 6135bea2b4
12 changed files with 69 additions and 53 deletions

View File

@@ -75,6 +75,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
private final Context appContext;
private final LocationUtils locationUtils;
private final DuplexPluginCallback callback;
private final String architecture;
private final int maxLatency, maxIdleTime, pollingInterval, socketTimeout;
private final File torDirectory, torFile, geoIpFile, configFile, doneFile;
private final File cookieFile, hostnameFile;
@@ -89,11 +90,13 @@ class TorPlugin implements DuplexPlugin, EventHandler {
TorPlugin(Executor ioExecutor, Context appContext,
LocationUtils locationUtils, DuplexPluginCallback callback,
int maxLatency, int maxIdleTime, int pollingInterval) {
String architecture, int maxLatency, int maxIdleTime,
int pollingInterval) {
this.ioExecutor = ioExecutor;
this.appContext = appContext;
this.locationUtils = locationUtils;
this.callback = callback;
this.architecture = architecture;
this.maxLatency = maxLatency;
this.maxIdleTime = maxIdleTime;
this.pollingInterval = pollingInterval;
@@ -266,14 +269,9 @@ class TorPlugin implements DuplexPlugin, EventHandler {
}
private InputStream getTorInputStream() throws IOException {
String filename;
if(Build.VERSION.SDK_INT >= 16) {
LOG.info("Installing PIE Tor binary");
filename = "tor-pie.zip";
} else {
LOG.info("Installing non-PIE Tor binary");
filename = "tor.zip";
}
if(LOG.isLoggable(INFO))
LOG.info("Installing Tor binary for " + architecture);
String filename = "tor-" + architecture + ".zip";
InputStream in = appContext.getResources().getAssets().open(filename);
ZipInputStream zin = new ZipInputStream(in);
if(zin.getNextEntry() == null) throw new IOException();

View File

@@ -1,17 +1,15 @@
package org.briarproject.plugins.tor;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
import org.briarproject.android.util.AndroidUtils;
import org.briarproject.api.TransportId;
import org.briarproject.api.plugins.duplex.DuplexPlugin;
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
import org.briarproject.api.system.LocationUtils;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
@@ -39,26 +37,25 @@ public class TorPluginFactory implements DuplexPluginFactory {
return TorPlugin.ID;
}
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
// Check that we have a Tor binary for this architecture
List<String> abis = new ArrayList<String>();
if(Build.VERSION.SDK_INT >= 21) {
for(String abi : Build.SUPPORTED_ABIS) abis.add(abi);
} else if(Build.VERSION.SDK_INT >= 8) {
abis.add(Build.CPU_ABI);
if(Build.CPU_ABI2 != null) abis.add(Build.CPU_ABI2);
} else {
abis.add(Build.CPU_ABI);
String architecture = null;
for(String abi : AndroidUtils.getSupportedArchitectures()) {
if(abi.startsWith("x86")) {
architecture = "x86";
break;
} else if(abi.startsWith("armeabi")) {
architecture = "arm";
break;
}
}
boolean supported = false;
for(String abi : abis) if(abi.startsWith("armeabi")) supported = true;
if(!supported) {
if(architecture == null) {
LOG.info("Tor is not supported on this architecture");
return null;
}
// Use position-independent executable for SDK >= 16
if(Build.VERSION.SDK_INT >= 16) architecture += "-pie";
return new TorPlugin(ioExecutor,appContext, locationUtils, callback,
MAX_LATENCY, MAX_IDLE_TIME, POLLING_INTERVAL);
architecture, MAX_LATENCY, MAX_IDLE_TIME, POLLING_INTERVAL);
}
}