vibrator: fix missing _hidl_cb when stubbed
If there is no haptics device the HAL stubs all behaviour, as for some
reason if it fails to start then the whole Android boot fails. This
fixes a few issues like a missing _hidl_cb and does a bit of clean up.
diff --git a/vibrator/Vibrator.cpp b/vibrator/Vibrator.cpp
index 96eef07..50aef4f 100644
--- a/vibrator/Vibrator.cpp
+++ b/vibrator/Vibrator.cpp
@@ -45,10 +45,16 @@
using EffectStrength = ::android::hardware::vibrator::V1_0::EffectStrength;
using Effect = ::android::hardware::vibrator::V1_1::Effect_1_1;
-// These have to be kept in line with HAL version
+/*
+ * These have to be kept in line with HAL version
+ */
static constexpr Effect MAX_EFFECT = Effect::TICK;
static constexpr EffectStrength MAX_EFFECT_STRENGTH = EffectStrength::STRONG;
+/**
+ * Helper to index effects in the mEffects map.
+ * from their strength and effect type.
+ */
#define EFFECT_INDEX(effect, strength) \
((uint16_t)effect * (uint16_t)MAX_EFFECT_STRENGTH + (uint16_t)strength)
@@ -225,12 +231,10 @@
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);
- if (effect > MAX_EFFECT){
+ if (effect > MAX_EFFECT || mIsStub){
_hidl_cb(Status::UNSUPPORTED_OPERATION, 0);
return Void();
}
diff --git a/vibrator/Vibrator.h b/vibrator/Vibrator.h
index c86e99c..2dc8cb0 100644
--- a/vibrator/Vibrator.h
+++ b/vibrator/Vibrator.h
@@ -36,24 +36,30 @@
/* Test the bit with given index=offset in an unsigned char array */
#define testBit(bit, array) ((array[ucharIndexForBit(bit)] >> bitOffsetInUchar(bit)) & 1)
-/*
+/**
* Builder for ff_effect struct.
* We don't bother using weak_magnitude here as most hardware
* doesn't have any way to differentiate strong / weak haptics
- */
-#define FF_EFFECT(rumbleStrenth) \
- { \
- .type = FF_RUMBLE, \
- .id = -1, \
- .direction = 0, \
- .trigger = { .button = 0, .interval = 0, }, \
- .replay = { .length = 0, .delay = 0, }, \
- .u = { \
- .rumble = { \
- .strong_magnitude = rumbleStrenth, \
- .weak_magnitude = 0, \
- }, \
- }, \
+ */
+#define FF_EFFECT(rumbleStrenth) \
+ { \
+ .type = FF_RUMBLE, \
+ .id = -1, \
+ .direction = 0, \
+ .trigger = { \
+ .button = 0, \
+ .interval = 0, \
+ }, \
+ .replay = { \
+ .length = 0, \
+ .delay = 0, \
+ }, \
+ .u = { \
+ .rumble = { \
+ .strong_magnitude = rumbleStrenth, \
+ .weak_magnitude = 0, \
+ }, \
+ }, \
}
namespace android {