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

Commit 7e3c0837 authored by Eric Laurent's avatar Eric Laurent
Browse files

AudioPolicyManager: add support for Bluetooth LE audio codec selection

Add support for Bluetooth LE audio codec reconfiguration similarly to
what is supported for A2DP.

Bug: 309909149
Test: connect BT LE device and check correct codec selection
Change-Id: I1759314fcf0e757db617980aa2129e8bd8af53c5
parent 70555564
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
@@ -267,6 +267,9 @@ status_t DeviceHalAidl::getParameters(const String8& keys, String8 *values) {
    if (status_t status = filterAndRetrieveBtA2dpParameters(parameterKeys, &result); status != OK) {
        ALOGW("%s: filtering or retrieving BT A2DP parameters failed: %d", __func__, status);
    }
    if (status_t status = filterAndRetrieveBtLeParameters(parameterKeys, &result); status != OK) {
        ALOGW("%s: filtering or retrieving BT LE parameters failed: %d", __func__, status);
    }
    *values = result.toString();
    return parseAndGetVendorParameters(mVendorExt, mModule, parameterKeys, values);
}
@@ -988,6 +991,23 @@ status_t DeviceHalAidl::filterAndRetrieveBtA2dpParameters(
    return OK;
}

status_t DeviceHalAidl::filterAndRetrieveBtLeParameters(
        AudioParameter &keys, AudioParameter *result) {
    if (String8 key = String8(AudioParameter::keyReconfigLeSupported); keys.containsKey(key)) {
        keys.remove(key);
        if (mBluetoothLe != nullptr) {
            bool supports;
            RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
                            mBluetoothLe->supportsOffloadReconfiguration(&supports)));
            result->addInt(key, supports ? 1 : 0);
        } else {
            ALOGI("%s: no mBluetoothLe on %s", __func__, mInstance.c_str());
            result->addInt(key, 0);
        }
    }
    return OK;
}

status_t DeviceHalAidl::filterAndUpdateBtA2dpParameters(AudioParameter &parameters) {
    std::optional<bool> a2dpEnabled;
    std::optional<std::vector<VendorParameter>> reconfigureOffload;
@@ -1069,6 +1089,7 @@ status_t DeviceHalAidl::filterAndUpdateBtHfpParameters(AudioParameter &parameter

status_t DeviceHalAidl::filterAndUpdateBtLeParameters(AudioParameter &parameters) {
    std::optional<bool> leEnabled;
    std::optional<std::vector<VendorParameter>> reconfigureOffload;
    (void)VALUE_OR_RETURN_STATUS(filterOutAndProcessParameter<String8>(
                    parameters, String8(AudioParameter::keyBtLeSuspended),
                    [&leEnabled](const String8& trueOrFalse) {
@@ -1083,9 +1104,27 @@ status_t DeviceHalAidl::filterAndUpdateBtLeParameters(AudioParameter &parameters
                                AudioParameter::keyBtLeSuspended, trueOrFalse.c_str());
                        return BAD_VALUE;
                    }));
    (void)VALUE_OR_RETURN_STATUS(filterOutAndProcessParameter<String8>(
                    parameters, String8(AudioParameter::keyReconfigLe),
                    [&](const String8& value) -> status_t {
                        if (mVendorExt != nullptr) {
                            std::vector<VendorParameter> result;
                            RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
                                    mVendorExt->parseBluetoothLeReconfigureOffload(
                                            std::string(value.c_str()), &result)));
                            reconfigureOffload = std::move(result);
                        } else {
                            reconfigureOffload = std::vector<VendorParameter>();
                        }
                        return OK;
                    }));
    if (mBluetoothLe != nullptr && leEnabled.has_value()) {
        return statusTFromBinderStatus(mBluetoothLe->setEnabled(leEnabled.value()));
    }
    if (mBluetoothLe != nullptr && reconfigureOffload.has_value()) {
        return statusTFromBinderStatus(mBluetoothLe->reconfigureOffload(
                        reconfigureOffload.value()));
    }
    return OK;
}

+1 −0
Original line number Diff line number Diff line
@@ -207,6 +207,7 @@ class DeviceHalAidl : public DeviceHalInterface, public ConversionHelperAidl,
    ~DeviceHalAidl() override = default;

    status_t filterAndRetrieveBtA2dpParameters(AudioParameter &keys, AudioParameter *result);
    status_t filterAndRetrieveBtLeParameters(AudioParameter &keys, AudioParameter *result);
    status_t filterAndUpdateBtA2dpParameters(AudioParameter &parameters);
    status_t filterAndUpdateBtHfpParameters(AudioParameter &parameters);
    status_t filterAndUpdateBtLeParameters(AudioParameter &parameters);
+2 −0
Original line number Diff line number Diff line
@@ -75,6 +75,8 @@ const char * const AudioParameter::keyBtA2dpSuspended = AUDIO_PARAMETER_KEY_BT_A
const char * const AudioParameter::keyReconfigA2dp = AUDIO_PARAMETER_RECONFIG_A2DP;
const char * const AudioParameter::keyReconfigA2dpSupported = AUDIO_PARAMETER_A2DP_RECONFIG_SUPPORTED;
const char * const AudioParameter::keyBtLeSuspended = AUDIO_PARAMETER_KEY_BT_LE_SUSPENDED;
const char * const AudioParameter::keyReconfigLe = AUDIO_PARAMETER_RECONFIG_LE;
const char * const AudioParameter::keyReconfigLeSupported = AUDIO_PARAMETER_LE_RECONFIG_SUPPORTED;
// const char * const AudioParameter::keyDeviceSupportedEncapsulationModes =
//        AUDIO_PARAMETER_DEVICE_SUP_ENCAPSULATION_MODES;
// const char * const AudioParameter::keyDeviceSupportedEncapsulationMetadataTypes =
+4 −0
Original line number Diff line number Diff line
@@ -121,10 +121,14 @@ public:
    // keyReconfigA2dp: Ask HwModule to reconfigure A2DP offloaded codec
    // keyReconfigA2dpSupported: Query if HwModule supports A2DP offload codec config
    // keyBtLeSuspended: 'true' or 'false'
    // keyReconfigLe: Ask HwModule to reconfigure LE offloaded codec
    // keyReconfigLeSupported: Query if HwModule supports LE offload codec config
    static const char * const keyBtA2dpSuspended;
    static const char * const keyReconfigA2dp;
    static const char * const keyReconfigA2dpSupported;
    static const char * const keyBtLeSuspended;
    static const char * const keyReconfigLe;
    static const char * const keyReconfigLeSupported;

    // For querying device supported encapsulation capabilities. All returned values are integer,
    // which are bit fields composed from using encapsulation capability values as position bits.
+1 −1
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ static inline bool device_distinguishes_on_address(audio_devices_t device)
 */
static inline bool device_has_encoding_capability(audio_devices_t device)
{
    return audio_is_a2dp_out_device(device);
    return audio_is_a2dp_out_device(device) || audio_is_ble_out_device(device);
}

/**
Loading