The headset_suspend_stream function should imediately fail if the headset
isn't connected or playing. This ensures that we return a proper error to
the unix socket client if the headset disconnect just before we receive a
STOP_STREAM request.
The media stream could be gone by the time that the AVDTP command timeout
expires (e.g. if the media transport channel gets closed prematurely). In
such a case there's no need to send a separate ABORT command but we can
directly proceed with closing the signalling channel.
The transition to ABORTING state when acting as initiator should happen
when we receive the ABORT reply and not when we send the initial ABORT
command. The reply handling is already correct but since there's a state
change also in the sending part the later state change request would fail.
This patch fixes the issue by removing the state change when sending the
ABORT command.
We might not have a stream anymore when receiving the reply to a AVDTP
command that assumes that there is an existing stream. So ignore the
replies to these commands if we don't have a stream anymore.
A device may attempt to initiate a duplicate avdtp channel while
a host-initiated channel connection is still pending. This
situation is referred to as 'XCASE connect:connect' in sink.c and
source.c. This fix rejects the device-initiated connection in this
circumstance.
AVRCP state isn't hooked up to the generic audio interface and its state
changes so it needs to clear the authorized variable when getting
disconnected if no other profile is active.
The caller of btd_request_authorization could assume that it's
callback will be called in a separate mainloop iteration as opposed to
from within the actual btd_request_authorization function. It's therefore
better to use an idle callback to make the trusted device callback
behavior similar to that of untrusted devices.
If the device is trusted and the authorization is canceled before the idle
callback takes place the idle callback should be removed. This patch adds
tracking of the idle id and removes it in the case of cancelation.
The current check for implicit authorization is if any other audio profile
is already connected. However, a the second profile might try to connect
right after we've gotten a positive authorization reply for the first one
but before the first profile has reached "connected" state. So just by
checking the connected state of other profiles we might get a false
negative for the decision of doing implicit authorization.
This patch adds a variable to the audio_device struct for keeping track of
if we've gotten a positive authorization reply that can be used in
addition to the "any other profiles" connected check. This variable gets
cleared when the (global audio) device state goes back to disconnected.
When manager.c (HFP/HSP), avdtp.c (A2DP) or control.c wants to cancel an
authorization request it shouldnd't affect the requests of the other
modules. So btd_cancel_authorization cannot be used. This patch adds a new
cancellation function to device.c which will remove the specific callback
from the list and only if the list is empty call btd_cancel_authorization.
The code shouldn't just blindly overwrite the existing client->interface
without freeing it first. This could happen e.g. if we get two consecutive
GET_CAPABILITIES requests over the IPC.
telephony_device_disconnected() shouldn't be called when transitioning
from "connecting" to "disconnected" state since
telephony_device_disconnected() requires that at least "connected" state
was reached previously.
If any of the IPC messages cause us to create a brand new AVDTP session
and then there's failure caused by disconnection, we have to unref the
session since there will not be a unix.c callback to do it when avdtp.c
wants to clean up in the next mainloop iteration.
If the AVDTP connection has just recently disconnected but not yet been
notified to the mainloop then we need to clean the unix.c avdtp session
reference within start_discovery() instead of doing it when the unix
client disconnects. This is because when the AVDTP disconnection finally
gets reported in the next mainloop iteration the unix.c reference wouldn't
get cleared as is intended (since unix.c doesn't have any callbacks at
this point).