summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Iván Budnik <ivanbuper@google.com> 2024-03-26 09:01:48 +0000
committer Iván Budnik <ivanbuper@google.com> 2024-03-26 09:27:55 +0000
commit923ecea34fbf2fdc9738d2faa45f1a6519cc61bc (patch)
tree298843ba3691ba53cc3fdeec85b2ddf048ba2c89
parent98d7df0218bbe183ad10d834af053afe46d78df4 (diff)
Use bluetooth alias as route name on AudioManager routes
Bluetooth routes that were obtained via AudioManagerRouteController were not using the bluetooth device's alias, and would not be updated whenever the user set a new device alias. Bug: 314324170 Bug: 328863853 Test: Manual. Change-Id: Icef2c91e246433f4ef669aa2db09341f664e3ab7
-rw-r--r--services/core/java/com/android/server/media/AudioManagerRouteController.java12
-rw-r--r--services/core/java/com/android/server/media/BluetoothDeviceRoutesManager.java27
2 files changed, 28 insertions, 11 deletions
diff --git a/services/core/java/com/android/server/media/AudioManagerRouteController.java b/services/core/java/com/android/server/media/AudioManagerRouteController.java
index 2439589eeb09..e7f717aa6c3b 100644
--- a/services/core/java/com/android/server/media/AudioManagerRouteController.java
+++ b/services/core/java/com/android/server/media/AudioManagerRouteController.java
@@ -387,16 +387,20 @@ import java.util.Objects;
private MediaRoute2Info createMediaRoute2InfoFromAudioDeviceInfo(
AudioDeviceInfo audioDeviceInfo) {
String address = audioDeviceInfo.getAddress();
+
// Passing a null route id means we want to get the default id for the route. Generally, we
// only expect to pass null for non-Bluetooth routes.
- String routeId =
- TextUtils.isEmpty(address)
- ? null
- : mBluetoothRouteController.getRouteIdForBluetoothAddress(address);
+ String routeId = null;
+
// We use the name from the port instead AudioDeviceInfo#getProductName because the latter
// replaces empty names with the name of the device (example: Pixel 8). In that case we want
// to derive a name ourselves from the type instead.
String deviceName = audioDeviceInfo.getPort().name();
+
+ if (!TextUtils.isEmpty(address)) {
+ routeId = mBluetoothRouteController.getRouteIdForBluetoothAddress(address);
+ deviceName = mBluetoothRouteController.getNameForBluetoothAddress(address);
+ }
return createMediaRoute2Info(routeId, audioDeviceInfo.getType(), deviceName, address);
}
diff --git a/services/core/java/com/android/server/media/BluetoothDeviceRoutesManager.java b/services/core/java/com/android/server/media/BluetoothDeviceRoutesManager.java
index 8119628aed7a..8ddcf76a1ba4 100644
--- a/services/core/java/com/android/server/media/BluetoothDeviceRoutesManager.java
+++ b/services/core/java/com/android/server/media/BluetoothDeviceRoutesManager.java
@@ -119,6 +119,7 @@ import java.util.stream.Collectors;
BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
deviceStateChangedIntentFilter.addAction(
BluetoothLeAudio.ACTION_LE_AUDIO_CONNECTION_STATE_CHANGED);
+ deviceStateChangedIntentFilter.addAction(BluetoothDevice.ACTION_ALIAS_CHANGED);
mContext.registerReceiverAsUser(mDeviceStateChangedReceiver, user,
deviceStateChangedIntentFilter, null, null);
@@ -140,6 +141,12 @@ import java.util.stream.Collectors;
: null;
}
+ @Nullable
+ public synchronized String getNameForBluetoothAddress(@NonNull String address) {
+ BluetoothDevice bluetoothDevice = mAddressToBondedDevice.get(address);
+ return bluetoothDevice != null ? getDeviceName(bluetoothDevice) : null;
+ }
+
public synchronized void activateBluetoothDeviceWithAddress(String address) {
BluetoothRouteInfo btRouteInfo = mBluetoothRoutes.get(address);
@@ -218,13 +225,7 @@ import java.util.stream.Collectors;
BluetoothRouteInfo
newBtRoute = new BluetoothRouteInfo();
newBtRoute.mBtDevice = device;
- String deviceName =
- Flags.enableUseOfBluetoothDeviceGetAliasForMr2infoGetName()
- ? device.getAlias()
- : device.getName();
- if (TextUtils.isEmpty(deviceName)) {
- deviceName = mContext.getResources().getText(R.string.unknownName).toString();
- }
+ String deviceName = getDeviceName(device);
String routeId = device.getAddress();
int type = MediaRoute2Info.TYPE_BLUETOOTH_A2DP;
@@ -262,6 +263,17 @@ import java.util.stream.Collectors;
return newBtRoute;
}
+ private String getDeviceName(BluetoothDevice device) {
+ String deviceName =
+ Flags.enableUseOfBluetoothDeviceGetAliasForMr2infoGetName()
+ ? device.getAlias()
+ : device.getName();
+ if (TextUtils.isEmpty(deviceName)) {
+ deviceName = mContext.getResources().getText(R.string.unknownName).toString();
+ }
+ return deviceName;
+ }
+
private static class BluetoothRouteInfo {
private BluetoothDevice mBtDevice;
private MediaRoute2Info mRoute;
@@ -300,6 +312,7 @@ import java.util.stream.Collectors;
case BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED:
case BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED:
case BluetoothLeAudio.ACTION_LE_AUDIO_CONNECTION_STATE_CHANGED:
+ case BluetoothDevice.ACTION_ALIAS_CHANGED:
updateBluetoothRoutes();
notifyBluetoothRoutesUpdated();
}