vibrator: Add click and tick duration config properties
Change-Id: I2d89b727960e6b015543c598fff68ada7ca84ae7
diff --git a/aidl/vibrator/Vibrator.h b/aidl/vibrator/Vibrator.h
index dfbc703..42df2fa 100644
--- a/aidl/vibrator/Vibrator.h
+++ b/aidl/vibrator/Vibrator.h
@@ -26,6 +26,9 @@
namespace hardware {
namespace vibrator {
+const std::string kVibratorPropPrefix = "ro.vendor.vibrator.hal.";
+const std::string kVibratorPropDuration = ".duration";
+
const std::string kVibratorState = "/sys/class/leds/vibrator/state";
const std::string kVibratorDuration = "/sys/class/leds/vibrator/duration";
const std::string kVibratorActivate = "/sys/class/leds/vibrator/activate";
@@ -34,11 +37,6 @@
const std::string kVibratorStrength = "/sys/kernel/thunderquake_engine/level";
const std::string kVibratorStrengthMax = "/sys/kernel/thunderquake_engine/max";
-static std::map<Effect, int32_t> vibEffects = {
- { Effect::CLICK, 50 },
- { Effect::TICK, 32 }
-};
-
static std::map<EffectStrength, float> vibStrengths = {
{ EffectStrength::LIGHT, 0.25 },
{ EffectStrength::MEDIUM, 0.5 },
@@ -83,9 +81,14 @@
const std::shared_ptr<IVibratorCallback> &callback) override;
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) },
+ };
bool mVibratorStrengthSupported;
int mVibratorStrengthMax;
#endif
diff --git a/aidl/vibrator/VibratorUtils.cpp b/aidl/vibrator/VibratorUtils.cpp
index db7bc0a..482cdf8 100644
--- a/aidl/vibrator/VibratorUtils.cpp
+++ b/aidl/vibrator/VibratorUtils.cpp
@@ -17,6 +17,7 @@
#include "Vibrator.h"
#include <android-base/logging.h>
+#include <android-base/properties.h>
#include <fstream>
namespace aidl {
@@ -80,6 +81,10 @@
}
#endif
+int Vibrator::getIntProperty(const std::string& key, const int fallback) {
+ return ::android::base::GetIntProperty(kVibratorPropPrefix + key, fallback);
+}
+
} // namespace vibrator
} // namespace hardware
} // namespace android