vibrator: don't fail on devices without haptics
Previously on kernels which don't have haptics support the service would
fail and cause Android UI not to start. Stub out support instead so that
Android will still start, just without haptics.
diff --git a/device-common.mk b/device-common.mk
index f3e0380..e5a73bb 100644
--- a/device-common.mk
+++ b/device-common.mk
@@ -177,8 +177,8 @@
android.hardware.light@2.0-service
# Haptics
-# PRODUCT_PACKAGES += \
-# android.hardware.vibrator@1.1-service.sdm845
+PRODUCT_PACKAGES += \
+ android.hardware.vibrator@1.1-service.sdm845
# Copy standard platform config files
PRODUCT_COPY_FILES += \
diff --git a/vibrator/Vibrator.cpp b/vibrator/Vibrator.cpp
index 25a031e..96eef07 100644
--- a/vibrator/Vibrator.cpp
+++ b/vibrator/Vibrator.cpp
@@ -59,6 +59,10 @@
{
// We just keep the input device open the whole time we're running.
// Closing / reopening it seems to break things.
+ if (mInputDevPath.length() < 2) {
+ mIsStub = true;
+ return;
+ }
mfd = openInputDev();
if (mfd < 0) {
ALOGE("%s() can't open FF input device %s", __func__, mInputDevPath.c_str());
@@ -93,11 +97,15 @@
}
int Vibrator::openInputDev() {
+ if (mIsStub)
+ return 0;
return open(mInputDevPath.c_str(), O_RDWR|O_CLOEXEC);
}
void Vibrator::uploadEffectToKernel(struct ff_effect* effect) {
int ret;
+ if (mIsStub)
+ return;
ret = ioctl(mfd, EVIOCSFF, effect);
if (ret < 0) {
@@ -107,6 +115,8 @@
void Vibrator::deleteEffectFromKernel(struct ff_effect* effect) { // Unload rumble effect
int ret;
+ if (mIsStub)
+ return;
ret = ioctl(mfd, EVIOCRMFF, effect);
if (ret < 0) {
@@ -119,6 +129,8 @@
// Methods from ::android::hardware::vibrator::V1_1::IVibrator follow.
Return<Status> Vibrator::on(uint32_t timeoutMs) {
struct ff_effect* effect;
+ if (mIsStub)
+ return Status::OK;
// If the active effect is set, use it instead of the default
if (mActiveEffectId < 0) {
effect = &mEffects[DEFAULT_EFFECT_ID];
@@ -151,6 +163,8 @@
ALOGV("%s", __func__);
struct input_event stop;
struct ff_effect* effect;
+ if (mIsStub)
+ return Status::OK;
// If the active effect is set, use it instead of the default
if (mActiveEffectId < 0) {
ALOGV("%s() no active effect, stopping default", __func__);
@@ -211,6 +225,8 @@
Status status = Status::OK;
uint32_t timeMs = 9;
bool doubleClick = effect == Effect::DOUBLE_CLICK;
+ if (mIsStub)
+ return Void();
ALOGV("%s() effect = %d, strength = %d", __func__, effect, (int)strength);
diff --git a/vibrator/Vibrator.h b/vibrator/Vibrator.h
index 8e6140d..c86e99c 100644
--- a/vibrator/Vibrator.h
+++ b/vibrator/Vibrator.h
@@ -90,6 +90,11 @@
std::string mInputDevPath;
int mfd;
int mActiveEffectId;
+ // If the haptics device path is invalid
+ // the just stub all behaviour. Otherwise
+ // the device will fail to boot because the haptics
+ // service keeps crashing.
+ bool mIsStub;
// Look up table of effects by type and strength
std::map<int, struct ff_effect> mEffects;
diff --git a/vibrator/service.cpp b/vibrator/service.cpp
index 349b998..f81da17 100644
--- a/vibrator/service.cpp
+++ b/vibrator/service.cpp
@@ -95,7 +95,8 @@
status_t registerVibratorService() {
std::string hapticsDev = findFirstFFDevice();
if (hapticsDev.length() < 2)
- return UNKNOWN_ERROR;
+ ALOGE("Couldn't find a haptics device, stubbing HAL to prevent"
+ " boot failing");
sp<IVibrator> vibrator = new Vibrator(hapticsDev);
return vibrator->registerAsService();