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

Commit aa257ab1 authored by Mikhail Naganov's avatar Mikhail Naganov Committed by Cherrypicker Worker
Browse files

libaudiohal@aidl: Fix `setPortConfigFromConfig` for unspecified values

AudioPortConfig type expects that unspecified parameters shall be
left unset: they are @nullable to match the legacy approach with
flags which was used in struct audio_port_config. However,
`setPortConfigFromConfig` was mistakingly setting parameters even
when they had default values in the source AudioConfig. This was
confusing the implementation of `IModule::setAudioPortConfig`.

Bug: 298175108
Test: atest audiosystem_tests
(cherry picked from https://android-review.googlesource.com/q/commit:6955713d1afc196c2012d9ec2f46fee735959477)
Merged-In: Ie352bb3874a9d0a357a30e766ebb6ba14ab6e0c9
Change-Id: Ie352bb3874a9d0a357a30e766ebb6ba14ab6e0c9
parent 490e1ab6
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ using aidl::android::media::audio::common::AudioConfig;
using aidl::android::media::audio::common::AudioDevice;
using aidl::android::media::audio::common::AudioDeviceAddress;
using aidl::android::media::audio::common::AudioDeviceType;
using aidl::android::media::audio::common::AudioFormatDescription;
using aidl::android::media::audio::common::AudioFormatType;
using aidl::android::media::audio::common::AudioInputFlags;
using aidl::android::media::audio::common::AudioIoFlags;
@@ -97,10 +98,16 @@ void setConfigFromPortConfig(AudioConfig* config, const AudioPortConfig& portCon
}

void setPortConfigFromConfig(AudioPortConfig* portConfig, const AudioConfig& config) {
    if (config.base.sampleRate != 0) {
        portConfig->sampleRate = Int{ .value = config.base.sampleRate };
    }
    if (config.base.channelMask != AudioChannelLayout{}) {
        portConfig->channelMask = config.base.channelMask;
    }
    if (config.base.format != AudioFormatDescription{}) {
        portConfig->format = config.base.format;
    }
}

// Note: these converters are for types defined in different AIDL files. Although these
// AIDL files are copies of each other, however formally these are different types
@@ -1069,7 +1076,9 @@ status_t DeviceHalAidl::setConnectedState(const struct audio_port_v7 *port, bool
        matchDevice.address = AudioDeviceAddress::make<AudioDeviceAddress::id>();
        auto portsIt = findPort(matchDevice);
        if (portsIt == mPorts.end()) {
            ALOGW("%s: device port for device %s is not found in the module %s",
            // Since 'setConnectedState' is called for all modules, it is normal when the device
            // port not found in every one of them.
            ALOGD("%s: device port for device %s is not found in the module %s",
                    __func__, matchDevice.toString().c_str(), mInstance.c_str());
            return BAD_VALUE;
        }