diff options
author | cyBerta <cyberta@riseup.net> | 2021-11-05 02:38:26 +0100 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2021-11-05 02:38:26 +0100 |
commit | 88b7dc2eb3dcbec8d1e637096867c15211818677 (patch) | |
tree | 739dd893e230ca9362b126bbb8fd47e78bfee5ea /app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderAPI.java | |
parent | d27af3b17d6636de8b2755090b6fe6329531f639 (diff) |
Ensure tor state is set to OFF after snowflake completely stopped.
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderAPI.java')
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderAPI.java | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderAPI.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderAPI.java index c8cc786a..4afeb26e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderAPI.java +++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderAPI.java @@ -154,7 +154,7 @@ public class ProviderAPI extends JobIntentService implements ProviderApiManagerB } @Override - public void startTorService() { + public void startTorService() throws InterruptedException, IllegalStateException { initTorServiceConnection(this); Intent torServiceIntent = new Intent(this, TorService.class); @@ -171,12 +171,16 @@ public class ProviderAPI extends JobIntentService implements ProviderApiManagerB @Override public int getTorHttpTunnelPort() { - initTorServiceConnection(this); - if (torServiceConnection != null) { - int tunnelPort = torServiceConnection.torService.getHttpTunnelPort(); - torServiceConnection.close(); - torServiceConnection = null; - return tunnelPort; + try { + initTorServiceConnection(this); + if (torServiceConnection != null) { + int tunnelPort = torServiceConnection.torService.getHttpTunnelPort(); + torServiceConnection.close(); + torServiceConnection = null; + return tunnelPort; + } + } catch (InterruptedException | IllegalStateException e) { + e.printStackTrace(); } return -1; @@ -195,18 +199,14 @@ public class ProviderAPI extends JobIntentService implements ProviderApiManagerB * @throws InterruptedException thrown if thread gets interrupted * @throws IllegalStateException thrown if this method was not called from a background thread */ - private void initTorServiceConnection(Context context) { + private void initTorServiceConnection(Context context) throws InterruptedException, IllegalStateException { if (PreferenceHelper.getUseBridges(context)) { - try { - if (torServiceConnection == null) { - Log.d(TAG, "serviceConnection is still null"); - if (!TorService.hasClientTransportPlugin()) { - TorService.setClientTransportPlugin(new ClientTransportPlugin(context.getApplicationContext())); - } - torServiceConnection = new TorServiceConnection(context); + if (torServiceConnection == null) { + Log.d(TAG, "serviceConnection is still null"); + if (!TorService.hasClientTransportPlugin()) { + TorService.setClientTransportPlugin(new ClientTransportPlugin(context.getApplicationContext())); } - } catch (InterruptedException | IllegalStateException e) { - e.printStackTrace(); + torServiceConnection = new TorServiceConnection(context); } } } |