Respect active BT device for routing and resolve flaky BT timing issues

This CL addresses three issues:

(1) The active BT device not being respected in the base routing.
Currently, the device ordering is determined by when the device is added
(paired). Depending on which device is actually active
(BT_ACTIVE_DEVICE_PRESENT), we should attempt to prioritize the active
device over others.

(2) BT not connecting via voice dial: We were seeing issues with BT
stack informing us of SCO audio disconnected once the search assistant
wasn't being used. The timing of when this occured was after active
focus for the call is received, which causes audio to be routed out of
BT. Instead, we should ignore switching the baseline route in the case
that BT is in the middle of connecting (or is already connected).

(3) There was an issue reported with transactional calling where if
there's a BT device connected and the user requests to switch the
callendpoint to speaker in the pre-call audio flow, then the request
isn't honored. This happens because the device is still in the middle of
connecting when the request comes in so Telecom ends up waiting for the
SCO audio connected message to be signaled in from the BT stack. But,
the switch will cause SCO to be disconnected before we set the
communication device for speaker, so the audio route controller stays
stuck waiting on the SCO audio connected pending msg to be received.
This CL ensures that when the original routing is being cleaned up that
we also clean up the associated SCO audio connected msg for it as well
if it exists.

Bug: 372029371
Flag: com.android.server.telecom.flags.resolve_active_bt_routing_and_bt_timing_issue
Test: Manual for voice dial and active device issue
Test: atest CallAudioRouteControllerTest (added unit tests for all
cases)

Change-Id: I16ee9c2afe3d73ae438d27660cf53744273399b2
5 files changed