From 8935ec2c2e7c57f0e57a792dd88da4665b1bc444 Mon Sep 17 00:00:00 2001 From: akwizgran Date: Fri, 22 Jun 2018 16:23:36 +0100 Subject: [PATCH] Don't wait for state change if BT is already discoverable. --- .../android/keyagreement/KeyAgreementActivity.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/briar-android/src/main/java/org/briarproject/briar/android/keyagreement/KeyAgreementActivity.java b/briar-android/src/main/java/org/briarproject/briar/android/keyagreement/KeyAgreementActivity.java index 55d8ea5b3..6af2e5f28 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/keyagreement/KeyAgreementActivity.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/keyagreement/KeyAgreementActivity.java @@ -177,9 +177,16 @@ public abstract class KeyAgreementActivity extends BriarActivity implements @Override public void onActivityResult(int request, int result, Intent data) { if (request == REQUEST_BLUETOOTH_DISCOVERABLE) { - // If the request was granted we'll catch the state change event - if (result == RESULT_CANCELED) + if (result == RESULT_CANCELED) { setBluetoothState(BluetoothState.REFUSED); + } else { + // If Bluetooth is already discoverable, show the QR code - + // otherwise wait for the state or scan mode to change + BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter(); + if (bt == null) throw new AssertionError(); + if (bt.getScanMode() == SCAN_MODE_CONNECTABLE_DISCOVERABLE) + setBluetoothState(BluetoothState.DISCOVERABLE); + } } }