diff options
5 files changed, 56 insertions, 50 deletions
diff --git a/services/vibratorservice/VibratorHalWrapper.cpp b/services/vibratorservice/VibratorHalWrapper.cpp index b06ee3b2b5..3ddc4f2aca 100644 --- a/services/vibratorservice/VibratorHalWrapper.cpp +++ b/services/vibratorservice/VibratorHalWrapper.cpp @@ -29,11 +29,11 @@ using aidl::android::hardware::vibrator::Braking; using aidl::android::hardware::vibrator::CompositeEffect; using aidl::android::hardware::vibrator::CompositePrimitive; +using aidl::android::hardware::vibrator::CompositePwleV2; using aidl::android::hardware::vibrator::Effect; using aidl::android::hardware::vibrator::EffectStrength; +using aidl::android::hardware::vibrator::FrequencyAccelerationMapEntry; 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 std::chrono::milliseconds; @@ -131,8 +131,7 @@ HalResult<void> HalWrapper::performPwleEffect(const std::vector<PrimitivePwle>&, return HalResult<void>::unsupported(); } -HalResult<void> HalWrapper::composePwleV2(const std::vector<PwleV2Primitive>&, - const std::function<void()>&) { +HalResult<void> HalWrapper::composePwleV2(const CompositePwleV2&, const std::function<void()>&) { ALOGV("Skipped composePwleV2 because it's not available in Vibrator HAL"); return HalResult<void>::unsupported(); } @@ -243,11 +242,11 @@ HalResult<milliseconds> HalWrapper::getMaxEnvelopeEffectControlPointDurationInte return HalResult<milliseconds>::unsupported(); } -HalResult<std::vector<PwleV2OutputMapEntry>> +HalResult<std::vector<FrequencyAccelerationMapEntry>> HalWrapper::getFrequencyToOutputAccelerationMapInternal() { ALOGV("Skipped getFrequencyToOutputAccelerationMapInternal because it's not " "available in Vibrator HAL"); - return HalResult<std::vector<PwleV2OutputMapEntry>>::unsupported(); + return HalResult<std::vector<FrequencyAccelerationMapEntry>>::unsupported(); } // ------------------------------------------------------------------------------------------------- @@ -360,7 +359,7 @@ HalResult<void> AidlHalWrapper::performPwleEffect(const std::vector<PrimitivePwl return HalResultFactory::fromStatus(getHal()->composePwle(primitives, cb)); } -HalResult<void> AidlHalWrapper::composePwleV2(const std::vector<PwleV2Primitive>& composite, +HalResult<void> AidlHalWrapper::composePwleV2(const CompositePwleV2& composite, const std::function<void()>& completionCallback) { // This method should always support callbacks, so no need to double check. auto cb = ndk::SharedRefBase::make<HalCallbackWrapper>(completionCallback); @@ -498,13 +497,13 @@ HalResult<milliseconds> AidlHalWrapper::getMaxEnvelopeEffectControlPointDuration return HalResultFactory::fromStatus<milliseconds>(std::move(status), milliseconds(durationMs)); } -HalResult<std::vector<PwleV2OutputMapEntry>> +HalResult<std::vector<FrequencyAccelerationMapEntry>> AidlHalWrapper::getFrequencyToOutputAccelerationMapInternal() { - std::vector<PwleV2OutputMapEntry> frequencyToOutputAccelerationMap; - auto status = - getHal()->getPwleV2FrequencyToOutputAccelerationMap(&frequencyToOutputAccelerationMap); + std::vector<FrequencyAccelerationMapEntry> frequencyToOutputAccelerationMap; + auto status = getHal()->getFrequencyToOutputAccelerationMap(&frequencyToOutputAccelerationMap); return HalResultFactory::fromStatus< - std::vector<PwleV2OutputMapEntry>>(std::move(status), frequencyToOutputAccelerationMap); + std::vector<FrequencyAccelerationMapEntry>>(std::move(status), + frequencyToOutputAccelerationMap); } std::shared_ptr<Aidl::IVibrator> AidlHalWrapper::getHal() { diff --git a/services/vibratorservice/include/vibratorservice/VibratorHalWrapper.h b/services/vibratorservice/include/vibratorservice/VibratorHalWrapper.h index b2bfffca1b..339a6e1d0d 100644 --- a/services/vibratorservice/include/vibratorservice/VibratorHalWrapper.h +++ b/services/vibratorservice/include/vibratorservice/VibratorHalWrapper.h @@ -243,7 +243,8 @@ public: using EffectStrength = aidl::android::hardware::vibrator::EffectStrength; using CompositePrimitive = aidl::android::hardware::vibrator::CompositePrimitive; using Braking = aidl::android::hardware::vibrator::Braking; - using PwleV2OutputMapEntry = aidl::android::hardware::vibrator::PwleV2OutputMapEntry; + using FrequencyAccelerationMapEntry = + aidl::android::hardware::vibrator::FrequencyAccelerationMapEntry; const HalResult<Capabilities> capabilities; const HalResult<std::vector<Effect>> supportedEffects; @@ -262,7 +263,7 @@ public: const HalResult<int32_t> maxEnvelopeEffectSize; const HalResult<std::chrono::milliseconds> minEnvelopeEffectControlPointDuration; const HalResult<std::chrono::milliseconds> maxEnvelopeEffectControlPointDuration; - const HalResult<std::vector<PwleV2OutputMapEntry>> frequencyToOutputAccelerationMap; + const HalResult<std::vector<FrequencyAccelerationMapEntry>> frequencyToOutputAccelerationMap; void logFailures() const { logFailure<Capabilities>(capabilities, "getCapabilities"); @@ -286,8 +287,9 @@ public: "getMinEnvelopeEffectControlPointDuration"); logFailure<std::chrono::milliseconds>(maxEnvelopeEffectControlPointDuration, "getMaxEnvelopeEffectControlPointDuration"); - logFailure<std::vector<PwleV2OutputMapEntry>>(frequencyToOutputAccelerationMap, - "getfrequencyToOutputAccelerationMap"); + logFailure< + std::vector<FrequencyAccelerationMapEntry>>(frequencyToOutputAccelerationMap, + "getfrequencyToOutputAccelerationMap"); } bool shouldRetry() const { @@ -365,8 +367,8 @@ private: HalResult<std::chrono::milliseconds>::transactionFailed(MSG); HalResult<std::chrono::milliseconds> mMaxEnvelopeEffectControlPointDuration = HalResult<std::chrono::milliseconds>::transactionFailed(MSG); - HalResult<std::vector<Info::PwleV2OutputMapEntry>> mFrequencyToOutputAccelerationMap = - HalResult<std::vector<Info::PwleV2OutputMapEntry>>::transactionFailed(MSG); + HalResult<std::vector<Info::FrequencyAccelerationMapEntry>> mFrequencyToOutputAccelerationMap = + HalResult<std::vector<Info::FrequencyAccelerationMapEntry>>::transactionFailed(MSG); friend class HalWrapper; }; @@ -381,8 +383,9 @@ public: using CompositeEffect = aidl::android::hardware::vibrator::CompositeEffect; using Braking = aidl::android::hardware::vibrator::Braking; using PrimitivePwle = aidl::android::hardware::vibrator::PrimitivePwle; - using PwleV2Primitive = aidl::android::hardware::vibrator::PwleV2Primitive; - using PwleV2OutputMapEntry = aidl::android::hardware::vibrator::PwleV2OutputMapEntry; + using CompositePwleV2 = aidl::android::hardware::vibrator::CompositePwleV2; + using FrequencyAccelerationMapEntry = + aidl::android::hardware::vibrator::FrequencyAccelerationMapEntry; explicit HalWrapper(std::shared_ptr<CallbackScheduler> scheduler) : mCallbackScheduler(std::move(scheduler)) {} @@ -420,7 +423,7 @@ public: virtual HalResult<void> performPwleEffect(const std::vector<PrimitivePwle>& primitives, const std::function<void()>& completionCallback); - virtual HalResult<void> composePwleV2(const std::vector<PwleV2Primitive>& composite, + virtual HalResult<void> composePwleV2(const CompositePwleV2& composite, const std::function<void()>& completionCallback); protected: @@ -450,7 +453,7 @@ protected: virtual HalResult<int32_t> getMaxEnvelopeEffectSizeInternal(); virtual HalResult<std::chrono::milliseconds> getMinEnvelopeEffectControlPointDurationInternal(); virtual HalResult<std::chrono::milliseconds> getMaxEnvelopeEffectControlPointDurationInternal(); - virtual HalResult<std::vector<PwleV2OutputMapEntry>> + virtual HalResult<std::vector<FrequencyAccelerationMapEntry>> getFrequencyToOutputAccelerationMapInternal(); private: @@ -508,7 +511,7 @@ public: const std::vector<PrimitivePwle>& primitives, const std::function<void()>& completionCallback) override final; - HalResult<void> composePwleV2(const std::vector<PwleV2Primitive>& composite, + HalResult<void> composePwleV2(const CompositePwleV2& composite, const std::function<void()>& completionCallback) override final; protected: @@ -532,8 +535,9 @@ protected: override final; HalResult<std::chrono::milliseconds> getMaxEnvelopeEffectControlPointDurationInternal() override final; - HalResult<std::vector<PwleV2OutputMapEntry>> getFrequencyToOutputAccelerationMapInternal() - override final; + + HalResult<std::vector<FrequencyAccelerationMapEntry>> + getFrequencyToOutputAccelerationMapInternal() override final; private: const reconnect_fn mReconnectFn; diff --git a/services/vibratorservice/test/VibratorHalWrapperAidlTest.cpp b/services/vibratorservice/test/VibratorHalWrapperAidlTest.cpp index d42aa5684f..c58e05cedb 100644 --- a/services/vibratorservice/test/VibratorHalWrapperAidlTest.cpp +++ b/services/vibratorservice/test/VibratorHalWrapperAidlTest.cpp @@ -34,12 +34,13 @@ using aidl::android::hardware::vibrator::Braking; using aidl::android::hardware::vibrator::CompositeEffect; using aidl::android::hardware::vibrator::CompositePrimitive; +using aidl::android::hardware::vibrator::CompositePwleV2; using aidl::android::hardware::vibrator::Effect; using aidl::android::hardware::vibrator::EffectStrength; +using aidl::android::hardware::vibrator::FrequencyAccelerationMapEntry; using aidl::android::hardware::vibrator::IVibrator; using aidl::android::hardware::vibrator::IVibratorCallback; 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; @@ -243,11 +244,11 @@ TEST_F(VibratorHalWrapperAidlTest, TestGetInfoDoesNotCacheFailedResult) { std::vector<CompositePrimitive> supportedPrimitives = {CompositePrimitive::CLICK}; std::vector<Braking> supportedBraking = {Braking::CLAB}; std::vector<float> amplitudes = {0.f, 1.f, 0.f}; - std::vector<PwleV2OutputMapEntry> - frequencyToOutputAccelerationMap{PwleV2OutputMapEntry(/*frequency=*/30.0f, - /*maxOutputAcceleration=*/0.2), - PwleV2OutputMapEntry(/*frequency=*/60.0f, - /*maxOutputAcceleration=*/0.8)}; + std::vector<FrequencyAccelerationMapEntry> frequencyToOutputAccelerationMap{ + FrequencyAccelerationMapEntry(/*frequency=*/30.0f, + /*maxOutputAcceleration=*/0.2), + FrequencyAccelerationMapEntry(/*frequency=*/60.0f, + /*maxOutputAcceleration=*/0.8)}; std::vector<std::chrono::milliseconds> primitiveDurations; constexpr auto primitiveRange = ndk::enum_range<CompositePrimitive>(); @@ -329,7 +330,7 @@ TEST_F(VibratorHalWrapperAidlTest, TestGetInfoDoesNotCacheFailedResult) { .WillOnce(Return(ndk::ScopedAStatus::fromExceptionCode(EX_SECURITY))) .WillOnce(DoAll(SetArgPointee<0>(PWLE_V2_MIN_REQUIRED_PRIMITIVE_MAX_DURATION_MS), Return(ndk::ScopedAStatus::ok()))); - EXPECT_CALL(*mMockHal.get(), getPwleV2FrequencyToOutputAccelerationMap(_)) + EXPECT_CALL(*mMockHal.get(), getFrequencyToOutputAccelerationMap(_)) .Times(Exactly(2)) .WillOnce(Return(ndk::ScopedAStatus::fromExceptionCode(EX_SECURITY))) .WillOnce(DoAll(SetArgPointee<0>(frequencyToOutputAccelerationMap), @@ -391,11 +392,11 @@ TEST_F(VibratorHalWrapperAidlTest, TestGetInfoCachesResult) { constexpr int32_t PWLE_V2_MAX_ALLOWED_PRIMITIVE_MIN_DURATION_MS = 20; constexpr int32_t PWLE_V2_MIN_REQUIRED_PRIMITIVE_MAX_DURATION_MS = 1000; std::vector<Effect> supportedEffects = {Effect::CLICK, Effect::TICK}; - std::vector<PwleV2OutputMapEntry> - frequencyToOutputAccelerationMap{PwleV2OutputMapEntry(/*frequency=*/30.0f, - /*maxOutputAcceleration=*/0.2), - PwleV2OutputMapEntry(/*frequency=*/60.0f, - /*maxOutputAcceleration=*/0.8)}; + std::vector<FrequencyAccelerationMapEntry> frequencyToOutputAccelerationMap{ + FrequencyAccelerationMapEntry(/*frequency=*/30.0f, + /*maxOutputAcceleration=*/0.2), + FrequencyAccelerationMapEntry(/*frequency=*/60.0f, + /*maxOutputAcceleration=*/0.8)}; EXPECT_CALL(*mMockHal.get(), getCapabilities(_)) .Times(Exactly(1)) @@ -451,7 +452,7 @@ TEST_F(VibratorHalWrapperAidlTest, TestGetInfoCachesResult) { .Times(Exactly(1)) .WillOnce(DoAll(SetArgPointee<0>(PWLE_V2_MIN_REQUIRED_PRIMITIVE_MAX_DURATION_MS), Return(ndk::ScopedAStatus::ok()))); - EXPECT_CALL(*mMockHal.get(), getPwleV2FrequencyToOutputAccelerationMap(_)) + EXPECT_CALL(*mMockHal.get(), getFrequencyToOutputAccelerationMap(_)) .Times(Exactly(1)) .WillOnce(DoAll(SetArgPointee<0>(frequencyToOutputAccelerationMap), Return(ndk::ScopedAStatus::ok()))); @@ -754,7 +755,8 @@ TEST_F(VibratorHalWrapperAidlTest, TestPerformPwleEffect) { } TEST_F(VibratorHalWrapperAidlTest, TestComposePwleV2) { - auto pwleEffect = { + CompositePwleV2 composite; + composite.pwlePrimitives = { PwleV2Primitive(/*amplitude=*/0.2, /*frequency=*/50, /*time=*/100), PwleV2Primitive(/*amplitude=*/0.5, /*frequency=*/150, /*time=*/100), PwleV2Primitive(/*amplitude=*/0.8, /*frequency=*/250, /*time=*/100), @@ -773,17 +775,17 @@ TEST_F(VibratorHalWrapperAidlTest, TestComposePwleV2) { std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>(); auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get()); - auto result = mWrapper->composePwleV2(pwleEffect, callback); + auto result = mWrapper->composePwleV2(composite, callback); ASSERT_TRUE(result.isUnsupported()); // Callback not triggered on failure ASSERT_EQ(0, *callbackCounter.get()); - result = mWrapper->composePwleV2(pwleEffect, callback); + result = mWrapper->composePwleV2(composite, callback); ASSERT_TRUE(result.isFailed()); // Callback not triggered for unsupported ASSERT_EQ(0, *callbackCounter.get()); - result = mWrapper->composePwleV2(pwleEffect, callback); + result = mWrapper->composePwleV2(composite, callback); ASSERT_TRUE(result.isOk()); ASSERT_EQ(1, *callbackCounter.get()); } diff --git a/services/vibratorservice/test/VibratorHalWrapperHidlV1_0Test.cpp b/services/vibratorservice/test/VibratorHalWrapperHidlV1_0Test.cpp index d6dab8d13c..04dbe4eb26 100644 --- a/services/vibratorservice/test/VibratorHalWrapperHidlV1_0Test.cpp +++ b/services/vibratorservice/test/VibratorHalWrapperHidlV1_0Test.cpp @@ -36,6 +36,7 @@ namespace V1_0 = android::hardware::vibrator::V1_0; using aidl::android::hardware::vibrator::Braking; using aidl::android::hardware::vibrator::CompositeEffect; using aidl::android::hardware::vibrator::CompositePrimitive; +using aidl::android::hardware::vibrator::CompositePwleV2; using aidl::android::hardware::vibrator::Effect; using aidl::android::hardware::vibrator::EffectStrength; using aidl::android::hardware::vibrator::IVibrator; @@ -380,7 +381,8 @@ TEST_F(VibratorHalWrapperHidlV1_0Test, TestPerformPwleEffectUnsupported) { } TEST_F(VibratorHalWrapperHidlV1_0Test, TestComposePwleV2Unsupported) { - auto pwleEffect = { + CompositePwleV2 composite; + composite.pwlePrimitives = { PwleV2Primitive(/*amplitude=*/0.2, /*frequency=*/50, /*time=*/100), PwleV2Primitive(/*amplitude=*/0.5, /*frequency=*/150, /*time=*/100), PwleV2Primitive(/*amplitude=*/0.8, /*frequency=*/250, /*time=*/100), @@ -389,7 +391,7 @@ TEST_F(VibratorHalWrapperHidlV1_0Test, TestComposePwleV2Unsupported) { std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>(); auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get()); - ASSERT_TRUE(mWrapper->composePwleV2(pwleEffect, callback).isUnsupported()); + ASSERT_TRUE(mWrapper->composePwleV2(composite, callback).isUnsupported()); // No callback is triggered. ASSERT_EQ(0, *callbackCounter.get()); diff --git a/services/vibratorservice/test/test_mocks.h b/services/vibratorservice/test/test_mocks.h index 5e090849af..ba273be69b 100644 --- a/services/vibratorservice/test/test_mocks.h +++ b/services/vibratorservice/test/test_mocks.h @@ -36,13 +36,13 @@ using namespace testing; using aidl::android::hardware::vibrator::Braking; using aidl::android::hardware::vibrator::CompositeEffect; using aidl::android::hardware::vibrator::CompositePrimitive; +using aidl::android::hardware::vibrator::CompositePwleV2; using aidl::android::hardware::vibrator::Effect; using aidl::android::hardware::vibrator::EffectStrength; +using aidl::android::hardware::vibrator::FrequencyAccelerationMapEntry; using aidl::android::hardware::vibrator::IVibrator; using aidl::android::hardware::vibrator::IVibratorCallback; using aidl::android::hardware::vibrator::PrimitivePwle; -using aidl::android::hardware::vibrator::PwleV2OutputMapEntry; -using aidl::android::hardware::vibrator::PwleV2Primitive; using aidl::android::hardware::vibrator::VendorEffect; // ------------------------------------------------------------------------------------------------- @@ -91,16 +91,15 @@ public: MOCK_METHOD(ndk::ScopedAStatus, getPwlePrimitiveDurationMax, (int32_t * ret), (override)); MOCK_METHOD(ndk::ScopedAStatus, getPwleCompositionSizeMax, (int32_t * ret), (override)); MOCK_METHOD(ndk::ScopedAStatus, getSupportedBraking, (std::vector<Braking> * ret), (override)); - MOCK_METHOD(ndk::ScopedAStatus, getPwleV2FrequencyToOutputAccelerationMap, - (std::vector<PwleV2OutputMapEntry> * ret), (override)); + MOCK_METHOD(ndk::ScopedAStatus, getFrequencyToOutputAccelerationMap, + (std::vector<FrequencyAccelerationMapEntry> * ret), (override)); MOCK_METHOD(ndk::ScopedAStatus, getPwleV2PrimitiveDurationMaxMillis, (int32_t* ret), (override)); MOCK_METHOD(ndk::ScopedAStatus, getPwleV2PrimitiveDurationMinMillis, (int32_t* ret), (override)); MOCK_METHOD(ndk::ScopedAStatus, getPwleV2CompositionSizeMax, (int32_t* ret), (override)); MOCK_METHOD(ndk::ScopedAStatus, composePwleV2, - (const std::vector<PwleV2Primitive>& e, - const std::shared_ptr<IVibratorCallback>& cb), + (const CompositePwleV2& e, const std::shared_ptr<IVibratorCallback>& cb), (override)); MOCK_METHOD(ndk::ScopedAStatus, getInterfaceVersion, (int32_t*), (override)); MOCK_METHOD(ndk::ScopedAStatus, getInterfaceHash, (std::string*), (override)); |