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

Commit a69a879d authored by François Gaffie's avatar François Gaffie Committed by Francois Gaffie
Browse files

[AudioPolicy][engine][Strategy] fallback on music stream



If a strategy matches a attributes, whatever a stream type has
been provided, the MUSIC stream type shall be returned as a fallback
to ensure AudioFlinger will apply the right gain to the right stream
(which always fallback as music if none is provided)

Test: build & run cts-dev -m CtsMediaTestCase --test android.media.cts.AudioProductStrategyTest
run cts-dev -m CtsMediaTestCase --test android.media.cts.AudioVolumeGroupTest
run cts-dev -m CtsMediaTestCase --test android.media.cts.AudioVolumeGroupChangeHandlerTest
run cts-dev -m CtsMediaTestCase --test android.media.cts.AudioManagerTest#testPermissionsForVolumePerAttributes
run cts-dev -m CtsMediaTestCase --test android.media.cts.AudioManagerTest#testGetAndValidateProductStrategies
run cts-dev -m CtsMediaTestCase --test android.media.cts.AudioManagerTest#testGetAndValidateVolumeGroups
run cts-dev -m CtsMediaTestCase --test android.media.cts.AudioManagerTest#testSetGetVolumePerAttributesWithInvalidAttributes
run cts-dev -m CtsMediaTestCase --test android.media.cts.AudioManagerTest#testSetGetVolumePerAttributes
run cts-dev -m CtsMediaTestCase --test android.media.cts.AudioManagerTest#testVolumeGroupCallback

Signed-off-by: default avatarFrançois Gaffie <francois.gaffie@renault.com>
Change-Id: Ic79effb1341b788d90f5d73d23ae92b983f17225
parent 5995f214
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -73,10 +73,18 @@ bool ProductStrategy::matches(const audio_attributes_t attr) const
audio_stream_type_t ProductStrategy::getStreamTypeForAttributes(
        const audio_attributes_t &attr) const
{
    const auto iter = std::find_if(begin(mAttributesVector), end(mAttributesVector),
    const auto &iter = std::find_if(begin(mAttributesVector), end(mAttributesVector),
                                   [&attr](const auto &supportedAttr) {
        return AudioProductStrategy::attributesMatches(supportedAttr.mAttributes, attr); });
    return iter != end(mAttributesVector) ? iter->mStream : AUDIO_STREAM_DEFAULT;
    if (iter == end(mAttributesVector)) {
        return AUDIO_STREAM_DEFAULT;
    }
    audio_stream_type_t streamType = iter->mStream;
    ALOGW_IF(streamType == AUDIO_STREAM_DEFAULT,
             "%s: Strategy %s supporting attributes %s has not stream type associated"
             "fallback on MUSIC. Do not use stream volume API", __func__, mName.c_str(),
             toString(attr).c_str());
    return streamType != AUDIO_STREAM_DEFAULT ? streamType : AUDIO_STREAM_MUSIC;
}

audio_attributes_t ProductStrategy::getAttributesForStreamType(audio_stream_type_t streamType) const