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>
This commit is contained in:
Harpreet \"Eli\" Sangha
2020-01-23 13:22:07 +09:00
committed by Harpreet "Eli" Sangha
parent fe5d3986e9
commit 13ef28c6a4

View File

@@ -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);
}
}