Merge 7cbccaa751edaec9cc5c3379613859398dca179d on remote branch

Change-Id: I664f55ae50a54eaed50775a71f7149d019455473
diff --git a/src/com/android/bluetooth/btservice/AdapterService.java b/src/com/android/bluetooth/btservice/AdapterService.java
index 2f0d6ab..562a32e 100644
--- a/src/com/android/bluetooth/btservice/AdapterService.java
+++ b/src/com/android/bluetooth/btservice/AdapterService.java
@@ -1789,10 +1789,6 @@
             if (service == null) {
                 return false;
             }
-            if ((getState() == BluetoothAdapter.STATE_BLE_ON) ||
-                (getState() == BluetoothAdapter.STATE_BLE_TURNING_ON)) {
-                service.onBrEdrDown();
-            }
             return service.factoryReset();
         }
 
diff --git a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
index ceef453..d8a64be 100644
--- a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
+++ b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java
@@ -1372,6 +1372,7 @@
                 // devices that previously successfully connected.
                 removeDeferredMessages(CONNECT);
             }
+            broadcastStateTransitions();
             if ((mPrevState == mAudioOn) || (mPrevState == mAudioDisconnecting)||
                  (mPrevState == mAudioConnecting)) {
                 if (!(mSystemInterface.isInCall() || mSystemInterface.isRinging())) {
@@ -1380,7 +1381,6 @@
                         mHeadsetService.getHfpA2DPSyncInterface().releaseA2DP(mDevice);
                 }
             }
-            broadcastStateTransitions();
         }
 
         @Override
@@ -1742,6 +1742,7 @@
                         //any devices before letting Audio knowing about it
                         stateLogI("TWS+ device and other SCO is still Active, no BT_SCO=off");
                     } else {
+                        mSystemInterface.getAudioManager().setBluetoothScoOn(false);
                         if(mSystemInterface.getAudioManager().isSpeakerphoneOn()) {
                             mSystemInterface.getAudioManager().setSpeakerphoneOn(true);
                         }
@@ -1825,6 +1826,7 @@
                          //any devices before letting Audio knowing about it
                          stateLogI("TWS+ device and other SCO is still Active, no BT_SCO=off");
                     } else {
+                        mSystemInterface.getAudioManager().setBluetoothScoOn(false);
                         if(mSystemInterface.getAudioManager().isSpeakerphoneOn()) {
                             mSystemInterface.getAudioManager().setSpeakerphoneOn(true);
                         }