1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <aidl/android/hardware/vibrator/BnVibrator.h> 20 #include <android-base/thread_annotations.h> 21 22 namespace aidl { 23 namespace android { 24 namespace hardware { 25 namespace vibrator { 26 27 class Vibrator : public BnVibrator { 28 public: 29 ndk::ScopedAStatus getCapabilities(int32_t* _aidl_return) override; 30 ndk::ScopedAStatus off() override; 31 ndk::ScopedAStatus on(int32_t timeoutMs, 32 const std::shared_ptr<IVibratorCallback>& callback) override; 33 ndk::ScopedAStatus perform(Effect effect, EffectStrength strength, 34 const std::shared_ptr<IVibratorCallback>& callback, 35 int32_t* _aidl_return) override; 36 ndk::ScopedAStatus performVendorEffect( 37 const VendorEffect& effect, 38 const std::shared_ptr<IVibratorCallback>& callback) override; 39 ndk::ScopedAStatus getSupportedEffects(std::vector<Effect>* _aidl_return) override; 40 ndk::ScopedAStatus setAmplitude(float amplitude) override; 41 ndk::ScopedAStatus setExternalControl(bool enabled) override; 42 ndk::ScopedAStatus getCompositionDelayMax(int32_t* maxDelayMs); 43 ndk::ScopedAStatus getCompositionSizeMax(int32_t* maxSize); 44 ndk::ScopedAStatus getSupportedPrimitives(std::vector<CompositePrimitive>* supported) override; 45 ndk::ScopedAStatus getPrimitiveDuration(CompositePrimitive primitive, 46 int32_t* durationMs) override; 47 ndk::ScopedAStatus compose(const std::vector<CompositeEffect>& composite, 48 const std::shared_ptr<IVibratorCallback>& callback) override; 49 ndk::ScopedAStatus getSupportedAlwaysOnEffects(std::vector<Effect>* _aidl_return) override; 50 ndk::ScopedAStatus alwaysOnEnable(int32_t id, Effect effect, EffectStrength strength) override; 51 ndk::ScopedAStatus alwaysOnDisable(int32_t id) override; 52 ndk::ScopedAStatus getResonantFrequency(float *resonantFreqHz) override; 53 ndk::ScopedAStatus getQFactor(float *qFactor) override; 54 ndk::ScopedAStatus getFrequencyResolution(float *freqResolutionHz) override; 55 ndk::ScopedAStatus getFrequencyMinimum(float *freqMinimumHz) override; 56 ndk::ScopedAStatus getBandwidthAmplitudeMap(std::vector<float> *_aidl_return) override; 57 ndk::ScopedAStatus getPwlePrimitiveDurationMax(int32_t *durationMs) override; 58 ndk::ScopedAStatus getPwleCompositionSizeMax(int32_t *maxSize) override; 59 ndk::ScopedAStatus getSupportedBraking(std::vector<Braking>* supported) override; 60 ndk::ScopedAStatus composePwle(const std::vector<PrimitivePwle> &composite, 61 const std::shared_ptr<IVibratorCallback> &callback) override; 62 ndk::ScopedAStatus getFrequencyToOutputAccelerationMap( 63 std::vector<FrequencyAccelerationMapEntry>* _aidl_return) override; 64 ndk::ScopedAStatus getPwleV2PrimitiveDurationMaxMillis(int32_t* maxDurationMs) override; 65 ndk::ScopedAStatus getPwleV2PrimitiveDurationMinMillis(int32_t* minDurationMs) override; 66 ndk::ScopedAStatus getPwleV2CompositionSizeMax(int32_t* maxSize) override; 67 ndk::ScopedAStatus composePwleV2(const CompositePwleV2& composite, 68 const std::shared_ptr<IVibratorCallback>& callback) override; 69 70 void setGlobalVibrationCallback(const std::shared_ptr<IVibratorCallback>& callback); 71 72 private: 73 mutable std::mutex mMutex; 74 bool mIsVibrating GUARDED_BY(mMutex) = false; 75 int32_t mCapabilities GUARDED_BY(mMutex) = 0; 76 std::shared_ptr<IVibratorCallback> mVibrationCallback GUARDED_BY(mMutex) = nullptr; 77 std::shared_ptr<IVibratorCallback> mGlobalVibrationCallback GUARDED_BY(mMutex) = nullptr; 78 79 void dispatchVibrate(int32_t timeoutMs, const std::shared_ptr<IVibratorCallback>& callback); 80 }; 81 82 } // namespace vibrator 83 } // namespace hardware 84 } // namespace android 85 } // namespace aidl 86