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

Commit f6d3bbe1 authored by François Gaffie's avatar François Gaffie Committed by Mikhail Naganov
Browse files

[BUG] audio: misalignement of native/java AudioAttributes



Native audio attributes are initialized with a default source,
whereas JAVA AudioAttributes are initialized with an INVALID source.
It leads to equality failure, thus preventing to identify the
right strategy / volume group.
This CL fixes this issue by forcing the source to invalid for
AudioAttributesGroups, only used for product strategies, thus dedicated
to playback use cases.

Test: AudioVolumeGroupTest
Bug: 248287204
Bug: 238058094

Signed-off-by: default avatarFrançois Gaffie <francois.gaffie@renault.com>
Merged-In: Ie40576421aff595112740821ea002bc70354f512
Change-Id: Ie40576421aff595112740821ea002bc70354f512
(cherry picked from commit 1e2b56f6)
parent 4a3734db
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ cc_library_headers {
cc_library {
    name: "libaudiopolicy",
    srcs: [
        "AudioAttributes.cpp",
        "VolumeGroupAttributes.cpp",
        "AudioPolicy.cpp",
        "AudioProductStrategy.cpp",
        "AudioVolumeGroup.cpp",
+5 −5
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@
//#define LOG_NDEBUG 0
#include <utils/Log.h>
#include <media/AudioProductStrategy.h>
#include <media/AudioAttributes.h>
#include <media/VolumeGroupAttributes.h>
#include <media/PolicyAidlConversion.h>

namespace android {
@@ -42,8 +42,8 @@ legacy2aidl_AudioProductStrategy(const AudioProductStrategy& legacy) {
    aidl.name = legacy.getName();
    aidl.audioAttributes = VALUE_OR_RETURN(
            convertContainer<std::vector<media::AudioAttributesEx>>(
                    legacy.getAudioAttributes(),
                    legacy2aidl_AudioAttributes_AudioAttributesEx));
                    legacy.getVolumeGroupAttributes(),
                    legacy2aidl_VolumeGroupAttributes_AudioAttributesEx));
    aidl.id = VALUE_OR_RETURN(legacy2aidl_product_strategy_t_int32_t(legacy.getId()));
    return aidl;
}
@@ -53,9 +53,9 @@ aidl2legacy_AudioProductStrategy(const media::AudioProductStrategy& aidl) {
    return AudioProductStrategy(
            aidl.name,
            VALUE_OR_RETURN(
                    convertContainer<std::vector<AudioAttributes>>(
                    convertContainer<std::vector<VolumeGroupAttributes>>(
                            aidl.audioAttributes,
                            aidl2legacy_AudioAttributesEx_AudioAttributes)),
                            aidl2legacy_AudioAttributesEx_VolumeGroupAttributes)),
            VALUE_OR_RETURN(aidl2legacy_int32_t_product_strategy_t(aidl.id)));
}

+12 −12
Original line number Diff line number Diff line
@@ -1341,7 +1341,7 @@ product_strategy_t AudioSystem::getStrategyForStream(audio_stream_type_t stream)
    return result.value_or(PRODUCT_STRATEGY_NONE);
}

