bluez5: don't try to autoconnect same device via multiple adapters

If you use multiple BT adapters, it's annoying that PW tries to
autoconnect to the device via all available adapters, and you end up
with multiple connections to the same device (which does not necessarily
work).

Avoid this by autoconnecting with only the first adapter that sees the
device.
This commit is contained in:
Pauli Virtanen 2021-08-29 15:40:14 +03:00
parent e90c436f3a
commit b057c9166d

View file

@ -1046,10 +1046,23 @@ static int device_try_connect_profile(struct spa_bt_device *device,
static int reconnect_device_profiles(struct spa_bt_device *device)
{
struct spa_bt_monitor *monitor = device->monitor;
struct spa_bt_device *d;
uint32_t reconnect = device->profiles
& device->reconnect_profiles
& (device->connected_profiles ^ device->profiles);
/* Don't try to connect to same device via multiple adapters */
spa_list_for_each(d, &monitor->device_list, link) {
if (d != device && spa_streq(d->address, device->address)) {
if (d->paired && d->trusted && !d->blocked &&
d->reconnect_state == BT_DEVICE_RECONNECT_STOP)
reconnect &= ~d->reconnect_profiles;
if (d->connected_profiles)
reconnect = 0;
}
}
if (!(device->connected_profiles & SPA_BT_PROFILE_HEADSET_HEAD_UNIT)) {
if (reconnect & SPA_BT_PROFILE_HFP_HF) {
SPA_FLAG_CLEAR(reconnect, SPA_BT_PROFILE_HSP_HS);