mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 13:49:53 +01:00
Restart discovery if it finishes too quickly.
Discovery finishes quickly on some devices if called at the wrong time.
This commit is contained in:
@@ -76,6 +76,7 @@ class AndroidBluetoothPlugin extends BluetoothPlugin<BluetoothServerSocket> {
|
|||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
getLogger(AndroidBluetoothPlugin.class.getName());
|
getLogger(AndroidBluetoothPlugin.class.getName());
|
||||||
|
|
||||||
|
private static final int MIN_DEVICE_DISCOVERY_MS = 2_000;
|
||||||
private static final int MAX_DEVICE_DISCOVERY_MS = 30_000;
|
private static final int MAX_DEVICE_DISCOVERY_MS = 30_000;
|
||||||
private static final int MAX_SERVICE_DISCOVERY_MS = 15_000;
|
private static final int MAX_SERVICE_DISCOVERY_MS = 15_000;
|
||||||
|
|
||||||
@@ -416,8 +417,9 @@ class AndroidBluetoothPlugin extends BluetoothPlugin<BluetoothServerSocket> {
|
|||||||
appContext.registerReceiver(receiver, filter);
|
appContext.registerReceiver(receiver, filter);
|
||||||
try {
|
try {
|
||||||
if (adapter.startDiscovery()) {
|
if (adapter.startDiscovery()) {
|
||||||
long now = clock.currentTimeMillis();
|
long start = clock.currentTimeMillis();
|
||||||
long end = now + MAX_DEVICE_DISCOVERY_MS;
|
long end = start + MAX_DEVICE_DISCOVERY_MS;
|
||||||
|
long now = start;
|
||||||
while (now < end) {
|
while (now < end) {
|
||||||
Intent i = intents.poll(end - now, MILLISECONDS);
|
Intent i = intents.poll(end - now, MILLISECONDS);
|
||||||
if (i == null) break;
|
if (i == null) break;
|
||||||
@@ -426,7 +428,16 @@ class AndroidBluetoothPlugin extends BluetoothPlugin<BluetoothServerSocket> {
|
|||||||
LOG.info("Discovery started");
|
LOG.info("Discovery started");
|
||||||
} else if (ACTION_DISCOVERY_FINISHED.equals(action)) {
|
} else if (ACTION_DISCOVERY_FINISHED.equals(action)) {
|
||||||
LOG.info("Discovery finished");
|
LOG.info("Discovery finished");
|
||||||
break;
|
now = clock.currentTimeMillis();
|
||||||
|
if (now - start < MIN_DEVICE_DISCOVERY_MS) {
|
||||||
|
LOG.info("Discovery finished quickly, retrying");
|
||||||
|
if (!adapter.startDiscovery()) {
|
||||||
|
LOG.info("Could not restart discovery");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else if (ACTION_FOUND.equals(action)) {
|
} else if (ACTION_FOUND.equals(action)) {
|
||||||
BluetoothDevice d = requireNonNull(
|
BluetoothDevice d = requireNonNull(
|
||||||
i.getParcelableExtra(EXTRA_DEVICE));
|
i.getParcelableExtra(EXTRA_DEVICE));
|
||||||
|
|||||||
Reference in New Issue
Block a user