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

Commit 877b27e1 authored by Kriti Dang's avatar Kriti Dang
Browse files

Fixing crash in surround sound settings which occurs

due to API getSurroundSound.

Bug: 178800104
Test: Tested manually
Change-Id: Ib0a13dfcdfa177676e8625703e9ddb2ce79e5d0e
parent c5634ebd
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -1849,19 +1849,22 @@ status_t AudioSystem::getSurroundFormats(unsigned int* numSurroundFormats,

    const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
    if (aps == 0) return PERMISSION_DENIED;

    media::Int numSurroundFormatsAidl;
    numSurroundFormatsAidl.value =
            VALUE_OR_RETURN_STATUS(convertIntegral<int32_t>(*numSurroundFormats));
    std::vector<media::audio::common::AudioFormat> surroundFormatsAidl;
    std::vector<bool> surroundFormatsEnabledAidl;
    RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
            aps->getSurroundFormats(reported, &numSurroundFormatsAidl, &surroundFormatsAidl,
                                    surroundFormatsEnabled)));
            aps->getSurroundFormats(reported, &numSurroundFormatsAidl,
                                    &surroundFormatsAidl, &surroundFormatsEnabledAidl)));

    *numSurroundFormats = VALUE_OR_RETURN_STATUS(
            convertIntegral<unsigned int>(numSurroundFormatsAidl.value));
    RETURN_STATUS_IF_ERROR(
            convertRange(surroundFormatsAidl.begin(), surroundFormatsAidl.end(), surroundFormats,
                         aidl2legacy_AudioFormat_audio_format_t));
    std::copy(surroundFormatsEnabledAidl.begin(), surroundFormatsEnabledAidl.end(),
            surroundFormatsEnabled);
    return OK;
}

+5 −4
Original line number Diff line number Diff line
@@ -272,16 +272,17 @@ interface IAudioPolicyService {
    float getStreamVolumeDB(AudioStreamType stream, int index, int /* audio_devices_t */ device);

    /**
     * Returns whether surround formats are enabled.
     * Populates supported surround formats and their enabled state in formats and formatsEnabled.
     *
     * On input, count represents the maximum length of the returned array.
     * On output, count is the total number of elements, which may be larger than the array size.
     * Passing '0' on input and inspecting the value on output is a common way of determining the
     * number of elements without actually retrieving them.
     */
    boolean getSurroundFormats(boolean reported,
    void getSurroundFormats(boolean reported,
                            inout Int count,
                               out AudioFormat[] formats);
                            out AudioFormat[] formats,
                            out boolean[] formatsEnabled);

    AudioFormat[] getHwOffloadEncodingFormatsSupportedForA2DP();

+7 −2
Original line number Diff line number Diff line
@@ -1804,7 +1804,7 @@ Status AudioPolicyService::getStreamVolumeDB(media::AudioStreamType streamAidl,
Status AudioPolicyService::getSurroundFormats(
        bool reported, media::Int* count,
        std::vector<media::audio::common::AudioFormat>* formats,
        bool* _aidl_return) {
        std::vector<bool>* formatsEnabled) {
    unsigned int numSurroundFormats = VALUE_OR_RETURN_BINDER_STATUS(
            convertIntegral<unsigned int>(count->value));
    if (numSurroundFormats > MAX_ITEMS_PER_LIST) {
@@ -1812,6 +1812,7 @@ Status AudioPolicyService::getSurroundFormats(
    }
    unsigned int numSurroundFormatsReq = numSurroundFormats;
    std::unique_ptr<audio_format_t[]>surroundFormats(new audio_format_t[numSurroundFormats]);
    std::unique_ptr<bool[]>surroundFormatsEnabled(new bool[numSurroundFormats]);

    if (mAudioPolicyManager == NULL) {
        return binderStatusFromStatusT(NO_INIT);
@@ -1820,11 +1821,15 @@ Status AudioPolicyService::getSurroundFormats(
    AutoCallerClear acc;
    RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(
            mAudioPolicyManager->getSurroundFormats(&numSurroundFormats, surroundFormats.get(),
                                                    _aidl_return, reported)));
                                                    surroundFormatsEnabled.get(), reported)));
    numSurroundFormatsReq = std::min(numSurroundFormats, numSurroundFormatsReq);
    RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(
            convertRange(surroundFormats.get(), surroundFormats.get() + numSurroundFormatsReq,
                         std::back_inserter(*formats), legacy2aidl_audio_format_t_AudioFormat)));
    formatsEnabled->insert(
            formatsEnabled->begin(),
            surroundFormatsEnabled.get(),
            surroundFormatsEnabled.get() + numSurroundFormatsReq);
    count->value = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<uint32_t>(numSurroundFormats));
    return Status::ok();
}
+1 −1
Original line number Diff line number Diff line
@@ -185,7 +185,7 @@ public:
                                     float* _aidl_return) override;
    binder::Status getSurroundFormats(bool reported, media::Int* count,
                                      std::vector<media::audio::common::AudioFormat>* formats,
                                      bool* _aidl_return) override;
                                      std::vector<bool>* formatsEnabled) override;
    binder::Status getHwOffloadEncodingFormatsSupportedForA2DP(
            std::vector<media::audio::common::AudioFormat>* _aidl_return) override;
    binder::Status setSurroundFormatEnabled(media::audio::common::AudioFormat audioFormat,