From bbb7706a17cdfbb9ec62684728402bc3a66258f7 Mon Sep 17 00:00:00 2001 From: leonardo meitz Date: Thu, 17 May 2018 15:40:20 +0200 Subject: [PATCH] added config.fs and sensor wrapper --- config.fs | 8 ++ msm8226.mk | 1 + sensors_wrapper/Android.mk | 29 ++++++ sensors_wrapper/sensorswrapper.c | 151 +++++++++++++++++++++++++++++++ 4 files changed, 189 insertions(+) create mode 100644 config.fs create mode 100644 sensors_wrapper/Android.mk create mode 100644 sensors_wrapper/sensorswrapper.c diff --git a/config.fs b/config.fs new file mode 100644 index 0000000..14d23f5 --- /dev/null +++ b/config.fs @@ -0,0 +1,8 @@ +[AID_QCOM_DIAG] +value:2950 + +[AID_RFS] +value:2951 + +[AID_RFS_SHARED] +value:2952 diff --git a/msm8226.mk b/msm8226.mk index c8abda3..a0e2e15 100644 --- a/msm8226.mk +++ b/msm8226.mk @@ -158,6 +158,7 @@ PRODUCT_PACKAGES += \ # Sensor HAL PRODUCT_PACKAGES += \ android.hardware.sensors@1.0-impl + sensors.msm8226 # Bluetooth diff --git a/sensors_wrapper/Android.mk b/sensors_wrapper/Android.mk new file mode 100644 index 0000000..474f29d --- /dev/null +++ b/sensors_wrapper/Android.mk @@ -0,0 +1,29 @@ +# Copyright (c) 2017 The LineageOS Project +# Copyright (C) 2017 Martin Bouchet +# +# 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) + +# Sensors HAL +include $(CLEAR_VARS) + +LOCAL_MODULE := sensors.$(TARGET_BOARD_PLATFORM) +LOCAL_MODULE_RELATIVE_PATH := hw +LOCAL_MODULE_TAGS := optional +LOCAL_SRC_FILES := sensorswrapper.c + +LOCAL_SHARED_LIBRARIES := liblog libcutils libhardware +LOCAL_MODULE_TAGS := optional + +include $(BUILD_SHARED_LIBRARY) diff --git a/sensors_wrapper/sensorswrapper.c b/sensors_wrapper/sensorswrapper.c new file mode 100644 index 0000000..81d32eb --- /dev/null +++ b/sensors_wrapper/sensorswrapper.c @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2017 The LineageOS Project + * Copyright (C) 2017 Martin Bouchet. + * + * 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. + */ + +#define LOG_TAG "sensors_hal_wrapper" +//#define LOG_NDEBUG 0 + +#include +#include + +#include +#include + +static struct sensors_module_t *gVendorModule = 0; +static struct sensors_poll_device_1 *samsung_hw_dev = NULL; + +#define WRAP_HAL(name, rettype, prototype, parameters) \ + static rettype wrapper_ ## name prototype { \ + return samsung_hw_dev->name parameters; \ + } + +static int check_vendor_module() { + int ret = 0; + + if (gVendorModule) + return 0; + + ret = hw_get_module_by_class("sensors", "vendor", (const hw_module_t **)&gVendorModule); + if (ret) + ALOGE("failed to open vendor sensors module"); + return ret; +} + +int sensors_list_get(struct sensors_module_t* module, struct sensor_t const** plist) { + if (check_vendor_module()) + return 0; + return gVendorModule->get_sensors_list(module, plist); +} + +static int wrapper_sensors_module_close(struct hw_device_t* device) { + int ret; + + if (!device) { + ret = -EINVAL; + } + + ret = samsung_hw_dev->common.close(device); + free(samsung_hw_dev); + + return ret; +} + +WRAP_HAL(setDelay, int, (struct sensors_poll_device_t *dev, int handle, int64_t ns), (samsung_hw_dev, handle, ns)) +WRAP_HAL(activate, int, (struct sensors_poll_device_t *dev, int handle, int enabled), (samsung_hw_dev, handle, enabled)) +WRAP_HAL(poll, int, (struct sensors_poll_device_t *dev, sensors_event_t* data, int count), (samsung_hw_dev, data, count)) +WRAP_HAL(flush, int, (struct sensors_poll_device_1_t *dev, int handle), (samsung_hw_dev, handle)) +WRAP_HAL(batch, int, (struct sensors_poll_device_1 *dev, int handle, int flags, int64_t ns, int64_t timeout), (samsung_hw_dev, handle, flags, ns, timeout)) + +static int sensors_module_open(const struct hw_module_t* module, const char* id, struct hw_device_t** device) { + int ret=0; + struct sensors_poll_device_1 *dev; + + ALOGI("Initializing wrapper for Samsung Sensor-HAL"); + if (samsung_hw_dev) { + ALOGE("Sensor HAL already opened!"); + ret = -ENODEV; + goto fail; + } + + ret = check_vendor_module(); + + if (ret) { + ALOGE("%s couldn't open sensors module in %s. (%s)", __func__, + SENSORS_HARDWARE_MODULE_ID, strerror(-ret)); + goto fail; + } + + ret = gVendorModule->common.methods->open((const hw_module_t*)gVendorModule, id, (hw_device_t**)&samsung_hw_dev); + + if (ret) { + ALOGE("%s couldn't open sensors module in %s. (%s)", __func__, + SENSORS_HARDWARE_MODULE_ID, strerror(-ret)); + goto fail; + } + + *device = malloc(sizeof(struct sensors_poll_device_1)); + + if (!*device) { + ALOGE("Can't allocate memory for device, aborting..."); + ret = -ENOMEM; + goto fail; + } + + memset(*device, 0, sizeof(struct sensors_poll_device_1)); + dev = (struct sensors_poll_device_1*)*device; + + dev->common.tag = HARDWARE_DEVICE_TAG; + dev->common.version = SENSORS_DEVICE_API_VERSION_1_3; + dev->common.module = (struct hw_module_t*)module; + + dev->common.close = wrapper_sensors_module_close; + dev->activate = wrapper_activate; + dev->setDelay = wrapper_setDelay; + dev->poll = wrapper_poll; + dev->batch = wrapper_batch; + dev->flush = wrapper_flush; + + return ret; + + fail: + if (samsung_hw_dev) { + free(samsung_hw_dev); + samsung_hw_dev = NULL; + } + if (dev) { + free(dev); + dev = NULL; + } + *device = NULL; + return ret; +} + +struct hw_module_methods_t sensors_module_methods = { + open: sensors_module_open +}; + +struct sensors_module_t HAL_MODULE_INFO_SYM = { + common: { + tag: HARDWARE_MODULE_TAG, + version_major: 1, + version_minor: 0, + id: SENSORS_HARDWARE_MODULE_ID, + name : "Samsung Sensors HAL Wrapper", + author : "Martin Bouchet (tincho5588@gmail.com)", + methods: &sensors_module_methods, + }, + get_sensors_list: sensors_list_get +};