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

Commit 4404ddb0 authored by Francois Gaffie's avatar Francois Gaffie
Browse files

[BUG] Do not fallback on music group for orphan streams



When using a specific engine configuration file with custom product strategies
definition, it is possible to define a strategy without any stream type attached
to it.
In order to prevent fallback on music when considering activity of non existing
stream, this CL adds an optional fallback parameter to stream to volume source
conversion APIs.

Bug: 179759299
Bug: 187173302
Test: plays with volumes

Signed-off-by: default avatarFrancois Gaffie <francois.gaffie@renault.com>
Change-Id: I0817586a5ac3f2a8be26bc9fb21ba1c079d28006
parent 593634d6
Loading
Loading
Loading
Loading
+34 −26
Original line number Diff line number Diff line
@@ -1810,7 +1810,7 @@ status_t AudioPolicyManager::startSource(const sp<SwAudioOutputDescriptor>& outp
    if (stream == AUDIO_STREAM_TTS) {
        ALOGV("\t found BEACON stream");
        if (!mTtsOutputAvailable && mOutputs.isAnyOutputActive(
                                    toVolumeSource(AUDIO_STREAM_TTS) /*sourceToIgnore*/)) {
                                    toVolumeSource(AUDIO_STREAM_TTS, false) /*sourceToIgnore*/)) {
            return INVALID_OPERATION;
        } else {
            beaconMuteLatency = handleEventForBeacon(STARTING_BEACON);
@@ -2842,7 +2842,7 @@ status_t AudioPolicyManager::setVolumeIndexForAttributes(const audio_attributes_
        // handled by system UI
        status_t volStatus = checkAndSetVolume(
                    curves, vs, index, desc, curDevices,
                    ((vs == toVolumeSource(AUDIO_STREAM_SYSTEM))?
                    ((vs == toVolumeSource(AUDIO_STREAM_SYSTEM, false))?
                         TOUCH_SOUND_FIXED_DELAY_MS : 0));
        if (volStatus != NO_ERROR) {
            status = volStatus;
@@ -3044,12 +3044,14 @@ status_t AudioPolicyManager::moveEffectsToIo(const std::vector<int>& ids, audio_

bool AudioPolicyManager::isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
{
    return mOutputs.isActive(toVolumeSource(stream), inPastMs);
    auto vs = toVolumeSource(stream, false);
    return vs != VOLUME_SOURCE_NONE ? mOutputs.isActive(vs, inPastMs) : false;
}

bool AudioPolicyManager::isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
{
    return mOutputs.isActiveRemotely(toVolumeSource(stream), inPastMs);
    auto vs = toVolumeSource(stream, false);
    return vs != VOLUME_SOURCE_NONE ? mOutputs.isActiveRemotely(vs, inPastMs) : false;
}

bool AudioPolicyManager::isSourceActive(audio_source_t source) const
@@ -5868,7 +5870,7 @@ DeviceVector AudioPolicyManager::getNewOutputDevices(const sp<SwAudioOutputDescr

        auto doGetOutputDevicesForVoice = [&]() {
            return hasVoiceStream(streams) && (outputDesc == mPrimaryOutput ||
                outputDesc->isActive(toVolumeSource(AUDIO_STREAM_VOICE_CALL))) &&
                outputDesc->isActive(toVolumeSource(AUDIO_STREAM_VOICE_CALL, false))) &&
                (isInCall() ||
                 mOutputs.isStrategyActiveOnSameModule(productStrategy, outputDesc)) &&
                !isStreamActive(AUDIO_STREAM_ENFORCED_AUDIBLE, 0);
@@ -5964,7 +5966,7 @@ audio_devices_t AudioPolicyManager::getDevicesForStream(audio_stream_type_t stre
        devices.merge(curDevices);
        for (audio_io_handle_t output : getOutputsForDevices(curDevices, mOutputs)) {
            sp<AudioOutputDescriptor> outputDesc = mOutputs.valueFor(output);
            if (outputDesc->isActive(toVolumeSource(curStream))) {
            if (outputDesc->isActive(toVolumeSource(curStream, false))) {
                activeDevices.merge(outputDesc->devices());
            }
        }
@@ -6065,7 +6067,11 @@ uint32_t AudioPolicyManager::setBeaconMute(bool mute) {
        // mute/unmute AUDIO_STREAM_TTS on all outputs
        ALOGV("\t muting %d", mute);
        uint32_t maxLatency = 0;
        auto ttsVolumeSource = toVolumeSource(AUDIO_STREAM_TTS);
        auto ttsVolumeSource = toVolumeSource(AUDIO_STREAM_TTS, false);
        if (ttsVolumeSource == VOLUME_SOURCE_NONE) {
            ALOGV("\t no tts volume source available");
            return 0;
        }
        for (size_t i = 0; i < mOutputs.size(); i++) {
            sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
            setVolumeSourceMute(ttsVolumeSource, mute/*on*/, desc, 0 /*delay*/, DeviceTypeSet());
@@ -6401,11 +6407,11 @@ float AudioPolicyManager::computeVolume(IVolumeCurves &curves,
    // louder than the accessibility prompt, the prompt cannot be heard, thus masking the touch
    // exploration of the dialer UI. In this situation, bring the accessibility volume closer to
    // the ringtone volume
    const auto callVolumeSrc = toVolumeSource(AUDIO_STREAM_VOICE_CALL);
    const auto ringVolumeSrc = toVolumeSource(AUDIO_STREAM_RING);
    const auto musicVolumeSrc = toVolumeSource(AUDIO_STREAM_MUSIC);
    const auto alarmVolumeSrc = toVolumeSource(AUDIO_STREAM_ALARM);
    const auto a11yVolumeSrc = toVolumeSource(AUDIO_STREAM_ACCESSIBILITY);
    const auto callVolumeSrc = toVolumeSource(AUDIO_STREAM_VOICE_CALL, false);
    const auto ringVolumeSrc = toVolumeSource(AUDIO_STREAM_RING, false);
    const auto musicVolumeSrc = toVolumeSource(AUDIO_STREAM_MUSIC, false);
    const auto alarmVolumeSrc = toVolumeSource(AUDIO_STREAM_ALARM, false);
    const auto a11yVolumeSrc = toVolumeSource(AUDIO_STREAM_ACCESSIBILITY, false);

    if (volumeSource == a11yVolumeSrc
            && (AUDIO_MODE_RINGTONE == mEngine->getPhoneState()) &&
@@ -6418,12 +6424,12 @@ float AudioPolicyManager::computeVolume(IVolumeCurves &curves,
    // in-call: always cap volume by voice volume + some low headroom
    if ((volumeSource != callVolumeSrc && (isInCall() ||
                                           mOutputs.isActiveLocally(callVolumeSrc))) &&
            (volumeSource == toVolumeSource(AUDIO_STREAM_SYSTEM) ||
            (volumeSource == toVolumeSource(AUDIO_STREAM_SYSTEM, false) ||
             volumeSource == ringVolumeSrc || volumeSource == musicVolumeSrc ||
             volumeSource == alarmVolumeSrc ||
             volumeSource == toVolumeSource(AUDIO_STREAM_NOTIFICATION) ||
             volumeSource == toVolumeSource(AUDIO_STREAM_ENFORCED_AUDIBLE) ||
             volumeSource == toVolumeSource(AUDIO_STREAM_DTMF) ||
             volumeSource == toVolumeSource(AUDIO_STREAM_NOTIFICATION, false) ||
             volumeSource == toVolumeSource(AUDIO_STREAM_ENFORCED_AUDIBLE, false) ||
             volumeSource == toVolumeSource(AUDIO_STREAM_DTMF, false) ||
             volumeSource == a11yVolumeSrc)) {
        auto &voiceCurves = getVolumeCurves(callVolumeSrc);
        int voiceVolumeIndex = voiceCurves.getVolumeIndex(deviceTypes);
@@ -6461,9 +6467,9 @@ float AudioPolicyManager::computeVolume(IVolumeCurves &curves,
             AUDIO_DEVICE_OUT_BLE_HEADSET}).empty() &&
            ((volumeSource == alarmVolumeSrc ||
              volumeSource == ringVolumeSrc) ||
             (volumeSource == toVolumeSource(AUDIO_STREAM_NOTIFICATION)) ||
             (volumeSource == toVolumeSource(AUDIO_STREAM_SYSTEM)) ||
             ((volumeSource == toVolumeSource(AUDIO_STREAM_ENFORCED_AUDIBLE)) &&
             (volumeSource == toVolumeSource(AUDIO_STREAM_NOTIFICATION, false)) ||
             (volumeSource == toVolumeSource(AUDIO_STREAM_SYSTEM, false)) ||
             ((volumeSource == toVolumeSource(AUDIO_STREAM_ENFORCED_AUDIBLE, false)) &&
              (mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_SYSTEM) == AUDIO_POLICY_FORCE_NONE))) &&
            curves.canBeMuted()) {

@@ -6549,10 +6555,10 @@ status_t AudioPolicyManager::checkAndSetVolume(IVolumeCurves &curves,
               outputDesc->getMuteCount(volumeSource), outputDesc->isActive(volumeSource));
        return NO_ERROR;
    }
    VolumeSource callVolSrc = toVolumeSource(AUDIO_STREAM_VOICE_CALL);
    VolumeSource btScoVolSrc = toVolumeSource(AUDIO_STREAM_BLUETOOTH_SCO);
    bool isVoiceVolSrc = callVolSrc == volumeSource;
    bool isBtScoVolSrc = btScoVolSrc == volumeSource;
    VolumeSource callVolSrc = toVolumeSource(AUDIO_STREAM_VOICE_CALL, false);
    VolumeSource btScoVolSrc = toVolumeSource(AUDIO_STREAM_BLUETOOTH_SCO, false);
    bool isVoiceVolSrc = (volumeSource != VOLUME_SOURCE_NONE) && (callVolSrc == volumeSource);
    bool isBtScoVolSrc = (volumeSource != VOLUME_SOURCE_NONE) && (btScoVolSrc == volumeSource);

    bool isScoRequested = isScoRequestedForComm();
    // do not change in call volume if bluetooth is connected and vice versa
@@ -6621,8 +6627,10 @@ void AudioPolicyManager::setStrategyMute(product_strategy_t strategy,
    for (auto attributes: mEngine->getAllAttributesForProductStrategy(strategy)) {
        ALOGVV("%s() attributes %s, mute %d, output ID %d", __func__,
               toString(attributes).c_str(), on, outputDesc->getId());
        VolumeSource source = toVolumeSource(attributes);
        if (std::find(begin(sourcesToMute), end(sourcesToMute), source) == end(sourcesToMute)) {
        VolumeSource source = toVolumeSource(attributes, false);
        if ((source != VOLUME_SOURCE_NONE) &&
                (std::find(begin(sourcesToMute), end(sourcesToMute), source)
                        == end(sourcesToMute))) {
            sourcesToMute.push_back(source);
        }
    }
@@ -6645,7 +6653,7 @@ void AudioPolicyManager::setVolumeSourceMute(VolumeSource volumeSource,
    if (on) {
        if (!outputDesc->isMuted(volumeSource)) {
            if (curves.canBeMuted() &&
                    (volumeSource != toVolumeSource(AUDIO_STREAM_ENFORCED_AUDIBLE) ||
                    (volumeSource != toVolumeSource(AUDIO_STREAM_ENFORCED_AUDIBLE, false) ||
                     (mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_SYSTEM) ==
                      AUDIO_POLICY_FORCE_NONE))) {
                checkAndSetVolume(curves, volumeSource, 0, outputDesc, deviceTypes, delayMs);
+21 −4
Original line number Diff line number Diff line
@@ -421,13 +421,30 @@ protected:
        {
            return static_cast<VolumeSource>(volumeGroup);
        }
        VolumeSource toVolumeSource(const audio_attributes_t &attributes) const
        /**
         * @brief toVolumeSource converts an audio attributes into a volume source
         * (either a legacy stream or a volume group). If fallback on default is allowed, and if
         * the audio attributes do not follow any specific product strategy's rule, it will be
         * associated to default volume source, e.g. music. Thus, any of call of volume API
         * using this translation function may affect the default volume source.
         * If fallback is not allowed and no matching rule is identified for the given attributes,
         * the volume source will be undefined, thus, no volume will be altered/modified.
         * @param attributes to be considered
         * @param fallbackOnDefault
         * @return volume source associated with given attributes, otherwise either music if
         * fallbackOnDefault is set or none.
         */
        VolumeSource toVolumeSource(
            const audio_attributes_t &attributes, bool fallbackOnDefault = true) const
        {
            return toVolumeSource(mEngine->getVolumeGroupForAttributes(attributes));
            return toVolumeSource(mEngine->getVolumeGroupForAttributes(
                attributes, fallbackOnDefault));
        }
        VolumeSource toVolumeSource(audio_stream_type_t stream) const
        VolumeSource toVolumeSource(
            audio_stream_type_t stream, bool fallbackOnDefault = true) const
        {
            return toVolumeSource(mEngine->getVolumeGroupForStreamType(stream));
            return toVolumeSource(mEngine->getVolumeGroupForStreamType(
                stream, fallbackOnDefault));
        }
        IVolumeCurves &getVolumeCurves(VolumeSource volumeSource)
        {