diff --git a/audio/aidl/aidl_api/android.hardware.audio.effect/current/android/hardware/audio/effect/HapticGenerator.aidl b/audio/aidl/aidl_api/android.hardware.audio.effect/current/android/hardware/audio/effect/HapticGenerator.aidl index 8addab7b5f..aa1a86f3aa 100644 --- a/audio/aidl/aidl_api/android.hardware.audio.effect/current/android/hardware/audio/effect/HapticGenerator.aidl +++ b/audio/aidl/aidl_api/android.hardware.audio.effect/current/android/hardware/audio/effect/HapticGenerator.aidl @@ -55,6 +55,9 @@ union HapticGenerator { parcelable HapticScale { int id; android.hardware.audio.effect.HapticGenerator.VibratorScale scale = android.hardware.audio.effect.HapticGenerator.VibratorScale.MUTE; + float scaleFactor = (-1.0f) /* -1.000000f */; + float adaptiveScaleFactor = (-1.0f) /* -1.000000f */; + const float UNDEFINED_SCALE_FACTOR = (-1.0f) /* -1.000000f */; } @VintfStability parcelable VibratorInformation { diff --git a/audio/aidl/android/hardware/audio/effect/HapticGenerator.aidl b/audio/aidl/android/hardware/audio/effect/HapticGenerator.aidl index 3cc5acb48c..f882d63ee2 100644 --- a/audio/aidl/android/hardware/audio/effect/HapticGenerator.aidl +++ b/audio/aidl/android/hardware/audio/effect/HapticGenerator.aidl @@ -55,14 +55,52 @@ union HapticGenerator { @VintfStability parcelable HapticScale { + /** + * Representation of undefined scale factor, applied by default for backwards compatibility. + */ + const float UNDEFINED_SCALE_FACTOR = -1.0f; + /** * Audio track ID. */ int id; + /** * Haptic intensity. + * + * This represents haptics scale as fixed levels defined by VibrationScale. If the field + * scaleFactor is defined then this will be ignored in favor of scaleFactor, otherwise this + * will be used to define the intensity for the haptics. */ VibratorScale scale = VibratorScale.MUTE; + + /** + * Haptic scale factor. + * + * This is a continuous scale representation of VibratorScale, allowing flexible number of + * scale levels. If this field is defined then it will be used to define the intensity of + * the haptics, instead of the old VibratorScale field. If this field is undefined then the + * old VibratorScale field will be used. + * + * The value zero represents the same as VibratorScale.MUTE and the value one represents + * VibratorScale.NONE. Values in (0,1) should scale down, and values > 1 should scale up + * within hardware bounds. Negative values will be ignored. + */ + float scaleFactor = -1.0f; // UNDEFINED_SCALE_FACTOR + + /** + * Haptic adaptive scale factor. + * + * This is an additional scale value that should be applied on top of the vibrator scale to + * adapt to the device current state. This should be applied to linearly scale the haptic + * data after scale/scaleFactor is applied. + * + * The value zero mutes the haptics, even if the scale/scaleFactor are not set to MUTE/zero. + * The value one will not scale the haptics, and can be used as a constant for no-op. + * Values in (0,1) should scale down. Values > 1 should scale up within hardware bounds. + * Negative values will be ignored. + */ + float adaptiveScaleFactor = -1.0f; // UNDEFINED_SCALE_FACTOR } /** diff --git a/audio/aidl/vts/VtsHalHapticGeneratorTargetTest.cpp b/audio/aidl/vts/VtsHalHapticGeneratorTargetTest.cpp index 6af326d01b..d8332aacfc 100644 --- a/audio/aidl/vts/VtsHalHapticGeneratorTargetTest.cpp +++ b/audio/aidl/vts/VtsHalHapticGeneratorTargetTest.cpp @@ -42,13 +42,15 @@ enum ParamName { PARAM_INSTANCE_NAME, PARAM_HAPTIC_SCALE_ID, PARAM_HAPTIC_SCALE_VIBRATOR_SCALE, + PARAM_HAPTIC_SCALE_SCALE_FACTOR, + PARAM_HAPTIC_SCALE_ADAPTIVE_SCALE_FACTOR, PARAM_VIBRATION_INFORMATION_RESONANT_FREQUENCY, PARAM_VIBRATION_INFORMATION_Q_FACTOR, PARAM_VIBRATION_INFORMATION_MAX_AMPLITUDE, }; using HapticGeneratorParamTestParam = std::tuple, Descriptor>, int, - HapticGenerator::VibratorScale, float, float, float>; + HapticGenerator::VibratorScale, float, float, float, float, float>; /* * Testing parameter range, assuming the parameter supported by effect is in this range. @@ -67,6 +69,10 @@ const std::vector kHapticScaleIdValues = {MIN_ID, 0, MAX_ID}; const std::vector kVibratorScaleValues = { ndk::enum_range().begin(), ndk::enum_range().end()}; +const std::vector kScaleFactorValues = {HapticGenerator::HapticScale::UNDEFINED_SCALE_FACTOR, + 0.0f, 0.5f, 1.0f, MAX_FLOAT}; +const std::vector kAdaptiveScaleFactorValues = { + HapticGenerator::HapticScale::UNDEFINED_SCALE_FACTOR, 0.0f, 0.5f, 1.0f, MAX_FLOAT}; const std::vector kResonantFrequencyValues = {MIN_FLOAT, 100, MAX_FLOAT}; const std::vector kQFactorValues = {MIN_FLOAT, 100, MAX_FLOAT}; @@ -78,6 +84,8 @@ class HapticGeneratorParamTest : public ::testing::TestWithParam(GetParam())), mParamVibratorScale(std::get(GetParam())), + mParamScaleFactor(std::get(GetParam())), + mParamAdaptiveScaleFactor(std::get(GetParam())), mParamResonantFrequency( std::get(GetParam())), mParamQFactor(std::get(GetParam())), @@ -107,6 +115,8 @@ class HapticGeneratorParamTest : public ::testing::TestWithParam hapticScales = {{.id = id, .scale = scale}}; + std::vector hapticScales = { + {.id = id, + .scale = scale, + .scaleFactor = scaleFactor, + .adaptiveScaleFactor = adaptiveScaleFactor}}; setHg.set(hapticScales); mTags.push_back({HapticGenerator::hapticScales, setHg}); } @@ -160,13 +175,16 @@ class HapticGeneratorParamTest : public ::testing::TestWithParam& info) { @@ -189,6 +209,10 @@ INSTANTIATE_TEST_SUITE_P( std::string hapticScaleID = std::to_string(std::get(info.param)); std::string hapticScaleVibScale = std::to_string( static_cast(std::get(info.param))); + std::string hapticScaleFactor = + std::to_string(std::get(info.param)); + std::string hapticAdaptiveScaleFactor = + std::to_string(std::get(info.param)); std::string resonantFrequency = std::to_string( std::get(info.param)); std::string qFactor = @@ -196,7 +220,9 @@ INSTANTIATE_TEST_SUITE_P( std::string maxAmplitude = std::to_string(std::get(info.param)); std::string name = getPrefix(descriptor) + "_hapticScaleId" + hapticScaleID + - "_hapticScaleVibScale" + hapticScaleVibScale + "_resonantFrequency" + + "_hapticScaleVibScale" + hapticScaleVibScale + "_hapticScaleFactor" + + hapticScaleFactor + "_hapticAdaptiveScaleFactor" + + hapticAdaptiveScaleFactor + "_resonantFrequency" + resonantFrequency + "_qFactor" + qFactor + "_maxAmplitude" + maxAmplitude; std::replace_if( @@ -210,6 +236,8 @@ INSTANTIATE_TEST_SUITE_P( IFactory::descriptor, getEffectTypeUuidHapticGenerator())), testing::Values(MIN_ID), testing::Values(HapticGenerator::VibratorScale::NONE), + testing::Values(HapticGenerator::HapticScale::UNDEFINED_SCALE_FACTOR), + testing::Values(HapticGenerator::HapticScale::UNDEFINED_SCALE_FACTOR), testing::Values(MIN_FLOAT), testing::Values(MIN_FLOAT), testing::Values(MIN_FLOAT)), [](const testing::TestParamInfo& info) { @@ -217,6 +245,10 @@ INSTANTIATE_TEST_SUITE_P( std::string hapticScaleID = std::to_string(std::get(info.param)); std::string hapticScaleVibScale = std::to_string( static_cast(std::get(info.param))); + std::string hapticScaleFactor = + std::to_string(std::get(info.param)); + std::string hapticAdaptiveScaleFactor = + std::to_string(std::get(info.param)); std::string resonantFrequency = std::to_string( std::get(info.param)); std::string qFactor = @@ -227,6 +259,8 @@ INSTANTIATE_TEST_SUITE_P( descriptor.common.name + "_UUID_" + toString(descriptor.common.id.uuid) + "_hapticScaleId" + hapticScaleID + "_hapticScaleVibScale" + hapticScaleVibScale + + "_hapticScaleFactor" + hapticScaleFactor + + "_hapticAdaptiveScaleFactor" + hapticAdaptiveScaleFactor + "_resonantFrequency" + resonantFrequency + "_qFactor" + qFactor + "_maxAmplitude" + maxAmplitude; std::replace_if(