Prashant Malani | 89fc3be | 2016-09-30 16:17:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 "VibratorService" |
Mark Salyzyn | 3ff5260 | 2017-01-10 10:16:48 -0800 | [diff] [blame] | 18 | |
| 19 | #include <log/log.h> |
| 20 | |
Prashant Malani | 89fc3be | 2016-09-30 16:17:16 -0700 | [diff] [blame] | 21 | #include <hardware/hardware.h> |
| 22 | #include <hardware/vibrator.h> |
Mark Salyzyn | 3ff5260 | 2017-01-10 10:16:48 -0800 | [diff] [blame] | 23 | |
Prashant Malani | 89fc3be | 2016-09-30 16:17:16 -0700 | [diff] [blame] | 24 | #include "Vibrator.h" |
| 25 | |
| 26 | namespace android { |
| 27 | namespace hardware { |
| 28 | namespace vibrator { |
| 29 | namespace V1_0 { |
| 30 | namespace implementation { |
| 31 | |
| 32 | Vibrator::Vibrator(vibrator_device_t *device) : mDevice(device) {} |
| 33 | |
| 34 | // Methods from ::android::hardware::vibrator::V1_0::IVibrator follow. |
| 35 | Return<Status> Vibrator::on(uint32_t timeout_ms) { |
| 36 | int32_t ret = mDevice->vibrator_on(mDevice, timeout_ms); |
| 37 | if (ret != 0) { |
| 38 | ALOGE("on command failed : %s", strerror(-ret)); |
| 39 | return Status::ERR; |
| 40 | } |
| 41 | return Status::OK; |
| 42 | } |
| 43 | |
| 44 | Return<Status> Vibrator::off() { |
| 45 | int32_t ret = mDevice->vibrator_off(mDevice); |
| 46 | if (ret != 0) { |
| 47 | ALOGE("off command failed : %s", strerror(-ret)); |
| 48 | return Status::ERR; |
| 49 | } |
| 50 | return Status::OK; |
| 51 | } |
| 52 | |
Chris Phoenix | 6823dd8 | 2017-01-19 15:51:29 -0800 | [diff] [blame^] | 53 | IVibrator* HIDL_FETCH_IVibrator(const char * /*hal*/) { |
Prashant Malani | 89fc3be | 2016-09-30 16:17:16 -0700 | [diff] [blame] | 54 | vibrator_device_t *vib_device; |
| 55 | const hw_module_t *hw_module = nullptr; |
| 56 | |
Chris Phoenix | 6823dd8 | 2017-01-19 15:51:29 -0800 | [diff] [blame^] | 57 | int ret = hw_get_module(VIBRATOR_HARDWARE_MODULE_ID, &hw_module); |
Prashant Malani | 89fc3be | 2016-09-30 16:17:16 -0700 | [diff] [blame] | 58 | if (ret == 0) { |
| 59 | ret = vibrator_open(hw_module, &vib_device); |
| 60 | if (ret != 0) { |
Chris Phoenix | 6823dd8 | 2017-01-19 15:51:29 -0800 | [diff] [blame^] | 61 | ALOGE("vibrator_open failed: %d", ret); |
Prashant Malani | 89fc3be | 2016-09-30 16:17:16 -0700 | [diff] [blame] | 62 | } |
| 63 | } else { |
Chris Phoenix | 6823dd8 | 2017-01-19 15:51:29 -0800 | [diff] [blame^] | 64 | ALOGE("hw_get_module %s failed: %d", VIBRATOR_HARDWARE_MODULE_ID, ret); |
Prashant Malani | 89fc3be | 2016-09-30 16:17:16 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | if (ret == 0) { |
| 68 | return new Vibrator(vib_device); |
| 69 | } else { |
| 70 | ALOGE("Passthrough failed to open legacy HAL."); |
| 71 | return nullptr; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | } // namespace implementation |
| 76 | } // namespace V1_0 |
| 77 | } // namespace vibrator |
| 78 | } // namespace hardware |
| 79 | } // namespace android |