opt persistent notifications & geoip not default

This commit is contained in:
Nathan Freitas 2012-01-25 20:04:41 -05:00
parent 63c4e97355
commit 1e3f6bbddf
1 changed files with 54 additions and 23 deletions

View File

@ -28,6 +28,7 @@ import org.torproject.android.TorConstants;
import org.torproject.android.Utils; import org.torproject.android.Utils;
import org.torproject.android.settings.AppManager; import org.torproject.android.settings.AppManager;
import android.app.Application;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
@ -59,6 +60,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
private static final int ERROR_NOTIFY_ID = 3; private static final int ERROR_NOTIFY_ID = 3;
private static final int HS_NOTIFY_ID = 3; private static final int HS_NOTIFY_ID = 3;
private boolean prefPersistNotifications = true;
private static final int MAX_START_TRIES = 3; private static final int MAX_START_TRIES = 3;
@ -178,7 +180,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
Notification notification = new Notification(icon, tickerText, when); Notification notification = new Notification(icon, tickerText, when);
if (flags != -1) if (prefPersistNotifications && flags != -1)
notification.flags |= flags; notification.flags |= flags;
Context context = getApplicationContext(); Context context = getApplicationContext();
@ -204,11 +206,11 @@ public class TorService extends Service implements TorServiceConstants, TorConst
initTorPaths(); initTorPaths();
//if Tor was deleted for some reason, do this again!
if (!fileTor.exists()) if (!fileTor.exists())
{ {
new Thread () new Thread ()
{ {
public void run () public void run ()
{ {
try { try {
@ -272,21 +274,30 @@ public class TorService extends Service implements TorServiceConstants, TorConst
public void run () public void run ()
{ {
boolean isRunning = _torInstance.findExistingProc (); if (currentStatus == STATUS_CONNECTING)
if (!isRunning)
{ {
try boolean isRunning = _torInstance.findExistingProc ();
{
initTor(); if (!isRunning)
isRunning = true; {
} try
catch (Exception e) {
{ initTor();
currentStatus = STATUS_OFF; isRunning = true;
this.showToolbarNotification(getString(R.string.status_disabled), ERROR_NOTIFY_ID, R.drawable.tornotificationerr, -1); }
Log.d(TAG,"Unable to start Tor: " + e.getMessage(),e); catch (Exception e)
} {
currentStatus = STATUS_OFF;
this.showToolbarNotification(getString(R.string.status_disabled), ERROR_NOTIFY_ID, R.drawable.tornotificationerr, -1);
Log.d(TAG,"Unable to start Tor: " + e.getMessage(),e);
}
}
}
else if (currentStatus == STATUS_OFF)
{
_torInstance.stopTor();
} }
} }
@ -453,7 +464,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
private void initTorPaths () private void initTorPaths ()
{ {
appBinHome = getDir("bin",0); appBinHome = getDir("bin",Application.MODE_PRIVATE);
appDataHome = getCacheDir(); appDataHome = getCacheDir();
fileTor = new File(appBinHome, TOR_BINARY_ASSET_KEY); fileTor = new File(appBinHome, TOR_BINARY_ASSET_KEY);
@ -976,7 +987,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
currentStatus = STATUS_OFF; currentStatus = STATUS_OFF;
sendCallbackStatusMessage (getString(R.string.status_shutting_down)); sendCallbackStatusMessage (getString(R.string.status_shutting_down));
_torInstance.stopTor(); Thread thread = new Thread(this);
thread.start();
} }
@ -1346,9 +1358,12 @@ public class TorService extends Service implements TorServiceConstants, TorConst
private boolean applyPreferences () throws RemoteException private boolean applyPreferences () throws RemoteException
{ {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
ENABLE_DEBUG_LOG = prefs.getBoolean("pref_enable_logging",false); ENABLE_DEBUG_LOG = prefs.getBoolean("pref_enable_logging",false);
Log.i(TAG,"debug logging:" + ENABLE_DEBUG_LOG); Log.i(TAG,"debug logging:" + ENABLE_DEBUG_LOG);
prefPersistNotifications = prefs.getBoolean(TorConstants.PREF_PERSIST_NOTIFICATIONS, true);
boolean useBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_ENABLED, false); boolean useBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_ENABLED, false);
//boolean autoUpdateBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_UPDATED, false); //boolean autoUpdateBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_UPDATED, false);
@ -1378,7 +1393,23 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{ {
//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");
mBinder.updateConfiguration("GeoIPFile", fileGeoIP.getAbsolutePath(), false);
try
{
if (!fileGeoIP.exists())
{
TorBinaryInstaller installer = new TorBinaryInstaller(this, appBinHome);
boolean success = installer.installGeoIP();
}
mBinder.updateConfiguration("GeoIPFile", fileGeoIP.getAbsolutePath(), false);
}
catch (IOException e)
{
showToolbarNotification (getString(R.string.error_installing_binares),ERROR_NOTIFY_ID,R.drawable.tornotificationon, Notification.FLAG_ONGOING_EVENT);
return false;
}
} }
mBinder.updateConfiguration("EntryNodes", entranceNodes, false); mBinder.updateConfiguration("EntryNodes", entranceNodes, false);