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"
18
19 #include <inttypes.h>
20
21 #include <log/log.h>
22
23 #include <hardware/hardware.h>
24 #include <hardware/vibrator.h>
25
26 #include "Vibrator.h"
27
28 namespace android {
29 namespace hardware {
30 namespace vibrator {
31 namespace V1_0 {
32 namespace implementation {
33
Vibrator(vibrator_device_t * device)34 Vibrator::Vibrator(vibrator_device_t *device) : mDevice(device) {}
35
36 // Methods from ::android::hardware::vibrator::V1_0::IVibrator follow.
on(uint32_t timeout_ms)37 Return<Status> Vibrator::on(uint32_t timeout_ms) {
38 int32_t ret = mDevice->vibrator_on(mDevice, timeout_ms);
39 if (ret != 0) {
40 ALOGE("on command failed : %s", strerror(-ret));
41 return Status::UNKNOWN_ERROR;
42 }
43 return Status::OK;
44 }
45
off()46 Return<Status> Vibrator::off() {
47 int32_t ret = mDevice->vibrator_off(mDevice);
48 if (ret != 0) {
49 ALOGE("off command failed : %s", strerror(-ret));
50 return Status::UNKNOWN_ERROR;
51 }
52 return Status::OK;
53 }
54
supportsAmplitudeControl()55 Return<bool> Vibrator::supportsAmplitudeControl() {
56 return false;
57 }
58
setAmplitude(uint8_t)59 Return<Status> Vibrator::setAmplitude(uint8_t) {
60 return Status::UNSUPPORTED_OPERATION;
61 }
62
perform(Effect,EffectStrength,perform_cb _hidl_cb)63 Return<void> Vibrator::perform(Effect, EffectStrength, perform_cb _hidl_cb) {
64 _hidl_cb(Status::UNSUPPORTED_OPERATION, 0);
65 return Void();
66 }
67
HIDL_FETCH_IVibrator(const char *)68 IVibrator* HIDL_FETCH_IVibrator(const char * /*hal*/) {
69 vibrator_device_t *vib_device;
70 const hw_module_t *hw_module = nullptr;
71
72 int ret = hw_get_module(VIBRATOR_HARDWARE_MODULE_ID, &hw_module);
73 if (ret == 0) {
74 ret = vibrator_open(hw_module, &vib_device);
75 if (ret != 0) {
76 ALOGE("vibrator_open failed: %d", ret);
77 }
78 } else {
79 ALOGE("hw_get_module %s failed: %d", VIBRATOR_HARDWARE_MODULE_ID, ret);
80 }
81
82 if (ret == 0) {
83 return new Vibrator(vib_device);
84 } else {
85 ALOGE("Passthrough failed to open legacy HAL.");
86 return nullptr;
87 }
88 }
89
90 } // namespace implementation
91 } // namespace V1_0
92 } // namespace vibrator
93 } // namespace hardware
94 } // namespace android
95