diff options
author | Harpreet \"Eli\" Sangha <eliptus@google.com> | 2020-01-23 13:22:07 +0900 |
---|---|---|
committer | Harpreet "Eli" Sangha <eliptus@google.com> | 2020-01-29 02:06:16 +0000 |
commit | 13ef28c6a4bf724bb8e2073ca9c61d238b4c6fe9 (patch) | |
tree | 5dfe00d8832b82a9310ff4c44f27f795a5a51aa0 | |
parent | fe5d3986e9f170f6f0c04dbf9e40bcb5646922f9 (diff) |
vibrator: Deduplicate Supported Primitives Check
Use the getSupportedPrimitives() as the single source of truth for
supported primitive checks.
Bug: 147844633
Test: atest VtsHalVibratorTargetTest
Change-Id: I8789b0ee9806c5887fca9a0b800fe2e903c76a58
Signed-off-by: Harpreet \"Eli\" Sangha <eliptus@google.com>
-rw-r--r-- | vibrator/aidl/default/Vibrator.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/vibrator/aidl/default/Vibrator.cpp b/vibrator/aidl/default/Vibrator.cpp index 0d7131aaf8..9236b95ddc 100644 --- a/vibrator/aidl/default/Vibrator.cpp +++ b/vibrator/aidl/default/Vibrator.cpp @@ -139,6 +139,9 @@ ndk::ScopedAStatus Vibrator::compose(const std::vector<CompositeEffect>& composi return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); } + std::vector<CompositePrimitive> supported; + getSupportedPrimitives(&supported); + for (auto& e : composite) { if (e.delayMs > kComposeDelayMaxMs) { return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); @@ -146,8 +149,7 @@ ndk::ScopedAStatus Vibrator::compose(const std::vector<CompositeEffect>& composi if (e.scale <= 0.0f || e.scale > 1.0f) { return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); } - if (e.primitive < CompositePrimitive::NOOP || - e.primitive > CompositePrimitive::LIGHT_TICK) { + if (std::find(supported.begin(), supported.end(), e.primitive) == supported.end()) { return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); } } |