Loading services/core/java/com/android/server/media/AudioManagerRouteController.java +8 −4 Original line number Diff line number Diff line Loading @@ -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); } Loading services/core/java/com/android/server/media/BluetoothDeviceRoutesManager.java +20 −7 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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); Loading Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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(); } Loading Loading
services/core/java/com/android/server/media/AudioManagerRouteController.java +8 −4 Original line number Diff line number Diff line Loading @@ -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); } Loading
services/core/java/com/android/server/media/BluetoothDeviceRoutesManager.java +20 −7 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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); Loading Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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(); } Loading