mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 11:36:00 +00:00
vibrator: example: Enforce API-Specific Effect Range
Bug: 130265348 Test: vts-tradefed run singleCommand vts-hal -m VtsHalVibratorV1_2Target Change-Id: I45cc2ad64295d6a63ef3280d4d5b869e19786ce3 Signed-off-by: Harpreet "Eli" Sangha <eliptus@google.com>
This commit is contained in:
@@ -56,27 +56,30 @@ Return<bool> Vibrator::supportsAmplitudeControl() {
|
||||
}
|
||||
|
||||
Return<Status> Vibrator::setAmplitude(uint8_t amplitude) {
|
||||
if (!amplitude) {
|
||||
return Status::BAD_VALUE;
|
||||
}
|
||||
ALOGI("Amplitude: %u -> %u\n", mAmplitude, amplitude);
|
||||
mAmplitude = amplitude;
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
Return<void> Vibrator::perform(V1_0::Effect effect, EffectStrength strength, perform_cb _hidl_cb) {
|
||||
return perform_1_1(static_cast<V1_1::Effect_1_1>(effect), strength, _hidl_cb);
|
||||
return perform<decltype(effect)>(effect, strength, _hidl_cb);
|
||||
}
|
||||
|
||||
// Methods from ::android::hardware::vibrator::V1_1::IVibrator follow.
|
||||
|
||||
Return<void> Vibrator::perform_1_1(V1_1::Effect_1_1 effect, EffectStrength strength,
|
||||
perform_cb _hidl_cb) {
|
||||
return perform_1_2(static_cast<V1_2::Effect>(effect), strength, _hidl_cb);
|
||||
return perform<decltype(effect)>(effect, strength, _hidl_cb);
|
||||
}
|
||||
|
||||
// Methods from ::android::hardware::vibrator::V1_2::IVibrator follow.
|
||||
|
||||
Return<void> Vibrator::perform_1_2(V1_2::Effect effect, EffectStrength strength,
|
||||
perform_cb _hidl_cb) {
|
||||
return perform_1_3(static_cast<V1_3::Effect>(effect), strength, _hidl_cb);
|
||||
return perform<decltype(effect)>(effect, strength, _hidl_cb);
|
||||
}
|
||||
|
||||
// Methods from ::android::hardware::vibrator::V1_3::IVibrator follow.
|
||||
@@ -98,6 +101,12 @@ Return<Status> Vibrator::setExternalControl(bool enabled) {
|
||||
}
|
||||
|
||||
Return<void> Vibrator::perform_1_3(Effect effect, EffectStrength strength, perform_cb _hidl_cb) {
|
||||
return perform<decltype(effect)>(effect, strength, _hidl_cb);
|
||||
}
|
||||
|
||||
// Private methods follow.
|
||||
|
||||
Return<void> Vibrator::perform(Effect effect, EffectStrength strength, perform_cb _hidl_cb) {
|
||||
uint8_t amplitude;
|
||||
uint32_t ms;
|
||||
Status status = Status::OK;
|
||||
@@ -123,7 +132,15 @@ Return<void> Vibrator::perform_1_3(Effect effect, EffectStrength strength, perfo
|
||||
return Void();
|
||||
}
|
||||
|
||||
// Private methods follow.
|
||||
template <typename T>
|
||||
Return<void> Vibrator::perform(T effect, EffectStrength strength, perform_cb _hidl_cb) {
|
||||
auto validRange = hidl_enum_range<T>();
|
||||
if (effect < *validRange.begin() || effect > *std::prev(validRange.end())) {
|
||||
_hidl_cb(Status::UNSUPPORTED_OPERATION, 0);
|
||||
return Void();
|
||||
}
|
||||
return perform(static_cast<Effect>(effect), strength, _hidl_cb);
|
||||
}
|
||||
|
||||
Status Vibrator::enable(bool enabled) {
|
||||
if (mExternalControl) {
|
||||
|
||||
@@ -54,6 +54,9 @@ class Vibrator : public IVibrator {
|
||||
Return<void> perform_1_3(Effect effect, EffectStrength strength, perform_cb _hidl_cb) override;
|
||||
|
||||
private:
|
||||
Return<void> perform(Effect effect, EffectStrength strength, perform_cb _hidl_cb);
|
||||
template <typename T>
|
||||
Return<void> perform(T effect, EffectStrength strength, perform_cb _hidl_cb);
|
||||
Status enable(bool enabled);
|
||||
Status activate(uint32_t ms);
|
||||
void timeout();
|
||||
|
||||
Reference in New Issue
Block a user