Skip to content

Commit 99c1af3

Browse files
committed
android: detect auto-reconnected AirPods via saved MAC instead of waiting for SDP UUID lookup
Closes #569
1 parent fb44f01 commit 99c1af3

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

android/app/src/main/java/me/kavishdevar/librepods/services/AirPodsService.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,14 +2377,18 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
23772377
Log.d(TAG, "Received bluetooth connection broadcast: action=$action")
23782378
if (BluetoothDevice.ACTION_ACL_CONNECTED == action) {
23792379
val uuid = ParcelUuid.fromString("74ec2172-0bad-4d01-8f77-997b2be0722a")
2380-
bluetoothDevice.fetchUuidsWithSdp()
2381-
if (bluetoothDevice.uuids != null) {
2382-
if (bluetoothDevice.uuids.contains(uuid)) {
2383-
val intent = Intent(AirPodsNotifications.AIRPODS_CONNECTION_DETECTED)
2384-
intent.putExtra("name", name)
2385-
intent.putExtra("device", bluetoothDevice)
2386-
context?.sendBroadcast(intent)
2387-
}
2380+
val savedMac = context?.getSharedPreferences("settings", MODE_PRIVATE)
2381+
?.getString("mac_address", "") ?: ""
2382+
val matchedByMac = savedMac.isNotEmpty() && bluetoothDevice.address == savedMac
2383+
val matchedByUuid = bluetoothDevice.uuids?.contains(uuid) == true
2384+
2385+
if (matchedByMac || matchedByUuid) {
2386+
val intent = Intent(AirPodsNotifications.AIRPODS_CONNECTION_DETECTED)
2387+
intent.putExtra("name", name)
2388+
intent.putExtra("device", bluetoothDevice)
2389+
context?.sendBroadcast(intent)
2390+
} else {
2391+
bluetoothDevice.fetchUuidsWithSdp()
23882392
}
23892393
}
23902394
}

0 commit comments

Comments
 (0)