diff --git a/bramble-core/src/test/java/org/briarproject/bramble/plugin/tcp/LanTcpPluginTest.java b/bramble-core/src/test/java/org/briarproject/bramble/plugin/tcp/LanTcpPluginTest.java index b4f360c7b53bddbc46b6e7d3ba62dd1998feb272..d6ea0b6390289463e1049bc3fff8acc3f3f7c934 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/plugin/tcp/LanTcpPluginTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/plugin/tcp/LanTcpPluginTest.java @@ -150,17 +150,14 @@ public class LanTcpPluginTest extends BrambleTestCase { int port = ss.getLocalPort(); CountDownLatch latch = new CountDownLatch(1); AtomicBoolean error = new AtomicBoolean(false); - new Thread() { - @Override - public void run() { - try { - ss.accept(); - latch.countDown(); - } catch (IOException e) { - error.set(true); - } + new Thread(() -> { + try { + ss.accept(); + latch.countDown(); + } catch (IOException e) { + error.set(true); } - }.start(); + }).start(); // Tell the plugin about the port TransportProperties p = new TransportProperties(); p.put("ipPorts", addrString + ":" + port); @@ -243,17 +240,14 @@ public class LanTcpPluginTest extends BrambleTestCase { ss.bind(new InetSocketAddress(addrString, 0), 10); CountDownLatch latch = new CountDownLatch(1); AtomicBoolean error = new AtomicBoolean(false); - new Thread() { - @Override - public void run() { - try { - ss.accept(); - latch.countDown(); - } catch (IOException e) { - error.set(true); - } + new Thread(() -> { + try { + ss.accept(); + latch.countDown(); + } catch (IOException e) { + error.set(true); } - }.start(); + }).start(); // Tell the plugin about the port BdfList descriptor = new BdfList(); descriptor.add(TRANSPORT_ID_LAN); diff --git a/briar-android/src/main/java/org/briarproject/briar/android/BriarService.java b/briar-android/src/main/java/org/briarproject/briar/android/BriarService.java index 0e6bb7c399b79d68f0bc942164f8d0b4013b6125..9149e10a06f596b1f937a670164a2352297133d5 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/BriarService.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/BriarService.java @@ -91,24 +91,21 @@ public class BriarService extends Service { b.setPriority(PRIORITY_MIN); startForeground(ONGOING_NOTIFICATION_ID, b.build()); // Start the services in a background thread - new Thread() { - @Override - public void run() { - String nickname = databaseConfig.getLocalAuthorName(); - StartResult result = lifecycleManager.startServices(nickname); - if (result == SUCCESS) { - started = true; - } else if (result == ALREADY_RUNNING) { - LOG.info("Already running"); - stopSelf(); - } else { - if (LOG.isLoggable(WARNING)) - LOG.warning("Startup failed: " + result); - showStartupFailureNotification(result); - stopSelf(); - } + new Thread(() -> { + String nickname = databaseConfig.getLocalAuthorName(); + StartResult result = lifecycleManager.startServices(nickname); + if (result == SUCCESS) { + started = true; + } else if (result == ALREADY_RUNNING) { + LOG.info("Already running"); + stopSelf(); + } else { + if (LOG.isLoggable(WARNING)) + LOG.warning("Startup failed: " + result); + showStartupFailureNotification(result); + stopSelf(); } - }.start(); + }).start(); } private void showStartupFailureNotification(StartResult result) { @@ -155,12 +152,9 @@ public class BriarService extends Service { LOG.info("Destroyed"); stopForeground(true); // Stop the services in a background thread - new Thread() { - @Override - public void run() { - if (started) lifecycleManager.stopServices(); - } - }.start(); + new Thread(() -> { + if (started) lifecycleManager.stopServices(); + }).start(); } @Override diff --git a/briar-android/src/main/java/org/briarproject/briar/android/controller/BriarControllerImpl.java b/briar-android/src/main/java/org/briarproject/briar/android/controller/BriarControllerImpl.java index a8d90dd0cc98a9162e9a1eaed234e53e404ad5c1..aa9861a7f64da4e8bbaaecf9960fa08201a9519e 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/controller/BriarControllerImpl.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/controller/BriarControllerImpl.java @@ -123,25 +123,22 @@ public class BriarControllerImpl implements BriarController { @Override public void signOut(ResultHandler<Void> eventHandler) { - new Thread() { - @Override - public void run() { - try { - // Wait for the service to finish starting up - IBinder binder = serviceConnection.waitForBinder(); - BriarService service = - ((BriarService.BriarBinder) binder).getService(); - service.waitForStartup(); - // Shut down the service and wait for it to shut down - LOG.info("Shutting down service"); - service.shutdown(); - service.waitForShutdown(); - } catch (InterruptedException e) { - LOG.warning("Interrupted while waiting for service"); - } - eventHandler.onResult(null); + new Thread(() -> { + try { + // Wait for the service to finish starting up + IBinder binder = serviceConnection.waitForBinder(); + BriarService service = + ((BriarService.BriarBinder) binder).getService(); + service.waitForStartup(); + // Shut down the service and wait for it to shut down + LOG.info("Shutting down service"); + service.shutdown(); + service.waitForShutdown(); + } catch (InterruptedException e) { + LOG.warning("Interrupted while waiting for service"); } - }.start(); + eventHandler.onResult(null); + }).start(); } private void unbindService() {