mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Bluetooth debugging and code cleanup.
Generate a random UUID instead of using a fixed UUID. Close sockets when exceptions are thrown (not doing so can cause problems with subsequent sockets on Android). Use a semaphore with tryAcquire() instead of a lock when making alien calls, to avoid possible deadlocks.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package net.sf.briar.plugins.bluetooth;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -20,14 +21,14 @@ public class BluetoothClientTest extends DuplexClientTest {
|
||||
// Store the server's Bluetooth address and UUID
|
||||
TransportProperties p = new TransportProperties();
|
||||
p.put("address", serverAddress);
|
||||
p.put("uuid", BluetoothTest.getUuid());
|
||||
p.put("uuid", BluetoothTest.EMPTY_UUID);
|
||||
Map<ContactId, TransportProperties> remote =
|
||||
Collections.singletonMap(contactId, p);
|
||||
// Create the plugin
|
||||
callback = new ClientCallback(new TransportConfig(),
|
||||
new TransportProperties(), remote);
|
||||
plugin = new BluetoothPlugin(executor, new SystemClock(), callback, 0,
|
||||
0);
|
||||
plugin = new BluetoothPlugin(executor, new SystemClock(),
|
||||
new SecureRandom(), callback, 0, 0);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.sf.briar.plugins.bluetooth;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -17,12 +18,12 @@ public class BluetoothServerTest extends DuplexServerTest {
|
||||
private BluetoothServerTest(Executor executor) {
|
||||
// Store the UUID
|
||||
TransportProperties local = new TransportProperties();
|
||||
local.put("uuid", BluetoothTest.getUuid());
|
||||
local.put("uuid", BluetoothTest.EMPTY_UUID);
|
||||
// Create the plugin
|
||||
callback = new ServerCallback(new TransportConfig(), local,
|
||||
Collections.singletonMap(contactId, new TransportProperties()));
|
||||
plugin = new BluetoothPlugin(executor, new SystemClock(), callback, 0,
|
||||
0);
|
||||
plugin = new BluetoothPlugin(executor, new SystemClock(),
|
||||
new SecureRandom(), callback, 0, 0);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
@@ -4,10 +4,6 @@ import java.util.UUID;
|
||||
|
||||
class BluetoothTest {
|
||||
|
||||
private static final String EMPTY_UUID =
|
||||
UUID.nameUUIDFromBytes(new byte[0]).toString().replaceAll("-", "");
|
||||
|
||||
static String getUuid() {
|
||||
return EMPTY_UUID;
|
||||
}
|
||||
static final String EMPTY_UUID =
|
||||
UUID.nameUUIDFromBytes(new byte[0]).toString();
|
||||
}
|
||||
Reference in New Issue
Block a user