Update HAL with new PWLE V2 APIs
Updating IVibrator.aidl to introduce APIs for PWLE V2 support. The updated interface now enables retrieval of minimum and maximum PWLE durations, maximum composition size, and facilitates the composition of PWLE effects using points.
Bug: 347034419
Flag: EXEMPT HAL interface change
Test: vts-tradefed run vts -m VtsHalVibratorTargetTest
Change-Id: Id0a93e4f8678622bdb698cddc2b39f46e0283fdd
diff --git a/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp b/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp
index 2502589..ffd38b1 100644
--- a/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp
+++ b/vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp
@@ -27,8 +27,12 @@
#include <cstdlib>
#include <ctime>
#include <future>
+#include <iomanip>
+#include <iostream>
+#include <random>
#include "persistable_bundle_utils.h"
+#include "pwle_v2_utils.h"
#include "test_utils.h"
using aidl::android::hardware::vibrator::ActivePwle;
@@ -42,12 +46,16 @@
using aidl::android::hardware::vibrator::IVibrator;
using aidl::android::hardware::vibrator::IVibratorManager;
using aidl::android::hardware::vibrator::PrimitivePwle;
+using aidl::android::hardware::vibrator::PwleV2OutputMapEntry;
+using aidl::android::hardware::vibrator::PwleV2Primitive;
using aidl::android::hardware::vibrator::VendorEffect;
using aidl::android::os::PersistableBundle;
using std::chrono::high_resolution_clock;
using namespace ::std::chrono_literals;
+namespace pwle_v2_utils = aidl::android::hardware::vibrator::testing::pwlev2;
+
const std::vector<Effect> kEffects{ndk::enum_range<Effect>().begin(),
ndk::enum_range<Effect>().end()};
const std::vector<EffectStrength> kEffectStrengths{ndk::enum_range<EffectStrength>().begin(),
@@ -80,6 +88,8 @@
// Timeout to wait for vibration callback completion.
static constexpr std::chrono::milliseconds VIBRATION_CALLBACK_TIMEOUT = 100ms;
+static constexpr int32_t VENDOR_EFFECTS_MIN_VERSION = 3;
+
static std::vector<std::string> findVibratorManagerNames() {
std::vector<std::string> names;
constexpr auto callback = [](const char* instance, void* context) {
@@ -137,6 +147,7 @@
}
ASSERT_NE(vibrator, nullptr);
+ EXPECT_OK(vibrator->getInterfaceVersion(&version));
EXPECT_OK(vibrator->getCapabilities(&capabilities));
}
@@ -146,6 +157,7 @@
}
std::shared_ptr<IVibrator> vibrator;
+ int32_t version;
int32_t capabilities;
};
@@ -476,6 +488,10 @@
}
TEST_P(VibratorAidl, PerformVendorEffectUnsupported) {
+ if (version < VENDOR_EFFECTS_MIN_VERSION) {
+ EXPECT_EQ(capabilities & IVibrator::CAP_PERFORM_VENDOR_EFFECTS, 0)
+ << "Vibrator version " << version << " should not report vendor effects capability";
+ }
if (capabilities & IVibrator::CAP_PERFORM_VENDOR_EFFECTS) return;
for (EffectStrength strength : kEffectStrengths) {
@@ -1035,6 +1051,156 @@
}
}
+TEST_P(VibratorAidl, PwleV2FrequencyToOutputAccelerationMapHasValidFrequencyRange) {
+ std::vector<PwleV2OutputMapEntry> frequencyToOutputAccelerationMap;
+ ndk::ScopedAStatus status =
+ vibrator->getPwleV2FrequencyToOutputAccelerationMap(&frequencyToOutputAccelerationMap);
+ if (capabilities & IVibrator::CAP_COMPOSE_PWLE_EFFECTS_V2) {
+ EXPECT_OK(std::move(status));
+ ASSERT_FALSE(frequencyToOutputAccelerationMap.empty());
+ auto sharpnessRange =
+ pwle_v2_utils::getPwleV2SharpnessRange(vibrator, frequencyToOutputAccelerationMap);
+ // Validate the curve provides a usable sharpness range, which is a range of frequencies
+ // that are supported by the device.
+ ASSERT_TRUE(sharpnessRange.first >= 0);
+ // Validate that the sharpness range is a valid interval, not a single point.
+ ASSERT_TRUE(sharpnessRange.first < sharpnessRange.second);
+ } else {
+ EXPECT_UNKNOWN_OR_UNSUPPORTED(std::move(status));
+ }
+}
+
+TEST_P(VibratorAidl, GetPwleV2PrimitiveDurationMaxMillis) {
+ int32_t durationMs;
+ ndk::ScopedAStatus status = vibrator->getPwleV2PrimitiveDurationMaxMillis(&durationMs);
+ if (capabilities & IVibrator::CAP_COMPOSE_PWLE_EFFECTS_V2) {
+ EXPECT_OK(std::move(status));
+ ASSERT_GT(durationMs, 0); // Ensure greater than zero
+ ASSERT_GE(durationMs,
+ pwle_v2_utils::COMPOSE_PWLE_V2_MIN_REQUIRED_PRIMITIVE_MAX_DURATION_MS);
+ } else {
+ EXPECT_UNKNOWN_OR_UNSUPPORTED(std::move(status));
+ }
+}
+
+TEST_P(VibratorAidl, GetPwleV2CompositionSizeMax) {
+ int32_t maxSize;
+ ndk::ScopedAStatus status = vibrator->getPwleV2CompositionSizeMax(&maxSize);
+ if (capabilities & IVibrator::CAP_COMPOSE_PWLE_EFFECTS_V2) {
+ EXPECT_OK(std::move(status));
+ ASSERT_GT(maxSize, 0); // Ensure greater than zero
+ ASSERT_GE(maxSize, pwle_v2_utils::COMPOSE_PWLE_V2_MIN_REQUIRED_SIZE);
+ } else {
+ EXPECT_UNKNOWN_OR_UNSUPPORTED(std::move(status));
+ }
+}
+
+TEST_P(VibratorAidl, GetPwleV2PrimitiveDurationMinMillis) {
+ int32_t durationMs;
+ ndk::ScopedAStatus status = vibrator->getPwleV2PrimitiveDurationMinMillis(&durationMs);
+ if (capabilities & IVibrator::CAP_COMPOSE_PWLE_EFFECTS_V2) {
+ EXPECT_OK(std::move(status));
+ ASSERT_GT(durationMs, 0); // Ensure greater than zero
+ ASSERT_LE(durationMs, pwle_v2_utils::COMPOSE_PWLE_V2_MAX_ALLOWED_PRIMITIVE_MIN_DURATION_MS);
+ } else {
+ EXPECT_UNKNOWN_OR_UNSUPPORTED(std::move(status));
+ }
+}
+
+TEST_P(VibratorAidl, ComposeValidPwleV2Effect) {
+ if (!(capabilities & IVibrator::CAP_COMPOSE_PWLE_EFFECTS_V2)) {
+ GTEST_SKIP() << "PWLE V2 not supported, skipping test";
+ return;
+ }
+
+ EXPECT_OK(vibrator->composePwleV2(pwle_v2_utils::composeValidPwleV2Effect(vibrator), nullptr));
+ EXPECT_OK(vibrator->off());
+}
+
+TEST_P(VibratorAidl, ComposeValidPwleV2EffectWithCallback) {
+ if (!(capabilities & IVibrator::CAP_COMPOSE_PWLE_EFFECTS_V2)) {
+ GTEST_SKIP() << "PWLE V2 not supported, skipping test";
+ return;
+ }
+
+ std::promise<void> completionPromise;
+ std::future<void> completionFuture{completionPromise.get_future()};
+ auto callback = ndk::SharedRefBase::make<CompletionCallback>(
+ [&completionPromise] { completionPromise.set_value(); });
+
+ int32_t minDuration;
+ EXPECT_OK(vibrator->getPwleV2PrimitiveDurationMinMillis(&minDuration));
+ auto timeout = std::chrono::milliseconds(minDuration) + VIBRATION_CALLBACK_TIMEOUT;
+ float minFrequency = pwle_v2_utils::getPwleV2FrequencyMinHz(vibrator);
+
+ EXPECT_OK(vibrator->composePwleV2(
+ {PwleV2Primitive(/*amplitude=*/0.5, minFrequency, minDuration)}, callback));
+ EXPECT_EQ(completionFuture.wait_for(timeout), std::future_status::ready);
+ EXPECT_OK(vibrator->off());
+}
+
+TEST_P(VibratorAidl, composePwleV2EffectWithTooManyPoints) {
+ if (!(capabilities & IVibrator::CAP_COMPOSE_PWLE_EFFECTS_V2)) {
+ GTEST_SKIP() << "PWLE V2 not supported, skipping test";
+ return;
+ }
+
+ EXPECT_ILLEGAL_ARGUMENT(vibrator->composePwleV2(
+ pwle_v2_utils::composePwleV2EffectWithTooManyPoints(vibrator), nullptr));
+}
+
+TEST_P(VibratorAidl, composeInvalidPwleV2Effect) {
+ if (!(capabilities & IVibrator::CAP_COMPOSE_PWLE_EFFECTS_V2)) {
+ GTEST_SKIP() << "PWLE V2 not supported, skipping test";
+ return;
+ }
+
+ // Retrieve min and max durations
+ int32_t minDurationMs, maxDurationMs;
+ EXPECT_OK(vibrator->getPwleV2PrimitiveDurationMinMillis(&minDurationMs));
+ EXPECT_OK(vibrator->getPwleV2PrimitiveDurationMaxMillis(&maxDurationMs));
+
+ std::vector<PwleV2Primitive> composePwle;
+
+ // Negative amplitude
+ composePwle.push_back(PwleV2Primitive(/*amplitude=*/-0.8f, /*frequency=*/100, minDurationMs));
+ EXPECT_ILLEGAL_ARGUMENT(vibrator->composePwleV2(composePwle, nullptr))
+ << "Composing PWLE V2 effect with negative amplitude should fail";
+ composePwle.clear();
+
+ // Amplitude exceeding 1.0
+ composePwle.push_back(PwleV2Primitive(/*amplitude=*/1.2f, /*frequency=*/100, minDurationMs));
+ EXPECT_ILLEGAL_ARGUMENT(vibrator->composePwleV2(composePwle, nullptr))
+ << "Composing PWLE V2 effect with amplitude greater than 1.0 should fail";
+ composePwle.clear();
+
+ // Duration exceeding maximum
+ composePwle.push_back(
+ PwleV2Primitive(/*amplitude=*/0.2f, /*frequency=*/100, maxDurationMs + 10));
+ EXPECT_ILLEGAL_ARGUMENT(vibrator->composePwleV2(composePwle, nullptr))
+ << "Composing PWLE V2 effect with duration exceeding maximum should fail";
+ composePwle.clear();
+
+ // Negative duration
+ composePwle.push_back(PwleV2Primitive(/*amplitude=*/0.2f, /*frequency=*/100, /*time=*/-1));
+ EXPECT_ILLEGAL_ARGUMENT(vibrator->composePwleV2(composePwle, nullptr))
+ << "Composing PWLE V2 effect with negative duration should fail";
+ composePwle.clear();
+
+ // Frequency below minimum
+ float minFrequency = pwle_v2_utils::getPwleV2FrequencyMinHz(vibrator);
+ composePwle.push_back(PwleV2Primitive(/*amplitude=*/0.2f, minFrequency - 1, minDurationMs));
+ EXPECT_ILLEGAL_ARGUMENT(vibrator->composePwleV2(composePwle, nullptr))
+ << "Composing PWLE V2 effect with frequency below minimum should fail";
+ composePwle.clear();
+
+ // Frequency above maximum
+ float maxFrequency = pwle_v2_utils::getPwleV2FrequencyMaxHz(vibrator);
+ composePwle.push_back(PwleV2Primitive(/*amplitude=*/0.2f, maxFrequency + 1, minDurationMs));
+ EXPECT_ILLEGAL_ARGUMENT(vibrator->composePwleV2(composePwle, nullptr))
+ << "Composing PWLE V2 effect with frequency above maximum should fail";
+}
+
std::vector<std::tuple<int32_t, int32_t>> GenerateVibratorMapping() {
std::vector<std::tuple<int32_t, int32_t>> tuples;