Send the AUDIO_CONNECTED broadcast after switching to the AudioOn state.

The broadcast is currently sent while the HFP client state machine is
in the Connected state. As a result, a broadcast receiver who wishes
to disconnect the incoming audio connection won't be able to successfully
call disconnectAudio. By changing the internal state first and then
broadcasting, receivers can immediately perform audio operations.

Bug: 23568208
Change-Id: I60de9775f9a0126774275d08ef999f082ae41747
diff --git a/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java b/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java
index b79cc24..de731a6 100644
--- a/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java
+++ b/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java
@@ -2039,8 +2039,6 @@
                     }
                     mAudioManager.setParameters("hfp_enable=true");
                     mAudioManager.setParameters("hfp_volume=" + volume);
-                    broadcastAudioState(device, BluetoothHeadsetClient.STATE_AUDIO_CONNECTED,
-                            BluetoothHeadsetClient.STATE_AUDIO_CONNECTING);
                     transitionTo(mAudioOn);
                     break;
                 case HeadsetClientHalConstants.AUDIO_STATE_CONNECTING:
@@ -2074,6 +2072,9 @@
             Log.d(TAG, "Enter AudioOn: " + getCurrentMessage().what);
 
             mAudioManager.setStreamSolo(AudioManager.STREAM_BLUETOOTH_SCO, true);
+
+            broadcastAudioState(mCurrentDevice, BluetoothHeadsetClient.STATE_AUDIO_CONNECTED,
+                BluetoothHeadsetClient.STATE_AUDIO_CONNECTING);
         }
 
         @Override