From 99a86c4080d0972393c5dd9092c2c9e2454b9e3a Mon Sep 17 00:00:00 2001 From: n8fr8 Date: Mon, 13 Jul 2015 14:40:11 -0400 Subject: [PATCH] handle null adapter case --- .../views/swap/SwapWorkflowActivity.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/F-Droid/src/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java b/F-Droid/src/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java index 075044e5e..432a6180f 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java +++ b/F-Droid/src/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java @@ -296,15 +296,16 @@ public class SwapWorkflowActivity extends ActionBarActivity { Log.d(TAG, "Initiating Bluetooth swap instead of wifi."); BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); - // TODO: May be null (e.g. on an emulator). - if (adapter.isEnabled()) { - Log.d(TAG, "Bluetooth enabled, will pair with device."); - ensureBluetoothDiscoverable(); - } else { - Log.d(TAG, "Bluetooth disabled, asking user to enable it."); - Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); - startActivityForResult(enableBtIntent, REQUEST_BLUETOOTH_ENABLE); - } + + if (adapter != null) + if (adapter.isEnabled()) { + Log.d(TAG, "Bluetooth enabled, will pair with device."); + ensureBluetoothDiscoverable(); + } else { + Log.d(TAG, "Bluetooth disabled, asking user to enable it."); + Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); + startActivityForResult(enableBtIntent, REQUEST_BLUETOOTH_ENABLE); + } } private void ensureBluetoothDiscoverable() { @@ -318,10 +319,11 @@ public class SwapWorkflowActivity extends ActionBarActivity { Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300); startActivityForResult(intent, REQUEST_BLUETOOTH_DISCOVERABLE); - } else { - Log.d(TAG, "Bluetooth is already discoverable, so lets start the Bluetooth server."); - startBluetoothServer(); } + + Log.d(TAG, "Staring the Bluetooth Server whether we are discoverable or not, since paired devices can still connect."); + startBluetoothServer(); + } private void startBluetoothServer() {