Merge "CSD: rename get/setOutputRs2 to include upper bound"

This commit is contained in:
Vlad Popa 2023-03-17 19:12:45 +00:00 committed by Gerrit Code Review
commit 429e51f4e7
5 changed files with 27 additions and 25 deletions

View file

@ -34,8 +34,8 @@
package android.hardware.audio.core.sounddose;
@VintfStability
interface ISoundDose {
void setOutputRs2(float rs2ValueDbA);
float getOutputRs2();
void setOutputRs2UpperBound(float rs2ValueDbA);
float getOutputRs2UpperBound();
void registerSoundDoseCallback(in android.hardware.audio.core.sounddose.ISoundDose.IHalSoundDoseCallback callback);
const int DEFAULT_MAX_RS2 = 100;
const int MIN_RS2 = 80;

View file

@ -35,21 +35,21 @@ interface ISoundDose {
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.
*
* @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
* 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
@ -68,9 +68,9 @@ interface ISoundDose {
@VintfStability
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
*/
void onMomentaryExposureWarning(float currentDbA, in AudioDevice audioDevice);
@ -78,14 +78,15 @@ interface ISoundDose {
@VintfStability
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'.
*/
float[] melValues;
/**
* Corresponds to the time in seconds when the first MEL entry in melValues
* was recorded. The timestamp values have to be consistent throughout all
* audio ports, equal timestamp values will be aggregated.
* Corresponds to the time in seconds, as reported by CLOCK_MONOTONIC, when
* the first MEL entry in melValues was recorded. The timestamp values have
* to be consistent throughout all audio ports, equal timestamp values will
* be aggregated.
*/
long timestamp;
}

View file

@ -22,7 +22,7 @@
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) {
LOG(ERROR) << __func__ << ": RS2 value is invalid: " << in_rs2ValueDbA;
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
@ -32,7 +32,7 @@ ndk::ScopedAStatus SoundDose::setOutputRs2(float in_rs2ValueDbA) {
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus SoundDose::getOutputRs2(float* _aidl_return) {
ndk::ScopedAStatus SoundDose::getOutputRs2UpperBound(float* _aidl_return) {
*_aidl_return = mRs2Value;
LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
return ndk::ScopedAStatus::ok();

View file

@ -29,8 +29,8 @@ 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 setOutputRs2UpperBound(float in_rs2ValueDbA) override;
ndk::ScopedAStatus getOutputRs2UpperBound(float* _aidl_return) override;
ndk::ScopedAStatus registerSoundDoseCallback(
const std::shared_ptr<ISoundDose::IHalSoundDoseCallback>& in_callback) override;

View file

@ -3543,26 +3543,27 @@ TEST_P(AudioCoreSoundDose, SameInstance) {
<< "getSoundDose must return the same interface instance across invocations";
}
TEST_P(AudioCoreSoundDose, GetSetOutputRs2) {
TEST_P(AudioCoreSoundDose, GetSetOutputRs2UpperBound) {
if (soundDose == nullptr) {
GTEST_SKIP() << "SoundDose is not supported";
}
bool isSupported = false;
EXPECT_NO_FATAL_FAILURE(TestAccessors<float>(soundDose.get(), &ISoundDose::getOutputRs2,
&ISoundDose::setOutputRs2,
EXPECT_NO_FATAL_FAILURE(TestAccessors<float>(soundDose.get(),
&ISoundDose::getOutputRs2UpperBound,
&ISoundDose::setOutputRs2UpperBound,
/*validValues=*/{80.f, 90.f, 100.f},
/*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) {
GTEST_SKIP() << "SoundDose is not supported";
}
float rs2Value;
ASSERT_IS_OK(soundDose->getOutputRs2(&rs2Value));
ASSERT_IS_OK(soundDose->getOutputRs2UpperBound(&rs2Value));
EXPECT_EQ(rs2Value, ISoundDose::DEFAULT_MAX_RS2);
}