1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-28 18:49:56 +02:00

Move bluetooth status logging to a separate method

This commit is contained in:
Erik Johansson
2018-06-14 21:49:37 +02:00
parent a013ad6553
commit ffa25af1bc

View File

@@ -387,20 +387,7 @@ public abstract class BluetoothCommunication {
public void connect(final 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());
}
logBluetoothStatus();
// 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
@@ -441,6 +428,23 @@ public abstract class BluetoothCommunication {
}
}
private void logBluetoothStatus() {
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());
}
}
private void connectGatt(BluetoothDevice device) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
bluetoothGatt = device.connectGatt(