From eedfa0d2775280f10fce3ac26c7b16f5962ee244 Mon Sep 17 00:00:00 2001 From: Abandoned Cart Date: Tue, 24 Oct 2023 17:34:01 -0400 Subject: [PATCH] Only return previous connection if possible --- .../java/com/hiddenramblings/tagmo/bluetooth/GattService.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/hiddenramblings/tagmo/bluetooth/GattService.kt b/app/src/main/java/com/hiddenramblings/tagmo/bluetooth/GattService.kt index 1d4c884ee..edce374b7 100644 --- a/app/src/main/java/com/hiddenramblings/tagmo/bluetooth/GattService.kt +++ b/app/src/main/java/com/hiddenramblings/tagmo/bluetooth/GattService.kt @@ -477,6 +477,7 @@ class GattService : Service() { Debug.verbose(Companion::class.java, "${serviceType.logTag} onMtuChange $mtu $status") if (status == BluetoothGatt.GATT_SUCCESS) maxTransmissionUnit = mtu - 3 + if (null == mBluetoothGatt) mBluetoothGatt = gatt when (serviceType) { Nordic.DEVICE.BLUUP, Nordic.DEVICE.FLASK, Nordic.DEVICE.SLIDE -> { listener?.onBluupServicesDiscovered() @@ -578,7 +579,9 @@ class GattService : Service() { if (emptyAdapater || address == null) return false // Previously connected device. Try to reconnect. - if (address == mBluetoothDeviceAddress) mBluetoothGatt?.let { return it.connect() } + mBluetoothGatt?.let { + if (address == mBluetoothDeviceAddress && it.connect()) return true + } val device = mBluetoothAdapter?.getRemoteDevice(address) ?: return false // We want to directly connect to the device, so we are setting the autoConnect // parameter to false.