Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 13ef28c6 authored by Harpreet \"Eli\" Sangha's avatar Harpreet \"Eli\" Sangha Committed by Harpreet "Eli" Sangha
Browse files

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: default avatarHarpreet \"Eli\" Sangha <eliptus@google.com>
parent fe5d3986
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -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);
        }
    }