Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b34de512 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use bluetooth alias as route name on AudioManager routes" into main

parents c5722d02 923ecea3
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -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);
    }

+20 −7
Original line number Diff line number Diff line
@@ -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();
            }