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

Commit 943b7e2b authored by Vlad Popa's avatar Vlad Popa Committed by Mikhail Naganov
Browse files

Add default implementation and VTS for ISoundDose

The ISoundDose HAL interface is used for reporting the sound dose
relevant information from/to the HAL. This is necessary for all devices
that certify with the IEC62368-1 3rd edition and EN50332-3 standard
for safe hearing.

Bug: 248567177
Test: atest VtsHalAudioCoreTargetTest
Change-Id: Ib89e09243a01cebc2f7996b6b572384a1471867a
Merged-In: Ib89e09243a01cebc2f7996b6b572384a1471867a
(cherry picked from commit 83a21465)
parent 83a6d827
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ cc_library_static {
        "Configuration.cpp",
        "EngineConfigXmlConverter.cpp",
        "Module.cpp",
        "SoundDose.cpp",
        "Stream.cpp",
        "Telephony.cpp",
    ],
+6 −2
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <aidl/android/media/audio/common/AudioOutputFlags.h>

#include "core-impl/Module.h"
#include "core-impl/SoundDose.h"
#include "core-impl/Telephony.h"
#include "core-impl/utils.h"

@@ -932,8 +933,11 @@ ndk::ScopedAStatus Module::updateScreenState(bool in_isTurnedOn) {
}

ndk::ScopedAStatus Module::getSoundDose(std::shared_ptr<ISoundDose>* _aidl_return) {
    *_aidl_return = nullptr;
    LOG(DEBUG) << __func__ << ": ISoundDose not implemented";
    if (mSoundDose == nullptr) {
        mSoundDose = ndk::SharedRefBase::make<SoundDose>();
    }
    *_aidl_return = mSoundDose;
    LOG(DEBUG) << __func__ << ": returning instance of ISoundDose: " << _aidl_return->get();
    return ndk::ScopedAStatus::ok();
}

+57 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "AHAL_SoundDose"

#include "core-impl/SoundDose.h"

#include <android-base/logging.h>

namespace aidl::android::hardware::audio::core {

ndk::ScopedAStatus SoundDose::setOutputRs2(float in_rs2ValueDbA) {
    if (in_rs2ValueDbA < MIN_RS2 || in_rs2ValueDbA > DEFAULT_MAX_RS2) {
        LOG(ERROR) << __func__ << ": RS2 value is invalid: " << in_rs2ValueDbA;
        return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
    }

    mRs2Value = in_rs2ValueDbA;
    return ndk::ScopedAStatus::ok();
}

ndk::ScopedAStatus SoundDose::getOutputRs2(float* _aidl_return) {
    *_aidl_return = mRs2Value;
    LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
    return ndk::ScopedAStatus::ok();
}

ndk::ScopedAStatus SoundDose::registerSoundDoseCallback(
        const std::shared_ptr<ISoundDose::IHalSoundDoseCallback>& in_callback) {
    if (in_callback.get() == nullptr) {
        LOG(ERROR) << __func__ << ": Callback is nullptr";
        return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
    }
    if (mCallback != nullptr) {
        LOG(ERROR) << __func__ << ": Sound dose callback was already registered";
        return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
    }

    mCallback = in_callback;
    LOG(DEBUG) << __func__ << ": Registered sound dose callback ";
    return ndk::ScopedAStatus::ok();
}

}  // namespace aidl::android::hardware::audio::core
+1 −0
Original line number Diff line number Diff line
@@ -124,6 +124,7 @@ class Module : public BnModule {
    bool mMasterMute = false;
    float mMasterVolume = 1.0f;
    bool mMicMute = false;
    std::shared_ptr<ISoundDose> mSoundDose;
};

}  // namespace aidl::android::hardware::audio::core
+42 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <mutex>

#include <aidl/android/hardware/audio/core/BnSoundDose.h>
#include <aidl/android/media/audio/common/AudioDevice.h>

using aidl::android::media::audio::common::AudioDevice;

namespace aidl::android::hardware::audio::core {

class SoundDose : public BnSoundDose {
  public:
    SoundDose() : mRs2Value(DEFAULT_MAX_RS2){};

    ndk::ScopedAStatus setOutputRs2(float in_rs2ValueDbA) override;
    ndk::ScopedAStatus getOutputRs2(float* _aidl_return) override;
    ndk::ScopedAStatus registerSoundDoseCallback(
            const std::shared_ptr<ISoundDose::IHalSoundDoseCallback>& in_callback) override;

  private:
    std::shared_ptr<ISoundDose::IHalSoundDoseCallback> mCallback;
    float mRs2Value;
};

}  // namespace aidl::android::hardware::audio::core
Loading