more changes for executing binaries from libs/jni folder

This commit is contained in:
Nathan Freitas 2013-12-27 12:30:20 -05:00
parent d40016b54a
commit 6b0b0fa069
3 changed files with 17 additions and 27 deletions

View File

@ -48,11 +48,6 @@ public class TorBinaryInstaller implements TorServiceConstants {
InputStream is; InputStream is;
File outFile; File outFile;
is = context.getResources().openRawResource(R.raw.tor);
outFile = new File(installFolder, TOR_BINARY_ASSET_KEY);
streamToFile(is, outFile, false, true);
is = context.getResources().openRawResource(R.raw.torrc); is = context.getResources().openRawResource(R.raw.torrc);
outFile = new File(installFolder, TORRC_ASSET_KEY); outFile = new File(installFolder, TORRC_ASSET_KEY);
streamToFile(is,outFile, false, false); streamToFile(is,outFile, false, false);
@ -61,24 +56,17 @@ public class TorBinaryInstaller implements TorServiceConstants {
outFile = new File(installFolder, TORRC_TETHER_KEY); outFile = new File(installFolder, TORRC_TETHER_KEY);
streamToFile(is, outFile, false, false); streamToFile(is, outFile, false, false);
is = context.getResources().openRawResource(R.raw.privoxy);
outFile = new File(installFolder, PRIVOXY_ASSET_KEY);
streamToFile(is,outFile, false, false);
is = context.getResources().openRawResource(R.raw.privoxy_config); is = context.getResources().openRawResource(R.raw.privoxy_config);
outFile = new File(installFolder, PRIVOXYCONFIG_ASSET_KEY); outFile = new File(installFolder, PRIVOXYCONFIG_ASSET_KEY);
streamToFile(is,outFile, false, false); streamToFile(is,outFile, false, false);
is = context.getResources().openRawResource(R.raw.obfsproxy);
outFile = new File(installFolder, OBFSPROXY_ASSET_KEY);
streamToFile(is,outFile, false, false);
return true; return true;
} }
/* /*
* Extract the Tor binary from the APK file using ZIP * Extract the Tor binary from the APK file using ZIP
*/ */
/*
public boolean installGeoIP () throws IOException, FileNotFoundException public boolean installGeoIP () throws IOException, FileNotFoundException
{ {
@ -90,7 +78,7 @@ public class TorBinaryInstaller implements TorServiceConstants {
streamToFile(is, outFile, false, true); streamToFile(is, outFile, false, true);
return true; return true;
} }*/
/* /*
private static void copyAssetFile(Context ctx, String asset, File file) throws IOException, InterruptedException private static void copyAssetFile(Context ctx, String asset, File file) throws IOException, InterruptedException
@ -248,6 +236,7 @@ public class TorBinaryInstaller implements TorServiceConstants {
* @param showErrors indicates if errors should be alerted * @param showErrors indicates if errors should be alerted
* @return false if the binary files could not be installed * @return false if the binary files could not be installed
*/ */
/*
public static boolean assertIpTablesBinaries(Context ctx, boolean showErrors) throws Exception { public static boolean assertIpTablesBinaries(Context ctx, boolean showErrors) throws Exception {
boolean changed = false; boolean changed = false;
@ -256,7 +245,7 @@ public class TorBinaryInstaller implements TorServiceConstants {
copyRawFile(ctx, R.raw.iptables, file, CHMOD_EXEC, false); copyRawFile(ctx, R.raw.iptables, file, CHMOD_EXEC, false);
return true; return true;
} }*/
} }

View File

