diff --git a/aidl/vibrator/Vibrator.cpp b/aidl/vibrator/Vibrator.cpp index f21eee31..95d5aec6 100644 --- a/aidl/vibrator/Vibrator.cpp +++ b/aidl/vibrator/Vibrator.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include namespace aidl { @@ -18,6 +19,14 @@ namespace android { namespace hardware { namespace vibrator { +static std::map CP_TRIGGER_EFFECTS { + { Effect::CLICK, 10 }, + { Effect::DOUBLE_CLICK, 14 }, + { Effect::HEAVY_CLICK, 23 }, + { Effect::TEXTURE_TICK, 50 }, + { Effect::TICK, 50 } +}; + /* * Write value to path and close file. */ @@ -48,6 +57,7 @@ static bool nodeExists(const std::string& path) { Vibrator::Vibrator() { mIsTimedOutVibrator = nodeExists(VIBRATOR_TIMEOUT_PATH); mHasTimedOutIntensity = nodeExists(VIBRATOR_INTENSITY_PATH); + mHasTimedOutEffect = nodeExists(VIBRATOR_CP_TRIGGER_PATH); } ndk::ScopedAStatus Vibrator::getCapabilities(int32_t* _aidl_return) { @@ -68,13 +78,18 @@ ndk::ScopedAStatus Vibrator::off() { } ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs, const std::shared_ptr& callback) { - ndk::ScopedAStatus status = activate(timeoutMs); + ndk::ScopedAStatus status; + + if (mHasTimedOutEffect) + writeNode(VIBRATOR_CP_TRIGGER_PATH, 0); // Clear all effects + + status = activate(timeoutMs); if (callback != nullptr) { std::thread([=] { - LOG(INFO) << "Starting on on another thread"; + LOG(DEBUG) << "Starting on on another thread"; usleep(timeoutMs * 1000); - LOG(INFO) << "Notifying on complete"; + LOG(DEBUG) << "Notifying on complete"; if (!callback->onComplete().isOk()) { LOG(ERROR) << "Failed to call onComplete"; } @@ -86,26 +101,34 @@ ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs, const std::shared_ptr& callback, int32_t* _aidl_return) { ndk::ScopedAStatus status; - uint8_t amplitude; - uint32_t ms; + uint32_t amplitude = strengthToAmplitude(strength, &status); + uint32_t ms = 1000; - amplitude = strengthToAmplitude(strength, &status); - if (!status.isOk()) { + if (!status.isOk()) return status; - } + + activate(0); setAmplitude(amplitude); - ms = effectToMs(effect, &status); - if (!status.isOk()) { - return status; + if (mHasTimedOutEffect && CP_TRIGGER_EFFECTS.find(effect) != CP_TRIGGER_EFFECTS.end()) { + writeNode(VIBRATOR_CP_TRIGGER_PATH, CP_TRIGGER_EFFECTS[effect]); + } else { + if (mHasTimedOutEffect) + writeNode(VIBRATOR_CP_TRIGGER_PATH, 0); // Clear previous effect + + ms = effectToMs(effect, &status); + + if (!status.isOk()) + return status; } + status = activate(ms); if (callback != nullptr) { std::thread([=] { - LOG(INFO) << "Starting perform on another thread"; + LOG(DEBUG) << "Starting perform on another thread"; usleep(ms * 1000); - LOG(INFO) << "Notifying perform complete"; + LOG(DEBUG) << "Notifying perform complete"; callback->onComplete(); }).detach(); } @@ -255,19 +278,18 @@ uint8_t Vibrator::strengthToAmplitude(EffectStrength strength, ndk::ScopedAStatu uint32_t Vibrator::effectToMs(Effect effect, ndk::ScopedAStatus* status) { *status = ndk::ScopedAStatus::ok(); - switch (effect) { case Effect::CLICK: - return 20; + return 10; case Effect::DOUBLE_CLICK: - return 25; - case Effect::HEAVY_CLICK: - return 30; + return 15; case Effect::TICK: case Effect::TEXTURE_TICK: case Effect::THUD: case Effect::POP: - return 15; + return 5; + case Effect::HEAVY_CLICK: + return 10; case Effect::RINGTONE_1: case Effect::RINGTONE_2: case Effect::RINGTONE_3: @@ -283,9 +305,8 @@ uint32_t Vibrator::effectToMs(Effect effect, ndk::ScopedAStatus* status) { case Effect::RINGTONE_13: case Effect::RINGTONE_14: case Effect::RINGTONE_15: - return 300; + return 30000; } - *status = ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); return 0; } diff --git a/aidl/vibrator/Vibrator.h b/aidl/vibrator/Vibrator.h index 67705275..785ad9d8 100644 --- a/aidl/vibrator/Vibrator.h +++ b/aidl/vibrator/Vibrator.h @@ -14,6 +14,7 @@ #define VIBRATOR_TIMEOUT_PATH "/sys/class/timed_output/vibrator/enable" #define VIBRATOR_INTENSITY_PATH "/sys/class/timed_output/vibrator/intensity" +#define VIBRATOR_CP_TRIGGER_PATH "/sys/class/timed_output/vibrator/cp_trigger_index" using ::aidl::android::hardware::vibrator::IVibratorCallback; using ::aidl::android::hardware::vibrator::Braking; @@ -67,6 +68,7 @@ private: bool mIsTimedOutVibrator; bool mHasTimedOutIntensity; + bool mHasTimedOutEffect; }; } // namespace vibrator diff --git a/aidl/vibrator/android.hardware.vibrator-service.samsung.rc b/aidl/vibrator/android.hardware.vibrator-service.samsung.rc index 3f439057..f211456f 100644 --- a/aidl/vibrator/android.hardware.vibrator-service.samsung.rc +++ b/aidl/vibrator/android.hardware.vibrator-service.samsung.rc @@ -1,3 +1,8 @@ +on init + chown system system /sys/class/timed_output/vibrator/cp_trigger_index + chown system system /sys/class/timed_output/vibrator/enable + chown system system /sys/class/timed_output/vibrator/intensity + service vendor.vibrator-default /vendor/bin/hw/android.hardware.vibrator-service.samsung class hal user system