vibrator/cs40l26: update default scales of click, tick and long vib

Flow:
1. If the calibration file exist, use the value.
2. If no property, use the default setting {5,95}.

Bug: 356823441
Bug: 322937989
Test: Check dumpsys records for the scaling results.
  case1: no calibration file and properties.
  case2: valid property range
  case3: float property (invalid)
Flag: EXEMPT bugfix
Change-Id: Ia3e89f34189e9725ab01d85d931925129745608c
(cherry picked from commit 4063493a64fcd0f20b49a492106f58b0e3349c5c)
This commit is contained in:
Tai Kuo 2024-02-01 15:22:37 +08:00
parent 03e46a5e0f
commit 46065a4462
3 changed files with 22 additions and 12 deletions

View file

@ -103,6 +103,19 @@ inline Enable_If_Unsigned<T, T> getProperty(const std::string &key, const T def)
return ::android::base::GetUintProperty(key, def);
}
template <typename T, size_t N>
inline std::array<T, N> getProperty(const std::string &key, const std::array<T, N> &def) {
std::string value = ::android::base::GetProperty(key, "");
if (!value.empty()) {
std::array<T, N> result{0};
std::stringstream stream{value};
utils::unpack(stream, &result);
if (stream && stream.eof())
return result;
}
return def;
}
template <>
inline bool getProperty<bool>(const std::string &key, const bool def) {
return ::android::base::GetBoolProperty(key, def);

View file

@ -318,9 +318,9 @@ class HwCal : public Vibrator::HwCal, private HwCalBase {
static constexpr uint32_t VERSION_DEFAULT = 2;
static constexpr int32_t DEFAULT_FREQUENCY_SHIFT = 0;
static constexpr std::array<uint32_t, 2> V_TICK_DEFAULT = {1, 100};
static constexpr std::array<uint32_t, 2> V_CLICK_DEFAULT = {1, 100};
static constexpr std::array<uint32_t, 2> V_LONG_DEFAULT = {1, 100};
static constexpr std::array<uint32_t, 2> V_TICK_DEFAULT = {5, 95};
static constexpr std::array<uint32_t, 2> V_CLICK_DEFAULT = {5, 95};
static constexpr std::array<uint32_t, 2> V_LONG_DEFAULT = {5, 95};
public:
HwCal() {}
@ -370,22 +370,19 @@ class HwCal : public Vibrator::HwCal, private HwCalBase {
if (getPersist(TICK_VOLTAGES_CONFIG, value)) {
return true;
}
*value = V_TICK_DEFAULT;
return true;
return getProperty(TICK_VOLTAGES_CONFIG, value, V_TICK_DEFAULT);
}
bool getClickVolLevels(std::array<uint32_t, 2> *value) override {
if (getPersist(CLICK_VOLTAGES_CONFIG, value)) {
return true;
}
*value = V_CLICK_DEFAULT;
return true;
return getProperty(CLICK_VOLTAGES_CONFIG, value, V_CLICK_DEFAULT);
}
bool getLongVolLevels(std::array<uint32_t, 2> *value) override {
if (getPersist(LONG_VOLTAGES_CONFIG, value)) {
return true;
}
*value = V_LONG_DEFAULT;
return true;
return getProperty(LONG_VOLTAGES_CONFIG, value, V_LONG_DEFAULT);
}
bool isChirpEnabled() override {
return utils::getProperty("persist.vendor.vibrator.hal.chirp.enabled", false);

View file

@ -30,9 +30,9 @@ using ::testing::Test;
class HwCalTest : public Test {
protected:
static constexpr std::array<uint32_t, 2> V_TICK_DEFAULT = {1, 100};
static constexpr std::array<uint32_t, 2> V_CLICK_DEFAULT = {1, 100};
static constexpr std::array<uint32_t, 2> V_LONG_DEFAULT = {1, 100};
static constexpr std::array<uint32_t, 2> V_TICK_DEFAULT = {5, 95};
static constexpr std::array<uint32_t, 2> V_CLICK_DEFAULT = {5, 95};
static constexpr std::array<uint32_t, 2> V_LONG_DEFAULT = {5, 95};
public:
void SetUp() override { setenv("CALIBRATION_FILEPATH", mCalFile.path, true); }