more updates for moving binaries to libs/armeabi

This commit is contained in:
Nathan Freitas 2013-12-27 15:27:20 -05:00
parent 5870a674d8
commit 1739473a1d
3 changed files with 54 additions and 174 deletions

View File

@ -1,32 +0,0 @@
package org.torproject.android.service;
import org.torproject.android.service.TorService;
import android.os.AsyncTask;
import android.os.RemoteException;
public class CheckBinariesAsyncTask extends AsyncTask<TorService, Integer, Long>
{
@Override
protected Long doInBackground(TorService... torService) {
try {
torService[0].checkTorBinaries(false);
} catch (Exception e) {
e.printStackTrace();
}
return 100L;
}
protected void onProgressUpdate(Integer... progress) {
}
protected void onPostExecute(Long result) {
}
}

View File

@ -42,7 +42,7 @@ 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, FileNotFoundException public boolean installResources () throws IOException, FileNotFoundException
{ {
InputStream is; InputStream is;
@ -66,7 +66,7 @@ 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 installGeoIP () throws IOException, FileNotFoundException public boolean installGeoIP () throws IOException, FileNotFoundException
{ {
@ -78,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

View File

@ -83,6 +83,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
private File fileTor; private File fileTor;
private File filePrivoxy; private File filePrivoxy;
private File fileObfsProxy; private File fileObfsProxy;
private File fileTorRc;
private TorTransProxy mTransProxy; private TorTransProxy mTransProxy;
@ -157,6 +158,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
/* (non-Javadoc) /* (non-Javadoc)
* @see android.app.Service#onLowMemory() * @see android.app.Service#onLowMemory()
*/ */
@Override
public void onLowMemory() { public void onLowMemory() {
super.onLowMemory(); super.onLowMemory();
@ -168,12 +170,11 @@ public class TorService extends Service implements TorServiceConstants, TorConst
/* (non-Javadoc) /* (non-Javadoc)
* @see android.app.Service#onUnbind(android.content.Intent) * @see android.app.Service#onUnbind(android.content.Intent)
*/ */
@Override
public boolean onUnbind(Intent intent) { public boolean onUnbind(Intent intent) {
// logNotice( "onUnbind Called: " + intent.getAction()); // logNotice( "onUnbind Called: " + intent.getAction());
return super.onUnbind(intent); return super.onUnbind(intent);
@ -224,6 +225,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
/* (non-Javadoc) /* (non-Javadoc)
* @see android.app.Service#onRebind(android.content.Intent) * @see android.app.Service#onRebind(android.content.Intent)
*/ */
@Override
public void onRebind(Intent intent) { public void onRebind(Intent intent) {
super.onRebind(intent); super.onRebind(intent);
@ -237,9 +239,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
/* (non-Javadoc) /* (non-Javadoc)
* @see android.app.Service#onStart(android.content.Intent, int) * @see android.app.Service#onStart(android.content.Intent, int)
*/ */
public void onStart(Intent intent, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
super.onStart(intent, startId);
_torInstance = this; _torInstance = this;
initTorPaths(); initTorPaths();
@ -250,23 +251,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
new Thread ()
{
public void run ()
{
try {
checkTorBinaries (false);
} catch (Exception e) {
logNotice("unable to find tor binaries: " + e.getMessage());
showToolbarNotification(getString(R.string.error_installing_binares), ERROR_NOTIFY_ID, R.drawable.ic_stat_notifyerr, -1);
Log.e(TAG, "error checking tor binaries", e);
}
}
}.start();
if (intent != null && intent.getAction()!=null && intent.getAction().equals("onboot")) if (intent != null && intent.getAction()!=null && intent.getAction().equals("onboot"))
@ -279,6 +263,11 @@ public class TorService extends Service implements TorServiceConstants, TorConst
setTorProfile(PROFILE_ON); setTorProfile(PROFILE_ON);
} }
} }
// We want this service to continue running until it is explicitly
// stopped, so return sticky.
return START_STICKY;
} }
public static SharedPreferences getSharedPrefs (Context context) public static SharedPreferences getSharedPrefs (Context context)
@ -508,91 +497,46 @@ public class TorService extends Service implements TorServiceConstants, TorConst
appCacheHome = getDir("data",Application.MODE_PRIVATE); appCacheHome = getDir("data",Application.MODE_PRIVATE);
appLibsHome = new File(getApplicationInfo().nativeLibraryDir); appLibsHome = new File(getApplicationInfo().nativeLibraryDir);
fileTor = new File(appLibsHome, TOR_BINARY_ASSET_KEY); fileTor = new File(appLibsHome, TOR_BINARY_ASSET_KEY);
if (fileTor.exists())
logNotice ("Tor binary exists: " + fileTor.getAbsolutePath());
else
throw new RuntimeException("Tor binary not installed");
filePrivoxy = new File(appLibsHome, PRIVOXY_ASSET_KEY); filePrivoxy = new File(appLibsHome, PRIVOXY_ASSET_KEY);
if (filePrivoxy.exists())
logNotice ("Privoxy binary exists: " + filePrivoxy.getAbsolutePath());
else
throw new RuntimeException("Privoxy binary not installed");
fileObfsProxy = new File(appLibsHome, OBFSPROXY_ASSET_KEY); fileObfsProxy = new File(appLibsHome, OBFSPROXY_ASSET_KEY);
if (fileObfsProxy.exists())
logNotice ("Obfsproxy binary exists: " + fileObfsProxy.getAbsolutePath());
else
throw new RuntimeException("Obfsproxy binary not installed");
fileTorRc = new File(appBinHome, TORRC_ASSET_KEY);
} if (!fileTorRc.exists())
public boolean checkTorBinaries (boolean forceInstall) throws Exception
{
SharedPreferences prefs =getSharedPrefs(getApplicationContext());
initTorPaths();
String currTorBinary = prefs.getString(TorServiceConstants.PREF_BINARY_TOR_VERSION_INSTALLED, null);
String currPrivoxyBinary = prefs.getString(TorServiceConstants.PREF_BINARY_PRIVOXY_VERSION_INSTALLED, null);
StringBuilder cmdLog = new StringBuilder();
int exitCode = -1;
if (currTorBinary == null || (!currTorBinary.equals(TorServiceConstants.BINARY_TOR_VERSION)))
if (fileTor.exists())
{
if (currentStatus != STATUS_OFF)
stopTor();
String[] cmds = {"rm " + fileTor.getAbsolutePath()};
exitCode = TorServiceUtils.doShellCommand(cmds, cmdLog, false, true);
}
if (currPrivoxyBinary == null || (!currPrivoxyBinary.equals(TorServiceConstants.BINARY_PRIVOXY_VERSION)))
if (filePrivoxy.exists())
{
if (currentStatus != STATUS_OFF)
stopTor();
String[] cmds = {"rm " + filePrivoxy.getAbsolutePath()};
exitCode = TorServiceUtils.doShellCommand(cmds, cmdLog, false, true);
}
logNotice( "checking Tor binaries");
if ((!(fileTor.exists() && filePrivoxy.exists())) || forceInstall)
{ {
stopTor();
TorBinaryInstaller installer = new TorBinaryInstaller(this, appBinHome); TorBinaryInstaller installer = new TorBinaryInstaller(this, appBinHome);
boolean success = installer.installFromRaw(); try {
boolean success = installer.installResources();
} catch (FileNotFoundException e) {
if (success) // TODO Auto-generated catch block
{ e.printStackTrace();
} catch (IOException e) {
Editor edit = prefs.edit(); // TODO Auto-generated catch block
edit.putString(TorServiceConstants.PREF_BINARY_TOR_VERSION_INSTALLED, TorServiceConstants.BINARY_TOR_VERSION); e.printStackTrace();
edit.putString(TorServiceConstants.PREF_BINARY_PRIVOXY_VERSION_INSTALLED, TorServiceConstants.BINARY_PRIVOXY_VERSION); }
edit.commit();
logNotice(getString(R.string.status_install_success));
//showToolbarNotification(getString(R.string.status_install_success), NOTIFY_ID, R.drawable.ic_stat_tor);
}
else
{
logNotice(getString(R.string.status_install_fail));
sendCallbackStatusMessage(getString(R.string.status_install_fail));
return false;
}
} }
setBinaryPerms();
return true;
} }
/*
private void setBinaryPerms () throws Exception private void setBinaryPerms () throws Exception
{ {
@ -610,7 +554,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
String[] cmd3 = {SHELL_CMD_CHMOD + ' ' + CHMOD_EXE_VALUE + ' ' + fileObfsProxy.getAbsolutePath()}; String[] cmd3 = {SHELL_CMD_CHMOD + ' ' + CHMOD_EXE_VALUE + ' ' + fileObfsProxy.getAbsolutePath()};
TorServiceUtils.doShellCommand(cmd3, log, false, true); TorServiceUtils.doShellCommand(cmd3, log, false, true);
} }*/
private boolean mHasRoot = false; private boolean mHasRoot = false;
private boolean mEnableTransparentProxy = false; private boolean mEnableTransparentProxy = false;
@ -647,7 +591,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
try { try {
setBinaryPerms(); //setBinaryPerms();
runTorShellCmd(); runTorShellCmd();
runPrivoxyShellCmd(); runPrivoxyShellCmd();
@ -1250,40 +1194,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
_torInstance = this; _torInstance = this;
initTorPaths(); initTorPaths();
findExistingProc ();
//if Tor was deleted for some reason, do this again!
if (!fileTor.exists())
{
new Thread ()
{
public void run ()
{
try {
checkTorBinaries (false);
} catch (Exception e) {
logNotice("unable to find tor binaries: " + e.getMessage());
showToolbarNotification(getString(R.string.error_installing_binares), ERROR_NOTIFY_ID, R.drawable.ic_stat_notifyerr, -1);
Log.e(TAG, "error checking tor binaries", e);
}
}
}.start();
}
new Thread ()
{
public void run ()
{
findExistingProc ();
}
}.start();
if (ITorService.class.getName().equals(intent.getAction())) { if (ITorService.class.getName().equals(intent.getAction())) {
return mBinder; return mBinder;
} }
@ -1667,19 +1579,19 @@ public class TorService extends Service implements TorServiceConstants, TorConst
if (entranceNodes.length() > 0 || exitNodes.length() > 0 || excludeNodes.length() > 0) if (entranceNodes.length() > 0 || exitNodes.length() > 0 || excludeNodes.length() > 0)
{ {
//only apple GeoIP if you need it //only apple GeoIP if you need it
File fileGeoIP = new File(appBinHome,"geoip"); File fileGeoIP = new File(appBinHome,GEOIP_ASSET_KEY);
try try
{ {
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 (Exception e) catch (Exception e)
{ {