summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author jiabin <jiabin@google.com> 2023-10-24 19:33:34 +0000
committer jiabin <jiabin@google.com> 2023-10-25 16:43:11 +0000
commita96b63c974d28c1ef6c08afd606375200d285713 (patch)
tree554af6db1b0a32675547063822a94cfd576142c0
parentf862be37675faef7c7767ef4e4f7b0ae69ea6f9d (diff)
Cache sco type when connecting.
Cache sco type when connecting for later use. This can help keep consistent sco type when communicating to the native audio server. Bug: 305089560 Test: make phone call over BT Change-Id: I8094691656ad6f2b1afcd5accfc2a176abb6a019
-rw-r--r--services/core/java/com/android/server/audio/BtHelper.java24
1 files changed, 22 insertions, 2 deletions
diff --git a/services/core/java/com/android/server/audio/BtHelper.java b/services/core/java/com/android/server/audio/BtHelper.java
index 6af409e7af3a..7d7e6d000f62 100644
--- a/services/core/java/com/android/server/audio/BtHelper.java
+++ b/services/core/java/com/android/server/audio/BtHelper.java
@@ -44,7 +44,9 @@ import com.android.server.utils.EventLogger;
import java.io.PrintWriter;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
/**
@@ -66,6 +68,8 @@ public class BtHelper {
// Bluetooth headset device
private @Nullable BluetoothDevice mBluetoothHeadsetDevice;
+ private final Map<BluetoothDevice, AudioDeviceAttributes> mResolvedScoAudioDevices =
+ new HashMap<>();
private @Nullable BluetoothHearingAid mHearingAid;
@@ -590,7 +594,16 @@ public class BtHelper {
if (mBluetoothHeadsetDevice == null) {
return null;
}
- return btHeadsetDeviceToAudioDevice(mBluetoothHeadsetDevice);
+ return getHeadsetAudioDevice(mBluetoothHeadsetDevice);
+ }
+
+ private @NonNull AudioDeviceAttributes getHeadsetAudioDevice(BluetoothDevice btDevice) {
+ AudioDeviceAttributes deviceAttr = mResolvedScoAudioDevices.get(btDevice);
+ if (deviceAttr != null) {
+ // Returns the cached device attributes so that it is consistent as the previous one.
+ return deviceAttr;
+ }
+ return btHeadsetDeviceToAudioDevice(btDevice);
}
private static AudioDeviceAttributes btHeadsetDeviceToAudioDevice(BluetoothDevice btDevice) {
@@ -628,7 +641,7 @@ public class BtHelper {
return true;
}
int inDevice = AudioSystem.DEVICE_IN_BLUETOOTH_SCO_HEADSET;
- AudioDeviceAttributes audioDevice = btHeadsetDeviceToAudioDevice(btDevice);
+ AudioDeviceAttributes audioDevice = btHeadsetDeviceToAudioDevice(btDevice);
boolean result = false;
if (isActive) {
result |= mDeviceBroker.handleDeviceConnection(audioDevice, isActive, btDevice);
@@ -648,6 +661,13 @@ public class BtHelper {
result = mDeviceBroker.handleDeviceConnection(new AudioDeviceAttributes(
inDevice, audioDevice.getAddress(), audioDevice.getName()),
isActive, btDevice) && result;
+ if (result) {
+ if (isActive) {
+ mResolvedScoAudioDevices.put(btDevice, audioDevice);
+ } else {
+ mResolvedScoAudioDevices.remove(btDevice);
+ }
+ }
return result;
}