1 /* 2 * Copyright (C) 2020 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/BnVibratorManager.h> 20 #include <android-base/thread_annotations.h> 21 22 #include "vibrator-impl/Vibrator.h" 23 24 namespace aidl { 25 namespace android { 26 namespace hardware { 27 namespace vibrator { 28 29 class VibratorManager : public BnVibratorManager { 30 public: VibratorManager(std::shared_ptr<Vibrator> vibrator)31 VibratorManager(std::shared_ptr<Vibrator> vibrator) : mDefaultVibrator(std::move(vibrator)) {}; 32 33 ndk::ScopedAStatus getCapabilities(int32_t* _aidl_return) override; 34 ndk::ScopedAStatus getVibratorIds(std::vector<int32_t>* _aidl_return) override; 35 ndk::ScopedAStatus getVibrator(int32_t vibratorId, 36 std::shared_ptr<IVibrator>* _aidl_return) override; 37 ndk::ScopedAStatus prepareSynced(const std::vector<int32_t>& vibratorIds) override; 38 ndk::ScopedAStatus triggerSynced(const std::shared_ptr<IVibratorCallback>& callback) override; 39 ndk::ScopedAStatus cancelSynced() override; 40 ndk::ScopedAStatus startSession(const std::vector<int32_t>& vibratorIds, 41 const VibrationSessionConfig& config, 42 const std::shared_ptr<IVibratorCallback>& callback, 43 std::shared_ptr<IVibrationSession>* _aidl_return) override; 44 ndk::ScopedAStatus clearSessions() override; 45 46 void abortSession(); 47 void closeSession(int32_t delayMs); 48 49 private: 50 std::shared_ptr<Vibrator> mDefaultVibrator; 51 mutable std::mutex mMutex; 52 int32_t mCapabilities GUARDED_BY(mMutex) = 0; 53 bool mIsPreparing GUARDED_BY(mMutex) = false; 54 bool mIsClosingSession GUARDED_BY(mMutex) = false; 55 std::shared_ptr<IVibrationSession> mSession GUARDED_BY(mMutex) = nullptr; 56 std::shared_ptr<IVibratorCallback> mSessionCallback GUARDED_BY(mMutex) = nullptr; 57 58 void clearSession(const std::shared_ptr<IVibrationSession>& session); 59 }; 60 61 } // namespace vibrator 62 } // namespace hardware 63 } // namespace android 64 } // namespace aidl 65