From eaff042601ca3bdf7c5222b8ef4073a5b67bdcd4 Mon Sep 17 00:00:00 2001 From: akwizgran <akwizgran@users.sourceforge.net> Date: Fri, 9 May 2014 18:16:10 +0100 Subject: [PATCH] Don't try to close server sockets twice. This may have been the cause of bug #69. Removed the wait-for-shutdown code in DroidtoothPlugin that was added to attempt to avoid that bug. --- .../plugins/droidtooth/DroidtoothPlugin.java | 37 +------------------ .../briarproject/plugins/tor/TorPlugin.java | 1 - .../briarproject/plugins/tcp/TcpPlugin.java | 1 - .../plugins/bluetooth/BluetoothPlugin.java | 1 - 4 files changed, 2 insertions(+), 38 deletions(-) diff --git a/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java b/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java index 3355a984ae..aaa38352b6 100644 --- a/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java +++ b/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java @@ -207,7 +207,6 @@ class DroidtoothPlugin implements DuplexPlugin { } catch(IOException e) { // This is expected when the socket is closed if(LOG.isLoggable(INFO)) LOG.info(e.toString()); - tryToClose(socket); return; } if(LOG.isLoggable(INFO)) { @@ -228,18 +227,8 @@ class DroidtoothPlugin implements DuplexPlugin { tryToClose(socket); // Disable Bluetooth if we enabled it and it's still enabled if(wasDisabled && adapter.isEnabled()) { - // Try to disable the adapter and wait for the result - LOG.info("Disabling Bluetooth"); - IntentFilter filter = new IntentFilter(ACTION_STATE_CHANGED); - DisableBluetoothReceiver receiver = new DisableBluetoothReceiver(); - appContext.registerReceiver(receiver, filter); - if(adapter.disable()) { - LOG.info("Disabling Bluetooth"); - receiver.waitForStateChange(); - } else { - LOG.info("Could not disable Bluetooth"); - } - appContext.unregisterReceiver(receiver); + if(adapter.disable()) LOG.info("Disabling Bluetooth"); + else LOG.info("Could not disable Bluetooth"); } } @@ -392,28 +381,6 @@ class DroidtoothPlugin implements DuplexPlugin { } } - private class DisableBluetoothReceiver extends BroadcastReceiver { - - private final CountDownLatch latch = new CountDownLatch(1); - - public void onReceive(Context ctx, Intent intent) { - int state = intent.getIntExtra(EXTRA_STATE, 0); - if(state == STATE_OFF) { - LOG.info("Bluetooth disabled"); - latch.countDown(); - } - } - - private void waitForStateChange() { - try { - latch.await(); - } catch(InterruptedException e) { - LOG.info("Interrupted while disabling Bluetooth"); - Thread.currentThread().interrupt(); - } - } - } - private class DiscoveryThread extends Thread { private final LatchedReference<BluetoothSocket> socketLatch; diff --git a/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java b/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java index a7e3186add..be89d867ee 100644 --- a/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java +++ b/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java @@ -534,7 +534,6 @@ class TorPlugin implements DuplexPlugin, EventHandler { } catch(IOException e) { // This is expected when the socket is closed if(LOG.isLoggable(INFO)) LOG.info(e.toString()); - tryToClose(ss); return; } LOG.info("Connection received"); diff --git a/briar-core/src/org/briarproject/plugins/tcp/TcpPlugin.java b/briar-core/src/org/briarproject/plugins/tcp/TcpPlugin.java index 673828b438..c5de9d6c86 100644 --- a/briar-core/src/org/briarproject/plugins/tcp/TcpPlugin.java +++ b/briar-core/src/org/briarproject/plugins/tcp/TcpPlugin.java @@ -139,7 +139,6 @@ abstract class TcpPlugin implements DuplexPlugin { } catch(IOException e) { // This is expected when the socket is closed if(LOG.isLoggable(INFO)) LOG.info(e.toString()); - tryToClose(socket); return; } if(LOG.isLoggable(INFO)) diff --git a/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothPlugin.java b/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothPlugin.java index ec2258c4ca..364b44a51a 100644 --- a/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothPlugin.java +++ b/briar-desktop/src/org/briarproject/plugins/bluetooth/BluetoothPlugin.java @@ -157,7 +157,6 @@ class BluetoothPlugin implements DuplexPlugin { } catch(IOException e) { // This is expected when the socket is closed if(LOG.isLoggable(INFO)) LOG.info(e.toString()); - tryToClose(ss); return; } callback.incomingConnectionCreated(wrapSocket(s)); -- GitLab