blob: 4cd3b305377117918a512f3fbbfb1e66549dffc3 [file] [log] [blame]
Prashant Malani89fc3be2016-09-30 16:17:16 -07001/*
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 <hardware/hardware.h>
20#include <hardware/vibrator.h>
21#include "Vibrator.h"
22
23namespace android {
24namespace hardware {
25namespace vibrator {
26namespace V1_0 {
27namespace implementation {
28
29Vibrator::Vibrator(vibrator_device_t *device) : mDevice(device) {}
30
31// Methods from ::android::hardware::vibrator::V1_0::IVibrator follow.
32Return<Status> Vibrator::on(uint32_t timeout_ms) {
33 int32_t ret = mDevice->vibrator_on(mDevice, timeout_ms);
34 if (ret != 0) {
35 ALOGE("on command failed : %s", strerror(-ret));
36 return Status::ERR;
37 }
38 return Status::OK;
39}
40
41Return<Status> Vibrator::off() {
42 int32_t ret = mDevice->vibrator_off(mDevice);
43 if (ret != 0) {
44 ALOGE("off command failed : %s", strerror(-ret));
45 return Status::ERR;
46 }
47 return Status::OK;
48}
49
50IVibrator* HIDL_FETCH_IVibrator(const char *hal) {
51 vibrator_device_t *vib_device;
52 const hw_module_t *hw_module = nullptr;
53
54 int ret = hw_get_module(hal, &hw_module);
55 if (ret == 0) {
56 ret = vibrator_open(hw_module, &vib_device);
57 if (ret != 0) {
58 ALOGE("vibrator_open %s failed: %d", hal, ret);
59 }
60 } else {
61 ALOGE("hw_get_module %s failed: %d", hal, ret);
62 }
63
64 if (ret == 0) {
65 return new Vibrator(vib_device);
66 } else {
67 ALOGE("Passthrough failed to open legacy HAL.");
68 return nullptr;
69 }
70}
71
72} // namespace implementation
73} // namespace V1_0
74} // namespace vibrator
75} // namespace hardware
76} // namespace android