bluez5: mark connected when all source/sink profiles connected

Don't require all device profiles to be connected before marking the
device as connected before profile timeout. Show device already when all
A2DP/HSP/HFP profiles for sink/source direction have connected.

There are devices that in principle can have both sink/source profiles
present, but cannot operate both directions at the same time.  In case
profiles come online later, the only effect is that the device profiles
will get an update after the device is published.
This commit is contained in:
Pauli Virtanen 2022-01-06 21:07:01 +02:00 committed by Wim Taymans
parent d33779cd11
commit b92a378a29

View file

@ -1238,19 +1238,34 @@ int spa_bt_device_check_profiles(struct spa_bt_device *device, bool force)
{
struct spa_bt_monitor *monitor = device->monitor;
uint32_t connected_profiles = device->connected_profiles;
uint32_t direction_masks[2] = {
SPA_BT_PROFILE_A2DP_SINK | SPA_BT_PROFILE_HEADSET_AUDIO,
SPA_BT_PROFILE_A2DP_SOURCE | SPA_BT_PROFILE_HEADSET_AUDIO_GATEWAY,
};
bool direction_connected = false;
bool all_connected;
size_t i;
if (connected_profiles & SPA_BT_PROFILE_HEADSET_HEAD_UNIT)
connected_profiles |= SPA_BT_PROFILE_HEADSET_HEAD_UNIT;
if (connected_profiles & SPA_BT_PROFILE_HEADSET_AUDIO_GATEWAY)
connected_profiles |= SPA_BT_PROFILE_HEADSET_AUDIO_GATEWAY;
for (i = 0; i < SPA_N_ELEMENTS(direction_masks); ++i) {
uint32_t mask = direction_masks[i] & device->profiles;
if (mask && (connected_profiles & mask) == mask)
direction_connected = true;
}
all_connected = (device->profiles & connected_profiles) == device->profiles;
spa_log_debug(monitor->log, "device %p: profiles %08x %08x %d",
device, device->profiles, connected_profiles, device->added);
if (connected_profiles == 0 && spa_list_is_empty(&device->codec_switch_list)) {
device_stop_timer(device);
device_connected(monitor, device, BT_DEVICE_DISCONNECTED);
} else if (force || (device->profiles & connected_profiles) == device->profiles) {
} else if (force || direction_connected || all_connected) {
device_stop_timer(device);
device_connected(monitor, device, BT_DEVICE_CONNECTED);
} else {