Skip to content
Snippets Groups Projects
Verified Commit 9d9bab1f authored by Hans-Christoph Steiner's avatar Hans-Christoph Steiner
Browse files

ensure TorService properly shuts down whenever the tor thread stops

This unnests the try/finally block that was added in pull #59, and moves it
to the main try block, where it now handles the whole shutdown procedure.

* https://github.com/guardianproject/tor-android/pull/61#discussion_r766016252
* https://github.com/guardianproject/tor-android/issues/57
* https://github.com/guardianproject/tor-android/pull/59
parent 1b4639dc
Branches
No related tags found
1 merge request!2update upstream
......@@ -42,9 +42,6 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager;
*/
public class TorService extends Service {
// TODO orbotserver and/or tor-android-server are the borders to use, strip out Prefs and VPN
// grep -rF org.torproject.android.service app/src/main/java/ ~/code/guardianproject/orbot/app/src/main/java
public static final String TAG = "TorService";
public static final String VERSION_NAME = org.torproject.jni.BuildConfig.VERSION_NAME;
......@@ -200,6 +197,7 @@ public class TorService extends Service {
@Override
public IBinder onBind(Intent intent) {
// TODO send broadcastStatus() here?
return binder;
}
......@@ -327,7 +325,6 @@ public class TorService extends Service {
}
runLock.lock();
Log.i(TAG, "Acquired lock");
try {
createTorConfiguration();
ArrayList<String> lines = new ArrayList<>(Arrays.asList("tor", "--verify-config", // must always be here
"--RunAsDaemon", "0",
......@@ -373,16 +370,15 @@ public class TorService extends Service {
if (runMain() != 0) {
throw new IllegalStateException("Tor could not start!");
}
} finally {
mainConfigurationFree();
Log.i(TAG, "Releasing lock");
runLock.unlock();
}
} catch (IllegalStateException | IllegalArgumentException | InterruptedException e) {
e.printStackTrace();
broadcastError(context, e);
} finally {
broadcastStatus(context, STATUS_STOPPING);
mainConfigurationFree();
Log.i(TAG, "Releasing lock");
runLock.unlock();
TorService.this.stopSelf();
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment