more updates to install clean-up process

This commit is contained in:
Nathan Freitas 2014-04-08 16:09:04 -04:00
parent f885059b94
commit 60a79a2ae0
4 changed files with 46 additions and 13 deletions

6
external/.tx/config vendored
View File

@ -8,3 +8,9 @@ host = https://www.transifex.com
source_file = ../res/values/strings.xml
source_lang = en
[orbot.DESCRIPTION]
file_filter=../docs/play/description-<lang>.txt
host = https://www.transifex.com
source_file = ../docs/play/description.txt
source_lang = en

View File

@ -37,6 +37,25 @@ public class TorResourceInstaller implements TorServiceConstants {
this.context = context;
}
public void deleteDirectory(File file) {
if( file.exists() ) {
if (file.isDirectory()) {
File[] files = file.listFiles();
for(int i=0; i<files.length; i++) {
if(files[i].isDirectory()) {
deleteDirectory(files[i]);
}
else {
files[i].delete();
}
}
}
file.delete();
}
}
private final static String COMMAND_RM_FORCE = "rm -f ";
//
/*
* Extract the Tor resources from the APK file using ZIP
@ -47,43 +66,45 @@ public class TorResourceInstaller implements TorServiceConstants {
InputStream is;
File outFile;
deleteDirectory(installFolder);
installFolder.mkdirs();
Shell shell = Shell.startShell(new ArrayList<String>(),installFolder.getAbsolutePath());
is = context.getResources().openRawResource(R.raw.torrc);
outFile = new File(installFolder, TORRC_ASSET_KEY);
shell.add(new SimpleCommand("rm " + outFile.getAbsolutePath())).waitForFinish();
shell.add(new SimpleCommand(COMMAND_RM_FORCE + outFile.getAbsolutePath())).waitForFinish();
streamToFile(is,outFile, false, false);
is = context.getResources().openRawResource(R.raw.torrctether);
outFile = new File(installFolder, TORRC_TETHER_KEY);
shell.add(new SimpleCommand("rm " + outFile.getAbsolutePath())).waitForFinish();
shell.add(new SimpleCommand(COMMAND_RM_FORCE + outFile.getAbsolutePath())).waitForFinish();
streamToFile(is, outFile, false, false);
is = context.getResources().openRawResource(R.raw.privoxy_config);
outFile = new File(installFolder, PRIVOXYCONFIG_ASSET_KEY);
shell.add(new SimpleCommand("rm " + outFile.getAbsolutePath())).waitForFinish();
shell.add(new SimpleCommand(COMMAND_RM_FORCE + outFile.getAbsolutePath())).waitForFinish();
streamToFile(is,outFile, false, false);
is = context.getResources().openRawResource(R.raw.tor);
outFile = new File(installFolder, TOR_ASSET_KEY);
shell.add(new SimpleCommand("rm " + outFile.getAbsolutePath())).waitForFinish();
shell.add(new SimpleCommand(COMMAND_RM_FORCE + outFile.getAbsolutePath())).waitForFinish();
streamToFile(is,outFile, false, true);
is = context.getResources().openRawResource(R.raw.privoxy);
outFile = new File(installFolder, PRIVOXY_ASSET_KEY);
shell.add(new SimpleCommand("rm " + outFile.getAbsolutePath())).waitForFinish();
shell.add(new SimpleCommand(COMMAND_RM_FORCE + outFile.getAbsolutePath())).waitForFinish();
streamToFile(is,outFile, false, true);
is = context.getResources().openRawResource(R.raw.obfsproxy);
outFile = new File(installFolder, OBFSPROXY_ASSET_KEY);
shell.add(new SimpleCommand("rm " + outFile.getAbsolutePath())).waitForFinish();
shell.add(new SimpleCommand(COMMAND_RM_FORCE + outFile.getAbsolutePath())).waitForFinish();
streamToFile(is,outFile, false, true);
is = context.getResources().openRawResource(R.raw.xtables);
outFile = new File(installFolder, IPTABLES_ASSET_KEY);
shell.add(new SimpleCommand("rm " + outFile.getAbsolutePath())).waitForFinish();
shell.add(new SimpleCommand(COMMAND_RM_FORCE + outFile.getAbsolutePath())).waitForFinish();
streamToFile(is,outFile, false, true);
return true;
@ -136,8 +157,7 @@ public class TorResourceInstaller implements TorServiceConstants {
int bytecount;
OutputStream stmOut = new FileOutputStream(outFile, append);
OutputStream stmOut = new FileOutputStream(outFile.getAbsolutePath(), append);
ZipInputStream zis = null;
if (zip)

View File

@ -270,6 +270,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
*/
public int onStartCommand(Intent intent, int flags, int startId) {
appBinHome = getDir(DIRECTORY_TOR_BINARY,Application.MODE_PRIVATE);
appCacheHome = getDir(DIRECTORY_TOR_DATA,Application.MODE_PRIVATE);
@ -517,11 +518,15 @@ public class TorService extends Service implements TorServiceConstants, TorConst
SharedPreferences prefs = getSharedPrefs(getApplicationContext());
String version = prefs.getString(PREF_BINARY_TOR_VERSION_INSTALLED,null);
logNotice("checking binary version: " + version);
if (version == null || (!version.equals(BINARY_TOR_VERSION)))
{
stopTor();
logNotice("upgrading binaries to latest version: " + BINARY_TOR_VERSION);
TorResourceInstaller installer = new TorResourceInstaller(this, appBinHome);
boolean success = installer.installResources();
@ -531,6 +536,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
else if (!fileTorRc.exists())
{
stopTor();
logNotice("upgrading binaries to latest version: " + BINARY_TOR_VERSION);
TorResourceInstaller installer = new TorResourceInstaller(this, appBinHome);
boolean success = installer.installResources();

View File

@ -7,7 +7,7 @@ public interface TorServiceConstants {
public final static String TOR_APP_USERNAME = "org.torproject.android";
public final static String ORWEB_APP_USERNAME = "info.guardianproject.browser";
public final static String DIRECTORY_TOR_BINARY = "bins";
public final static String DIRECTORY_TOR_BINARY = "bin";
public final static String DIRECTORY_TOR_DATA = "data";
//name of the tor C binary
@ -79,10 +79,10 @@ public interface TorServiceConstants {
public static final int DISABLE_TOR_MSG = 3;
public static final int LOG_MSG = 4;
public static final String BINARY_TOR_VERSION = "0.2.4.21-openssl1.0.1g-installfix";
public static final String BINARY_TOR_VERSION = "0.2.4.21-openssl1.0.1g-if6";
public static final String BINARY_PRIVOXY_VERSION = "3.0.12";
public static final String PREF_BINARY_TOR_VERSION_INSTALLED = "BINARY_TOR_VERSION_INTALLED";
public static final String PREF_BINARY_PRIVOXY_VERSION_INSTALLED = "BINARY_PRIVOXY_VERSION_INTALLED";
public static final String PREF_BINARY_TOR_VERSION_INSTALLED = "BINARY_TOR_VERSION_INSTALLED";
public static final String PREF_BINARY_PRIVOXY_VERSION_INSTALLED = "BINARY_PRIVOXY_VERSION_INSTALLED";
//obfsproxy
public static final String OBFSPROXY_ASSET_KEY = "obfsproxy";