From 5ba6e050e1ed22d0edc205cef7447e3ff8492f7f Mon Sep 17 00:00:00 2001 From: Krisjans Blukis Date: Thu, 29 Jul 2021 14:19:20 +0300 Subject: [PATCH] BluetoothCommunication: Stop state machine only if setNotification operation was enqueued; --- .../core/bluetooth/BluetoothCommunication.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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 b09ea16f..3cd29a83 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 @@ -308,14 +308,20 @@ public abstract class BluetoothCommunication { * Set notification flag on for the Bluetooth device. * * @param characteristic the Bluetooth UUID characteristic + * @return true if the operation was enqueued, false if the characteristic doesn't support notification or indications or */ - protected void setNotificationOn(UUID service, UUID characteristic) { + protected boolean setNotificationOn(UUID service, UUID characteristic) { Timber.d("Invoke set notification on " + BluetoothGattUuid.prettyPrint(characteristic)); if(btPeripheral.getService(service) != null) { - stopMachineState(); BluetoothGattCharacteristic currentTimeCharacteristic = btPeripheral.getCharacteristic(service, characteristic); - btPeripheral.setNotify(currentTimeCharacteristic, true); + if (currentTimeCharacteristic != null) { + if (btPeripheral.setNotify(currentTimeCharacteristic, true)) { + stopMachineState(); + return true; + } + } } + return false; } /**