Skip to content

Commit

Permalink
Only return previous connection if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
AbandonedCart committed Oct 24, 2023
1 parent 7f7b7fa commit eedfa0d
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit eedfa0d

Please sign in to comment.