Skip to content

Commit a7eaffb

Browse files
committed
manually manage starting and stopping of TorService
- more coming on this front
1 parent d8560ea commit a7eaffb

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

orbotservice/src/main/java/org/torproject/android/service/OrbotService.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ private void disableSnowflakeProxy() {
407407
// if someone stops during startup, we may have to wait for the conn port to be setup, so we can properly shutdown tor
408408
private void stopTor() {
409409
if (shouldUnbindTorService) {
410+
TOR_SERVICE_STARTED = false;
411+
stopService(torServiceIntent);
410412
unbindService(torServiceConnection); //unbinding from the tor service will stop tor
411413
shouldUnbindTorService = false;
412414
conn = null;
@@ -742,7 +744,7 @@ private void updateV3OnionNames() throws SecurityException {
742744
}
743745
}
744746

745-
private synchronized void startTorService() throws Exception {
747+
private void startTorService() throws Exception {
746748
updateTorConfigCustom(TorService.getDefaultsTorrc(this),
747749
"DNSPort 0\n" +
748750
"TransPort 0\n" +
@@ -830,14 +832,25 @@ public void onBindingDied(ComponentName componentName) {
830832
}
831833
};
832834

833-
Intent serviceIntent = new Intent(this, TorService.class);
835+
if (torServiceIntent == null)
836+
torServiceIntent = new Intent(this, TorService.class);
837+
838+
if (!TOR_SERVICE_STARTED) {
839+
startService(torServiceIntent);
840+
TOR_SERVICE_STARTED = true;
841+
}
842+
834843
if (Build.VERSION.SDK_INT < 29) {
835-
shouldUnbindTorService = bindService(serviceIntent, torServiceConnection, BIND_AUTO_CREATE);
844+
845+
shouldUnbindTorService = bindService(torServiceIntent, torServiceConnection, 0);
836846
} else {
837-
shouldUnbindTorService = bindService(serviceIntent, BIND_AUTO_CREATE, mExecutor, torServiceConnection);
847+
shouldUnbindTorService = bindService(torServiceIntent, 0, mExecutor, torServiceConnection);
838848
}
839849
}
840850

851+
private Intent torServiceIntent = null;
852+
private static boolean TOR_SERVICE_STARTED = false;
853+
841854
private void sendLocalStatusOffBroadcast() {
842855
var localOffStatus = new Intent(LOCAL_ACTION_STATUS).putExtra(EXTRA_STATUS, STATUS_OFF);
843856
LocalBroadcastManager.getInstance(this).sendBroadcast(localOffStatus);

0 commit comments

Comments
 (0)