Changes done for disconnecting sco connection based on disconnectAudioNative() return status, instead of waiting till BTA_AG_AUDIO_CLOSE_EVT is received. The delay in disconnecting sco was causing audio to be routed to earpiece instead of speaker, when selected from incall screen.
Change-Id: I307c3e9c114676649750cb64f1043fc7fe79d71b
diff --git a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
index 5eb9753..94452fa 100755
--- a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
+++ b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
@@ -769,7 +769,12 @@
}
// fall through
case DISCONNECT_AUDIO:
- disconnectAudioNative(getByteAddress(mCurrentDevice));
+ if (disconnectAudioNative(getByteAddress(mCurrentDevice))) {
+ mAudioState = BluetoothHeadset.STATE_AUDIO_DISCONNECTED;
+ mAudioManager.setBluetoothScoOn(false);
+ broadcastAudioState(mCurrentDevice, BluetoothHeadset.STATE_AUDIO_DISCONNECTED,
+ BluetoothHeadset.STATE_AUDIO_CONNECTED);
+ }
break;
case VOICE_RECOGNITION_START:
processLocalVrEvent(HeadsetHalConstants.VR_STATE_STARTED);
@@ -904,10 +909,12 @@
switch (state) {
case HeadsetHalConstants.AUDIO_STATE_DISCONNECTED:
- mAudioState = BluetoothHeadset.STATE_AUDIO_DISCONNECTED;
- mAudioManager.setBluetoothScoOn(false);
- broadcastAudioState(device, BluetoothHeadset.STATE_AUDIO_DISCONNECTED,
- BluetoothHeadset.STATE_AUDIO_CONNECTED);
+ if (mAudioState != BluetoothHeadset.STATE_AUDIO_DISCONNECTED) {
+ mAudioState = BluetoothHeadset.STATE_AUDIO_DISCONNECTED;
+ mAudioManager.setBluetoothScoOn(false);
+ broadcastAudioState(device, BluetoothHeadset.STATE_AUDIO_DISCONNECTED,
+ BluetoothHeadset.STATE_AUDIO_CONNECTED);
+ }
transitionTo(mConnected);
break;
case HeadsetHalConstants.AUDIO_STATE_DISCONNECTING: