If a device that has a fixed PIN was selected before a device that
doesn't have one (for example, select a printer or audio headset,
before selecting a phone), then the automatic_pincode would have
been TRUE.
We need to reset the automatic_pincode every time we change devices.
Bug 594055 - applet fails to connect to any disconnected audio device
Hunted down by Peter Hurley <email address hidden>.
Description
If the remote device is disconnected when the applet starts, the applet
will be unable to initiate connection to the audio interface of the
device.
Cause
Incorrect use of g_hash_table_lookup in the device_list_nodes() function
in lib/bluetooth-client.c
Discussion
For a given device, device_list_nodes() loops through the known
detectable interfaces (those in detectable_interfaces[]) and adds
them to the returned hash table if calling the interfaces's
.GetProperties dbus method returns true.
The value of the "Connected" property is then stored as the associated
value with the interface name as the key in the hash table.
The *connectable* interface "org.bluez.Audio" is only added if at least
either of the *detectable* interfaces "org.bluez.Headset" or
"org.bluez.AudioSink" were added the the hash table in previous
iterations within device_list_nodes().
However, the test for whether those *detectable* interfaces were added
is not correct. Currently, g_hash_table_lookup() is used to determine
if the interface names are in the hash table. g_hash_table_lookup()
will return NULL if the the key is not present in the hash table,
OTHERWISE IT RETURNS THE VALUE ASSOCIATED WITH THE KEY. If that value
is 0 (== BLUETOOTH_STATUS_DISCONNECTED), the logic mistakenly believes
that the key is not present in the hash table, and as a result, fails
to add the only connectable audio interface "org.bluez.Audio".
Recommend
Either use g_hash_table_lookup_extended() to test for key presence
or change enum BLUET00TH_STATUS_DISCONNECTED to be != 0.