From a55dfa959f26a4446c3772877eaa85cf11c53db7 Mon Sep 17 00:00:00 2001 From: Erik Johansson Date: Sat, 26 May 2018 23:03:32 +0200 Subject: [PATCH] Log current bluetooth state when connecting To help debug issues such as #252 --- .../core/bluetooth/BluetoothCommunication.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java index e8799f19..3af90833 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java @@ -24,6 +24,7 @@ import android.bluetooth.BluetoothGattCallback; import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattDescriptor; import android.bluetooth.BluetoothGattService; +import android.bluetooth.BluetoothManager; import android.bluetooth.BluetoothProfile; import android.content.Context; import android.content.pm.PackageManager; @@ -382,6 +383,21 @@ public abstract class BluetoothCommunication { public void connect(String hwAddress) { Timber.i("Connecting to [%s] (driver: %s)", hwAddress, driverName()); + Timber.d("BT is%s enabled, state=%d, scan mode=%d, is%s discovering", + btAdapter.isEnabled() ? "" : " not", btAdapter.getState(), + btAdapter.getScanMode(), btAdapter.isDiscovering() ? "" : " not"); + + BluetoothManager manager = + (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE); + for (BluetoothDevice device : manager.getConnectedDevices(BluetoothProfile.GATT)) { + Timber.d("Connected GATT device: %s [%s]", + device.getName(), device.getAddress()); + } + for (BluetoothDevice device : manager.getConnectedDevices(BluetoothProfile.GATT_SERVER)) { + Timber.d("Connected GATT_SERVER device: %s [%s]", + device.getName(), device.getAddress()); + } + // Some good tips to improve BLE connections: // https://android.jlelse.eu/lessons-for-first-time-android-bluetooth-le-developers-i-learned-the-hard-way-fee07646624