Loading vibrator/aidl/android/hardware/vibrator/IVibrator.aidl +8 −0 Original line number Diff line number Diff line Loading @@ -73,6 +73,14 @@ interface IVibrator { */ int perform(in Effect effect, in EffectStrength strength, in IVibratorCallback callback); /** * List supported effects. * * Return the effects which are supported (an effect is expected to be supported at every * strength level. */ Effect[] getSupportedEffects(); /** * Sets the motor's vibrational amplitude. * Loading vibrator/aidl/default/Vibrator.cpp +5 −0 Original line number Diff line number Diff line Loading @@ -78,6 +78,11 @@ ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength strength, return ndk::ScopedAStatus::ok(); } ndk::ScopedAStatus Vibrator::getSupportedEffects(std::vector<Effect>* _aidl_return) { *_aidl_return = {Effect::CLICK, Effect::TICK}; return ndk::ScopedAStatus::ok(); } ndk::ScopedAStatus Vibrator::setAmplitude(int32_t amplitude) { LOG(INFO) << "Vibrator set amplitude: " << amplitude; if (amplitude <= 0 || amplitude > 255) { Loading vibrator/aidl/default/Vibrator.h +1 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ class Vibrator : public BnVibrator { ndk::ScopedAStatus perform(Effect effect, EffectStrength strength, const std::shared_ptr<IVibratorCallback>& callback, int32_t* _aidl_return) override; ndk::ScopedAStatus getSupportedEffects(std::vector<Effect>* _aidl_return) override; ndk::ScopedAStatus setAmplitude(int32_t amplitude) override; ndk::ScopedAStatus setExternalControl(bool enabled) override; }; Loading vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp +28 −6 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ using android::hardware::vibrator::Effect; using android::hardware::vibrator::EffectStrength; using android::hardware::vibrator::IVibrator; // TODO(b/143992652): autogenerate const std::vector<Effect> kEffects = { Effect::CLICK, Effect::DOUBLE_CLICK, Effect::TICK, Effect::THUD, Effect::POP, Effect::HEAVY_CLICK, Effect::RINGTONE_1, Effect::RINGTONE_2, Loading @@ -40,6 +41,7 @@ const std::vector<Effect> kEffects = { Effect::RINGTONE_11, Effect::RINGTONE_12, Effect::RINGTONE_13, Effect::RINGTONE_14, Effect::RINGTONE_15, Effect::TEXTURE_TICK}; // TODO(b/143992652): autogenerate const std::vector<EffectStrength> kEffectStrengths = {EffectStrength::LIGHT, EffectStrength::MEDIUM, EffectStrength::STRONG}; Loading Loading @@ -105,15 +107,22 @@ TEST_P(VibratorAidl, OnCallbackNotSupported) { } TEST_P(VibratorAidl, ValidateEffect) { std::vector<Effect> supported; ASSERT_TRUE(vibrator->getSupportedEffects(&supported).isOk()); for (Effect effect : kEffects) { bool isEffectSupported = std::find(supported.begin(), supported.end(), effect) != supported.end(); for (EffectStrength strength : kEffectStrengths) { int32_t lengthMs = 0; Status status = vibrator->perform(effect, strength, nullptr /*callback*/, &lengthMs); EXPECT_TRUE(status.isOk() || status.exceptionCode() == Status::EX_UNSUPPORTED_OPERATION); if (status.isOk()) { if (isEffectSupported) { EXPECT_TRUE(status.isOk()); EXPECT_GT(lengthMs, 0); } else { EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION); EXPECT_EQ(lengthMs, 0); } } Loading @@ -123,16 +132,29 @@ TEST_P(VibratorAidl, ValidateEffect) { TEST_P(VibratorAidl, ValidateEffectWithCallback) { if (!(capabilities & IVibrator::CAP_PERFORM_CALLBACK)) return; std::vector<Effect> supported; ASSERT_TRUE(vibrator->getSupportedEffects(&supported).isOk()); for (Effect effect : kEffects) { bool isEffectSupported = std::find(supported.begin(), supported.end(), effect) != supported.end(); for (EffectStrength strength : kEffectStrengths) { std::promise<void> completionPromise; std::future<void> completionFuture{completionPromise.get_future()}; sp<CompletionCallback> callback = new CompletionCallback([&completionPromise] { completionPromise.set_value(); }); int lengthMs; int lengthMs = 0; Status status = vibrator->perform(effect, strength, callback, &lengthMs); EXPECT_TRUE(status.isOk() || status.exceptionCode() == Status::EX_UNSUPPORTED_OPERATION); if (isEffectSupported) { EXPECT_TRUE(status.isOk()); EXPECT_GT(lengthMs, 0); } else { EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION); EXPECT_EQ(lengthMs, 0); } if (!status.isOk()) continue; std::chrono::milliseconds timeout{lengthMs * 2}; Loading Loading
vibrator/aidl/android/hardware/vibrator/IVibrator.aidl +8 −0 Original line number Diff line number Diff line Loading @@ -73,6 +73,14 @@ interface IVibrator { */ int perform(in Effect effect, in EffectStrength strength, in IVibratorCallback callback); /** * List supported effects. * * Return the effects which are supported (an effect is expected to be supported at every * strength level. */ Effect[] getSupportedEffects(); /** * Sets the motor's vibrational amplitude. * Loading
vibrator/aidl/default/Vibrator.cpp +5 −0 Original line number Diff line number Diff line Loading @@ -78,6 +78,11 @@ ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength strength, return ndk::ScopedAStatus::ok(); } ndk::ScopedAStatus Vibrator::getSupportedEffects(std::vector<Effect>* _aidl_return) { *_aidl_return = {Effect::CLICK, Effect::TICK}; return ndk::ScopedAStatus::ok(); } ndk::ScopedAStatus Vibrator::setAmplitude(int32_t amplitude) { LOG(INFO) << "Vibrator set amplitude: " << amplitude; if (amplitude <= 0 || amplitude > 255) { Loading
vibrator/aidl/default/Vibrator.h +1 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ class Vibrator : public BnVibrator { ndk::ScopedAStatus perform(Effect effect, EffectStrength strength, const std::shared_ptr<IVibratorCallback>& callback, int32_t* _aidl_return) override; ndk::ScopedAStatus getSupportedEffects(std::vector<Effect>* _aidl_return) override; ndk::ScopedAStatus setAmplitude(int32_t amplitude) override; ndk::ScopedAStatus setExternalControl(bool enabled) override; }; Loading
vibrator/aidl/vts/VtsHalVibratorTargetTest.cpp +28 −6 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ using android::hardware::vibrator::Effect; using android::hardware::vibrator::EffectStrength; using android::hardware::vibrator::IVibrator; // TODO(b/143992652): autogenerate const std::vector<Effect> kEffects = { Effect::CLICK, Effect::DOUBLE_CLICK, Effect::TICK, Effect::THUD, Effect::POP, Effect::HEAVY_CLICK, Effect::RINGTONE_1, Effect::RINGTONE_2, Loading @@ -40,6 +41,7 @@ const std::vector<Effect> kEffects = { Effect::RINGTONE_11, Effect::RINGTONE_12, Effect::RINGTONE_13, Effect::RINGTONE_14, Effect::RINGTONE_15, Effect::TEXTURE_TICK}; // TODO(b/143992652): autogenerate const std::vector<EffectStrength> kEffectStrengths = {EffectStrength::LIGHT, EffectStrength::MEDIUM, EffectStrength::STRONG}; Loading Loading @@ -105,15 +107,22 @@ TEST_P(VibratorAidl, OnCallbackNotSupported) { } TEST_P(VibratorAidl, ValidateEffect) { std::vector<Effect> supported; ASSERT_TRUE(vibrator->getSupportedEffects(&supported).isOk()); for (Effect effect : kEffects) { bool isEffectSupported = std::find(supported.begin(), supported.end(), effect) != supported.end(); for (EffectStrength strength : kEffectStrengths) { int32_t lengthMs = 0; Status status = vibrator->perform(effect, strength, nullptr /*callback*/, &lengthMs); EXPECT_TRUE(status.isOk() || status.exceptionCode() == Status::EX_UNSUPPORTED_OPERATION); if (status.isOk()) { if (isEffectSupported) { EXPECT_TRUE(status.isOk()); EXPECT_GT(lengthMs, 0); } else { EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION); EXPECT_EQ(lengthMs, 0); } } Loading @@ -123,16 +132,29 @@ TEST_P(VibratorAidl, ValidateEffect) { TEST_P(VibratorAidl, ValidateEffectWithCallback) { if (!(capabilities & IVibrator::CAP_PERFORM_CALLBACK)) return; std::vector<Effect> supported; ASSERT_TRUE(vibrator->getSupportedEffects(&supported).isOk()); for (Effect effect : kEffects) { bool isEffectSupported = std::find(supported.begin(), supported.end(), effect) != supported.end(); for (EffectStrength strength : kEffectStrengths) { std::promise<void> completionPromise; std::future<void> completionFuture{completionPromise.get_future()}; sp<CompletionCallback> callback = new CompletionCallback([&completionPromise] { completionPromise.set_value(); }); int lengthMs; int lengthMs = 0; Status status = vibrator->perform(effect, strength, callback, &lengthMs); EXPECT_TRUE(status.isOk() || status.exceptionCode() == Status::EX_UNSUPPORTED_OPERATION); if (isEffectSupported) { EXPECT_TRUE(status.isOk()); EXPECT_GT(lengthMs, 0); } else { EXPECT_EQ(status.exceptionCode(), Status::EX_UNSUPPORTED_OPERATION); EXPECT_EQ(lengthMs, 0); } if (!status.isOk()) continue; std::chrono::milliseconds timeout{lengthMs * 2}; Loading