summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinux Build Service Account <lnxbuild@localhost>2020-08-19 19:24:48 -0700
committerLinux Build Service Account <lnxbuild@localhost>2020-08-19 19:24:48 -0700
commit522182998f7c6d9780ad5c961d784a66ffbdcbfc (patch)
tree6fe0685986743c43447f0927a4aadb724673a260
parent32c1c70bc991dc0fb223a5b98dbe5ed1673964ea (diff)
parentdaef05db0a49485cd0b3efb6aafd245ccec3ed67 (diff)
Merge daef05db0a49485cd0b3efb6aafd245ccec3ed67 on remote branch
Change-Id: Ie986c5529810b18716a7cf504dd3833e48658680
-rw-r--r--aidl/Vibrator.cpp115
-rw-r--r--aidl/include/Vibrator.h11
-rw-r--r--vibrator-vendor-product.mk2
3 files changed, 125 insertions, 3 deletions
diff --git a/aidl/Vibrator.cpp b/aidl/Vibrator.cpp
index 9a3aa9b..13b254a 100644
--- a/aidl/Vibrator.cpp
+++ b/aidl/Vibrator.cpp
@@ -58,6 +58,8 @@ 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;
@@ -293,8 +295,98 @@ 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)
@@ -310,7 +402,10 @@ ndk::ScopedAStatus Vibrator::off() {
int ret;
ALOGD("QTI Vibrator off");
- ret = ff.off();
+ if (ledVib.mDetected)
+ ret = ledVib.off();
+ else
+ ret = ff.off();
if (ret != 0)
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_SERVICE_SPECIFIC));
@@ -322,7 +417,11 @@ ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs,
int ret;
ALOGD("Vibrator on for timeoutMs: %d", timeoutMs);
- ret = ff.on(timeoutMs);
+ if (ledVib.mDetected)
+ ret = ledVib.on(timeoutMs);
+ else
+ ret = ff.on(timeoutMs);
+
if (ret != 0)
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_SERVICE_SPECIFIC));
@@ -344,6 +443,9 @@ 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 ||
@@ -371,6 +473,9 @@ ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength es, const std
}
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,
Effect::POP, Effect::HEAVY_CLICK};
@@ -381,6 +486,9 @@ 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)
@@ -398,6 +506,9 @@ 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/aidl/include/Vibrator.h b/aidl/include/Vibrator.h
index 3132c44..e0694ca 100644
--- a/aidl/include/Vibrator.h
+++ b/aidl/include/Vibrator.h
@@ -54,9 +54,20 @@ 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,
diff --git a/vibrator-vendor-product.mk b/vibrator-vendor-product.mk
index f7d19ec..c6c49fe 100644
--- a/vibrator-vendor-product.mk
+++ b/vibrator-vendor-product.mk
@@ -1,4 +1,4 @@
-ifeq ($(call is-board-platform-in-list, msmnile kona lahaina shima), true)
+ifeq ($(call is-board-platform-in-list, msmnile kona lahaina shima lito atoll sm6150), true)
QTI_VIBRATOR_HAL_SERVICE := \
vendor.qti.hardware.vibrator.service