diff --git a/vibrator/Vibrator.cpp b/vibrator/Vibrator.cpp index 8f397c8..4e1891c 100644 --- a/vibrator/Vibrator.cpp +++ b/vibrator/Vibrator.cpp @@ -61,8 +61,6 @@ namespace vibrator { #define test_bit(bit, array) ((array)[(bit)/8] & (1<<((bit)%8))) -static const char LED_DEVICE[] = "/sys/class/leds/vibrator"; - InputFFDevice::InputFFDevice() { DIR *dp; @@ -305,98 +303,9 @@ int InputFFDevice::playEffect(int effectId, EffectStrength es, long *playLengthM return play(effectId, INVALID_VALUE, playLengthMs); } -LedVibratorDevice::LedVibratorDevice() { - char devicename[PATH_MAX]; - int fd; - - mDetected = false; - - snprintf(devicename, sizeof(devicename), "%s/%s", LED_DEVICE, "activate"); - fd = TEMP_FAILURE_RETRY(open(devicename, O_RDWR)); - if (fd < 0) { - ALOGE("open %s failed, errno = %d", devicename, errno); - return; - } - - mDetected = true; -} - -int LedVibratorDevice::write_value(const char *file, const char *value) { - int fd; - int ret; - - fd = TEMP_FAILURE_RETRY(open(file, O_WRONLY)); - if (fd < 0) { - ALOGE("open %s failed, errno = %d", file, errno); - return -errno; - } - - ret = TEMP_FAILURE_RETRY(write(fd, value, strlen(value) + 1)); - if (ret == -1) { - ret = -errno; - } else if (ret != strlen(value) + 1) { - /* even though EAGAIN is an errno value that could be set - by write() in some cases, none of them apply here. So, this return - value can be clearly identified when debugging and suggests the - caller that it may try to call vibrator_on() again */ - ret = -EAGAIN; - } else { - ret = 0; - } - - errno = 0; - close(fd); - - return ret; -} - -int LedVibratorDevice::on(int32_t timeoutMs) { - char file[PATH_MAX]; - char value[32]; - int ret; - - snprintf(file, sizeof(file), "%s/%s", LED_DEVICE, "state"); - ret = write_value(file, "1"); - if (ret < 0) - goto error; - - snprintf(file, sizeof(file), "%s/%s", LED_DEVICE, "duration"); - snprintf(value, sizeof(value), "%u\n", timeoutMs); - ret = write_value(file, value); - if (ret < 0) - goto error; - - snprintf(file, sizeof(file), "%s/%s", LED_DEVICE, "activate"); - ret = write_value(file, "1"); - if (ret < 0) - goto error; - - return 0; - -error: - ALOGE("Failed to turn on vibrator ret: %d\n", ret); - return ret; -} - -int LedVibratorDevice::off() -{ - char file[PATH_MAX]; - int ret; - - snprintf(file, sizeof(file), "%s/%s", LED_DEVICE, "activate"); - ret = write_value(file, "0"); - return ret; -} - ndk::ScopedAStatus Vibrator::getCapabilities(int32_t* _aidl_return) { *_aidl_return = IVibrator::CAP_ON_CALLBACK; - if (ledVib.mDetected) { - *_aidl_return |= IVibrator::CAP_PERFORM_CALLBACK; - ALOGD("QTI Vibrator reporting capabilities: %d", *_aidl_return); - return ndk::ScopedAStatus::ok(); - } - if (ff.mSupportGain) *_aidl_return |= IVibrator::CAP_AMPLITUDE_CONTROL; if (ff.mSupportEffects) @@ -412,10 +321,8 @@ ndk::ScopedAStatus Vibrator::off() { int ret; ALOGD("QTI Vibrator off"); - if (ledVib.mDetected) - ret = ledVib.off(); - else - ret = ff.off(); + + ret = ff.off(); if (ret != 0) return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_SERVICE_SPECIFIC)); @@ -427,11 +334,8 @@ ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs, int ret; ALOGD("Vibrator on for timeoutMs: %d", timeoutMs); - if (ledVib.mDetected) - ret = ledVib.on(timeoutMs); - else - ret = ff.on(timeoutMs); + ret = ff.on(timeoutMs); if (ret != 0) return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_SERVICE_SPECIFIC)); @@ -453,9 +357,6 @@ ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength es, const std long playLengthMs; int ret; - if (ledVib.mDetected) - return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); - ALOGD("Vibrator perform effect %d", effect); if (effect < Effect::CLICK || @@ -483,9 +384,6 @@ ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength es, const std } ndk::ScopedAStatus Vibrator::getSupportedEffects(std::vector* _aidl_return) { - if (ledVib.mDetected) - return ndk::ScopedAStatus::ok(); - *_aidl_return = {Effect::CLICK, Effect::DOUBLE_CLICK, Effect::TICK, Effect::THUD, Effect::POP, Effect::HEAVY_CLICK}; @@ -496,9 +394,6 @@ ndk::ScopedAStatus Vibrator::setAmplitude(float amplitude) { uint8_t tmp; int ret; - if (ledVib.mDetected) - return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); - ALOGD("Vibrator set amplitude: %f", amplitude); if (amplitude <= 0.0f || amplitude > 1.0f) @@ -516,9 +411,6 @@ ndk::ScopedAStatus Vibrator::setAmplitude(float amplitude) { } ndk::ScopedAStatus Vibrator::setExternalControl(bool enabled) { - if (ledVib.mDetected) - return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); - ALOGD("Vibrator set external control: %d", enabled); if (!ff.mSupportExternalControl) return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); diff --git a/vibrator/include/Vibrator.h b/vibrator/include/Vibrator.h index e0694ca..3132c44 100644 --- a/vibrator/include/Vibrator.h +++ b/vibrator/include/Vibrator.h @@ -54,20 +54,9 @@ private: int16_t mCurrMagnitude; }; -class LedVibratorDevice { -public: - LedVibratorDevice(); - int on(int32_t timeoutMs); - int off(); - bool mDetected; -private: - int write_value(const char *file, const char *value); -}; - class Vibrator : public BnVibrator { public: class InputFFDevice ff; - class LedVibratorDevice ledVib; ndk::ScopedAStatus getCapabilities(int32_t* _aidl_return) override; ndk::ScopedAStatus off() override; ndk::ScopedAStatus on(int32_t timeoutMs,