fetch service UUIDs before checking UUIDs of a bluetooth device when starting service

This commit is contained in:
Kavish Devar
2025-01-06 14:26:13 +05:30
parent c941d0d320
commit 130b83c91a

View File

@@ -319,23 +319,31 @@ class AirPodsService: Service() {
val bluetoothAdapter = getSystemService(BluetoothManager::class.java).adapter val bluetoothAdapter = getSystemService(BluetoothManager::class.java).adapter
bluetoothAdapter.bondedDevices.forEach { device -> bluetoothAdapter.bondedDevices.forEach { device ->
if (device.uuids.contains(ParcelUuid.fromString("74ec2172-0bad-4d01-8f77-997b2be0722a"))) { device.fetchUuidsWithSdp()
bluetoothAdapter.getProfileProxy(this, object : BluetoothProfile.ServiceListener { if (device.uuids != null)
override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) { {
if (profile == BluetoothProfile.A2DP) { if (device.uuids.contains(ParcelUuid.fromString("74ec2172-0bad-4d01-8f77-997b2be0722a"))) {
val connectedDevices = proxy.connectedDevices bluetoothAdapter.getProfileProxy(
if (connectedDevices.isNotEmpty()) { this,
connectToSocket(device) object : BluetoothProfile.ServiceListener {
this@AirPodsService.sendBroadcast( override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) {
Intent(AirPodsNotifications.Companion.AIRPODS_CONNECTED) if (profile == BluetoothProfile.A2DP) {
) val connectedDevices = proxy.connectedDevices
if (connectedDevices.isNotEmpty()) {
connectToSocket(device)
this@AirPodsService.sendBroadcast(
Intent(AirPodsNotifications.Companion.AIRPODS_CONNECTED)
)
}
}
bluetoothAdapter.closeProfileProxy(profile, proxy)
} }
}
bluetoothAdapter.closeProfileProxy(profile, proxy)
}
override fun onServiceDisconnected(profile: Int) { } override fun onServiceDisconnected(profile: Int) {}
}, BluetoothProfile.A2DP) },
BluetoothProfile.A2DP
)
}
} }
} }