From 36977e29925839092c17737f7dff379b42f79a6b Mon Sep 17 00:00:00 2001 From: Tim Zimmermann Date: Fri, 15 Apr 2022 10:04:25 +0200 Subject: [PATCH] aidl: vibrator: Don't allow intensity 0 * Even if amplitude is > 0 resulting intensity might be 0 sometimes * New devices just return EINVAL in kernel and ignore it, but on older ones this may result in very weak vibration Change-Id: I5d290d60d8414ca747dce4af847f190e3caedbe0 --- aidl/vibrator/Vibrator.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/aidl/vibrator/Vibrator.cpp b/aidl/vibrator/Vibrator.cpp index 95d5aec..0f64702 100644 --- a/aidl/vibrator/Vibrator.cpp +++ b/aidl/vibrator/Vibrator.cpp @@ -162,6 +162,11 @@ ndk::ScopedAStatus Vibrator::setAmplitude(float amplitude) { if (intensity > INTENSITY_MAX) { intensity = INTENSITY_MAX; } + + if (intensity == 0) { + return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); + } + LOG(DEBUG) << "Setting intensity: " << intensity; if (mHasTimedOutIntensity) { -- 2.20.1