AudioService BtHelper: fix Bluetooth Headset to audio device mapping

Fix BtHelper.getTypeFromProfile() to return a refined audio device type
for HEADSET profile, consistent with BtHelper.getHeadsetAudioDevice()

Bug: 420508724
Test: repro steps in bug
Flag: android.media.audio.sco_managed_by_audio
Change-Id: I5847b95128cc9b31184cda0e30b35ddc1bd93383
diff --git a/services/core/java/com/android/server/audio/AudioDeviceBroker.java b/services/core/java/com/android/server/audio/AudioDeviceBroker.java
index 1e52b23..6ecb3b8 100644
--- a/services/core/java/com/android/server/audio/AudioDeviceBroker.java
+++ b/services/core/java/com/android/server/audio/AudioDeviceBroker.java
@@ -1039,7 +1039,8 @@
 
     /*package*/ static BtDeviceInfo createBtDeviceInfo(@NonNull BtDeviceChangedData d,
             @NonNull BluetoothDevice device, int state) {
-        int audioDevice = BtHelper.getTypeFromProfile(d.mInfo.getProfile(), d.mInfo.isLeOutput());
+        int audioDevice = BtHelper.getTypeFromProfile(
+                d.mInfo.getProfile(), d.mInfo.isLeOutput(), device);
         return new BtDeviceInfo(d, device, state, audioDevice, AudioSystem.AUDIO_FORMAT_DEFAULT);
     }
 
diff --git a/services/core/java/com/android/server/audio/AudioDeviceInventory.java b/services/core/java/com/android/server/audio/AudioDeviceInventory.java
index 2dc2cde..8921d2d 100644
--- a/services/core/java/com/android/server/audio/AudioDeviceInventory.java
+++ b/services/core/java/com/android/server/audio/AudioDeviceInventory.java
@@ -991,7 +991,8 @@
                 "onBluetoothDeviceConfigChange addr=" + address
                     + " event=" + BtHelper.deviceEventToString(event)));
 
-        int deviceType = BtHelper.getTypeFromProfile(btInfo.mProfile, btInfo.mIsLeOutput);
+        int deviceType = BtHelper.getTypeFromProfile(
+                btInfo.mProfile, btInfo.mIsLeOutput, btDevice);
 
         synchronized (mDevicesLock) {
             if (mDeviceBroker.hasScheduledA2dpConnection(btDevice, btInfo.mProfile)) {
diff --git a/services/core/java/com/android/server/audio/BtHelper.java b/services/core/java/com/android/server/audio/BtHelper.java
index 79ac009..b93ca6b 100644
--- a/services/core/java/com/android/server/audio/BtHelper.java
+++ b/services/core/java/com/android/server/audio/BtHelper.java
@@ -1298,7 +1298,8 @@
         return 0; // 0 is not a valid profile
     }
 
-    /*package */ static int getTypeFromProfile(int profile, boolean isLeOutput) {
+    /*package */ static int getTypeFromProfile(
+            int profile, boolean isLeOutput, BluetoothDevice device) {
         switch (profile) {
             case BluetoothProfile.A2DP_SINK:
                 return AudioSystem.DEVICE_IN_BLUETOOTH_A2DP;
@@ -1315,7 +1316,7 @@
             case BluetoothProfile.LE_AUDIO_BROADCAST:
                 return AudioSystem.DEVICE_OUT_BLE_BROADCAST;
             case BluetoothProfile.HEADSET:
-                return AudioSystem.DEVICE_OUT_BLUETOOTH_SCO;
+                return btHeadsetDeviceToAudioDevice(device).getInternalType();
             default:
                 throw new IllegalArgumentException("Invalid profile " + profile);
         }