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

Commit db18df93 authored by Vlad Popa's avatar Vlad Popa Committed by Android Build Coastguard Worker
Browse files

APM: apply volumes when abs volume stream changes

Whenever the stream that drives the absolute volume changes also reapply
all the stream volumes for all the active outputs.

Reapplying the reverted CL ag/30134818, do not use timeout when applying volumes and
only apply if something changes.

Test: manual + logs
Flag: EXEMPT bugfix
Bug: 378613219
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:6319b2d1d6e38637e2967292a83ed25b340cb646)
Merged-In: Ia746926472f942b3c506bf6e55d614a67ddbad1a
Change-Id: Ia746926472f942b3c506bf6e55d614a67ddbad1a
parent 8002e15d
Loading
Loading
Loading
Loading
+26 −9
Original line number Diff line number Diff line
@@ -3573,19 +3573,36 @@ status_t AudioPolicyManager::setDeviceAbsoluteVolumeEnabled(audio_devices_t devi
    ALOGI("%s: deviceType 0x%X, enabled %d, streamToDriveAbs %d", __func__, deviceType, enabled,
          streamToDriveAbs);

    if (!enabled) {
        mAbsoluteVolumeDrivingStreams.erase(deviceType);
        return NO_ERROR;
    }

    bool changed = false;
    audio_attributes_t attributesToDriveAbs = mEngine->getAttributesForStreamType(streamToDriveAbs);
    if (enabled) {
        if (attributesToDriveAbs == AUDIO_ATTRIBUTES_INITIALIZER) {
            ALOGW("%s: no attributes for stream %s, bailing out", __func__,
                  toString(streamToDriveAbs).c_str());
            return BAD_VALUE;
        }

        if (mAbsoluteVolumeDrivingStreams[deviceType] != attributesToDriveAbs) {
            mAbsoluteVolumeDrivingStreams[deviceType] = attributesToDriveAbs;
            changed = true;
        }
    } else {
        if (mAbsoluteVolumeDrivingStreams.find(deviceType) != mAbsoluteVolumeDrivingStreams.end()) {
            mAbsoluteVolumeDrivingStreams.erase(deviceType);
            changed = true;
        }
    }

    // if something changed, apply the stream volumes regarding the new absolute mode to all the
    // outputs without any delay
    if (changed) {
        for (size_t i = 0; i < mOutputs.size(); i++) {
            sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
            ALOGV("%s: apply stream volumes for portId %d", __func__, desc->getId());
            applyStreamVolumes(desc, {deviceType});
        }
    }

    return NO_ERROR;
}