vibrator: Always enable effects to modify durations

Change-Id: I5c71aa34d8a095e7fefe3add22b1853e2e3503cc
This commit is contained in:
Erfan Abdi
2023-08-06 09:21:31 +03:30
committed by Matsvei Niaverau
parent 19190288a8
commit 36ec620cc0
2 changed files with 13 additions and 23 deletions

View File

@@ -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<IVibratorCallback>& 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<IVibratorCallback>& /* callback */,
int32_t* /* _aidl_return */) {
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
#endif
}
#ifdef VIBRATOR_SUPPORTS_EFFECTS
ndk::ScopedAStatus Vibrator::getSupportedEffects(std::vector<Effect>* _aidl_return) {
for (auto const& pair : vibEffects) _aidl_return->push_back(pair.first);
#else
ndk::ScopedAStatus Vibrator::getSupportedEffects(std::vector<Effect>* /* _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) {

View File

@@ -7,9 +7,7 @@
#pragma once
#include <aidl/android/hardware/vibrator/BnVibrator.h>
#ifdef VIBRATOR_SUPPORTS_EFFECTS
#include <map>
#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<EffectStrength, float> 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<Effect, int32_t> 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