AudioService: Don't honour SCO ON request if SCO is not connected

Usecase:
1. Pair and connect BT headset supporting HFP.
2. Make VOIP calls using application that calls
   setBluetoothScoOn(true) before SCO is actually connected.

Failure:
No audio / ANR are observed on connecting and disconnecting BT headset
during VOIP call.

Rootcause:
On BT connection during VOIP call, app is calling startBluetoothSco()
to setup BT SCO connection. Even before remote BT device SCO connection
establishment(which is taking around 4 secs in issue case), VOIP app
is calling force SCO routing using setBluetoothScoOn() API. This will
result audio modules to force route VOIP call to BT SCO, which results
audio failure/side effects as BT driver return failures. As SCO routing
retry continues several iterations (because of connection delays), this
results ADSP render buffer full followed by improper behavior.

Fix:
Check if SCO connection is establisted before honouring the
setBluetoothScoOn request, if SCO is not connected then
do not process SCO connection.
Only modify internal state when calls to setBluetoothScoOn() are from
system component
Inform audio HAL of SCO audio state via setParameters.

Test: 1. Pair and connect BT headset supporting HFP
      2. Make VOIP calls using application that calls
         setBluetoothScoOn(true) before SCO is actually connected.

Bug: 62051216
Bug: 63740200
Change-Id: Iab8e83613e21831abf5502a0268b1c4f89d6bba5
1 file changed