Lais Andrade | 80b1861 | 2020-10-12 18:44:40 +0000 | [diff] [blame] | 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 | #include "vibrator-impl/VibratorManager.h" |
| 18 | |
| 19 | #include <android-base/logging.h> |
| 20 | #include <thread> |
| 21 | |
| 22 | namespace aidl { |
| 23 | namespace android { |
| 24 | namespace hardware { |
| 25 | namespace vibrator { |
| 26 | |
| 27 | static constexpr int32_t kDefaultVibratorId = 1; |
| 28 | |
| 29 | ndk::ScopedAStatus VibratorManager::getCapabilities(int32_t* _aidl_return) { |
| 30 | LOG(INFO) << "Vibrator manager reporting capabilities"; |
| 31 | *_aidl_return = |
| 32 | IVibratorManager::CAP_SYNC | IVibratorManager::CAP_PREPARE_ON | |
| 33 | IVibratorManager::CAP_PREPARE_PERFORM | IVibratorManager::CAP_PREPARE_COMPOSE | |
| 34 | IVibratorManager::CAP_MIXED_TRIGGER_ON | IVibratorManager::CAP_MIXED_TRIGGER_PERFORM | |
| 35 | IVibratorManager::CAP_MIXED_TRIGGER_COMPOSE | IVibratorManager::CAP_TRIGGER_CALLBACK; |
| 36 | return ndk::ScopedAStatus::ok(); |
| 37 | } |
| 38 | |
| 39 | ndk::ScopedAStatus VibratorManager::getVibratorIds(std::vector<int32_t>* _aidl_return) { |
| 40 | LOG(INFO) << "Vibrator manager getting vibrator ids"; |
| 41 | *_aidl_return = {kDefaultVibratorId}; |
| 42 | return ndk::ScopedAStatus::ok(); |
| 43 | } |
| 44 | |
| 45 | ndk::ScopedAStatus VibratorManager::getVibrator(int32_t vibratorId, |
| 46 | std::shared_ptr<IVibrator>* _aidl_return) { |
| 47 | LOG(INFO) << "Vibrator manager getting vibrator " << vibratorId; |
| 48 | if (vibratorId == kDefaultVibratorId) { |
| 49 | *_aidl_return = mDefaultVibrator; |
| 50 | return ndk::ScopedAStatus::ok(); |
| 51 | } else { |
| 52 | *_aidl_return = nullptr; |
| 53 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | ndk::ScopedAStatus VibratorManager::prepareSynced(const std::vector<int32_t>& vibratorIds) { |
| 58 | LOG(INFO) << "Vibrator Manager prepare synced"; |
| 59 | if (vibratorIds.size() == 1 && vibratorIds[0] == kDefaultVibratorId) { |
| 60 | return ndk::ScopedAStatus::ok(); |
| 61 | } else { |
| 62 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | ndk::ScopedAStatus VibratorManager::triggerSynced( |
| 67 | const std::shared_ptr<IVibratorCallback>& callback) { |
| 68 | LOG(INFO) << "Vibrator Manager trigger synced"; |
Simon Bowden | 608655b | 2022-06-01 12:09:41 +0000 | [diff] [blame^] | 69 | std::thread([callback] { |
Lais Andrade | 80b1861 | 2020-10-12 18:44:40 +0000 | [diff] [blame] | 70 | if (callback != nullptr) { |
| 71 | LOG(INFO) << "Notifying perform complete"; |
| 72 | callback->onComplete(); |
| 73 | } |
| 74 | }).detach(); |
| 75 | |
| 76 | return ndk::ScopedAStatus::ok(); |
| 77 | } |
| 78 | |
| 79 | ndk::ScopedAStatus VibratorManager::cancelSynced() { |
| 80 | LOG(INFO) << "Vibrator Manager cancel synced"; |
| 81 | return ndk::ScopedAStatus::ok(); |
| 82 | } |
| 83 | |
| 84 | } // namespace vibrator |
| 85 | } // namespace hardware |
| 86 | } // namespace android |
| 87 | } // namespace aidl |