blob: e86e68152d9a00912e7086ecc001773a590ee56d [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"
Mark Salyzyn3ff52602017-01-10 10:16:48 -080018
19#include <log/log.h>
20
Prashant Malani89fc3be2016-09-30 16:17:16 -070021#include <hardware/hardware.h>
22#include <hardware/vibrator.h>
Mark Salyzyn3ff52602017-01-10 10:16:48 -080023
Prashant Malani89fc3be2016-09-30 16:17:16 -070024#include "Vibrator.h"
25
26namespace android {
27namespace hardware {
28namespace vibrator {
29namespace V1_0 {
30namespace implementation {
31
32Vibrator::Vibrator(vibrator_device_t *device) : mDevice(device) {}
33
34// Methods from ::android::hardware::vibrator::V1_0::IVibrator follow.
35Return<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
44Return<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
53IVibrator* HIDL_FETCH_IVibrator(const char *hal) {
54 vibrator_device_t *vib_device;
55 const hw_module_t *hw_module = nullptr;
56
57 int ret = hw_get_module(hal, &hw_module);
58 if (ret == 0) {
59 ret = vibrator_open(hw_module, &vib_device);
60 if (ret != 0) {
61 ALOGE("vibrator_open %s failed: %d", hal, ret);
62 }
63 } else {
64 ALOGE("hw_get_module %s failed: %d", hal, ret);
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