Skip to content
Snippets Groups Projects
Commit a9d196d5 authored by akwizgran's avatar akwizgran
Browse files

Use the same method as Android to generate the Bluetooth UUID.

parent f4b34ca9
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
......@@ -126,7 +127,7 @@ class BluetoothPlugin implements DuplexPlugin {
// Generate a (weakly) random UUID and store it
byte[] b = new byte[16];
new Random().nextBytes(b);
uuid = StringUtils.toHexString(b);
uuid = generateUuid(b);
p.put("uuid", uuid);
callback.setLocalProperties(p);
}
......@@ -321,7 +322,7 @@ class BluetoothPlugin implements DuplexPlugin {
if(!running) return null;
}
// Use the invitation code to generate the UUID
String uuid = StringUtils.toHexString(r.nextBytes(16));
String uuid = generateUuid(r.nextBytes(16));
// The invitee's device may not be discoverable, so both parties must
// try to initiate connections
final ConnectionCallback c = new ConnectionCallback(uuid, timeout);
......@@ -346,6 +347,11 @@ class BluetoothPlugin implements DuplexPlugin {
}
}
private String generateUuid(byte[] b) {
UUID uuid = UUID.nameUUIDFromBytes(b);
return uuid.toString().replaceAll("-", "");
}
private void createInvitationConnection(ConnectionCallback c) {
LocalDevice localDevice;
synchronized(this) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment