improve reliability of starting and stopping

This commit is contained in:
Nathan Freitas 2017-06-01 16:32:02 -04:00
parent 62fec5343c
commit 2403e8c333
2 changed files with 13 additions and 5 deletions

View File

@ -197,7 +197,7 @@ public class OrbotMainActivity extends AppCompatActivity
private void stopTor() { private void stopTor() {
requestTorStatus(); // requestTorStatus();
Intent torService = new Intent(OrbotMainActivity.this, TorService.class); Intent torService = new Intent(OrbotMainActivity.this, TorService.class);
stopService(torService); stopService(torService);

View File

@ -439,8 +439,8 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
@Override @Override
public void onDestroy() { public void onDestroy() {
stopTor(); stopTor();
unregisterReceiver(mNetworkStateReceiver);
try try
{ {
@ -456,13 +456,13 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
private void stopTor () private void stopTor ()
{ {
exec(new Runnable () new Thread(new Runnable ()
{ {
public void run () public void run ()
{ {
stopTorAsync(); stopTorAsync();
} }
}); }).start();
} }
@ -491,6 +491,14 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
} }
clearNotifications(); clearNotifications();
sendCallbackStatus(STATUS_OFF); sendCallbackStatus(STATUS_OFF);
try {
unregisterReceiver(mNetworkStateReceiver);
}
catch (IllegalArgumentException iae)
{
//not registered yet
}
} }
private void killAllDaemons() throws Exception { private void killAllDaemons() throws Exception {
@ -856,7 +864,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
showToolbarNotification( showToolbarNotification(
getString(R.string.unable_to_start_tor) + ": " + e.getMessage(), getString(R.string.unable_to_start_tor) + ": " + e.getMessage(),
ERROR_NOTIFY_ID, R.drawable.ic_stat_notifyerr); ERROR_NOTIFY_ID, R.drawable.ic_stat_notifyerr);
stopTor(); //stopTor();
} }
} }