diff --git a/src/net/sf/briar/plugins/bluetooth/BluetoothPlugin.java b/src/net/sf/briar/plugins/bluetooth/BluetoothPlugin.java index ae10cf8fcc153c94f88df9d893c957ab8ee17ef6..76ce8cd5a26ac0860f1c9dcf6ee3c4bf15869581 100644 --- a/src/net/sf/briar/plugins/bluetooth/BluetoothPlugin.java +++ b/src/net/sf/briar/plugins/bluetooth/BluetoothPlugin.java @@ -236,7 +236,7 @@ class BluetoothPlugin implements DuplexPlugin { synchronized(this) { if(!running) return null; } - // Use the invitation code to generate the UUID + // Use the same pseudo-random UUID as the contact String uuid = generateUuid(r.nextBytes(16)); // Discover nearby devices and connect to any with the right UUID DiscoveryAgent discoveryAgent = localDevice.getDiscoveryAgent(); @@ -279,7 +279,7 @@ class BluetoothPlugin implements DuplexPlugin { synchronized(this) { if(!running) return null; } - // Use the invitation code to generate the UUID + // Use the same pseudo-random UUID as the contact String uuid = generateUuid(r.nextBytes(16)); String url = makeUrl("localhost", uuid); // Make the device discoverable if possible diff --git a/src/net/sf/briar/plugins/droidtooth/DroidtoothPlugin.java b/src/net/sf/briar/plugins/droidtooth/DroidtoothPlugin.java index 0c63b9d2124cc4baf13bccb1958d7fe671cd92b6..a0eef9b98f7cea420b48b0e12c6a7e0cc598c652 100644 --- a/src/net/sf/briar/plugins/droidtooth/DroidtoothPlugin.java +++ b/src/net/sf/briar/plugins/droidtooth/DroidtoothPlugin.java @@ -43,7 +43,6 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.os.Build; class DroidtoothPlugin implements DuplexPlugin { @@ -122,7 +121,6 @@ class DroidtoothPlugin implements DuplexPlugin { LOG.info("Could not enable Bluetooth"); return; } - makeDeviceDiscoverable(); if(LOG.isLoggable(Level.INFO)) LOG.info("Local address " + adapter.getAddress()); // Advertise the Bluetooth address to contacts @@ -167,19 +165,6 @@ class DroidtoothPlugin implements DuplexPlugin { } } - private void makeDeviceDiscoverable() { - synchronized(this) { - if(!running) return; - } - if(adapter.getScanMode() == SCAN_MODE_CONNECTABLE_DISCOVERABLE) return; - // Indefinite discoverability can only be set on API Level 8 or higher - if(Build.VERSION.SDK_INT < 8) return; - Intent intent = new Intent(ACTION_REQUEST_DISCOVERABLE); - intent.putExtra(EXTRA_DISCOVERABLE_DURATION, 0); - intent.addFlags(FLAG_ACTIVITY_NEW_TASK); - appContext.startActivity(intent); - } - // FIXME: Get the UUID from the local transport properties private UUID getUuid() { return UUID.nameUUIDFromBytes(new byte[0]); @@ -333,6 +318,8 @@ class DroidtoothPlugin implements DuplexPlugin { } // Use the same pseudo-random UUID as the contact UUID uuid = UUID.nameUUIDFromBytes(r.nextBytes(16)); + // Make the device discoverable if the user allows it + makeDeviceDiscoverable(); // Bind a new server socket to accept the invitation connection final BluetoothServerSocket ss; try { @@ -355,6 +342,17 @@ class DroidtoothPlugin implements DuplexPlugin { } } + private void makeDeviceDiscoverable() { + synchronized(this) { + if(!running) return; + } + if(adapter.getScanMode() == SCAN_MODE_CONNECTABLE_DISCOVERABLE) return; + Intent intent = new Intent(ACTION_REQUEST_DISCOVERABLE); + intent.putExtra(EXTRA_DISCOVERABLE_DURATION, 60); + intent.addFlags(FLAG_ACTIVITY_NEW_TASK); + appContext.startActivity(intent); + } + private static class BluetoothStateReceiver extends BroadcastReceiver { private final CountDownLatch finished = new CountDownLatch(1);