diff --git a/vibrator/effect/Android.bp b/vibrator/effect/Android.bp index bfd7f11..1ee28e1 100644 --- a/vibrator/effect/Android.bp +++ b/vibrator/effect/Android.bp @@ -9,6 +9,7 @@ cc_library_shared { "effect.cpp", ], shared_libs: [ + "android.hardware.vibrator-V2-ndk", "libbase", "libcutils", "libutils", diff --git a/vibrator/effect/effect.cpp b/vibrator/effect/effect.cpp index a11ba39..5655922 100644 --- a/vibrator/effect/effect.cpp +++ b/vibrator/effect/effect.cpp @@ -34,6 +34,7 @@ #define LOG_TAG "libqtivibratoreffect.xiaomi" +#include #include #include #include @@ -43,6 +44,8 @@ #include "effect.h" +using aidl::android::hardware::vibrator::Effect; + namespace { const uint32_t kDefaultPlayRateHz = 24000; @@ -81,6 +84,21 @@ std::unique_ptr readEffectStreamFromFile(uint32_t uniqueEffectId) result.first->second.data()); } +std::unique_ptr duplicateEffect(const effect_stream* effectStream, + uint32_t newEffectId) { + const std::uint32_t newEffectLength = effectStream->length * 4; + std::vector fifoData(newEffectLength); + + std::copy(effectStream->data, effectStream->data + effectStream->length, fifoData.begin()); + std::copy(effectStream->data, effectStream->data + effectStream->length, + fifoData.begin() + newEffectLength - effectStream->length); + + auto result = sEffectFifoData.emplace(newEffectId, std::move(fifoData)); + + return std::make_unique(newEffectId, newEffectLength, kDefaultPlayRateHz, + result.first->second.data()); +} + } // namespace const struct effect_stream* get_effect_stream(uint32_t effectId) { @@ -91,6 +109,14 @@ const struct effect_stream* get_effect_stream(uint32_t effectId) { if (newEffectStream) { auto result = sEffectStreams.emplace(effectId, *newEffectStream); return &result.first->second; + } else if (effectId == (uint32_t)Effect::DOUBLE_CLICK) { + LOG(VERBOSE) << "Could not get double click effect, duplicating click effect"; + newEffectStream = duplicateEffect(get_effect_stream((uint32_t)Effect::CLICK), + (uint32_t)Effect::DOUBLE_CLICK); + if (newEffectStream) { + auto result = sEffectStreams.emplace(effectId, *newEffectStream); + return &result.first->second; + } } } else { return &it->second;