@@ -319,23 +319,31 @@ class AirPodsService: Service() {
319319
320320 val bluetoothAdapter = getSystemService(BluetoothManager ::class .java).adapter
321321 bluetoothAdapter.bondedDevices.forEach { device ->
322- if (device.uuids.contains(ParcelUuid .fromString(" 74ec2172-0bad-4d01-8f77-997b2be0722a" ))) {
323- bluetoothAdapter.getProfileProxy(this , object : BluetoothProfile .ServiceListener {
324- override fun onServiceConnected (profile : Int , proxy : BluetoothProfile ) {
325- if (profile == BluetoothProfile .A2DP ) {
326- val connectedDevices = proxy.connectedDevices
327- if (connectedDevices.isNotEmpty()) {
328- connectToSocket(device)
329- this @AirPodsService.sendBroadcast(
330- Intent (AirPodsNotifications .Companion .AIRPODS_CONNECTED )
331- )
322+ device.fetchUuidsWithSdp()
323+ if (device.uuids != null )
324+ {
325+ if (device.uuids.contains(ParcelUuid .fromString(" 74ec2172-0bad-4d01-8f77-997b2be0722a" ))) {
326+ bluetoothAdapter.getProfileProxy(
327+ this ,
328+ object : BluetoothProfile .ServiceListener {
329+ override fun onServiceConnected (profile : Int , proxy : BluetoothProfile ) {
330+ if (profile == BluetoothProfile .A2DP ) {
331+ val connectedDevices = proxy.connectedDevices
332+ if (connectedDevices.isNotEmpty()) {
333+ connectToSocket(device)
334+ this @AirPodsService.sendBroadcast(
335+ Intent (AirPodsNotifications .Companion .AIRPODS_CONNECTED )
336+ )
337+ }
338+ }
339+ bluetoothAdapter.closeProfileProxy(profile, proxy)
332340 }
333- }
334- bluetoothAdapter.closeProfileProxy(profile, proxy)
335- }
336341
337- override fun onServiceDisconnected (profile : Int ) { }
338- }, BluetoothProfile .A2DP )
342+ override fun onServiceDisconnected (profile : Int ) {}
343+ },
344+ BluetoothProfile .A2DP
345+ )
346+ }
339347 }
340348 }
341349
0 commit comments