From 36ec620cc0da46608dbff01155c4eae006b24eab Mon Sep 17 00:00:00 2001 From: Erfan Abdi Date: Sun, 6 Aug 2023 09:21:31 +0330 Subject: [PATCH] vibrator: Always enable effects to modify durations Change-Id: I5c71aa34d8a095e7fefe3add22b1853e2e3503cc --- aidl/vibrator/Vibrator.cpp | 26 +++++++++----------------- aidl/vibrator/Vibrator.h | 10 ++++------ 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/aidl/vibrator/Vibrator.cpp b/aidl/vibrator/Vibrator.cpp index f193fd4..3ff1aa9 100644 --- a/aidl/vibrator/Vibrator.cpp +++ b/aidl/vibrator/Vibrator.cpp @@ -63,7 +63,6 @@ ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs, return ndk::ScopedAStatus::ok(); } -#ifdef VIBRATOR_SUPPORTS_EFFECTS ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength strength, const std::shared_ptr& callback, int32_t* _aidl_return) { @@ -76,7 +75,9 @@ ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength strength, if (vibStrengths.find(strength) == vibStrengths.end()) return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); +#ifdef VIBRATOR_SUPPORTS_EFFECTS setAmplitude(vibStrengths[strength]); +#endif timeoutMs = vibEffects[effect]; @@ -94,30 +95,24 @@ ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength strength, *_aidl_return = timeoutMs; return ndk::ScopedAStatus::ok(); -#else -ndk::ScopedAStatus Vibrator::perform(Effect /* effect */, EffectStrength /* strength */, - const std::shared_ptr& /* callback */, - int32_t* /* _aidl_return */) { - return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); -#endif } -#ifdef VIBRATOR_SUPPORTS_EFFECTS ndk::ScopedAStatus Vibrator::getSupportedEffects(std::vector* _aidl_return) { - for (auto const& pair : vibEffects) _aidl_return->push_back(pair.first); -#else -ndk::ScopedAStatus Vibrator::getSupportedEffects(std::vector* /* _aidl_return */) { -#endif + for (auto const& pair : vibEffects) + _aidl_return->push_back(pair.first); + return ndk::ScopedAStatus::ok(); } -#ifdef VIBRATOR_SUPPORTS_EFFECTS ndk::ScopedAStatus Vibrator::setAmplitude(float amplitude) { +#ifdef VIBRATOR_SUPPORTS_EFFECTS int32_t intensity; +#endif if (amplitude <= 0.0f || amplitude > 1.0f) return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_ARGUMENT)); +#ifdef VIBRATOR_SUPPORTS_EFFECTS LOG(VERBOSE) << "Setting amplitude: " << amplitude; intensity = amplitude * mVibratorStrengthMax; @@ -125,12 +120,9 @@ ndk::ScopedAStatus Vibrator::setAmplitude(float amplitude) { LOG(VERBOSE) << "Setting intensity: " << intensity; if (mVibratorStrengthSupported) setNode(kVibratorStrength, intensity); +#endif return ndk::ScopedAStatus::ok(); -#else -ndk::ScopedAStatus Vibrator::setAmplitude(float amplitude __unused) { - return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); -#endif } ndk::ScopedAStatus Vibrator::setExternalControl(bool enabled __unused) { diff --git a/aidl/vibrator/Vibrator.h b/aidl/vibrator/Vibrator.h index b57ad8c..2a7c1ed 100644 --- a/aidl/vibrator/Vibrator.h +++ b/aidl/vibrator/Vibrator.h @@ -7,9 +7,7 @@ #pragma once #include -#ifdef VIBRATOR_SUPPORTS_EFFECTS #include -#endif namespace aidl { namespace android { @@ -26,10 +24,10 @@ const std::string kVibratorActivate = "/sys/class/leds/vibrator/activate"; #ifdef VIBRATOR_SUPPORTS_EFFECTS const std::string kVibratorStrength = "/sys/kernel/thunderquake_engine/level"; const std::string kVibratorStrengthMax = "/sys/kernel/thunderquake_engine/max"; +#endif static std::map vibStrengths = { {EffectStrength::LIGHT, 0.25}, {EffectStrength::MEDIUM, 0.5}, {EffectStrength::STRONG, 1}}; -#endif class Vibrator : public BnVibrator { public: @@ -70,14 +68,14 @@ class Vibrator : public BnVibrator { private: static ndk::ScopedAStatus setNode(const std::string path, const int32_t value); static int getIntProperty(const std::string& key, const int fallback); -#ifdef VIBRATOR_SUPPORTS_EFFECTS - static bool exists(const std::string path); - static int getNode(const std::string path, const int fallback); std::map vibEffects = { {Effect::CLICK, getIntProperty("click" + kVibratorPropDuration, 50)}, {Effect::TICK, getIntProperty("tick" + kVibratorPropDuration, 32)}, {Effect::TEXTURE_TICK, getIntProperty("texture_tick" + kVibratorPropDuration, 25)}, }; +#ifdef VIBRATOR_SUPPORTS_EFFECTS + static bool exists(const std::string path); + static int getNode(const std::string path, const int fallback); bool mVibratorStrengthSupported; int mVibratorStrengthMax; #endif