sm8350-common: vibrator: remove unused led vibrator device support

This commit is contained in:
Cosmin Tanislav 2021-09-05 14:56:57 +03:00
parent 1e781f9173
commit 67fe0e2f57
2 changed files with 3 additions and 122 deletions

View File

@ -61,8 +61,6 @@ namespace vibrator {
#define test_bit(bit, array) ((array)[(bit)/8] & (1<<((bit)%8))) #define test_bit(bit, array) ((array)[(bit)/8] & (1<<((bit)%8)))
static const char LED_DEVICE[] = "/sys/class/leds/vibrator";
InputFFDevice::InputFFDevice() InputFFDevice::InputFFDevice()
{ {
DIR *dp; DIR *dp;
@ -305,98 +303,9 @@ int InputFFDevice::playEffect(int effectId, EffectStrength es, long *playLengthM
return play(effectId, INVALID_VALUE, playLengthMs); 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) { ndk::ScopedAStatus Vibrator::getCapabilities(int32_t* _aidl_return) {
*_aidl_return = IVibrator::CAP_ON_CALLBACK; *_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) if (ff.mSupportGain)
*_aidl_return |= IVibrator::CAP_AMPLITUDE_CONTROL; *_aidl_return |= IVibrator::CAP_AMPLITUDE_CONTROL;
if (ff.mSupportEffects) if (ff.mSupportEffects)
@ -412,9 +321,7 @@ ndk::ScopedAStatus Vibrator::off() {
int ret; int ret;
ALOGD("QTI Vibrator off"); ALOGD("QTI Vibrator off");
if (ledVib.mDetected)
ret = ledVib.off();
else
ret = ff.off(); ret = ff.off();
if (ret != 0) if (ret != 0)
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_SERVICE_SPECIFIC)); return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_SERVICE_SPECIFIC));
@ -427,11 +334,8 @@ ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs,
int ret; int ret;
ALOGD("Vibrator on for timeoutMs: %d", timeoutMs); 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) if (ret != 0)
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_SERVICE_SPECIFIC)); return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_SERVICE_SPECIFIC));
@ -453,9 +357,6 @@ ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength es, const std
long playLengthMs; long playLengthMs;
int ret; int ret;
if (ledVib.mDetected)
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
ALOGD("Vibrator perform effect %d", effect); ALOGD("Vibrator perform effect %d", effect);
if (effect < Effect::CLICK || if (effect < Effect::CLICK ||
@ -483,9 +384,6 @@ ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength es, const std
} }
ndk::ScopedAStatus Vibrator::getSupportedEffects(std::vector<Effect>* _aidl_return) { ndk::ScopedAStatus Vibrator::getSupportedEffects(std::vector<Effect>* _aidl_return) {
if (ledVib.mDetected)
return ndk::ScopedAStatus::ok();
*_aidl_return = {Effect::CLICK, Effect::DOUBLE_CLICK, Effect::TICK, Effect::THUD, *_aidl_return = {Effect::CLICK, Effect::DOUBLE_CLICK, Effect::TICK, Effect::THUD,
Effect::POP, Effect::HEAVY_CLICK}; Effect::POP, Effect::HEAVY_CLICK};
@ -496,9 +394,6 @@ ndk::ScopedAStatus Vibrator::setAmplitude(float amplitude) {
uint8_t tmp; uint8_t tmp;
int ret; int ret;
if (ledVib.mDetected)
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
ALOGD("Vibrator set amplitude: %f", amplitude); ALOGD("Vibrator set amplitude: %f", amplitude);
if (amplitude <= 0.0f || amplitude > 1.0f) if (amplitude <= 0.0f || amplitude > 1.0f)
@ -516,9 +411,6 @@ ndk::ScopedAStatus Vibrator::setAmplitude(float amplitude) {
} }
ndk::ScopedAStatus Vibrator::setExternalControl(bool enabled) { ndk::ScopedAStatus Vibrator::setExternalControl(bool enabled) {
if (ledVib.mDetected)
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
ALOGD("Vibrator set external control: %d", enabled); ALOGD("Vibrator set external control: %d", enabled);
if (!ff.mSupportExternalControl) if (!ff.mSupportExternalControl)
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION)); return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));

View File

@ -54,20 +54,9 @@ private:
int16_t mCurrMagnitude; 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 { class Vibrator : public BnVibrator {
public: public:
class InputFFDevice ff; class InputFFDevice ff;
class LedVibratorDevice ledVib;
ndk::ScopedAStatus getCapabilities(int32_t* _aidl_return) override; ndk::ScopedAStatus getCapabilities(int32_t* _aidl_return) override;
ndk::ScopedAStatus off() override; ndk::ScopedAStatus off() override;
ndk::ScopedAStatus on(int32_t timeoutMs, ndk::ScopedAStatus on(int32_t timeoutMs,