From b270f0e8b18d1620c982a3d2abd28c79105cc118 Mon Sep 17 00:00:00 2001 From: akwizgran <akwizgran@users.sourceforge.net> Date: Wed, 12 Mar 2014 21:11:11 +0000 Subject: [PATCH] Call Thread.currentThread().interrupt() when handling interruption. --- .../src/org/briarproject/android/AndroidExecutorImpl.java | 5 +++++ .../src/org/briarproject/android/BriarActivity.java | 1 + .../src/org/briarproject/android/TestingActivity.java | 3 ++- .../briarproject/plugins/droidtooth/DroidtoothPlugin.java | 4 +++- .../src/org/briarproject/plugins/tor/TorPlugin.java | 3 +++ .../src/org/briarproject/invitation/ConnectorGroup.java | 1 + .../org/briarproject/messaging/duplex/DuplexConnection.java | 1 + 7 files changed, 16 insertions(+), 2 deletions(-) diff --git a/briar-android/src/org/briarproject/android/AndroidExecutorImpl.java b/briar-android/src/org/briarproject/android/AndroidExecutorImpl.java index 5d9c470915..079df65e2e 100644 --- a/briar-android/src/org/briarproject/android/AndroidExecutorImpl.java +++ b/briar-android/src/org/briarproject/android/AndroidExecutorImpl.java @@ -6,6 +6,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.FutureTask; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.logging.Logger; import javax.inject.Inject; @@ -19,6 +20,9 @@ class AndroidExecutorImpl implements AndroidExecutor { private static final int SHUTDOWN = 0, RUN = 1; + private static final Logger LOG = + Logger.getLogger(AndroidExecutorImpl.class.getName()); + private final Runnable loop; private final AtomicBoolean started = new AtomicBoolean(false); private final CountDownLatch startLatch = new CountDownLatch(1); @@ -43,6 +47,7 @@ class AndroidExecutorImpl implements AndroidExecutor { try { startLatch.await(); } catch(InterruptedException e) { + LOG.warning("Interrupted while starting executor thread"); Thread.currentThread().interrupt(); } } diff --git a/briar-android/src/org/briarproject/android/BriarActivity.java b/briar-android/src/org/briarproject/android/BriarActivity.java index 43305d5d5a..a80e276b1f 100644 --- a/briar-android/src/org/briarproject/android/BriarActivity.java +++ b/briar-android/src/org/briarproject/android/BriarActivity.java @@ -92,6 +92,7 @@ public class BriarActivity extends RoboFragmentActivity { service.waitForShutdown(); } catch(InterruptedException e) { LOG.warning("Interrupted while waiting for service"); + Thread.currentThread().interrupt(); } finishAndExit(); } diff --git a/briar-android/src/org/briarproject/android/TestingActivity.java b/briar-android/src/org/briarproject/android/TestingActivity.java index 3889f82d39..076d29f0aa 100644 --- a/briar-android/src/org/briarproject/android/TestingActivity.java +++ b/briar-android/src/org/briarproject/android/TestingActivity.java @@ -261,7 +261,8 @@ public class TestingActivity extends BriarActivity implements OnClickListener { } }); } catch(InterruptedException e) { - if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); + LOG.warning("Interrupted while getting BluetoothAdapter"); + Thread.currentThread().interrupt(); } catch(ExecutionException e) { if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); } diff --git a/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java b/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java index acc2ffc107..c44ddf5a42 100644 --- a/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java +++ b/briar-android/src/org/briarproject/plugins/droidtooth/DroidtoothPlugin.java @@ -110,7 +110,8 @@ class DroidtoothPlugin implements DuplexPlugin { } }); } catch(InterruptedException e) { - throw new IOException(e.toString()); + Thread.currentThread().interrupt(); + throw new IOException("Interrupted while getting BluetoothAdapter"); } catch(ExecutionException e) { throw new IOException(e.toString()); } @@ -427,6 +428,7 @@ class DroidtoothPlugin implements DuplexPlugin { addresses = discoverDevices(end - now); } catch(InterruptedException e) { LOG.warning("Interrupted while discovering devices"); + Thread.currentThread().interrupt(); return; } // Connect to any device with the right UUID diff --git a/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java b/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java index 0c4e515cd4..18aa760104 100644 --- a/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java +++ b/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java @@ -178,6 +178,7 @@ class TorPlugin implements DuplexPlugin, EventHandler { } } catch(InterruptedException e1) { LOG.warning("Interrupted while starting Tor"); + Thread.currentThread().interrupt(); return false; } // Now we should be able to connect to the new process @@ -471,6 +472,8 @@ class TorPlugin implements DuplexPlugin, EventHandler { if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); } catch(InterruptedException e) { LOG.warning("Interrupted while creating hidden service"); + Thread.currentThread().interrupt(); + return; } } // Publish the hidden service's onion hostname in transport properties diff --git a/briar-core/src/org/briarproject/invitation/ConnectorGroup.java b/briar-core/src/org/briarproject/invitation/ConnectorGroup.java index abc4a9ecc8..7ce73fcc85 100644 --- a/briar-core/src/org/briarproject/invitation/ConnectorGroup.java +++ b/briar-core/src/org/briarproject/invitation/ConnectorGroup.java @@ -159,6 +159,7 @@ class ConnectorGroup extends Thread implements InvitationTask { for(Connector c : connectors) c.join(); } catch(InterruptedException e) { LOG.warning("Interrupted while waiting for connectors"); + Thread.currentThread().interrupt(); } // If none of the threads connected, inform the listeners if(!connected.get()) { diff --git a/briar-core/src/org/briarproject/messaging/duplex/DuplexConnection.java b/briar-core/src/org/briarproject/messaging/duplex/DuplexConnection.java index 853249cf6d..06d4758045 100644 --- a/briar-core/src/org/briarproject/messaging/duplex/DuplexConnection.java +++ b/briar-core/src/org/briarproject/messaging/duplex/DuplexConnection.java @@ -252,6 +252,7 @@ abstract class DuplexConnection implements EventListener { } } catch(InterruptedException e) { LOG.warning("Interrupted while waiting for task"); + Thread.currentThread().interrupt(); dispose(true, true); } catch(IOException e) { if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); -- GitLab