Loading services/vibratorservice/VibratorHalWrapper.cpp +11 −12 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); } Loading Loading @@ -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(); } // ------------------------------------------------------------------------------------------------- Loading Loading @@ -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); Loading Loading @@ -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() { Loading services/vibratorservice/include/vibratorservice/VibratorHalWrapper.h +17 −13 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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"); Loading @@ -286,7 +287,8 @@ public: "getMinEnvelopeEffectControlPointDuration"); logFailure<std::chrono::milliseconds>(maxEnvelopeEffectControlPointDuration, "getMaxEnvelopeEffectControlPointDuration"); logFailure<std::vector<PwleV2OutputMapEntry>>(frequencyToOutputAccelerationMap, logFailure< std::vector<FrequencyAccelerationMapEntry>>(frequencyToOutputAccelerationMap, "getfrequencyToOutputAccelerationMap"); } Loading Loading @@ -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; }; Loading @@ -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)) {} Loading Loading @@ -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: Loading Loading @@ -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: Loading Loading @@ -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: Loading @@ -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; Loading services/vibratorservice/test/VibratorHalWrapperAidlTest.cpp +19 −17 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -243,10 +244,10 @@ 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, std::vector<FrequencyAccelerationMapEntry> frequencyToOutputAccelerationMap{ FrequencyAccelerationMapEntry(/*frequency=*/30.0f, /*maxOutputAcceleration=*/0.2), PwleV2OutputMapEntry(/*frequency=*/60.0f, FrequencyAccelerationMapEntry(/*frequency=*/60.0f, /*maxOutputAcceleration=*/0.8)}; std::vector<std::chrono::milliseconds> primitiveDurations; Loading Loading @@ -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), Loading Loading @@ -391,10 +392,10 @@ 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, std::vector<FrequencyAccelerationMapEntry> frequencyToOutputAccelerationMap{ FrequencyAccelerationMapEntry(/*frequency=*/30.0f, /*maxOutputAcceleration=*/0.2), PwleV2OutputMapEntry(/*frequency=*/60.0f, FrequencyAccelerationMapEntry(/*frequency=*/60.0f, /*maxOutputAcceleration=*/0.8)}; EXPECT_CALL(*mMockHal.get(), getCapabilities(_)) Loading Loading @@ -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()))); Loading Loading @@ -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), Loading @@ -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()); } services/vibratorservice/test/VibratorHalWrapperHidlV1_0Test.cpp +4 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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), Loading @@ -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()); Loading services/vibratorservice/test/test_mocks.h +5 −6 Original line number Diff line number Diff line Loading @@ -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; // ------------------------------------------------------------------------------------------------- Loading Loading @@ -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)); Loading Loading
services/vibratorservice/VibratorHalWrapper.cpp +11 −12 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); } Loading Loading @@ -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(); } // ------------------------------------------------------------------------------------------------- Loading Loading @@ -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); Loading Loading @@ -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() { Loading
services/vibratorservice/include/vibratorservice/VibratorHalWrapper.h +17 −13 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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"); Loading @@ -286,7 +287,8 @@ public: "getMinEnvelopeEffectControlPointDuration"); logFailure<std::chrono::milliseconds>(maxEnvelopeEffectControlPointDuration, "getMaxEnvelopeEffectControlPointDuration"); logFailure<std::vector<PwleV2OutputMapEntry>>(frequencyToOutputAccelerationMap, logFailure< std::vector<FrequencyAccelerationMapEntry>>(frequencyToOutputAccelerationMap, "getfrequencyToOutputAccelerationMap"); } Loading Loading @@ -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; }; Loading @@ -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)) {} Loading Loading @@ -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: Loading Loading @@ -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: Loading Loading @@ -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: Loading @@ -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; Loading
services/vibratorservice/test/VibratorHalWrapperAidlTest.cpp +19 −17 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -243,10 +244,10 @@ 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, std::vector<FrequencyAccelerationMapEntry> frequencyToOutputAccelerationMap{ FrequencyAccelerationMapEntry(/*frequency=*/30.0f, /*maxOutputAcceleration=*/0.2), PwleV2OutputMapEntry(/*frequency=*/60.0f, FrequencyAccelerationMapEntry(/*frequency=*/60.0f, /*maxOutputAcceleration=*/0.8)}; std::vector<std::chrono::milliseconds> primitiveDurations; Loading Loading @@ -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), Loading Loading @@ -391,10 +392,10 @@ 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, std::vector<FrequencyAccelerationMapEntry> frequencyToOutputAccelerationMap{ FrequencyAccelerationMapEntry(/*frequency=*/30.0f, /*maxOutputAcceleration=*/0.2), PwleV2OutputMapEntry(/*frequency=*/60.0f, FrequencyAccelerationMapEntry(/*frequency=*/60.0f, /*maxOutputAcceleration=*/0.8)}; EXPECT_CALL(*mMockHal.get(), getCapabilities(_)) Loading Loading @@ -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()))); Loading Loading @@ -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), Loading @@ -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()); }
services/vibratorservice/test/VibratorHalWrapperHidlV1_0Test.cpp +4 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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), Loading @@ -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()); Loading
services/vibratorservice/test/test_mocks.h +5 −6 Original line number Diff line number Diff line Loading @@ -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; // ------------------------------------------------------------------------------------------------- Loading Loading @@ -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)); Loading