diff options
author | Harpreet \"Eli\" Sangha <eliptus@google.com> | 2019-10-23 09:25:52 +0900 |
---|---|---|
committer | Harpreet \"Eli\" Sangha <eliptus@google.com> | 2019-11-21 16:12:13 +0900 |
commit | f4de5b065f1ab341b1475f39f2d62658f8e54ab9 (patch) | |
tree | a335959899e78c0f49485fa55c0319b4f0bd0557 /vibrator/aidl/default/Vibrator.cpp | |
parent | 942de9e663138ca90bff873d65c7f2c8c36562b7 (diff) |
vibrator: Add Composition APIs
Bug: 139762802
Test: Manual Invocation via 'idlcli'
Change-Id: Ibc938d08f186039681d523784b90f4172a52af51
Signed-off-by: Harpreet \"Eli\" Sangha <eliptus@google.com>
Diffstat (limited to 'vibrator/aidl/default/Vibrator.cpp')
-rw-r--r-- | vibrator/aidl/default/Vibrator.cpp | 58 |
1 files changed, 55 insertions, 3 deletions
diff --git a/vibrator/aidl/default/Vibrator.cpp b/vibrator/aidl/default/Vibrator.cpp index 09cd2345bf..a77c49a0a2 100644 --- a/vibrator/aidl/default/Vibrator.cpp +++ b/vibrator/aidl/default/Vibrator.cpp @@ -24,11 +24,14 @@ namespace android { namespace hardware { namespace vibrator { +static constexpr int32_t kComposeDelayMaxMs = 1000; +static constexpr int32_t kComposeSizeMax = 256; + ndk::ScopedAStatus Vibrator::getCapabilities(int32_t* _aidl_return) { LOG(INFO) << "Vibrator reporting capabilities"; *_aidl_return = IVibrator::CAP_ON_CALLBACK | IVibrator::CAP_PERFORM_CALLBACK | IVibrator::CAP_AMPLITUDE_CONTROL | IVibrator::CAP_EXTERNAL_CONTROL | - IVibrator::CAP_EXTERNAL_AMPLITUDE_CONTROL; + IVibrator::CAP_EXTERNAL_AMPLITUDE_CONTROL | IVibrator::CAP_COMPOSE_EFFECTS; return ndk::ScopedAStatus::ok(); } @@ -84,9 +87,9 @@ ndk::ScopedAStatus Vibrator::getSupportedEffects(std::vector<Effect>* _aidl_retu return ndk::ScopedAStatus::ok(); } -ndk::ScopedAStatus Vibrator::setAmplitude(int32_t amplitude) { +ndk::ScopedAStatus Vibrator::setAmplitude(float amplitude) { LOG(INFO) << "Vibrator set amplitude: " << amplitude; - if (amplitude <= 0 || amplitude > 255) { + if (amplitude <= 0.0f || amplitude > 1.0f) { return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_ILLEGAL_ARGUMENT)); } return ndk::ScopedAStatus::ok(); @@ -97,6 +100,55 @@ ndk::ScopedAStatus Vibrator::setExternalControl(bool enabled) { return ndk::ScopedAStatus::ok(); } +ndk::ScopedAStatus Vibrator::getCompositionDelayMax(int32_t* maxDelayMs) { + *maxDelayMs = kComposeDelayMaxMs; + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus Vibrator::getCompositionSizeMax(int32_t* maxSize) { + *maxSize = kComposeSizeMax; + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus Vibrator::compose(const std::vector<CompositeEffect>& composite, + const std::shared_ptr<IVibratorCallback>& callback) { + if (composite.size() > kComposeSizeMax) { + return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); + } + + for (auto& e : composite) { + if (e.delayMs > kComposeDelayMaxMs) { + return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); + } + if (e.scale <= 0.0f || e.scale > 1.0f) { + return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); + } + if (e.primitive < CompositePrimitive::NOOP || + e.primitive > CompositePrimitive::QUICK_FALL) { + return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); + } + } + + std::thread([=] { + LOG(INFO) << "Starting compose on another thread"; + + for (auto& e : composite) { + if (e.delayMs) { + usleep(e.delayMs * 1000); + } + LOG(INFO) << "triggering primitive " << static_cast<int>(e.primitive) << " @ scale " + << e.scale; + } + + if (callback != nullptr) { + LOG(INFO) << "Notifying perform complete"; + callback->onComplete(); + } + }).detach(); + + return ndk::ScopedAStatus::ok(); +} + } // namespace vibrator } // namespace hardware } // namespace android |