mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
We only need Bluetooth discoverabilty when accepting an invitation.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user