status_t AudioSystem::getDevicesForAttributes(const AudioAttributes& aa,
status_t AudioSystem::getDevicesForAttributes(const audio_attributes_t& aa,
                                              AudioDeviceTypeAddrVector* devices,
                                              bool forVolume) {
    if (devices == nullptr) {
@@ -1350,8 +1350,8 @@ status_t AudioSystem::getDevicesForAttributes(const AudioAttributes& aa,
    const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
    if (aps == 0) return PERMISSION_DENIED;

    media::AudioAttributesEx aaAidl = VALUE_OR_RETURN_STATUS(
            legacy2aidl_AudioAttributes_AudioAttributesEx(aa));
    media::AudioAttributesInternal aaAidl = VALUE_OR_RETURN_STATUS(
             legacy2aidl_audio_attributes_t_AudioAttributesInternal(aa));
    std::vector<AudioDevice> retAidl;
    RETURN_STATUS_IF_ERROR(
            statusTFromBinderStatus(aps->getDevicesForAttributes(aaAidl, forVolume, &retAidl)));
@@ -2107,7 +2107,7 @@ audio_attributes_t AudioSystem::streamTypeToAttributes(audio_stream_type_t strea
    AudioProductStrategyVector strategies;
    listAudioProductStrategies(strategies);
    for (const auto& strategy : strategies) {
        auto attrVect = strategy.getAudioAttributes();
        auto attrVect = strategy.getVolumeGroupAttributes();
        auto iter = std::find_if(begin(attrVect), end(attrVect), [&stream](const auto& attributes) {
            return attributes.getStreamType() == stream;
        });
@@ -2121,7 +2121,7 @@ audio_attributes_t AudioSystem::streamTypeToAttributes(audio_stream_type_t strea

audio_stream_type_t AudioSystem::attributesToStreamType(const audio_attributes_t& attr) {
    product_strategy_t psId;
    status_t ret = AudioSystem::getProductStrategyFromAudioAttributes(AudioAttributes(attr), psId);
    status_t ret = AudioSystem::getProductStrategyFromAudioAttributes(attr, psId);
    if (ret != NO_ERROR) {
        ALOGE("no strategy found for attributes %s", toString(attr).c_str());
        return AUDIO_STREAM_MUSIC;
@@ -2130,7 +2130,7 @@ audio_stream_type_t AudioSystem::attributesToStreamType(const audio_attributes_t
    listAudioProductStrategies(strategies);
    for (const auto& strategy : strategies) {
        if (strategy.getId() == psId) {
            auto attrVect = strategy.getAudioAttributes();
            auto attrVect = strategy.getVolumeGroupAttributes();
            auto iter = std::find_if(begin(attrVect), end(attrVect), [&attr](const auto& refAttr) {
                return AudioProductStrategy::attributesMatches(
                        refAttr.getAttributes(), attr);
@@ -2151,14 +2151,14 @@ audio_stream_type_t AudioSystem::attributesToStreamType(const audio_attributes_t
    return AUDIO_STREAM_MUSIC;
}

status_t AudioSystem::getProductStrategyFromAudioAttributes(const AudioAttributes& aa,
status_t AudioSystem::getProductStrategyFromAudioAttributes(const audio_attributes_t& aa,
                                                            product_strategy_t& productStrategy,
                                                            bool fallbackOnDefault) {
    const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
    if (aps == 0) return PERMISSION_DENIED;

    media::AudioAttributesEx aaAidl = VALUE_OR_RETURN_STATUS(
            legacy2aidl_AudioAttributes_AudioAttributesEx(aa));
    media::AudioAttributesInternal aaAidl = VALUE_OR_RETURN_STATUS(
            legacy2aidl_audio_attributes_t_AudioAttributesInternal(aa));
    int32_t productStrategyAidl;

    RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
@@ -2181,14 +2181,14 @@ status_t AudioSystem::listAudioVolumeGroups(AudioVolumeGroupVector& groups) {
    return OK;
}

status_t AudioSystem::getVolumeGroupFromAudioAttributes(const AudioAttributes& aa,
status_t AudioSystem::getVolumeGroupFromAudioAttributes(const audio_attributes_t &aa,
                                                        volume_group_t& volumeGroup,
                                                        bool fallbackOnDefault) {
    const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
    if (aps == 0) return PERMISSION_DENIED;

    media::AudioAttributesEx aaAidl = VALUE_OR_RETURN_STATUS(
            legacy2aidl_AudioAttributes_AudioAttributesEx(aa));
    media::AudioAttributesInternal aaAidl = VALUE_OR_RETURN_STATUS(
            legacy2aidl_audio_attributes_t_AudioAttributesInternal(aa));
    int32_t volumeGroupAidl;
    RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
            aps->getVolumeGroupFromAudioAttributes(aaAidl, fallbackOnDefault, &volumeGroupAidl)));
+0 −1
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@

#include <media/AidlConversion.h>
#include <media/AudioVolumeGroup.h>
#include <media/AudioAttributes.h>
#include <media/PolicyAidlConversion.h>

namespace android {
+10 −10
Original line number Diff line number Diff line
@@ -14,33 +14,33 @@
 * limitations under the License.
 */

#define LOG_TAG "AudioAttributes"
#define LOG_TAG "VolumeGroupAttributes"
//#define LOG_NDEBUG 0
#include <utils/Log.h>

#include <binder/Parcel.h>

#include <media/AidlConversion.h>
#include <media/AudioAttributes.h>
#include <media/VolumeGroupAttributes.h>
#include <media/PolicyAidlConversion.h>

namespace android {

status_t AudioAttributes::readFromParcel(const Parcel* parcel) {
status_t VolumeGroupAttributes::readFromParcel(const Parcel* parcel) {
    media::AudioAttributesEx aidl;
    RETURN_STATUS_IF_ERROR(aidl.readFromParcel(parcel));
    *this = VALUE_OR_RETURN_STATUS(aidl2legacy_AudioAttributesEx_AudioAttributes(aidl));
    *this = VALUE_OR_RETURN_STATUS(aidl2legacy_AudioAttributesEx_VolumeGroupAttributes(aidl));
    return OK;
}

status_t AudioAttributes::writeToParcel(Parcel* parcel) const {
status_t VolumeGroupAttributes::writeToParcel(Parcel* parcel) const {
    media::AudioAttributesEx aidl = VALUE_OR_RETURN_STATUS(
            legacy2aidl_AudioAttributes_AudioAttributesEx(*this));
            legacy2aidl_VolumeGroupAttributes_AudioAttributesEx(*this));
    return aidl.writeToParcel(parcel);
}

ConversionResult<media::AudioAttributesEx>
legacy2aidl_AudioAttributes_AudioAttributesEx(const AudioAttributes& legacy) {
legacy2aidl_VolumeGroupAttributes_AudioAttributesEx(const VolumeGroupAttributes& legacy) {
    media::AudioAttributesEx aidl;
    aidl.attributes = VALUE_OR_RETURN(
            legacy2aidl_audio_attributes_t_AudioAttributesInternal(legacy.getAttributes()));
@@ -50,9 +50,9 @@ legacy2aidl_AudioAttributes_AudioAttributesEx(const AudioAttributes& legacy) {
    return aidl;
}

ConversionResult<AudioAttributes>
aidl2legacy_AudioAttributesEx_AudioAttributes(const media::AudioAttributesEx& aidl) {
    return AudioAttributes(VALUE_OR_RETURN(aidl2legacy_int32_t_volume_group_t(aidl.groupId)),
ConversionResult<VolumeGroupAttributes>
aidl2legacy_AudioAttributesEx_VolumeGroupAttributes(const media::AudioAttributesEx& aidl) {
    return VolumeGroupAttributes(VALUE_OR_RETURN(aidl2legacy_int32_t_volume_group_t(aidl.groupId)),
                           VALUE_OR_RETURN(aidl2legacy_AudioStreamType_audio_stream_type_t(
                                   aidl.streamType)),
                           VALUE_OR_RETURN(aidl2legacy_AudioAttributesInternal_audio_attributes_t(
Loading