mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-23 08:09:54 +01:00
Support Tor on Android x86 (thanks to n8fr8).
This commit is contained in:
BIN
briar-android/assets/tor-arm-pie.zip
Normal file
BIN
briar-android/assets/tor-arm-pie.zip
Normal file
Binary file not shown.
BIN
briar-android/assets/tor-arm.zip
Normal file
BIN
briar-android/assets/tor-arm.zip
Normal file
Binary file not shown.
Binary file not shown.
BIN
briar-android/assets/tor-x86-pie.zip
Normal file
BIN
briar-android/assets/tor-x86-pie.zip
Normal file
Binary file not shown.
BIN
briar-android/assets/tor-x86.zip
Normal file
BIN
briar-android/assets/tor-x86.zip
Normal file
Binary file not shown.
Binary file not shown.
@@ -27,6 +27,7 @@ import java.io.IOException;
|
|||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -38,6 +39,7 @@ import java.util.logging.Logger;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.briarproject.R;
|
import org.briarproject.R;
|
||||||
|
import org.briarproject.android.util.AndroidUtils;
|
||||||
import org.briarproject.android.util.HorizontalBorder;
|
import org.briarproject.android.util.HorizontalBorder;
|
||||||
import org.briarproject.android.util.LayoutUtils;
|
import org.briarproject.android.util.LayoutUtils;
|
||||||
import org.briarproject.android.util.ListLoadingProgressBar;
|
import org.briarproject.android.util.ListLoadingProgressBar;
|
||||||
@@ -181,7 +183,6 @@ public class CrashReportActivity extends Activity implements OnClickListener {
|
|||||||
|
|
||||||
// FIXME: Load strings from resources if we're keeping this activity
|
// FIXME: Load strings from resources if we're keeping this activity
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private Map<String, String> getStatusMap() {
|
private Map<String, String> getStatusMap() {
|
||||||
Map<String, String> statusMap = new LinkedHashMap<String, String>();
|
Map<String, String> statusMap = new LinkedHashMap<String, String>();
|
||||||
|
|
||||||
@@ -202,19 +203,9 @@ public class CrashReportActivity extends Activity implements OnClickListener {
|
|||||||
statusMap.put("Android version:", release + " (" + sdk + ")");
|
statusMap.put("Android version:", release + " (" + sdk + ")");
|
||||||
|
|
||||||
// CPU architectures
|
// CPU architectures
|
||||||
String arch = null;
|
Collection<String> abis = AndroidUtils.getSupportedArchitectures();
|
||||||
if(Build.VERSION.SDK_INT >= 21) {
|
String joined = StringUtils.join(abis, ", ");
|
||||||
for(String abi : Build.SUPPORTED_ABIS) {
|
statusMap.put("Architecture:", joined);
|
||||||
if(arch == null) arch = abi;
|
|
||||||
else arch = arch + ", " + abi;
|
|
||||||
}
|
|
||||||
} else if(Build.VERSION.SDK_INT >= 8) {
|
|
||||||
if(Build.CPU_ABI2 == null) arch = Build.CPU_ABI;
|
|
||||||
else arch = Build.CPU_ABI + ", " + Build.CPU_ABI2;
|
|
||||||
} else {
|
|
||||||
arch = Build.CPU_ABI;
|
|
||||||
}
|
|
||||||
statusMap.put("Architecture:", arch);
|
|
||||||
|
|
||||||
// System memory
|
// System memory
|
||||||
Object o = getSystemService(ACTIVITY_SERVICE);
|
Object o = getSystemService(ACTIVITY_SERVICE);
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import java.io.IOException;
|
|||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -39,6 +40,7 @@ import java.util.regex.Pattern;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.briarproject.R;
|
import org.briarproject.R;
|
||||||
|
import org.briarproject.android.util.AndroidUtils;
|
||||||
import org.briarproject.android.util.ElasticHorizontalSpace;
|
import org.briarproject.android.util.ElasticHorizontalSpace;
|
||||||
import org.briarproject.android.util.HorizontalBorder;
|
import org.briarproject.android.util.HorizontalBorder;
|
||||||
import org.briarproject.android.util.LayoutUtils;
|
import org.briarproject.android.util.LayoutUtils;
|
||||||
@@ -192,7 +194,6 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
|||||||
|
|
||||||
// FIXME: Load strings from resources if we're keeping this activity
|
// FIXME: Load strings from resources if we're keeping this activity
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private Map<String, String> getStatusMap() {
|
private Map<String, String> getStatusMap() {
|
||||||
Map<String, String> statusMap = new LinkedHashMap<String, String>();
|
Map<String, String> statusMap = new LinkedHashMap<String, String>();
|
||||||
|
|
||||||
@@ -212,18 +213,10 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
|||||||
int sdk = Build.VERSION.SDK_INT;
|
int sdk = Build.VERSION.SDK_INT;
|
||||||
statusMap.put("Android version:", release + " (" + sdk + ")");
|
statusMap.put("Android version:", release + " (" + sdk + ")");
|
||||||
|
|
||||||
// CPU architecture
|
// CPU architectures
|
||||||
String arch = null;
|
Collection<String> abis = AndroidUtils.getSupportedArchitectures();
|
||||||
if(Build.VERSION.SDK_INT >= 21) {
|
String joined = StringUtils.join(abis, ", ");
|
||||||
for(String abi : Build.SUPPORTED_ABIS) {
|
statusMap.put("Architecture:", joined);
|
||||||
if(arch == null) arch = abi;
|
|
||||||
else arch = arch + ", " + abi;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(Build.CPU_ABI2 == null) arch = Build.CPU_ABI;
|
|
||||||
else arch = Build.CPU_ABI + ", " + Build.CPU_ABI2;
|
|
||||||
}
|
|
||||||
statusMap.put("Architecture:", arch);
|
|
||||||
|
|
||||||
// System memory
|
// System memory
|
||||||
Object o = getSystemService(ACTIVITY_SERVICE);
|
Object o = getSystemService(ACTIVITY_SERVICE);
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package org.briarproject.android.util;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.os.Build;
|
||||||
|
|
||||||
|
public class AndroidUtils {
|
||||||
|
|
||||||
|
@SuppressLint("NewApi")
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public static Collection<String> getSupportedArchitectures() {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
return Collections.unmodifiableList(abis);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -75,6 +75,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
|||||||
private final Context appContext;
|
private final Context appContext;
|
||||||
private final LocationUtils locationUtils;
|
private final LocationUtils locationUtils;
|
||||||
private final DuplexPluginCallback callback;
|
private final DuplexPluginCallback callback;
|
||||||
|
private final String architecture;
|
||||||
private final int maxLatency, maxIdleTime, pollingInterval, socketTimeout;
|
private final int maxLatency, maxIdleTime, pollingInterval, socketTimeout;
|
||||||
private final File torDirectory, torFile, geoIpFile, configFile, doneFile;
|
private final File torDirectory, torFile, geoIpFile, configFile, doneFile;
|
||||||
private final File cookieFile, hostnameFile;
|
private final File cookieFile, hostnameFile;
|
||||||
@@ -89,11 +90,13 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
|||||||
|
|
||||||
TorPlugin(Executor ioExecutor, Context appContext,
|
TorPlugin(Executor ioExecutor, Context appContext,
|
||||||
LocationUtils locationUtils, DuplexPluginCallback callback,
|
LocationUtils locationUtils, DuplexPluginCallback callback,
|
||||||
int maxLatency, int maxIdleTime, int pollingInterval) {
|
String architecture, int maxLatency, int maxIdleTime,
|
||||||
|
int pollingInterval) {
|
||||||
this.ioExecutor = ioExecutor;
|
this.ioExecutor = ioExecutor;
|
||||||
this.appContext = appContext;
|
this.appContext = appContext;
|
||||||
this.locationUtils = locationUtils;
|
this.locationUtils = locationUtils;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
|
this.architecture = architecture;
|
||||||
this.maxLatency = maxLatency;
|
this.maxLatency = maxLatency;
|
||||||
this.maxIdleTime = maxIdleTime;
|
this.maxIdleTime = maxIdleTime;
|
||||||
this.pollingInterval = pollingInterval;
|
this.pollingInterval = pollingInterval;
|
||||||
@@ -266,14 +269,9 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private InputStream getTorInputStream() throws IOException {
|
private InputStream getTorInputStream() throws IOException {
|
||||||
String filename;
|
if(LOG.isLoggable(INFO))
|
||||||
if(Build.VERSION.SDK_INT >= 16) {
|
LOG.info("Installing Tor binary for " + architecture);
|
||||||
LOG.info("Installing PIE Tor binary");
|
String filename = "tor-" + architecture + ".zip";
|
||||||
filename = "tor-pie.zip";
|
|
||||||
} else {
|
|
||||||
LOG.info("Installing non-PIE Tor binary");
|
|
||||||
filename = "tor.zip";
|
|
||||||
}
|
|
||||||
InputStream in = appContext.getResources().getAssets().open(filename);
|
InputStream in = appContext.getResources().getAssets().open(filename);
|
||||||
ZipInputStream zin = new ZipInputStream(in);
|
ZipInputStream zin = new ZipInputStream(in);
|
||||||
if(zin.getNextEntry() == null) throw new IOException();
|
if(zin.getNextEntry() == null) throw new IOException();
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
package org.briarproject.plugins.tor;
|
package org.briarproject.plugins.tor;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.briarproject.android.util.AndroidUtils;
|
||||||
import org.briarproject.api.TransportId;
|
import org.briarproject.api.TransportId;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
import org.briarproject.api.plugins.duplex.DuplexPlugin;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
import org.briarproject.api.plugins.duplex.DuplexPluginCallback;
|
||||||
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
||||||
import org.briarproject.api.system.LocationUtils;
|
import org.briarproject.api.system.LocationUtils;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
@@ -39,26 +37,25 @@ public class TorPluginFactory implements DuplexPluginFactory {
|
|||||||
return TorPlugin.ID;
|
return TorPlugin.ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
||||||
// Check that we have a Tor binary for this architecture
|
// Check that we have a Tor binary for this architecture
|
||||||
List<String> abis = new ArrayList<String>();
|
String architecture = null;
|
||||||
if(Build.VERSION.SDK_INT >= 21) {
|
for(String abi : AndroidUtils.getSupportedArchitectures()) {
|
||||||
for(String abi : Build.SUPPORTED_ABIS) abis.add(abi);
|
if(abi.startsWith("x86")) {
|
||||||
} else if(Build.VERSION.SDK_INT >= 8) {
|
architecture = "x86";
|
||||||
abis.add(Build.CPU_ABI);
|
break;
|
||||||
if(Build.CPU_ABI2 != null) abis.add(Build.CPU_ABI2);
|
} else if(abi.startsWith("armeabi")) {
|
||||||
} else {
|
architecture = "arm";
|
||||||
abis.add(Build.CPU_ABI);
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
boolean supported = false;
|
if(architecture == null) {
|
||||||
for(String abi : abis) if(abi.startsWith("armeabi")) supported = true;
|
|
||||||
if(!supported) {
|
|
||||||
LOG.info("Tor is not supported on this architecture");
|
LOG.info("Tor is not supported on this architecture");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
// Use position-independent executable for SDK >= 16
|
||||||
|
if(Build.VERSION.SDK_INT >= 16) architecture += "-pie";
|
||||||
return new TorPlugin(ioExecutor,appContext, locationUtils, callback,
|
return new TorPlugin(ioExecutor,appContext, locationUtils, callback,
|
||||||
MAX_LATENCY, MAX_IDLE_TIME, POLLING_INTERVAL);
|
architecture, MAX_LATENCY, MAX_IDLE_TIME, POLLING_INTERVAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.briarproject.util;
|
package org.briarproject.util;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
public class StringUtils {
|
public class StringUtils {
|
||||||
|
|
||||||
@@ -13,6 +14,15 @@ public class StringUtils {
|
|||||||
return s == null || s.length() == 0;
|
return s == null || s.length() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String join(Collection<String> strings, String separator) {
|
||||||
|
StringBuilder joined = new StringBuilder();
|
||||||
|
for(String s : strings) {
|
||||||
|
if(joined.length() > 0) joined.append(separator);
|
||||||
|
joined.append(s);
|
||||||
|
}
|
||||||
|
return joined.toString();
|
||||||
|
}
|
||||||
|
|
||||||
public static byte[] toUtf8(String s) {
|
public static byte[] toUtf8(String s) {
|
||||||
try {
|
try {
|
||||||
return s.getBytes("UTF-8");
|
return s.getBytes("UTF-8");
|
||||||
|
|||||||
Reference in New Issue
Block a user