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

Commit 773ec318 authored by Eric Laurent's avatar Eric Laurent
Browse files

Audio Policy: fix selection of unique device for volume control

The rules in apm_extract_one_audio_device() only took A2DP devices
into account and should also consider LE Audio and other removable
devices.

Bug: 398232386
Test: make
Flag: EXEMPT bug fix
Change-Id: Ic26fdf789c0c69c219db69ff3a78ae08a6283d57
parent 1847a689
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -84,6 +84,13 @@ const DeviceTypeSet& getAudioDeviceOutLeAudioBroadcastSet() {
    return audioDeviceOutLeAudioUnicastSet;
}

const DeviceTypeSet& getAudioDeviceOutPickForVolumeSet() {
    static const DeviceTypeSet audioDevicePickForVolumeSet = DeviceTypeSet(
            std::begin(AUDIO_DEVICE_OUT_PICK_FOR_VOLUME_ARRAY),
            std::end(AUDIO_DEVICE_OUT_PICK_FOR_VOLUME_ARRAY));
    return audioDevicePickForVolumeSet;
}

std::string deviceTypesToString(const DeviceTypeSet &deviceTypes) {
    if (deviceTypes.empty()) {
        return "Empty device types";
+1 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ const DeviceTypeSet& getAudioDeviceInAllUsbSet();
const DeviceTypeSet& getAudioDeviceOutAllBleSet();
const DeviceTypeSet& getAudioDeviceOutLeAudioUnicastSet();
const DeviceTypeSet& getAudioDeviceOutLeAudioBroadcastSet();
const DeviceTypeSet& getAudioDeviceOutPickForVolumeSet();

template<typename T>
static std::vector<T> Intersection(const std::set<T>& a, const std::set<T>& b) {
+6 −6
Original line number Diff line number Diff line
@@ -289,8 +289,8 @@ static inline audio_devices_t apm_extract_one_audio_device(
        // Multiple device selection is either:
        //  - dock + one other device: give priority to dock in this case.
        //  - speaker + one other device: give priority to speaker in this case.
        //  - one A2DP device + another device: happens with duplicated output. In this case
        // retain the device on the A2DP output as the other must not correspond to an active
        //  - one removable device + another device: happens with duplicated output. In this case
        // retain the removable device as the other must not correspond to an active
        // selection if not the speaker.
        //  - HDMI-CEC system audio mode only output: give priority to available item in order.
        if (deviceTypes.count(AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) != 0) {
@@ -308,13 +308,13 @@ static inline audio_devices_t apm_extract_one_audio_device(
        } else if (deviceTypes.count(AUDIO_DEVICE_OUT_SPDIF) != 0) {
            return AUDIO_DEVICE_OUT_SPDIF;
        } else {
            std::vector<audio_devices_t> a2dpDevices = android::Intersection(
                    deviceTypes, android::getAudioDeviceOutAllA2dpSet());
            if (a2dpDevices.empty() || a2dpDevices.size() > 1) {
            std::vector<audio_devices_t> volumeDevices = android::Intersection(
                    deviceTypes, android::getAudioDeviceOutPickForVolumeSet());
            if (volumeDevices.empty() || volumeDevices.size() > 1) {
                ALOGW("%s invalid device combination: %s",
                      __func__, android::dumpDeviceTypes(deviceTypes).c_str());
            }
            return a2dpDevices.empty() ? AUDIO_DEVICE_NONE : a2dpDevices[0];
            return volumeDevices.empty() ? AUDIO_DEVICE_NONE : volumeDevices[0];
        }
    }
}