Lais Andrade | 24b5b8f | 2020-08-27 15:55:54 +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 | #define LOG_TAG "VibratorManagerHalWrapper" |
| 18 | |
| 19 | #include <utils/Log.h> |
| 20 | |
| 21 | #include <vibratorservice/VibratorManagerHalWrapper.h> |
| 22 | |
| 23 | namespace android { |
| 24 | |
| 25 | namespace vibrator { |
| 26 | |
| 27 | constexpr int32_t SINGLE_VIBRATOR_ID = 0; |
| 28 | |
| 29 | HalResult<void> LegacyManagerHalWrapper::ping() { |
| 30 | return mController->ping(); |
| 31 | } |
| 32 | |
| 33 | void LegacyManagerHalWrapper::tryReconnect() { |
| 34 | mController->tryReconnect(); |
| 35 | } |
| 36 | |
| 37 | HalResult<std::vector<int32_t>> LegacyManagerHalWrapper::getVibratorIds() { |
| 38 | if (mController->init()) { |
| 39 | return HalResult<std::vector<int32_t>>::ok(std::vector<int32_t>(1, SINGLE_VIBRATOR_ID)); |
| 40 | } |
| 41 | // Controller.init did not connect to any vibrator HAL service, so the device has no vibrator. |
| 42 | return HalResult<std::vector<int32_t>>::ok(std::vector<int32_t>()); |
| 43 | } |
| 44 | |
| 45 | HalResult<std::shared_ptr<HalController>> LegacyManagerHalWrapper::getVibrator(int32_t id) { |
| 46 | if (id == SINGLE_VIBRATOR_ID && mController->init()) { |
| 47 | return HalResult<std::shared_ptr<HalController>>::ok(mController); |
| 48 | } |
| 49 | // Controller.init did not connect to any vibrator HAL service, so the device has no vibrator. |
| 50 | return HalResult<std::shared_ptr<HalController>>::failed("No vibrator with id = " + |
| 51 | std::to_string(id)); |
| 52 | } |
| 53 | |
| 54 | HalResult<void> LegacyManagerHalWrapper::prepareSynced(const std::vector<int32_t>&) { |
| 55 | return HalResult<void>::unsupported(); |
| 56 | } |
| 57 | |
| 58 | HalResult<void> LegacyManagerHalWrapper::triggerSynced(const std::function<void()>&) { |
| 59 | return HalResult<void>::unsupported(); |
| 60 | } |
| 61 | |
| 62 | HalResult<void> LegacyManagerHalWrapper::cancelSynced() { |
| 63 | return HalResult<void>::unsupported(); |
| 64 | } |
| 65 | |
| 66 | }; // namespace vibrator |
| 67 | |
| 68 | }; // namespace android |