improved handling of binary upgrade process
This commit is contained in:
parent
5ff9e40851
commit
2962f58447
|
@ -7,6 +7,7 @@ import java.io.BufferedReader;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -45,28 +46,36 @@ public class TorBinaryInstaller implements TorServiceConstants {
|
||||||
/*
|
/*
|
||||||
* Extract the Tor binary from the APK file using ZIP
|
* Extract the Tor binary from the APK file using ZIP
|
||||||
*/
|
*/
|
||||||
public boolean installFromRaw () throws IOException
|
public boolean installFromRaw () throws IOException, FileNotFoundException
|
||||||
{
|
{
|
||||||
|
|
||||||
InputStream is;
|
InputStream is;
|
||||||
|
File outFile;
|
||||||
|
|
||||||
|
|
||||||
is = context.getResources().openRawResource(R.raw.tor);
|
is = context.getResources().openRawResource(R.raw.tor);
|
||||||
streamToFile(is,installFolder, TOR_BINARY_ASSET_KEY, false, true);
|
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);
|
||||||
streamToFile(is,installFolder, TORRC_ASSET_KEY, false, false);
|
outFile = new File(installFolder, TORRC_ASSET_KEY);
|
||||||
|
streamToFile(is,outFile, false, false);
|
||||||
|
|
||||||
is = context.getResources().openRawResource(R.raw.torrctether);
|
is = context.getResources().openRawResource(R.raw.torrctether);
|
||||||
streamToFile(is,installFolder, TORRC_TETHER_KEY, false, false);
|
outFile = new File(installFolder, TORRC_TETHER_KEY);
|
||||||
|
streamToFile(is, outFile, false, false);
|
||||||
|
|
||||||
is = context.getResources().openRawResource(R.raw.privoxy);
|
is = context.getResources().openRawResource(R.raw.privoxy);
|
||||||
streamToFile(is,installFolder, PRIVOXY_ASSET_KEY, false, false);
|
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);
|
||||||
streamToFile(is,installFolder, PRIVOXYCONFIG_ASSET_KEY, false, false);
|
outFile = new File(installFolder, PRIVOXYCONFIG_ASSET_KEY);
|
||||||
|
streamToFile(is,outFile, false, false);
|
||||||
|
|
||||||
is = context.getResources().openRawResource(R.raw.geoip);
|
is = context.getResources().openRawResource(R.raw.geoip);
|
||||||
streamToFile(is,installFolder, GEOIP_ASSET_KEY, false, true);
|
outFile = new File(installFolder, GEOIP_ASSET_KEY);
|
||||||
|
streamToFile(is, outFile, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -88,14 +97,13 @@ public class TorBinaryInstaller implements TorServiceConstants {
|
||||||
/*
|
/*
|
||||||
* Write the inputstream contents to the file
|
* Write the inputstream contents to the file
|
||||||
*/
|
*/
|
||||||
private static boolean streamToFile(InputStream stm, File folder, String targetFilename, boolean append, boolean zip) throws IOException
|
private static boolean streamToFile(InputStream stm, File outFile, boolean append, boolean zip) throws IOException
|
||||||
|
|
||||||
{
|
{
|
||||||
byte[] buffer = new byte[FILE_WRITE_BUFFER_SIZE];
|
byte[] buffer = new byte[FILE_WRITE_BUFFER_SIZE];
|
||||||
|
|
||||||
int bytecount;
|
int bytecount;
|
||||||
|
|
||||||
File outFile = new File(folder, targetFilename);
|
|
||||||
|
|
||||||
OutputStream stmOut = new FileOutputStream(outFile, append);
|
OutputStream stmOut = new FileOutputStream(outFile, append);
|
||||||
|
|
||||||
|
|
|
@ -207,11 +207,11 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
Log.i(TAG, "service started: " + intent.getAction());
|
Log.i(TAG, "service started: " + intent.getAction());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
checkTorBinaries ();
|
checkTorBinaries (false);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
logNotice("unable to find tor binaries: " + e.getMessage());
|
logNotice("unable to find tor binaries: " + e.getMessage());
|
||||||
showToolbarNotification(e.getMessage(), NOTIFY_ID, R.drawable.tornotificationerr);
|
showToolbarNotification(getString(R.string.error_installing_binares), NOTIFY_ID, R.drawable.tornotificationerr);
|
||||||
|
|
||||||
Log.e(TAG, "error checking tor binaries", e);
|
Log.e(TAG, "error checking tor binaries", e);
|
||||||
}
|
}
|
||||||
|
@ -412,24 +412,46 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean checkTorBinaries (boolean forceInstall) throws Exception
|
||||||
private boolean checkTorBinaries () throws Exception
|
|
||||||
{
|
{
|
||||||
|
|
||||||
//check and install iptables
|
//check and install iptables
|
||||||
TorBinaryInstaller.assertIpTablesBinaries(this, true);
|
TorBinaryInstaller.assertIpTablesBinaries(this, true);
|
||||||
|
|
||||||
appBinHome = getDir("bin",0);
|
appBinHome = getDir("bin",0);
|
||||||
appDataHome = getCacheDir();
|
appDataHome = getCacheDir();
|
||||||
|
|
||||||
// logNotice( "appHome=" + appHome);
|
File fileTor = new File(appBinHome, TOR_BINARY_ASSET_KEY);
|
||||||
|
|
||||||
File fileTor = new File(appBinHome, TOR_BINARY_ASSET_KEY);
|
|
||||||
File filePrivoxy = new File(appBinHome, PRIVOXY_ASSET_KEY);
|
File filePrivoxy = new File(appBinHome, PRIVOXY_ASSET_KEY);
|
||||||
|
|
||||||
|
File fileTorOld = null;
|
||||||
|
File filePrivoxyOld = null;
|
||||||
|
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
String currTorBinary = prefs.getString(TorServiceConstants.PREF_BINARY_TOR_VERSION_INSTALLED, null);
|
||||||
|
String currPrivoxyBinary = prefs.getString(TorServiceConstants.PREF_BINARY_PRIVOXY_VERSION_INSTALLED, null);
|
||||||
|
|
||||||
|
if (currTorBinary == null || (!currTorBinary.equals(TorServiceConstants.BINARY_TOR_VERSION)))
|
||||||
|
if (fileTor.exists())
|
||||||
|
{
|
||||||
|
killTorProcess ();
|
||||||
|
fileTorOld = new File(fileTor.getAbsolutePath() + ".old");
|
||||||
|
fileTor.renameTo(fileTorOld);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currPrivoxyBinary == null || (!currPrivoxyBinary.equals(TorServiceConstants.BINARY_PRIVOXY_VERSION)))
|
||||||
|
if (filePrivoxy.exists())
|
||||||
|
{
|
||||||
|
killTorProcess ();
|
||||||
|
filePrivoxyOld = new File(filePrivoxy.getAbsolutePath() + ".old");
|
||||||
|
filePrivoxy.renameTo(filePrivoxyOld);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
logNotice( "checking Tor binaries");
|
logNotice( "checking Tor binaries");
|
||||||
|
|
||||||
if (!(fileTor.exists() && filePrivoxy.exists()))
|
if ((!(fileTor.exists() && filePrivoxy.exists())) || forceInstall)
|
||||||
{
|
{
|
||||||
killTorProcess ();
|
killTorProcess ();
|
||||||
|
|
||||||
|
@ -438,6 +460,18 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Editor edit = prefs.edit();
|
||||||
|
edit.putString(TorServiceConstants.PREF_BINARY_TOR_VERSION_INSTALLED, TorServiceConstants.BINARY_TOR_VERSION);
|
||||||
|
edit.putString(TorServiceConstants.PREF_BINARY_PRIVOXY_VERSION_INSTALLED, TorServiceConstants.BINARY_PRIVOXY_VERSION);
|
||||||
|
edit.commit();
|
||||||
|
|
||||||
|
if (fileTorOld != null)
|
||||||
|
fileTorOld.delete();
|
||||||
|
|
||||||
|
if (filePrivoxyOld != null)
|
||||||
|
filePrivoxyOld.delete();
|
||||||
|
|
||||||
logNotice(getString(R.string.status_install_success));
|
logNotice(getString(R.string.status_install_success));
|
||||||
|
|
||||||
showToolbarNotification(getString(R.string.status_install_success), NOTIFY_ID, R.drawable.tornotification);
|
showToolbarNotification(getString(R.string.status_install_success), NOTIFY_ID, R.drawable.tornotification);
|
||||||
|
@ -1028,10 +1062,11 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
|
|
||||||
_torInstance = this;
|
_torInstance = this;
|
||||||
|
|
||||||
|
/*
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
checkTorBinaries();
|
checkTorBinaries(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -1041,7 +1076,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
|
|
||||||
Log.d(TAG,"Unable to check for Tor binaries",e);
|
Log.d(TAG,"Unable to check for Tor binaries",e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
findExistingProc ();
|
findExistingProc ();
|
||||||
|
|
||||||
|
|
|
@ -85,4 +85,12 @@ public interface TorServiceConstants {
|
||||||
public static final int ENABLE_TOR_MSG = 2;
|
public static final int ENABLE_TOR_MSG = 2;
|
||||||
public static final int DISABLE_TOR_MSG = 3;
|
public static final int DISABLE_TOR_MSG = 3;
|
||||||
public static final int LOG_MSG = 4;
|
public static final int LOG_MSG = 4;
|
||||||
|
|
||||||
|
public static final String BINARY_TOR_VERSION = "0.2.3.10-alpha";
|
||||||
|
public static final String BINARY_PRIVOXY_VERSION = "1.4.13";
|
||||||
|
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";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue