Skip to content

Commit

Permalink
Fix disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
Mygod committed Dec 18, 2024
1 parent e5825a2 commit a8d7090
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions app/src/main/java/be/mygod/pogoplusplus/SfidaManager.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package be.mygod.pogoplusplus

import android.bluetooth.BluetoothClass
import android.bluetooth.BluetoothDevice
import android.bluetooth.BluetoothGatt
import android.bluetooth.BluetoothGattCallback
Expand Down Expand Up @@ -41,10 +40,6 @@ object SfidaManager : BluetoothGattCallback() {
} catch (_: SecurityException) {
null
}
@RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
fun isDisconnected(device: BluetoothDevice) = device.bondState == BluetoothDevice.BOND_NONE ||
Build.VERSION.SDK_INT >= 31 && bluetooth.getConnectionState(device, BluetoothProfile.GATT) !=
BluetoothProfile.STATE_CONNECTED

@RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
private fun getDeviceName(device: BluetoothDevice, action: String? = null): Optional<String>? {
Expand Down Expand Up @@ -86,7 +81,9 @@ object SfidaManager : BluetoothGattCallback() {
@RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
fun disconnect(device: BluetoothDevice) {
if (bluetooth.adapter.bondedDevices?.contains(device) != false && removeBond(device) ||
isDisconnected(device)) return
device.name == DEVICE_NAME_PGP && device.bondState == BluetoothDevice.BOND_NONE ||
Build.VERSION.SDK_INT >= 31 && bluetooth.getConnectionState(device, BluetoothProfile.GATT) !=
BluetoothProfile.STATE_CONNECTED) return
disconnectGatt(device)
}
@RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
Expand Down

0 comments on commit a8d7090

Please sign in to comment.