improve ability to do a full clean stop of all services

This commit is contained in:
Nathan Freitas 2014-06-13 13:51:51 -04:00
parent af51290aa9
commit 01299768e3
1 changed files with 20 additions and 49 deletions

View File

@ -192,20 +192,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} }
/* (non-Javadoc)
* @see android.app.Service#onUnbind(android.content.Intent)
*/
@Override
public boolean onUnbind(Intent intent) {
if (intent != null)
logNotice( "onUnbind Called: " + intent.getAction());
return super.onUnbind(intent);
}
public int getTorStatus () public int getTorStatus ()
{ {
@ -270,24 +256,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} }
/* (non-Javadoc)
* @see android.app.Service#onRebind(android.content.Intent)
*/
@Override
public void onRebind(Intent intent) {
super.onRebind(intent);
try
{
sendCallbackLogMessage("Welcome back, Carter!");
}
catch (Exception e)
{
Log.e(TAG,"unable to init Tor",e);
throw new RuntimeException("Unable to init Tor");
}
}
/* (non-Javadoc) /* (non-Javadoc)
* @see android.app.Service#onStart(android.content.Intent, int) * @see android.app.Service#onStart(android.content.Intent, int)
@ -298,7 +266,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{ {
new startTorOperation().execute(intent); new startTorOperation().execute(intent);
return START_STICKY; return Service.START_NOT_STICKY;
} }
catch (Exception e) catch (Exception e)
@ -309,7 +277,12 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} }
private class startTorOperation extends AsyncTask<Intent, Void, Boolean> { @Override
public void onTaskRemoved(Intent rootIntent) {
logNotice("Orbot was swiped away... background service will keep running");
}
private class startTorOperation extends AsyncTask<Intent, Void, Boolean> {
@Override @Override
protected Boolean doInBackground(Intent... params) { protected Boolean doInBackground(Intent... params) {
@ -360,25 +333,20 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{ {
super.onDestroy(); super.onDestroy();
if (currentStatus == STATUS_ON) logNotice("TorService is being destroyed... shutting down!");
{
//make sure we stop Tor processes
stopTor();
showToolbarNotification("Tor service stopped unexpectedly", ERROR_NOTIFY_ID, R.drawable.ic_stat_notifyerr, false);
}
stopTor();
// Unregister all callbacks. // Unregister all callbacks.
mCallbacks.kill(); mCallbacks.kill();
unregisterReceiver(mNetworkStateReceiver);
unregisterReceiver(mNetworkStateReceiver);
} }
private void stopTor () private void stopTor ()
{ {
currentStatus = STATUS_OFF;
try try
{ {
killTorProcess (); killTorProcess ();
@ -477,7 +445,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
private void killTorProcess () throws Exception private void killTorProcess () throws Exception
{ {
stopTorMinder(); //stopTorMinder();
if (conn != null) if (conn != null)
{ {
@ -489,6 +457,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
logNotice("sending SHUTDOWN signal to Tor process"); logNotice("sending SHUTDOWN signal to Tor process");
conn.shutdownTor("SHUTDOWN"); conn.shutdownTor("SHUTDOWN");
logNotice("closing tor socket");
torConnSocket.close();
} catch (Exception e) { } catch (Exception e) {
Log.d(TAG,"error shutting down Tor via connection",e); Log.d(TAG,"error shutting down Tor via connection",e);
@ -816,7 +786,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
processSettingsImpl(); processSettingsImpl();
startTorMinder (); // startTorMinder ();
} }
@ -2176,6 +2146,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} }
/**
private Timer mTorMinder; private Timer mTorMinder;
private void startTorMinder () private void startTorMinder ()
@ -2225,6 +2196,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
if (mTorMinder != null) if (mTorMinder != null)
mTorMinder.cancel(); mTorMinder.cancel();
} }
**/
} }