am 56910cf5: Merge "DO NOT MERGE BLE peripheral mode (1/4): change HAL to support service data and service uuids." into klp-dev
* commit '56910cf52332219c6a23bc12596b261c127d93bf':
DO NOT MERGE BLE peripheral mode (1/4): change HAL to support service data and service uuids.
diff --git a/hardware.c b/hardware.c
index 9651f4c..6713ea0 100644
--- a/hardware.c
+++ b/hardware.c
@@ -28,8 +28,13 @@
#include <utils/Log.h>
/** Base path of the hal modules */
+#if defined(__LP64__)
+#define HAL_LIBRARY_PATH1 "/system/lib64/hw"
+#define HAL_LIBRARY_PATH2 "/vendor/lib64/hw"
+#else
#define HAL_LIBRARY_PATH1 "/system/lib/hw"
#define HAL_LIBRARY_PATH2 "/vendor/lib/hw"
+#endif
/**
* There are a set of variant filename for modules. The form of the filename
@@ -117,15 +122,34 @@
return status;
}
+/*
+ * Check if a HAL with given name and subname exists, if so return 0, otherwise
+ * otherwise return negative. On success path will contain the path to the HAL.
+ */
+static int hw_module_exists(char *path, size_t path_len, const char *name,
+ const char *subname)
+{
+ snprintf(path, path_len, "%s/%s.%s.so",
+ HAL_LIBRARY_PATH2, name, subname);
+ if (access(path, R_OK) == 0)
+ return 0;
+
+ snprintf(path, path_len, "%s/%s.%s.so",
+ HAL_LIBRARY_PATH1, name, subname);
+ if (access(path, R_OK) == 0)
+ return 0;
+
+ return -ENOENT;
+}
+
int hw_get_module_by_class(const char *class_id, const char *inst,
const struct hw_module_t **module)
{
- int status;
int i;
- const struct hw_module_t *hmi = NULL;
char prop[PATH_MAX];
char path[PATH_MAX];
char name[PATH_MAX];
+ char prop_name[PATH_MAX];
if (inst)
snprintf(name, PATH_MAX, "%s.%s", class_id, inst);
@@ -139,38 +163,35 @@
* We also assume that dlopen() is thread-safe.
*/
- /* Loop through the configuration variants looking for a module */
- for (i=0 ; i<HAL_VARIANT_KEYS_COUNT+1 ; i++) {
- if (i < HAL_VARIANT_KEYS_COUNT) {
- if (property_get(variant_keys[i], prop, NULL) == 0) {
- continue;
- }
- snprintf(path, sizeof(path), "%s/%s.%s.so",
- HAL_LIBRARY_PATH2, name, prop);
- if (access(path, R_OK) == 0) break;
-
- snprintf(path, sizeof(path), "%s/%s.%s.so",
- HAL_LIBRARY_PATH1, name, prop);
- if (access(path, R_OK) == 0) break;
- } else {
- snprintf(path, sizeof(path), "%s/%s.default.so",
- HAL_LIBRARY_PATH2, name);
- if (access(path, R_OK) == 0) break;
-
- snprintf(path, sizeof(path), "%s/%s.default.so",
- HAL_LIBRARY_PATH1, name);
- if (access(path, R_OK) == 0) break;
+ /* First try a property specific to the class and possibly instance */
+ snprintf(prop_name, sizeof(prop_name), "ro.hardware.%s", name);
+ if (property_get(prop_name, prop, NULL) > 0) {
+ if (hw_module_exists(path, sizeof(path), name, prop) == 0) {
+ goto found;
}
}
- status = -ENOENT;
- if (i < HAL_VARIANT_KEYS_COUNT+1) {
- /* load the module, if this fails, we're doomed, and we should not try
- * to load a different variant. */
- status = load(class_id, path, module);
+ /* Loop through the configuration variants looking for a module */
+ for (i=0 ; i<HAL_VARIANT_KEYS_COUNT; i++) {
+ if (property_get(variant_keys[i], prop, NULL) == 0) {
+ continue;
+ }
+ if (hw_module_exists(path, sizeof(path), name, prop) == 0) {
+ goto found;
+ }
}
- return status;
+ /* Nothing found, try the default */
+ if (hw_module_exists(path, sizeof(path), name, "default") == 0) {
+ goto found;
+ }
+
+ return -ENOENT;
+
+found:
+ /* load the module, if this fails, we're doomed, and we should not try
+ * to load a different variant. */
+ return load(class_id, path, module);
}
int hw_get_module(const char *id, const struct hw_module_t **module)
diff --git a/include/hardware/qemu_pipe.h b/include/hardware/qemu_pipe.h
index 1a67022..814b20b 100644
--- a/include/hardware/qemu_pipe.h
+++ b/include/hardware/qemu_pipe.h
@@ -66,6 +66,8 @@
snprintf(buff, sizeof buff, "pipe:%s", pipeName);
fd = open("/dev/qemu_pipe", O_RDWR);
+ if (fd < 0 && errno == ENOENT)
+ fd = open("/dev/goldfish_pipe", O_RDWR);
if (fd < 0) {
D("%s: Could not open /dev/qemu_pipe: %s", __FUNCTION__, strerror(errno));
//errno = ENOSYS;
diff --git a/include/hardware/vibrator.h b/include/hardware/vibrator.h
new file mode 100644
index 0000000..795d23e
--- /dev/null
+++ b/include/hardware/vibrator.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _HARDWARE_VIBRATOR_H
+#define _HARDWARE_VIBRATOR_H
+
+#include <hardware/hardware.h>
+
+__BEGIN_DECLS
+
+#define VIBRATOR_API_VERSION HARDWARE_MODULE_API_VERSION(1,0)
+
+/**
+ * The id of this module
+ */
+#define VIBRATOR_HARDWARE_MODULE_ID "vibrator"
+
+/**
+ * The id of the main vibrator device
+ */
+#define VIBRATOR_DEVICE_ID_MAIN "main_vibrator"
+
+struct vibrator_device;
+typedef struct vibrator_device {
+ struct hw_device_t common;
+
+ /** Turn on vibrator
+ *
+ * What happens when this function is called while the the timeout of a
+ * previous call has not expired is implementation dependent.
+ *
+ * @param timeout_ms number of milliseconds to vibrate
+ *
+ * @return 0 in case of success, negative errno code else
+ */
+ int (*vibrator_on)(struct vibrator_device* vibradev, unsigned int timeout_ms);
+
+ /** Turn off vibrator
+ *
+ * It is not guaranteed that the vibrator will be immediately stopped: the
+ * behaviour is implementation dependent.
+ *
+ * @return 0 in case of success, negative errno code else
+ */
+ int (*vibrator_off)(struct vibrator_device* vibradev);
+} vibrator_device_t;
+
+static inline int vibrator_open(const struct hw_module_t* module, vibrator_device_t** device)
+{
+ return module->methods->open(module, VIBRATOR_DEVICE_ID_MAIN, (struct hw_device_t**)device);
+}
+
+__END_DECLS
+
+#endif // _HARDWARE_VIBRATOR_H
diff --git a/modules/Android.mk b/modules/Android.mk
index b2d5a2a..de41f6f 100644
--- a/modules/Android.mk
+++ b/modules/Android.mk
@@ -1,3 +1,3 @@
hardware_modules := gralloc hwcomposer audio nfc nfc-nci local_time \
- power usbaudio audio_remote_submix camera consumerir
+ power usbaudio audio_remote_submix camera consumerir vibrator
include $(call all-named-subdir-makefiles,$(hardware_modules))
diff --git a/modules/audio/Android.mk b/modules/audio/Android.mk
index f773079..49ed312 100644
--- a/modules/audio/Android.mk
+++ b/modules/audio/Android.mk
@@ -23,7 +23,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := audio.primary.default
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := audio_hw.c
LOCAL_SHARED_LIBRARIES := liblog libcutils
LOCAL_MODULE_TAGS := optional
@@ -35,7 +35,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := audio_policy.stub
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := audio_policy.c
LOCAL_SHARED_LIBRARIES := liblog libcutils
LOCAL_MODULE_TAGS := optional
diff --git a/modules/audio_remote_submix/Android.mk b/modules/audio_remote_submix/Android.mk
index 5f54902..50c8cb2 100644
--- a/modules/audio_remote_submix/Android.mk
+++ b/modules/audio_remote_submix/Android.mk
@@ -17,7 +17,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := audio.r_submix.default
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := \
audio_hw.cpp
LOCAL_C_INCLUDES += \
diff --git a/modules/camera/Android.mk b/modules/camera/Android.mk
index e02a143..fbe44c5 100644
--- a/modules/camera/Android.mk
+++ b/modules/camera/Android.mk
@@ -17,7 +17,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := camera.default
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_C_INCLUDES += \
system/core/include \
diff --git a/modules/consumerir/Android.mk b/modules/consumerir/Android.mk
index ed6aa0f..b881572 100644
--- a/modules/consumerir/Android.mk
+++ b/modules/consumerir/Android.mk
@@ -17,7 +17,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := consumerir.default
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := consumerir.c
LOCAL_SHARED_LIBRARIES := liblog libcutils
LOCAL_MODULE_TAGS := optional
diff --git a/modules/gralloc/Android.mk b/modules/gralloc/Android.mk
index b24c4cd..a4ffd20 100644
--- a/modules/gralloc/Android.mk
+++ b/modules/gralloc/Android.mk
@@ -19,15 +19,15 @@
# hw/<OVERLAY_HARDWARE_MODULE_ID>.<ro.product.board>.so
include $(CLEAR_VARS)
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SHARED_LIBRARIES := liblog libcutils
LOCAL_SRC_FILES := \
gralloc.cpp \
framebuffer.cpp \
mapper.cpp
-
+
LOCAL_MODULE := gralloc.default
-LOCAL_CFLAGS:= -DLOG_TAG=\"gralloc\"
+LOCAL_CFLAGS:= -DLOG_TAG=\"gralloc\" -Wno-missing-field-initializers
include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/gralloc/gralloc.cpp b/modules/gralloc/gralloc.cpp
index a2dec6b..bdc789d 100644
--- a/modules/gralloc/gralloc.cpp
+++ b/modules/gralloc/gralloc.cpp
@@ -72,31 +72,31 @@
/*****************************************************************************/
static struct hw_module_methods_t gralloc_module_methods = {
- open: gralloc_device_open
+ .open = gralloc_device_open
};
struct private_module_t HAL_MODULE_INFO_SYM = {
- base: {
- common: {
- tag: HARDWARE_MODULE_TAG,
- version_major: 1,
- version_minor: 0,
- id: GRALLOC_HARDWARE_MODULE_ID,
- name: "Graphics Memory Allocator Module",
- author: "The Android Open Source Project",
- methods: &gralloc_module_methods
+ .base = {
+ .common = {
+ .tag = HARDWARE_MODULE_TAG,
+ .version_major = 1,
+ .version_minor = 0,
+ .id = GRALLOC_HARDWARE_MODULE_ID,
+ .name = "Graphics Memory Allocator Module",
+ .author = "The Android Open Source Project",
+ .methods = &gralloc_module_methods
},
- registerBuffer: gralloc_register_buffer,
- unregisterBuffer: gralloc_unregister_buffer,
- lock: gralloc_lock,
- unlock: gralloc_unlock,
+ .registerBuffer = gralloc_register_buffer,
+ .unregisterBuffer = gralloc_unregister_buffer,
+ .lock = gralloc_lock,
+ .unlock = gralloc_unlock,
},
- framebuffer: 0,
- flags: 0,
- numBuffers: 0,
- bufferMask: 0,
- lock: PTHREAD_MUTEX_INITIALIZER,
- currentBuffer: 0,
+ .framebuffer = 0,
+ .flags = 0,
+ .numBuffers = 0,
+ .bufferMask = 0,
+ .lock = PTHREAD_MUTEX_INITIALIZER,
+ .currentBuffer = 0,
};
/*****************************************************************************/
@@ -166,7 +166,7 @@
}
static int gralloc_alloc_buffer(alloc_device_t* dev,
- size_t size, int usage, buffer_handle_t* pHandle)
+ size_t size, int /*usage*/, buffer_handle_t* pHandle)
{
int err = 0;
int fd = -1;
diff --git a/modules/gralloc/gralloc_priv.h b/modules/gralloc/gralloc_priv.h
index 86a5d52..22a5715 100644
--- a/modules/gralloc/gralloc_priv.h
+++ b/modules/gralloc/gralloc_priv.h
@@ -75,11 +75,13 @@
int offset;
// FIXME: the attributes below should be out-of-line
- int base;
+ uintptr_t base;
int pid;
#ifdef __cplusplus
- static const int sNumInts = 6;
+ static inline int sNumInts() {
+ return (((sizeof(private_handle_t) - sizeof(native_handle_t))/sizeof(int)) - sNumFds);
+ }
static const int sNumFds = 1;
static const int sMagic = 0x3141592;
@@ -88,7 +90,7 @@
base(0), pid(getpid())
{
version = sizeof(native_handle);
- numInts = sNumInts;
+ numInts = sNumInts();
numFds = sNumFds;
}
~private_handle_t() {
@@ -98,7 +100,7 @@
static int validate(const native_handle* h) {
const private_handle_t* hnd = (const private_handle_t*)h;
if (!h || h->version != sizeof(native_handle) ||
- h->numInts != sNumInts || h->numFds != sNumFds ||
+ h->numInts != sNumInts() || h->numFds != sNumFds ||
hnd->magic != sMagic)
{
ALOGE("invalid gralloc handle (at %p)", h);
diff --git a/modules/gralloc/mapper.cpp b/modules/gralloc/mapper.cpp
index e57dba9..5a882e2 100644
--- a/modules/gralloc/mapper.cpp
+++ b/modules/gralloc/mapper.cpp
@@ -43,7 +43,7 @@
/*****************************************************************************/
-static int gralloc_map(gralloc_module_t const* module,
+static int gralloc_map(gralloc_module_t const* /*module*/,
buffer_handle_t handle,
void** vaddr)
{
@@ -56,7 +56,7 @@
ALOGE("Could not mmap %s", strerror(errno));
return -errno;
}
- hnd->base = intptr_t(mappedAddress) + hnd->offset;
+ hnd->base = uintptr_t(mappedAddress) + hnd->offset;
//ALOGD("gralloc_map() succeeded fd=%d, off=%d, size=%d, vaddr=%p",
// hnd->fd, hnd->offset, hnd->size, mappedAddress);
}
@@ -64,7 +64,7 @@
return 0;
}
-static int gralloc_unmap(gralloc_module_t const* module,
+static int gralloc_unmap(gralloc_module_t const* /*module*/,
buffer_handle_t handle)
{
private_handle_t* hnd = (private_handle_t*)handle;
@@ -82,10 +82,6 @@
/*****************************************************************************/
-static pthread_mutex_t sMapLock = PTHREAD_MUTEX_INITIALIZER;
-
-/*****************************************************************************/
-
int gralloc_register_buffer(gralloc_module_t const* module,
buffer_handle_t handle)
{
@@ -167,9 +163,9 @@
return 0;
}
-int gralloc_lock(gralloc_module_t const* module,
- buffer_handle_t handle, int usage,
- int l, int t, int w, int h,
+int gralloc_lock(gralloc_module_t const* /*module*/,
+ buffer_handle_t handle, int /*usage*/,
+ int /*l*/, int /*t*/, int /*w*/, int /*h*/,
void** vaddr)
{
// this is called when a buffer is being locked for software
@@ -188,7 +184,7 @@
return 0;
}
-int gralloc_unlock(gralloc_module_t const* module,
+int gralloc_unlock(gralloc_module_t const* /*module*/,
buffer_handle_t handle)
{
// we're done with a software buffer. nothing to do in this
diff --git a/modules/hwcomposer/Android.mk b/modules/hwcomposer/Android.mk
index f1e819b..35c0fae 100644
--- a/modules/hwcomposer/Android.mk
+++ b/modules/hwcomposer/Android.mk
@@ -19,7 +19,7 @@
# hw/<OVERLAY_HARDWARE_MODULE_ID>.<ro.product.board>.so
include $(CLEAR_VARS)
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SHARED_LIBRARIES := liblog libEGL
LOCAL_SRC_FILES := hwcomposer.cpp
LOCAL_MODULE := hwcomposer.default
diff --git a/modules/local_time/Android.mk b/modules/local_time/Android.mk
index f840dc7..91885aa 100644
--- a/modules/local_time/Android.mk
+++ b/modules/local_time/Android.mk
@@ -26,7 +26,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := local_time.default
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := local_time_hw.c
LOCAL_SHARED_LIBRARIES := liblog libcutils
LOCAL_MODULE_TAGS := optional
diff --git a/modules/nfc-nci/Android.mk b/modules/nfc-nci/Android.mk
index 97262ef..c1f679a 100644
--- a/modules/nfc-nci/Android.mk
+++ b/modules/nfc-nci/Android.mk
@@ -17,7 +17,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := nfc_nci.default
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := nfc_nci_example.c
LOCAL_SHARED_LIBRARIES := liblog libcutils
LOCAL_MODULE_TAGS := optional
diff --git a/modules/nfc/Android.mk b/modules/nfc/Android.mk
index 429fb43..29b239c 100644
--- a/modules/nfc/Android.mk
+++ b/modules/nfc/Android.mk
@@ -17,7 +17,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := nfc.default
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := nfc_pn544_example.c
LOCAL_SHARED_LIBRARIES := liblog libcutils
LOCAL_MODULE_TAGS := optional
diff --git a/modules/power/Android.mk b/modules/power/Android.mk
index 50ab221..c868ded 100644
--- a/modules/power/Android.mk
+++ b/modules/power/Android.mk
@@ -17,7 +17,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := power.default
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := power.c
LOCAL_SHARED_LIBRARIES := liblog
LOCAL_MODULE_TAGS := optional
diff --git a/modules/usbaudio/Android.mk b/modules/usbaudio/Android.mk
index 6b5e66d..199eb09 100644
--- a/modules/usbaudio/Android.mk
+++ b/modules/usbaudio/Android.mk
@@ -17,7 +17,7 @@
include $(CLEAR_VARS)
LOCAL_MODULE := audio.usb.default
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := \
audio_hw.c
LOCAL_C_INCLUDES += \
diff --git a/modules/vibrator/Android.mk b/modules/vibrator/Android.mk
new file mode 100644
index 0000000..b6b480c
--- /dev/null
+++ b/modules/vibrator/Android.mk
@@ -0,0 +1,30 @@
+# Copyright (C) 2012 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := vibrator.default
+
+# HAL module implementation stored in
+# hw/<VIBRATOR_HARDWARE_MODULE_ID>.default.so
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_C_INCLUDES := hardware/libhardware
+LOCAL_SRC_FILES := vibrator.c
+LOCAL_SHARED_LIBRARIES := liblog
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_SHARED_LIBRARY)
+
diff --git a/modules/vibrator/vibrator.c b/modules/vibrator/vibrator.c
new file mode 100644
index 0000000..ce4c03c
--- /dev/null
+++ b/modules/vibrator/vibrator.c
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <hardware/vibrator.h>
+#include <hardware/hardware.h>
+
+#include <cutils/log.h>
+
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <math.h>
+
+static const char THE_DEVICE[] = "/sys/class/timed_output/vibrator/enable";
+
+static int vibra_exists() {
+ int fd;
+
+ fd = TEMP_FAILURE_RETRY(open(THE_DEVICE, O_RDWR));
+ if(fd < 0) {
+ ALOGE("Vibrator file does not exist : %d", fd);
+ return 0;
+ }
+
+ close(fd);
+ return 1;
+}
+
+static int sendit(unsigned int timeout_ms)
+{
+ int to_write, written, ret, fd;
+
+ char value[20]; /* large enough for millions of years */
+
+ fd = TEMP_FAILURE_RETRY(open(THE_DEVICE, O_RDWR));
+ if(fd < 0) {
+ return -errno;
+ }
+
+ to_write = snprintf(value, sizeof(value), "%u\n", timeout_ms);
+ written = TEMP_FAILURE_RETRY(write(fd, value, to_write));
+
+ if (written == -1) {
+ ret = -errno;
+ } else if (written != to_write) {
+ /* even though EAGAIN is an errno value that could be set
+ by write() in some cases, none of them apply here. So, this return
+ value can be clearly identified when debugging and suggests the
+ caller that it may try to call vibraror_on() again */
+ ret = -EAGAIN;
+ } else {
+ ret = 0;
+ }
+
+ errno = 0;
+ close(fd);
+
+ return ret;
+}
+
+static int vibra_on(vibrator_device_t* vibradev __unused, unsigned int timeout_ms)
+{
+ /* constant on, up to maximum allowed time */
+ return sendit(timeout_ms);
+}
+
+static int vibra_off(vibrator_device_t* vibradev __unused)
+{
+ return sendit(0);
+}
+
+static int vibra_close(hw_device_t *device)
+{
+ free(device);
+ return 0;
+}
+
+static int vibra_open(const hw_module_t* module, const char* id __unused,
+ hw_device_t** device __unused) {
+ if (!vibra_exists()) {
+ ALOGE("Vibrator device does not exist. Cannot start vibrator");
+ return -ENODEV;
+ }
+
+ vibrator_device_t *vibradev = calloc(1, sizeof(vibrator_device_t));
+
+ if (!vibradev) {
+ ALOGE("Can not allocate memory for the vibrator device");
+ return -ENOMEM;
+ }
+
+ vibradev->common.tag = HARDWARE_DEVICE_TAG;
+ vibradev->common.module = (hw_module_t *) module;
+ vibradev->common.version = HARDWARE_DEVICE_API_VERSION(1,0);
+ vibradev->common.close = vibra_close;
+
+ vibradev->vibrator_on = vibra_on;
+ vibradev->vibrator_off = vibra_off;
+
+ *device = (hw_device_t *) vibradev;
+
+ return 0;
+}
+
+/*===========================================================================*/
+/* Default vibrator HW module interface definition */
+/*===========================================================================*/
+
+static struct hw_module_methods_t vibrator_module_methods = {
+ .open = vibra_open,
+};
+
+struct hw_module_t HAL_MODULE_INFO_SYM = {
+ .tag = HARDWARE_MODULE_TAG,
+ .module_api_version = VIBRATOR_API_VERSION,
+ .hal_api_version = HARDWARE_HAL_API_VERSION,
+ .id = VIBRATOR_HARDWARE_MODULE_ID,
+ .name = "Default vibrator HAL",
+ .author = "The Android Open Source Project",
+ .methods = &vibrator_module_methods,
+};
diff --git a/tests/keymaster/keymaster_test.cpp b/tests/keymaster/keymaster_test.cpp
index ad89012..6b76ccb 100644
--- a/tests/keymaster/keymaster_test.cpp
+++ b/tests/keymaster/keymaster_test.cpp
@@ -32,7 +32,8 @@
#define LOG_TAG "keymaster_test"
#include <utils/Log.h>
-#include <utils/UniquePtr.h>
+
+#include <UniquePtr.h>
#include <hardware/keymaster.h>