@ -86,6 +86,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
// private String appHome; // private String appHome;
private File appBinHome; private File appBinHome;
private File appCacheHome; private File appCacheHome;
private File appLibsHome;
private File fileTor; private File fileTor;
private File filePrivoxy; private File filePrivoxy;
@ -528,10 +529,11 @@ public class TorService extends Service implements TorServiceConstants, TorConst
appBinHome = getDir("bin",Application.MODE_PRIVATE); appBinHome = getDir("bin",Application.MODE_PRIVATE);
appCacheHome = getDir("data",Application.MODE_PRIVATE); appCacheHome = getDir("data",Application.MODE_PRIVATE);
appLibsHome = new File(getApplicationInfo().nativeLibraryDir);
fileTor = new File(appBinHome, TOR_BINARY_ASSET_KEY); fileTor = new File(appLibsHome, TOR_BINARY_ASSET_KEY);
filePrivoxy = new File(appBinHome, PRIVOXY_ASSET_KEY); filePrivoxy = new File(appLibsHome, PRIVOXY_ASSET_KEY);
fileObfsProxy = new File(appBinHome, OBFSPROXY_ASSET_KEY); fileObfsProxy = new File(appLibsHome, OBFSPROXY_ASSET_KEY);
} }
@ -541,9 +543,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
SharedPreferences prefs =getSharedPrefs(getApplicationContext()); SharedPreferences prefs =getSharedPrefs(getApplicationContext());
//check and install iptables
TorBinaryInstaller.assertIpTablesBinaries(this, true);
initTorPaths(); initTorPaths();
String currTorBinary = prefs.getString(TorServiceConstants.PREF_BINARY_TOR_VERSION_INSTALLED, null); String currTorBinary = prefs.getString(TorServiceConstants.PREF_BINARY_TOR_VERSION_INSTALLED, null);
@ -1707,13 +1706,15 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{ {
if (!fileGeoIP.exists()) if (!fileGeoIP.exists())
{ {
TorBinaryInstaller installer = new TorBinaryInstaller(this, appBinHome); //TorBinaryInstaller installer = new TorBinaryInstaller(this, appBinHome);
boolean success = installer.installGeoIP(); //boolean success = installer.installGeoIP();
//TODO get GEOIP add-on here
} }
mBinder.updateConfiguration("GeoIPFile", fileGeoIP.getAbsolutePath(), false); mBinder.updateConfiguration("GeoIPFile", fileGeoIP.getAbsolutePath(), false);
} }
catch (IOException e) catch (Exception e)
{ {
showToolbarNotification (getString(R.string.error_installing_binares),ERROR_NOTIFY_ID,R.drawable.ic_stat_tor, Notification.FLAG_ONGOING_EVENT); showToolbarNotification (getString(R.string.error_installing_binares),ERROR_NOTIFY_ID,R.drawable.ic_stat_tor, Notification.FLAG_ONGOING_EVENT);

View File

@ -12,7 +12,7 @@ public interface TorServiceConstants {
//home directory of Android application //home directory of Android application
//name of the tor C binary //name of the tor C binary
public final static String TOR_BINARY_ASSET_KEY = "tor"; public final static String TOR_BINARY_ASSET_KEY = "libtor.so";
//torrc (tor config file) //torrc (tor config file)
public final static String TORRC_ASSET_KEY = "torrc"; public final static String TORRC_ASSET_KEY = "torrc";
@ -24,7 +24,7 @@ public interface TorServiceConstants {
// public final static String TOR_COMMAND_LINE_ARGS = "-f " + TORRC_INSTALL_PATH + " || exit\n"; // public final static String TOR_COMMAND_LINE_ARGS = "-f " + TORRC_INSTALL_PATH + " || exit\n";
//privoxy //privoxy
public final static String PRIVOXY_ASSET_KEY = "privoxy"; public final static String PRIVOXY_ASSET_KEY = "libprivoxy.so";
//privoxy.config //privoxy.config
public final static String PRIVOXYCONFIG_ASSET_KEY = "privoxy.config"; public final static String PRIVOXYCONFIG_ASSET_KEY = "privoxy.config";
@ -82,7 +82,7 @@ public interface TorServiceConstants {
public static final String PREF_BINARY_PRIVOXY_VERSION_INSTALLED = "BINARY_PRIVOXY_VERSION_INTALLED"; public static final String PREF_BINARY_PRIVOXY_VERSION_INSTALLED = "BINARY_PRIVOXY_VERSION_INTALLED";
//obfsproxy //obfsproxy
public static final String OBFSPROXY_ASSET_KEY = "obfsproxy"; public static final String OBFSPROXY_ASSET_KEY = "libobfsproxy.so";
public static final int MESSAGE_TRAFFIC_COUNT = 5; public static final int MESSAGE_TRAFFIC_COUNT = 5;