@@ -407,6 +407,8 @@ private void disableSnowflakeProxy() {
407
407
// if someone stops during startup, we may have to wait for the conn port to be setup, so we can properly shutdown tor
408
408
private void stopTor () {
409
409
if (shouldUnbindTorService ) {
410
+ TOR_SERVICE_STARTED = false ;
411
+ stopService (torServiceIntent );
410
412
unbindService (torServiceConnection ); //unbinding from the tor service will stop tor
411
413
shouldUnbindTorService = false ;
412
414
conn = null ;
@@ -742,7 +744,7 @@ private void updateV3OnionNames() throws SecurityException {
742
744
}
743
745
}
744
746
745
- private synchronized void startTorService () throws Exception {
747
+ private void startTorService () throws Exception {
746
748
updateTorConfigCustom (TorService .getDefaultsTorrc (this ),
747
749
"DNSPort 0\n " +
748
750
"TransPort 0\n " +
@@ -830,14 +832,25 @@ public void onBindingDied(ComponentName componentName) {
830
832
}
831
833
};
832
834
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
+
834
843
if (Build .VERSION .SDK_INT < 29 ) {
835
- shouldUnbindTorService = bindService (serviceIntent , torServiceConnection , BIND_AUTO_CREATE );
844
+
845
+ shouldUnbindTorService = bindService (torServiceIntent , torServiceConnection , 0 );
836
846
} else {
837
- shouldUnbindTorService = bindService (serviceIntent , BIND_AUTO_CREATE , mExecutor , torServiceConnection );
847
+ shouldUnbindTorService = bindService (torServiceIntent , 0 , mExecutor , torServiceConnection );
838
848
}
839
849
}
840
850
851
+ private Intent torServiceIntent = null ;
852
+ private static boolean TOR_SERVICE_STARTED = false ;
853
+
841
854
private void sendLocalStatusOffBroadcast () {
842
855
var localOffStatus = new Intent (LOCAL_ACTION_STATUS ).putExtra (EXTRA_STATUS , STATUS_OFF );
843
856
LocalBroadcastManager .getInstance (this ).sendBroadcast (localOffStatus );
0 commit comments