blob: 26edf5a8051566e032d11d2aa4f82efe4a7a4089 [file] [log] [blame]
Lais Andrade80b18612020-10-12 18:44:40 +00001/*
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
22namespace aidl {
23namespace android {
24namespace hardware {
25namespace vibrator {
26
27static constexpr int32_t kDefaultVibratorId = 1;
28
29ndk::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
39ndk::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
45ndk::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
57ndk::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
66ndk::ScopedAStatus VibratorManager::triggerSynced(
67 const std::shared_ptr<IVibratorCallback>& callback) {
68 LOG(INFO) << "Vibrator Manager trigger synced";
Simon Bowden608655b2022-06-01 12:09:41 +000069 std::thread([callback] {
Lais Andrade80b18612020-10-12 18:44:40 +000070 if (callback != nullptr) {
71 LOG(INFO) << "Notifying perform complete";
72 callback->onComplete();
73 }
74 }).detach();
75
76 return ndk::ScopedAStatus::ok();
77}
78
79ndk::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