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

Commit 34f4c1d5 authored by Vlad Popa's avatar Vlad Popa
Browse files

CSD: rename get/setOutputRs2 to include upper bound

RS2 represents an interval of power levels. This is why it is clearer to
specify upper bound in the naming to make it clear that we refer to the
upper limit which when exceeded will trigger a momentary exposure.

Test: atest VtsHalAudioCoreTargetTest
Bug: 273961110
Change-Id: If4e065deeedb32c3e5e81caf4cd6924fb5815dc0
parent 54ddd069
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -34,8 +34,8 @@
package android.hardware.audio.core.sounddose;
package android.hardware.audio.core.sounddose;
@VintfStability
@VintfStability
interface ISoundDose {
interface ISoundDose {
  void setOutputRs2(float rs2ValueDbA);
  void setOutputRs2UpperBound(float rs2ValueDbA);
  float getOutputRs2();
  float getOutputRs2UpperBound();
  void registerSoundDoseCallback(in android.hardware.audio.core.sounddose.ISoundDose.IHalSoundDoseCallback callback);
  void registerSoundDoseCallback(in android.hardware.audio.core.sounddose.ISoundDose.IHalSoundDoseCallback callback);
  const int DEFAULT_MAX_RS2 = 100;
  const int DEFAULT_MAX_RS2 = 100;
  const int MIN_RS2 = 80;
  const int MIN_RS2 = 80;
+14 −13
Original line number Original line Diff line number Diff line
@@ -35,21 +35,21 @@ interface ISoundDose {
    const int MIN_RS2 = 80;
    const int MIN_RS2 = 80;


    /**
    /**
     * Sets the RS2 value used for momentary exposure warnings. Default value is
     * Sets the RS2 upper bound used for momentary exposure warnings. Default value is
     * DEFAULT_MAX_RS2 as specified in IEC62368-1 3rd edition.
     * DEFAULT_MAX_RS2 as specified in IEC62368-1 3rd edition.
     *
     *
     * @param rs2ValueDbA custom RS2 value to use. Must not be higher than DEFAULT_MAX_RS2
     * @param rs2ValueDbA custom RS2 upper bound to use
     * @throws EX_ILLEGAL_ARGUMENT if rs2ValueDbA is greater than DEFAULT_MAX_RS2 or lower
     * @throws EX_ILLEGAL_ARGUMENT if rs2ValueDbA is greater than DEFAULT_MAX_RS2 or lower
     *                             than 80dBA
     *                             than MIN_RS2
     */
     */
    void setOutputRs2(float rs2ValueDbA);
    void setOutputRs2UpperBound(float rs2ValueDbA);


    /**
    /**
     * Gets the RS2 value used for momentary exposure warnings.
     * Gets the RS2 upper bound used for momentary exposure warnings.
     *
     *
     * @return the RS2 value in dBA
     * @return the RS2 upper bound in dBA
     */
     */
    float getOutputRs2();
    float getOutputRs2UpperBound();


    /**
    /**
     * Registers the HAL callback for sound dose computation. If sound dose is supported
     * Registers the HAL callback for sound dose computation. If sound dose is supported
@@ -68,9 +68,9 @@ interface ISoundDose {
    @VintfStability
    @VintfStability
    oneway interface IHalSoundDoseCallback {
    oneway interface IHalSoundDoseCallback {
        /**
        /**
         * Called whenever the current MEL value exceeds the set RS2 value.
         * Called whenever the current MEL value exceeds the set RS2 upper bound.
         *
         *
         * @param currentDbA the current MEL value which exceeds the RS2 value
         * @param currentDbA the current MEL value which exceeds the RS2 upper bound
         * @param audioDevice the audio device where the MEL exposure warning was recorded
         * @param audioDevice the audio device where the MEL exposure warning was recorded
         */
         */
        void onMomentaryExposureWarning(float currentDbA, in AudioDevice audioDevice);
        void onMomentaryExposureWarning(float currentDbA, in AudioDevice audioDevice);
@@ -78,14 +78,15 @@ interface ISoundDose {
        @VintfStability
        @VintfStability
        parcelable MelRecord {
        parcelable MelRecord {
            /**
            /**
             * Array of continuously recorded MEL values >= RS1 (1 per second).
             * Array of continuously recorded MEL values >= MIN_RS2 (1 per second).
             * First value in the array was recorded at 'timestamp'.
             * First value in the array was recorded at 'timestamp'.
             */
             */
            float[] melValues;
            float[] melValues;
            /**
            /**
             * Corresponds to the time in seconds when the first MEL entry in melValues
             * Corresponds to the time in seconds, as reported by CLOCK_MONOTONIC, when
             * was recorded. The timestamp values have to be consistent throughout all
             * the first MEL entry in melValues was recorded. The timestamp values have
             * audio ports, equal timestamp values will be aggregated.
             * to be consistent throughout all audio ports, equal timestamp values will
             * be aggregated.
             */
             */
            long timestamp;
            long timestamp;
        }
        }
+2 −2
Original line number Original line Diff line number Diff line
@@ -22,7 +22,7 @@


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


ndk::ScopedAStatus SoundDose::setOutputRs2(float in_rs2ValueDbA) {
ndk::ScopedAStatus SoundDose::setOutputRs2UpperBound(float in_rs2ValueDbA) {
    if (in_rs2ValueDbA < MIN_RS2 || in_rs2ValueDbA > DEFAULT_MAX_RS2) {
    if (in_rs2ValueDbA < MIN_RS2 || in_rs2ValueDbA > DEFAULT_MAX_RS2) {
        LOG(ERROR) << __func__ << ": RS2 value is invalid: " << in_rs2ValueDbA;
        LOG(ERROR) << __func__ << ": RS2 value is invalid: " << in_rs2ValueDbA;
        return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
        return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
@@ -32,7 +32,7 @@ ndk::ScopedAStatus SoundDose::setOutputRs2(float in_rs2ValueDbA) {
    return ndk::ScopedAStatus::ok();
    return ndk::ScopedAStatus::ok();
}
}


ndk::ScopedAStatus SoundDose::getOutputRs2(float* _aidl_return) {
ndk::ScopedAStatus SoundDose::getOutputRs2UpperBound(float* _aidl_return) {
    *_aidl_return = mRs2Value;
    *_aidl_return = mRs2Value;
    LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
    LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
    return ndk::ScopedAStatus::ok();
    return ndk::ScopedAStatus::ok();
+2 −2
Original line number Original line Diff line number Diff line
@@ -29,8 +29,8 @@ class SoundDose : public BnSoundDose {
  public:
  public:
    SoundDose() : mRs2Value(DEFAULT_MAX_RS2){};
    SoundDose() : mRs2Value(DEFAULT_MAX_RS2){};


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


+7 −6
Original line number Original line Diff line number Diff line
@@ -3543,26 +3543,27 @@ TEST_P(AudioCoreSoundDose, SameInstance) {
            << "getSoundDose must return the same interface instance across invocations";
            << "getSoundDose must return the same interface instance across invocations";
}
}


TEST_P(AudioCoreSoundDose, GetSetOutputRs2) {
TEST_P(AudioCoreSoundDose, GetSetOutputRs2UpperBound) {
    if (soundDose == nullptr) {
    if (soundDose == nullptr) {
        GTEST_SKIP() << "SoundDose is not supported";
        GTEST_SKIP() << "SoundDose is not supported";
    }
    }


    bool isSupported = false;
    bool isSupported = false;
    EXPECT_NO_FATAL_FAILURE(TestAccessors<float>(soundDose.get(), &ISoundDose::getOutputRs2,
    EXPECT_NO_FATAL_FAILURE(TestAccessors<float>(soundDose.get(),
                                                 &ISoundDose::setOutputRs2,
                                                 &ISoundDose::getOutputRs2UpperBound,
                                                 &ISoundDose::setOutputRs2UpperBound,
                                                 /*validValues=*/{80.f, 90.f, 100.f},
                                                 /*validValues=*/{80.f, 90.f, 100.f},
                                                 /*invalidValues=*/{79.f, 101.f}, &isSupported));
                                                 /*invalidValues=*/{79.f, 101.f}, &isSupported));
    EXPECT_TRUE(isSupported) << "Getting/Setting RS2 must be supported";
    EXPECT_TRUE(isSupported) << "Getting/Setting RS2 upper bound must be supported";
}
}


TEST_P(AudioCoreSoundDose, CheckDefaultRs2Value) {
TEST_P(AudioCoreSoundDose, CheckDefaultRs2UpperBound) {
    if (soundDose == nullptr) {
    if (soundDose == nullptr) {
        GTEST_SKIP() << "SoundDose is not supported";
        GTEST_SKIP() << "SoundDose is not supported";
    }
    }


    float rs2Value;
    float rs2Value;
    ASSERT_IS_OK(soundDose->getOutputRs2(&rs2Value));
    ASSERT_IS_OK(soundDose->getOutputRs2UpperBound(&rs2Value));
    EXPECT_EQ(rs2Value, ISoundDose::DEFAULT_MAX_RS2);
    EXPECT_EQ(rs2Value, ISoundDose::DEFAULT_MAX_RS2);
}
}