upload android base code part4
This commit is contained in:
parent
b9e30e05b1
commit
78ea2404cd
23455 changed files with 5250148 additions and 0 deletions
66
android/hardware/interfaces/sensors/1.0/Android.bp
Normal file
66
android/hardware/interfaces/sensors/1.0/Android.bp
Normal file
|
@ -0,0 +1,66 @@
|
|||
// This file is autogenerated by hidl-gen. Do not edit manually.
|
||||
|
||||
filegroup {
|
||||
name: "android.hardware.sensors@1.0_hal",
|
||||
srcs: [
|
||||
"types.hal",
|
||||
"ISensors.hal",
|
||||
],
|
||||
}
|
||||
|
||||
genrule {
|
||||
name: "android.hardware.sensors@1.0_genc++",
|
||||
tools: ["hidl-gen"],
|
||||
cmd: "$(location hidl-gen) -o $(genDir) -Lc++-sources -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.sensors@1.0",
|
||||
srcs: [
|
||||
":android.hardware.sensors@1.0_hal",
|
||||
],
|
||||
out: [
|
||||
"android/hardware/sensors/1.0/types.cpp",
|
||||
"android/hardware/sensors/1.0/SensorsAll.cpp",
|
||||
],
|
||||
}
|
||||
|
||||
genrule {
|
||||
name: "android.hardware.sensors@1.0_genc++_headers",
|
||||
tools: ["hidl-gen"],
|
||||
cmd: "$(location hidl-gen) -o $(genDir) -Lc++-headers -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.sensors@1.0",
|
||||
srcs: [
|
||||
":android.hardware.sensors@1.0_hal",
|
||||
],
|
||||
out: [
|
||||
"android/hardware/sensors/1.0/types.h",
|
||||
"android/hardware/sensors/1.0/hwtypes.h",
|
||||
"android/hardware/sensors/1.0/ISensors.h",
|
||||
"android/hardware/sensors/1.0/IHwSensors.h",
|
||||
"android/hardware/sensors/1.0/BnHwSensors.h",
|
||||
"android/hardware/sensors/1.0/BpHwSensors.h",
|
||||
"android/hardware/sensors/1.0/BsSensors.h",
|
||||
],
|
||||
}
|
||||
|
||||
cc_library {
|
||||
name: "android.hardware.sensors@1.0",
|
||||
defaults: ["hidl-module-defaults"],
|
||||
generated_sources: ["android.hardware.sensors@1.0_genc++"],
|
||||
generated_headers: ["android.hardware.sensors@1.0_genc++_headers"],
|
||||
export_generated_headers: ["android.hardware.sensors@1.0_genc++_headers"],
|
||||
vendor_available: true,
|
||||
vndk: {
|
||||
enabled: true,
|
||||
},
|
||||
shared_libs: [
|
||||
"libhidlbase",
|
||||
"libhidltransport",
|
||||
"libhwbinder",
|
||||
"liblog",
|
||||
"libutils",
|
||||
"libcutils",
|
||||
],
|
||||
export_shared_lib_headers: [
|
||||
"libhidlbase",
|
||||
"libhidltransport",
|
||||
"libhwbinder",
|
||||
"libutils",
|
||||
],
|
||||
}
|
40
android/hardware/interfaces/sensors/1.0/Android.mk
Normal file
40
android/hardware/interfaces/sensors/1.0/Android.mk
Normal file
|
@ -0,0 +1,40 @@
|
|||
# This file is autogenerated by hidl-gen. Do not edit manually.
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
################################################################################
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := android.hardware.sensors-V1.0-java-constants
|
||||
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
|
||||
|
||||
intermediates := $(call local-generated-sources-dir, COMMON)
|
||||
|
||||
HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/sensors/V1_0/Constants.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(GEN): $(LOCAL_PATH)/ISensors.hal
|
||||
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava-constants \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.sensors@1.0
|
||||
|
||||
$(GEN):
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
# Avoid dependency cycle of framework.jar -> this-library -> framework.jar
|
||||
LOCAL_NO_STANDARD_LIBRARIES := true
|
||||
LOCAL_JAVA_LIBRARIES := core-oj
|
||||
|
||||
include $(BUILD_STATIC_JAVA_LIBRARY)
|
||||
|
||||
|
||||
|
||||
include $(call all-makefiles-under,$(LOCAL_PATH))
|
196
android/hardware/interfaces/sensors/1.0/ISensors.hal
Normal file
196
android/hardware/interfaces/sensors/1.0/ISensors.hal
Normal file
|
@ -0,0 +1,196 @@
|
|||
/*
|
||||
* Copyright (C) 2016 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.
|
||||
*/
|
||||
|
||||
package android.hardware.sensors@1.0;
|
||||
|
||||
interface ISensors {
|
||||
/**
|
||||
* Enumerate all available (static) sensors.
|
||||
*/
|
||||
getSensorsList() generates (vec<SensorInfo> list);
|
||||
|
||||
/**
|
||||
* Place the module in a specific mode. The following modes are defined
|
||||
*
|
||||
* SENSOR_HAL_NORMAL_MODE - Normal operation. Default state of the module.
|
||||
*
|
||||
* SENSOR_HAL_DATA_INJECTION_MODE - Loopback mode.
|
||||
* Data is injected for the supported sensors by the sensor service in
|
||||
* this mode.
|
||||
*
|
||||
* @return OK on success
|
||||
* BAD_VALUE if requested mode is not supported
|
||||
* PERMISSION_DENIED if operation is not allowed
|
||||
*/
|
||||
setOperationMode(OperationMode mode) generates (Result result);
|
||||
|
||||
/**
|
||||
* Activate/de-activate one sensor.
|
||||
*
|
||||
* After sensor de-activation, existing sensor events that have not
|
||||
* been picked up by poll() must be abandoned immediately so that
|
||||
* subsequent activation will not get stale sensor events (events
|
||||
* that are generated prior to the latter activation).
|
||||
*
|
||||
* @param sensorHandle is the handle of the sensor to change.
|
||||
* @param enabled set to true to enable, or false to disable the sensor.
|
||||
*
|
||||
* @return result OK on success, BAD_VALUE if sensorHandle is invalid.
|
||||
*/
|
||||
activate(int32_t sensorHandle, bool enabled) generates (Result result);
|
||||
|
||||
/**
|
||||
* Generate a vector of sensor events containing at most "maxCount"
|
||||
* entries.
|
||||
*
|
||||
* Additionally a vector of SensorInfos is returned for any dynamic sensors
|
||||
* connected as notified by returned events of type DYNAMIC_SENSOR_META.
|
||||
*
|
||||
* If there is no sensor event when this function is being called, block
|
||||
* until there are sensor events available.
|
||||
*
|
||||
* @param maxCount max number of samples can be returned, must be > 0.
|
||||
* Actual number of events returned in data must be <= maxCount
|
||||
* and > 0.
|
||||
* @return result OK on success or BAD_VALUE if maxCount <= 0.
|
||||
* @return data vector of Event contains sensor events.
|
||||
* @return dynamicSensorsAdded vector of SensorInfo contains dynamic sensor
|
||||
* added. Each element corresponds to a dynamic sensor meta events
|
||||
* in data.
|
||||
*/
|
||||
poll(int32_t maxCount)
|
||||
generates (
|
||||
Result result,
|
||||
vec<Event> data,
|
||||
vec<SensorInfo> dynamicSensorsAdded);
|
||||
|
||||
/**
|
||||
* Sets a sensor’s parameters, including sampling frequency and maximum
|
||||
* report latency. This function can be called while the sensor is
|
||||
* activated, in which case it must not cause any sensor measurements to
|
||||
* be lost: transitioning from one sampling rate to the other cannot cause
|
||||
* lost events, nor can transitioning from a high maximum report latency to
|
||||
* a low maximum report latency.
|
||||
* See the Batching sensor results page for details:
|
||||
* http://source.android.com/devices/sensors/batching.html
|
||||
*
|
||||
* @param sensorHandle handle of sensor to be changed.
|
||||
* @param samplingPeriodNs specifies sensor sample period in nanoseconds.
|
||||
* @param maxReportLatencyNs allowed delay time before an event is sampled
|
||||
* to time of report.
|
||||
* @return result OK on success, BAD_VALUE if any parameters are invalid.
|
||||
*/
|
||||
batch(int32_t sensorHandle,
|
||||
int64_t samplingPeriodNs,
|
||||
int64_t maxReportLatencyNs) generates (Result result);
|
||||
|
||||
/**
|
||||
* Trigger a flush of internal FIFO.
|
||||
*
|
||||
* Flush adds a FLUSH_COMPLETE metadata event to the end of the "batch mode"
|
||||
* FIFO for the specified sensor and flushes the FIFO. If the FIFO is empty
|
||||
* or if the sensor doesn't support batching (FIFO size zero), return
|
||||
* SUCCESS and add a trivial FLUSH_COMPLETE event added to the event stream.
|
||||
* This applies to all sensors other than one-shot sensors. If the sensor
|
||||
* is a one-shot sensor, flush must return BAD_VALUE and not generate any
|
||||
* flush complete metadata. If the sensor is not active at the time flush()
|
||||
* is called, flush() return BAD_VALUE.
|
||||
*
|
||||
* @param sensorHandle handle of sensor to be flushed.
|
||||
* @return result OK on success and BAD_VALUE if sensorHandle is invalid.
|
||||
*/
|
||||
flush(int32_t sensorHandle) generates (Result result);
|
||||
|
||||
/**
|
||||
* Inject a single sensor event or push operation environment parameters to
|
||||
* device.
|
||||
*
|
||||
* When device is in NORMAL mode, this function is called to push operation
|
||||
* environment data to device. In this operation, Event is always of
|
||||
* SensorType::AdditionalInfo type. See operation evironment parameters
|
||||
* section in AdditionalInfoType.
|
||||
*
|
||||
* When device is in DATA_INJECTION mode, this function is also used for
|
||||
* injecting sensor events.
|
||||
*
|
||||
* Regardless of OperationMode, injected SensorType::ADDITIONAL_INFO
|
||||
* type events should not be routed back to poll() function.
|
||||
*
|
||||
* @see AdditionalInfoType
|
||||
* @see OperationMode
|
||||
* @param event sensor event to be injected
|
||||
* @return result OK on success; PERMISSION_DENIED if operation is not
|
||||
* allowed; INVALID_OPERATION, if this functionality is
|
||||
* unsupported; BAD_VALUE if sensor event cannot be injected.
|
||||
*/
|
||||
injectSensorData(Event event) generates (Result result);
|
||||
|
||||
/**
|
||||
* Register direct report channel.
|
||||
*
|
||||
* Register a direct channel with supplied shared memory information. Upon
|
||||
* return, the sensor hardware is responsible for resetting the memory
|
||||
* content to initial value (depending on memory format settings).
|
||||
*
|
||||
* @param mem shared memory info data structure.
|
||||
* @return result OK on success; BAD_VALUE if shared memory information is
|
||||
* not consistent; NO_MEMORY if shared memory cannot be used by
|
||||
* sensor system; INVALID_OPERATION if functionality is not
|
||||
* supported.
|
||||
* @return channelHandle a positive integer used for referencing registered
|
||||
* direct channel (>0) in configureDirectReport and
|
||||
* unregisterDirectChannel if result is OK, -1 otherwise.
|
||||
*/
|
||||
registerDirectChannel(SharedMemInfo mem)
|
||||
generates (Result result, int32_t channelHandle);
|
||||
|
||||
/**
|
||||
* Unregister direct report channel.
|
||||
*
|
||||
* Unregister a direct channel previously registered using
|
||||
* registerDirectChannel, and remove all active sensor report configured in
|
||||
* still active sensor report configured in the direct channel.
|
||||
*
|
||||
* @param channelHandle handle of direct channel to be unregistered.
|
||||
* @return result OK if direct report is supported; INVALID_OPERATION
|
||||
* otherwise.
|
||||
*/
|
||||
unregisterDirectChannel(int32_t channelHandle) generates (Result result);
|
||||
|
||||
/**
|
||||
* Configure direct sensor event report in direct channel.
|
||||
*
|
||||
* This function start, modify rate or stop direct report of a sensor in a
|
||||
* certain direct channel.
|
||||
*
|
||||
* @param sensorHandle handle of sensor to be configured. When combined
|
||||
* with STOP rate, sensorHandle can be -1 to denote all active
|
||||
* sensors in the direct channel specified by channel Handle.
|
||||
* @param channelHandle handle of direct channel to be configured.
|
||||
* @param rate rate level, see RateLevel enum.
|
||||
*
|
||||
* @return result OK on success; BAD_VALUE if parameter is invalid (such as
|
||||
* rate level is not supported by sensor, channelHandle does not
|
||||
* exist, etc); INVALID_OPERATION if functionality is not
|
||||
* supported.
|
||||
* @return reportToken positive integer to identify multiple sensors of
|
||||
* the same type in a single direct channel. Ignored if rate is
|
||||
* STOP. See SharedMemFormat.
|
||||
*/
|
||||
configDirectReport(
|
||||
int32_t sensorHandle, int32_t channelHandle, RateLevel rate)
|
||||
generates (Result result, int32_t reportToken);
|
||||
};
|
46
android/hardware/interfaces/sensors/1.0/default/Android.bp
Normal file
46
android/hardware/interfaces/sensors/1.0/default/Android.bp
Normal file
|
@ -0,0 +1,46 @@
|
|||
cc_library_shared {
|
||||
name: "android.hardware.sensors@1.0-impl",
|
||||
defaults: ["hidl_defaults"],
|
||||
proprietary: true,
|
||||
relative_install_path: "hw",
|
||||
srcs: ["Sensors.cpp"],
|
||||
shared_libs: [
|
||||
"liblog",
|
||||
"libcutils",
|
||||
"libhardware",
|
||||
"libbase",
|
||||
"libutils",
|
||||
"libhidlbase",
|
||||
"libhidltransport",
|
||||
"android.hardware.sensors@1.0",
|
||||
],
|
||||
static_libs: [
|
||||
"android.hardware.sensors@1.0-convert",
|
||||
"multihal",
|
||||
],
|
||||
local_include_dirs: ["include/sensors"],
|
||||
}
|
||||
|
||||
cc_library_static {
|
||||
name: "android.hardware.sensors@1.0-convert",
|
||||
vendor_available: true,
|
||||
defaults: ["hidl_defaults"],
|
||||
srcs: ["convert.cpp"],
|
||||
export_include_dirs: ["include"],
|
||||
shared_libs: [
|
||||
"liblog",
|
||||
"libcutils",
|
||||
"libhardware",
|
||||
"libbase",
|
||||
"libutils",
|
||||
"libhidlbase",
|
||||
"libhidltransport",
|
||||
"android.hardware.sensors@1.0",
|
||||
],
|
||||
local_include_dirs: ["include/sensors"],
|
||||
export_shared_lib_headers: [
|
||||
"libhardware",
|
||||
],
|
||||
}
|
||||
|
||||
|
23
android/hardware/interfaces/sensors/1.0/default/Android.mk
Normal file
23
android/hardware/interfaces/sensors/1.0/default/Android.mk
Normal file
|
@ -0,0 +1,23 @@
|
|||
LOCAL_PATH:= $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE_RELATIVE_PATH := hw
|
||||
LOCAL_PROPRIETARY_MODULE := true
|
||||
LOCAL_MODULE := android.hardware.sensors@1.0-service
|
||||
LOCAL_INIT_RC := android.hardware.sensors@1.0-service.rc
|
||||
LOCAL_SRC_FILES := \
|
||||
service.cpp \
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := \
|
||||
liblog \
|
||||
libcutils \
|
||||
libdl \
|
||||
libbase \
|
||||
libutils \
|
||||
|
||||
LOCAL_SHARED_LIBRARIES += \
|
||||
libhidlbase \
|
||||
libhidltransport \
|
||||
android.hardware.sensors@1.0 \
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
360
android/hardware/interfaces/sensors/1.0/default/Sensors.cpp
Normal file
360
android/hardware/interfaces/sensors/1.0/default/Sensors.cpp
Normal file
|
@ -0,0 +1,360 @@
|
|||
/*
|
||||
* Copyright (C) 2016 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 "Sensors.h"
|
||||
#include "convert.h"
|
||||
#include "multihal.h"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace sensors {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
/*
|
||||
* If a multi-hal configuration file exists in the proper location,
|
||||
* return true indicating we need to use multi-hal functionality.
|
||||
*/
|
||||
static bool UseMultiHal() {
|
||||
const std::string& name = MULTI_HAL_CONFIG_FILE_PATH;
|
||||
struct stat buffer;
|
||||
return (stat (name.c_str(), &buffer) == 0);
|
||||
}
|
||||
|
||||
static Result ResultFromStatus(status_t err) {
|
||||
switch (err) {
|
||||
case OK:
|
||||
return Result::OK;
|
||||
case PERMISSION_DENIED:
|
||||
return Result::PERMISSION_DENIED;
|
||||
case NO_MEMORY:
|
||||
return Result::NO_MEMORY;
|
||||
case BAD_VALUE:
|
||||
return Result::BAD_VALUE;
|
||||
default:
|
||||
return Result::INVALID_OPERATION;
|
||||
}
|
||||
}
|
||||
|
||||
Sensors::Sensors()
|
||||
: mInitCheck(NO_INIT),
|
||||
mSensorModule(nullptr),
|
||||
mSensorDevice(nullptr) {
|
||||
status_t err = OK;
|
||||
if (UseMultiHal()) {
|
||||
mSensorModule = ::get_multi_hal_module_info();
|
||||
} else {
|
||||
err = hw_get_module(
|
||||
SENSORS_HARDWARE_MODULE_ID,
|
||||
(hw_module_t const **)&mSensorModule);
|
||||
}
|
||||
if (mSensorModule == NULL) {
|
||||
err = UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
if (err != OK) {
|
||||
LOG(ERROR) << "Couldn't load "
|
||||
<< SENSORS_HARDWARE_MODULE_ID
|
||||
<< " module ("
|
||||
<< strerror(-err)
|
||||
<< ")";
|
||||
|
||||
mInitCheck = err;
|
||||
return;
|
||||
}
|
||||
|
||||
err = sensors_open_1(&mSensorModule->common, &mSensorDevice);
|
||||
|
||||
if (err != OK) {
|
||||
LOG(ERROR) << "Couldn't open device for module "
|
||||
<< SENSORS_HARDWARE_MODULE_ID
|
||||
<< " ("
|
||||
<< strerror(-err)
|
||||
<< ")";
|
||||
|
||||
mInitCheck = err;
|
||||
return;
|
||||
}
|
||||
|
||||
// Require all the old HAL APIs to be present except for injection, which
|
||||
// is considered optional.
|
||||
CHECK_GE(getHalDeviceVersion(), SENSORS_DEVICE_API_VERSION_1_3);
|
||||
|
||||
if (getHalDeviceVersion() == SENSORS_DEVICE_API_VERSION_1_4) {
|
||||
if (mSensorDevice->inject_sensor_data == nullptr) {
|
||||
LOG(ERROR) << "HAL specifies version 1.4, but does not implement inject_sensor_data()";
|
||||
}
|
||||
if (mSensorModule->set_operation_mode == nullptr) {
|
||||
LOG(ERROR) << "HAL specifies version 1.4, but does not implement set_operation_mode()";
|
||||
}
|
||||
}
|
||||
|
||||
mInitCheck = OK;
|
||||
}
|
||||
|
||||
status_t Sensors::initCheck() const {
|
||||
return mInitCheck;
|
||||
}
|
||||
|
||||
Return<void> Sensors::getSensorsList(getSensorsList_cb _hidl_cb) {
|
||||
sensor_t const *list;
|
||||
size_t count = mSensorModule->get_sensors_list(mSensorModule, &list);
|
||||
|
||||
hidl_vec<SensorInfo> out;
|
||||
out.resize(count);
|
||||
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
const sensor_t *src = &list[i];
|
||||
SensorInfo *dst = &out[i];
|
||||
|
||||
convertFromSensor(*src, dst);
|
||||
}
|
||||
|
||||
_hidl_cb(out);
|
||||
|
||||
return Void();
|
||||
}
|
||||
|
||||
int Sensors::getHalDeviceVersion() const {
|
||||
if (!mSensorDevice) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return mSensorDevice->common.version;
|
||||
}
|
||||
|
||||
Return<Result> Sensors::setOperationMode(OperationMode mode) {
|
||||
if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4
|
||||
|| mSensorModule->set_operation_mode == nullptr) {
|
||||
return Result::INVALID_OPERATION;
|
||||
}
|
||||
return ResultFromStatus(mSensorModule->set_operation_mode((uint32_t)mode));
|
||||
}
|
||||
|
||||
Return<Result> Sensors::activate(
|
||||
int32_t sensor_handle, bool enabled) {
|
||||
return ResultFromStatus(
|
||||
mSensorDevice->activate(
|
||||
reinterpret_cast<sensors_poll_device_t *>(mSensorDevice),
|
||||
sensor_handle,
|
||||
enabled));
|
||||
}
|
||||
|
||||
Return<void> Sensors::poll(int32_t maxCount, poll_cb _hidl_cb) {
|
||||
|
||||
hidl_vec<Event> out;
|
||||
hidl_vec<SensorInfo> dynamicSensorsAdded;
|
||||
|
||||
std::unique_ptr<sensors_event_t[]> data;
|
||||
int err = android::NO_ERROR;
|
||||
|
||||
{ // scope of reentry lock
|
||||
|
||||
// This enforces a single client, meaning that a maximum of one client can call poll().
|
||||
// If this function is re-entred, it means that we are stuck in a state that may prevent
|
||||
// the system from proceeding normally.
|
||||
//
|
||||
// Exit and let the system restart the sensor-hal-implementation hidl service.
|
||||
//
|
||||
// This function must not call _hidl_cb(...) or return until there is no risk of blocking.
|
||||
std::unique_lock<std::mutex> lock(mPollLock, std::try_to_lock);
|
||||
if(!lock.owns_lock()){
|
||||
// cannot get the lock, hidl service will go into deadlock if it is not restarted.
|
||||
// This is guaranteed to not trigger in passthrough mode.
|
||||
LOG(ERROR) <<
|
||||
"ISensors::poll() re-entry. I do not know what to do except killing myself.";
|
||||
::exit(-1);
|
||||
}
|
||||
|
||||
if (maxCount <= 0) {
|
||||
err = android::BAD_VALUE;
|
||||
} else {
|
||||
int bufferSize = maxCount <= kPollMaxBufferSize ? maxCount : kPollMaxBufferSize;
|
||||
data.reset(new sensors_event_t[bufferSize]);
|
||||
err = mSensorDevice->poll(
|
||||
reinterpret_cast<sensors_poll_device_t *>(mSensorDevice),
|
||||
data.get(), bufferSize);
|
||||
}
|
||||
}
|
||||
|
||||
if (err < 0) {
|
||||
_hidl_cb(ResultFromStatus(err), out, dynamicSensorsAdded);
|
||||
return Void();
|
||||
}
|
||||
|
||||
const size_t count = (size_t)err;
|
||||
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
if (data[i].type != SENSOR_TYPE_DYNAMIC_SENSOR_META) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const dynamic_sensor_meta_event_t *dyn = &data[i].dynamic_sensor_meta;
|
||||
|
||||
if (!dyn->connected) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CHECK(dyn->sensor != nullptr);
|
||||
CHECK_EQ(dyn->sensor->handle, dyn->handle);
|
||||
|
||||
SensorInfo info;
|
||||
convertFromSensor(*dyn->sensor, &info);
|
||||
|
||||
size_t numDynamicSensors = dynamicSensorsAdded.size();
|
||||
dynamicSensorsAdded.resize(numDynamicSensors + 1);
|
||||
dynamicSensorsAdded[numDynamicSensors] = info;
|
||||
}
|
||||
|
||||
out.resize(count);
|
||||
convertFromSensorEvents(err, data.get(), &out);
|
||||
|
||||
_hidl_cb(Result::OK, out, dynamicSensorsAdded);
|
||||
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<Result> Sensors::batch(
|
||||
int32_t sensor_handle,
|
||||
int64_t sampling_period_ns,
|
||||
int64_t max_report_latency_ns) {
|
||||
return ResultFromStatus(
|
||||
mSensorDevice->batch(
|
||||
mSensorDevice,
|
||||
sensor_handle,
|
||||
0, /*flags*/
|
||||
sampling_period_ns,
|
||||
max_report_latency_ns));
|
||||
}
|
||||
|
||||
Return<Result> Sensors::flush(int32_t sensor_handle) {
|
||||
return ResultFromStatus(mSensorDevice->flush(mSensorDevice, sensor_handle));
|
||||
}
|
||||
|
||||
Return<Result> Sensors::injectSensorData(const Event& event) {
|
||||
if (getHalDeviceVersion() < SENSORS_DEVICE_API_VERSION_1_4
|
||||
|| mSensorDevice->inject_sensor_data == nullptr) {
|
||||
return Result::INVALID_OPERATION;
|
||||
}
|
||||
|
||||
sensors_event_t out;
|
||||
convertToSensorEvent(event, &out);
|
||||
|
||||
return ResultFromStatus(
|
||||
mSensorDevice->inject_sensor_data(mSensorDevice, &out));
|
||||
}
|
||||
|
||||
Return<void> Sensors::registerDirectChannel(
|
||||
const SharedMemInfo& mem, registerDirectChannel_cb _hidl_cb) {
|
||||
if (mSensorDevice->register_direct_channel == nullptr
|
||||
|| mSensorDevice->config_direct_report == nullptr) {
|
||||
// HAL does not support
|
||||
_hidl_cb(Result::INVALID_OPERATION, -1);
|
||||
return Void();
|
||||
}
|
||||
|
||||
sensors_direct_mem_t m;
|
||||
if (!convertFromSharedMemInfo(mem, &m)) {
|
||||
_hidl_cb(Result::BAD_VALUE, -1);
|
||||
return Void();
|
||||
}
|
||||
|
||||
int err = mSensorDevice->register_direct_channel(mSensorDevice, &m, -1);
|
||||
|
||||
if (err < 0) {
|
||||
_hidl_cb(ResultFromStatus(err), -1);
|
||||
} else {
|
||||
int32_t channelHandle = static_cast<int32_t>(err);
|
||||
_hidl_cb(Result::OK, channelHandle);
|
||||
}
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<Result> Sensors::unregisterDirectChannel(int32_t channelHandle) {
|
||||
if (mSensorDevice->register_direct_channel == nullptr
|
||||
|| mSensorDevice->config_direct_report == nullptr) {
|
||||
// HAL does not support
|
||||
return Result::INVALID_OPERATION;
|
||||
}
|
||||
|
||||
mSensorDevice->register_direct_channel(mSensorDevice, nullptr, channelHandle);
|
||||
|
||||
return Result::OK;
|
||||
}
|
||||
|
||||
Return<void> Sensors::configDirectReport(
|
||||
int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
|
||||
configDirectReport_cb _hidl_cb) {
|
||||
if (mSensorDevice->register_direct_channel == nullptr
|
||||
|| mSensorDevice->config_direct_report == nullptr) {
|
||||
// HAL does not support
|
||||
_hidl_cb(Result::INVALID_OPERATION, -1);
|
||||
return Void();
|
||||
}
|
||||
|
||||
sensors_direct_cfg_t cfg = {
|
||||
.rate_level = convertFromRateLevel(rate)
|
||||
};
|
||||
if (cfg.rate_level < 0) {
|
||||
_hidl_cb(Result::BAD_VALUE, -1);
|
||||
return Void();
|
||||
}
|
||||
|
||||
int err = mSensorDevice->config_direct_report(mSensorDevice,
|
||||
sensorHandle, channelHandle, &cfg);
|
||||
|
||||
if (rate == RateLevel::STOP) {
|
||||
_hidl_cb(ResultFromStatus(err), -1);
|
||||
} else {
|
||||
_hidl_cb(err > 0 ? Result::OK : ResultFromStatus(err), err);
|
||||
}
|
||||
return Void();
|
||||
}
|
||||
|
||||
// static
|
||||
void Sensors::convertFromSensorEvents(
|
||||
size_t count,
|
||||
const sensors_event_t *srcArray,
|
||||
hidl_vec<Event> *dstVec) {
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
const sensors_event_t &src = srcArray[i];
|
||||
Event *dst = &(*dstVec)[i];
|
||||
|
||||
convertFromSensorEvent(src, dst);
|
||||
}
|
||||
}
|
||||
|
||||
ISensors *HIDL_FETCH_ISensors(const char * /* hal */) {
|
||||
Sensors *sensors = new Sensors;
|
||||
if (sensors->initCheck() != OK) {
|
||||
delete sensors;
|
||||
sensors = nullptr;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return sensors;
|
||||
}
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace sensors
|
||||
} // namespace hardware
|
||||
} // namespace android
|
88
android/hardware/interfaces/sensors/1.0/default/Sensors.h
Normal file
88
android/hardware/interfaces/sensors/1.0/default/Sensors.h
Normal file
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright (C) 2016 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_INTERFACES_SENSORS_V1_0_DEFAULT_SENSORS_H_
|
||||
|
||||
#define HARDWARE_INTERFACES_SENSORS_V1_0_DEFAULT_SENSORS_H_
|
||||
|
||||
#include <android-base/macros.h>
|
||||
#include <android/hardware/sensors/1.0/ISensors.h>
|
||||
#include <hardware/sensors.h>
|
||||
#include <mutex>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace sensors {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
|
||||
struct Sensors : public ::android::hardware::sensors::V1_0::ISensors {
|
||||
Sensors();
|
||||
|
||||
status_t initCheck() const;
|
||||
|
||||
Return<void> getSensorsList(getSensorsList_cb _hidl_cb) override;
|
||||
|
||||
Return<Result> setOperationMode(OperationMode mode) override;
|
||||
|
||||
Return<Result> activate(
|
||||
int32_t sensor_handle, bool enabled) override;
|
||||
|
||||
Return<void> poll(int32_t maxCount, poll_cb _hidl_cb) override;
|
||||
|
||||
Return<Result> batch(
|
||||
int32_t sensor_handle,
|
||||
int64_t sampling_period_ns,
|
||||
int64_t max_report_latency_ns) override;
|
||||
|
||||
Return<Result> flush(int32_t sensor_handle) override;
|
||||
|
||||
Return<Result> injectSensorData(const Event& event) override;
|
||||
|
||||
Return<void> registerDirectChannel(
|
||||
const SharedMemInfo& mem, registerDirectChannel_cb _hidl_cb) override;
|
||||
|
||||
Return<Result> unregisterDirectChannel(int32_t channelHandle) override;
|
||||
|
||||
Return<void> configDirectReport(
|
||||
int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
|
||||
configDirectReport_cb _hidl_cb) override;
|
||||
|
||||
private:
|
||||
static constexpr int32_t kPollMaxBufferSize = 128;
|
||||
status_t mInitCheck;
|
||||
sensors_module_t *mSensorModule;
|
||||
sensors_poll_device_1_t *mSensorDevice;
|
||||
std::mutex mPollLock;
|
||||
|
||||
int getHalDeviceVersion() const;
|
||||
|
||||
static void convertFromSensorEvents(
|
||||
size_t count, const sensors_event_t *src, hidl_vec<Event> *dst);
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Sensors);
|
||||
};
|
||||
|
||||
extern "C" ISensors *HIDL_FETCH_ISensors(const char *name);
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace sensors
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
||||
#endif // HARDWARE_INTERFACES_SENSORS_V1_0_DEFAULT_SENSORS_H_
|
|
@ -0,0 +1,5 @@
|
|||
service sensors-hal-1-0 /vendor/bin/hw/android.hardware.sensors@1.0-service
|
||||
class hal
|
||||
user system
|
||||
group system wakelock input
|
||||
capabilities BLOCK_SUSPEND SYS_NICE
|
408
android/hardware/interfaces/sensors/1.0/default/convert.cpp
Normal file
408
android/hardware/interfaces/sensors/1.0/default/convert.cpp
Normal file
|
@ -0,0 +1,408 @@
|
|||
/*
|
||||
* Copyright (C) 2016 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 "convert.h"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace sensors {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
void convertFromSensor(const sensor_t &src, SensorInfo *dst) {
|
||||
dst->name = src.name;
|
||||
dst->vendor = src.vendor;
|
||||
dst->version = src.version;
|
||||
dst->sensorHandle = src.handle;
|
||||
dst->type = (SensorType)src.type;
|
||||
dst->maxRange = src.maxRange;
|
||||
dst->resolution = src.resolution;
|
||||
dst->power = src.power;
|
||||
dst->minDelay = src.minDelay;
|
||||
dst->fifoReservedEventCount = src.fifoReservedEventCount;
|
||||
dst->fifoMaxEventCount = src.fifoMaxEventCount;
|
||||
dst->typeAsString = src.stringType;
|
||||
dst->requiredPermission = src.requiredPermission;
|
||||
dst->maxDelay = src.maxDelay;
|
||||
dst->flags = src.flags;
|
||||
}
|
||||
|
||||
void convertToSensor(
|
||||
const ::android::hardware::sensors::V1_0::SensorInfo &src,
|
||||
sensor_t *dst) {
|
||||
dst->name = strdup(src.name.c_str());
|
||||
dst->vendor = strdup(src.vendor.c_str());
|
||||
dst->version = src.version;
|
||||
dst->handle = src.sensorHandle;
|
||||
dst->type = (int)src.type;
|
||||
dst->maxRange = src.maxRange;
|
||||
dst->resolution = src.resolution;
|
||||
dst->power = src.power;
|
||||
dst->minDelay = src.minDelay;
|
||||
dst->fifoReservedEventCount = src.fifoReservedEventCount;
|
||||
dst->fifoMaxEventCount = src.fifoMaxEventCount;
|
||||
dst->stringType = strdup(src.typeAsString.c_str());
|
||||
dst->requiredPermission = strdup(src.requiredPermission.c_str());
|
||||
dst->maxDelay = src.maxDelay;
|
||||
dst->flags = src.flags;
|
||||
dst->reserved[0] = dst->reserved[1] = 0;
|
||||
}
|
||||
|
||||
void convertFromSensorEvent(const sensors_event_t &src, Event *dst) {
|
||||
typedef ::android::hardware::sensors::V1_0::SensorType SensorType;
|
||||
typedef ::android::hardware::sensors::V1_0::MetaDataEventType MetaDataEventType;
|
||||
|
||||
*dst = {
|
||||
.sensorHandle = src.sensor,
|
||||
.sensorType = (SensorType)src.type,
|
||||
.timestamp = src.timestamp
|
||||
};
|
||||
|
||||
switch (dst->sensorType) {
|
||||
case SensorType::META_DATA:
|
||||
{
|
||||
dst->u.meta.what = (MetaDataEventType)src.meta_data.what;
|
||||
// Legacy HALs contain the handle reference in the meta data field.
|
||||
// Copy that over to the handle of the event. In legacy HALs this
|
||||
// field was expected to be 0.
|
||||
dst->sensorHandle = src.meta_data.sensor;
|
||||
break;
|
||||
}
|
||||
|
||||
case SensorType::ACCELEROMETER:
|
||||
case SensorType::MAGNETIC_FIELD:
|
||||
case SensorType::ORIENTATION:
|
||||
case SensorType::GYROSCOPE:
|
||||
case SensorType::GRAVITY:
|
||||
case SensorType::LINEAR_ACCELERATION:
|
||||
{
|
||||
dst->u.vec3.x = src.acceleration.x;
|
||||
dst->u.vec3.y = src.acceleration.y;
|
||||
dst->u.vec3.z = src.acceleration.z;
|
||||
dst->u.vec3.status = (SensorStatus)src.acceleration.status;
|
||||
break;
|
||||
}
|
||||
|
||||
case SensorType::ROTATION_VECTOR:
|
||||
case SensorType::GAME_ROTATION_VECTOR:
|
||||
case SensorType::GEOMAGNETIC_ROTATION_VECTOR:
|
||||
{
|
||||
dst->u.vec4.x = src.data[0];
|
||||
dst->u.vec4.y = src.data[1];
|
||||
dst->u.vec4.z = src.data[2];
|
||||
dst->u.vec4.w = src.data[3];
|
||||
break;
|
||||
}
|
||||
|
||||
case SensorType::MAGNETIC_FIELD_UNCALIBRATED:
|
||||
case SensorType::GYROSCOPE_UNCALIBRATED:
|
||||
case SensorType::ACCELEROMETER_UNCALIBRATED:
|
||||
{
|
||||
dst->u.uncal.x = src.uncalibrated_gyro.x_uncalib;
|
||||
dst->u.uncal.y = src.uncalibrated_gyro.y_uncalib;
|
||||
dst->u.uncal.z = src.uncalibrated_gyro.z_uncalib;
|
||||
dst->u.uncal.x_bias = src.uncalibrated_gyro.x_bias;
|
||||
dst->u.uncal.y_bias = src.uncalibrated_gyro.y_bias;
|
||||
dst->u.uncal.z_bias = src.uncalibrated_gyro.z_bias;
|
||||
break;
|
||||
}
|
||||
|
||||
case SensorType::DEVICE_ORIENTATION:
|
||||
case SensorType::LIGHT:
|
||||
case SensorType::PRESSURE:
|
||||
case SensorType::TEMPERATURE:
|
||||
case SensorType::PROXIMITY:
|
||||
case SensorType::RELATIVE_HUMIDITY:
|
||||
case SensorType::AMBIENT_TEMPERATURE:
|
||||
case SensorType::SIGNIFICANT_MOTION:
|
||||
case SensorType::STEP_DETECTOR:
|
||||
case SensorType::TILT_DETECTOR:
|
||||
case SensorType::WAKE_GESTURE:
|
||||
case SensorType::GLANCE_GESTURE:
|
||||
case SensorType::PICK_UP_GESTURE:
|
||||
case SensorType::WRIST_TILT_GESTURE:
|
||||
case SensorType::STATIONARY_DETECT:
|
||||
case SensorType::MOTION_DETECT:
|
||||
case SensorType::HEART_BEAT:
|
||||
case SensorType::LOW_LATENCY_OFFBODY_DETECT:
|
||||
{
|
||||
dst->u.scalar = src.data[0];
|
||||
break;
|
||||
}
|
||||
|
||||
case SensorType::STEP_COUNTER:
|
||||
{
|
||||
dst->u.stepCount = src.u64.step_counter;
|
||||
break;
|
||||
}
|
||||
|
||||
case SensorType::HEART_RATE:
|
||||
{
|
||||
dst->u.heartRate.bpm = src.heart_rate.bpm;
|
||||
dst->u.heartRate.status = (SensorStatus)src.heart_rate.status;
|
||||
break;
|
||||
}
|
||||
|
||||
case SensorType::POSE_6DOF: // 15 floats
|
||||
{
|
||||
for (size_t i = 0; i < 15; ++i) {
|
||||
dst->u.pose6DOF[i] = src.data[i];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SensorType::DYNAMIC_SENSOR_META:
|
||||
{
|
||||
dst->u.dynamic.connected = src.dynamic_sensor_meta.connected;
|
||||
dst->u.dynamic.sensorHandle = src.dynamic_sensor_meta.handle;
|
||||
|
||||
memcpy(dst->u.dynamic.uuid.data(),
|
||||
src.dynamic_sensor_meta.uuid,
|
||||
16);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case SensorType::ADDITIONAL_INFO:
|
||||
{
|
||||
::android::hardware::sensors::V1_0::AdditionalInfo *dstInfo =
|
||||
&dst->u.additional;
|
||||
|
||||
const additional_info_event_t &srcInfo = src.additional_info;
|
||||
|
||||
dstInfo->type =
|
||||
(::android::hardware::sensors::V1_0::AdditionalInfoType)
|
||||
srcInfo.type;
|
||||
|
||||
dstInfo->serial = srcInfo.serial;
|
||||
|
||||
CHECK_EQ(sizeof(dstInfo->u), sizeof(srcInfo.data_int32));
|
||||
memcpy(&dstInfo->u, srcInfo.data_int32, sizeof(srcInfo.data_int32));
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
CHECK_GE((int32_t)dst->sensorType,
|
||||
(int32_t)SensorType::DEVICE_PRIVATE_BASE);
|
||||
|
||||
memcpy(dst->u.data.data(), src.data, 16 * sizeof(float));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void convertToSensorEvent(const Event &src, sensors_event_t *dst) {
|
||||
*dst = {
|
||||
.version = sizeof(sensors_event_t),
|
||||
.sensor = src.sensorHandle,
|
||||
.type = (int32_t)src.sensorType,
|
||||
.reserved0 = 0,
|
||||
.timestamp = src.timestamp
|
||||
};
|
||||
|
||||
switch (src.sensorType) {
|
||||
case SensorType::META_DATA:
|
||||
{
|
||||
// Legacy HALs expect the handle reference in the meta data field.
|
||||
// Copy it over from the handle of the event.
|
||||
dst->meta_data.what = (int32_t)src.u.meta.what;
|
||||
dst->meta_data.sensor = src.sensorHandle;
|
||||
// Set the sensor handle to 0 to maintain compatibility.
|
||||
dst->sensor = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
case SensorType::ACCELEROMETER:
|
||||
case SensorType::MAGNETIC_FIELD:
|
||||
case SensorType::ORIENTATION:
|
||||
case SensorType::GYROSCOPE:
|
||||
case SensorType::GRAVITY:
|
||||
case SensorType::LINEAR_ACCELERATION:
|
||||
{
|
||||
dst->acceleration.x = src.u.vec3.x;
|
||||
dst->acceleration.y = src.u.vec3.y;
|
||||
dst->acceleration.z = src.u.vec3.z;
|
||||
dst->acceleration.status = (int8_t)src.u.vec3.status;
|
||||
break;
|
||||
}
|
||||
|
||||
case SensorType::ROTATION_VECTOR:
|
||||
case SensorType::GAME_ROTATION_VECTOR:
|
||||
case SensorType::GEOMAGNETIC_ROTATION_VECTOR:
|
||||
{
|
||||
dst->data[0] = src.u.vec4.x;
|
||||
dst->data[1] = src.u.vec4.y;
|
||||
dst->data[2] = src.u.vec4.z;
|
||||
dst->data[3] = src.u.vec4.w;
|
||||
break;
|
||||
}
|
||||
|
||||
case SensorType::MAGNETIC_FIELD_UNCALIBRATED:
|
||||
case SensorType::GYROSCOPE_UNCALIBRATED:
|
||||
case SensorType::ACCELEROMETER_UNCALIBRATED:
|
||||
{
|
||||
dst->uncalibrated_gyro.x_uncalib = src.u.uncal.x;
|
||||
dst->uncalibrated_gyro.y_uncalib = src.u.uncal.y;
|
||||
dst->uncalibrated_gyro.z_uncalib = src.u.uncal.z;
|
||||
dst->uncalibrated_gyro.x_bias = src.u.uncal.x_bias;
|
||||
dst->uncalibrated_gyro.y_bias = src.u.uncal.y_bias;
|
||||
dst->uncalibrated_gyro.z_bias = src.u.uncal.z_bias;
|
||||
break;
|
||||
}
|
||||
|
||||
case SensorType::DEVICE_ORIENTATION:
|
||||
case SensorType::LIGHT:
|
||||
case SensorType::PRESSURE:
|
||||
case SensorType::TEMPERATURE:
|
||||
case SensorType::PROXIMITY:
|
||||
case SensorType::RELATIVE_HUMIDITY:
|
||||
case SensorType::AMBIENT_TEMPERATURE:
|
||||
case SensorType::SIGNIFICANT_MOTION:
|
||||
case SensorType::STEP_DETECTOR:
|
||||
case SensorType::TILT_DETECTOR:
|
||||
case SensorType::WAKE_GESTURE:
|
||||
case SensorType::GLANCE_GESTURE:
|
||||
case SensorType::PICK_UP_GESTURE:
|
||||
case SensorType::WRIST_TILT_GESTURE:
|
||||
case SensorType::STATIONARY_DETECT:
|
||||
case SensorType::MOTION_DETECT:
|
||||
case SensorType::HEART_BEAT:
|
||||
case SensorType::LOW_LATENCY_OFFBODY_DETECT:
|
||||
{
|
||||
dst->data[0] = src.u.scalar;
|
||||
break;
|
||||
}
|
||||
|
||||
case SensorType::STEP_COUNTER:
|
||||
{
|
||||
dst->u64.step_counter = src.u.stepCount;
|
||||
break;
|
||||
}
|
||||
|
||||
case SensorType::HEART_RATE:
|
||||
{
|
||||
dst->heart_rate.bpm = src.u.heartRate.bpm;
|
||||
dst->heart_rate.status = (int8_t)src.u.heartRate.status;
|
||||
break;
|
||||
}
|
||||
|
||||
case SensorType::POSE_6DOF: // 15 floats
|
||||
{
|
||||
for (size_t i = 0; i < 15; ++i) {
|
||||
dst->data[i] = src.u.pose6DOF[i];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SensorType::DYNAMIC_SENSOR_META:
|
||||
{
|
||||
dst->dynamic_sensor_meta.connected = src.u.dynamic.connected;
|
||||
dst->dynamic_sensor_meta.handle = src.u.dynamic.sensorHandle;
|
||||
dst->dynamic_sensor_meta.sensor = NULL; // to be filled in later
|
||||
|
||||
memcpy(dst->dynamic_sensor_meta.uuid,
|
||||
src.u.dynamic.uuid.data(),
|
||||
16);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case SensorType::ADDITIONAL_INFO:
|
||||
{
|
||||
const ::android::hardware::sensors::V1_0::AdditionalInfo &srcInfo =
|
||||
src.u.additional;
|
||||
|
||||
additional_info_event_t *dstInfo = &dst->additional_info;
|
||||
dstInfo->type = (int32_t)srcInfo.type;
|
||||
dstInfo->serial = srcInfo.serial;
|
||||
|
||||
CHECK_EQ(sizeof(srcInfo.u), sizeof(dstInfo->data_int32));
|
||||
|
||||
memcpy(dstInfo->data_int32,
|
||||
&srcInfo.u,
|
||||
sizeof(dstInfo->data_int32));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
CHECK_GE((int32_t)src.sensorType,
|
||||
(int32_t)SensorType::DEVICE_PRIVATE_BASE);
|
||||
|
||||
memcpy(dst->data, src.u.data.data(), 16 * sizeof(float));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool convertFromSharedMemInfo(const SharedMemInfo& memIn, sensors_direct_mem_t *memOut) {
|
||||
if (memOut == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch(memIn.type) {
|
||||
case SharedMemType::ASHMEM:
|
||||
memOut->type = SENSOR_DIRECT_MEM_TYPE_ASHMEM;
|
||||
break;
|
||||
case SharedMemType::GRALLOC:
|
||||
memOut->type = SENSOR_DIRECT_MEM_TYPE_GRALLOC;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
switch(memIn.format) {
|
||||
case SharedMemFormat::SENSORS_EVENT:
|
||||
memOut->format = SENSOR_DIRECT_FMT_SENSORS_EVENT;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (memIn.memoryHandle == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
memOut->size = memIn.size;
|
||||
memOut->handle = memIn.memoryHandle;
|
||||
return true;
|
||||
}
|
||||
|
||||
int convertFromRateLevel(RateLevel rate) {
|
||||
switch(rate) {
|
||||
case RateLevel::STOP:
|
||||
return SENSOR_DIRECT_RATE_STOP;
|
||||
case RateLevel::NORMAL:
|
||||
return SENSOR_DIRECT_RATE_NORMAL;
|
||||
case RateLevel::FAST:
|
||||
return SENSOR_DIRECT_RATE_FAST;
|
||||
case RateLevel::VERY_FAST:
|
||||
return SENSOR_DIRECT_RATE_VERY_FAST;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace sensors
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (C) 2016 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_INTERFACES_SENSORS_V1_0_DEFAULT_INCLUDE_CONVERT_H_
|
||||
|
||||
#define HARDWARE_INTERFACES_SENSORS_V1_0_DEFAULT_INCLUDE_CONVERT_H_
|
||||
|
||||
#include <android/hardware/sensors/1.0/ISensors.h>
|
||||
#include <hardware/sensors.h>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace sensors {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
void convertFromSensor(const sensor_t &src, SensorInfo *dst);
|
||||
void convertToSensor(const SensorInfo &src, sensor_t *dst);
|
||||
|
||||
void convertFromSensorEvent(const sensors_event_t &src, Event *dst);
|
||||
void convertToSensorEvent(const Event &src, sensors_event_t *dst);
|
||||
|
||||
bool convertFromSharedMemInfo(const SharedMemInfo& memIn, sensors_direct_mem_t *memOut);
|
||||
int convertFromRateLevel(RateLevel rate);
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace sensors
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
||||
#endif // HARDWARE_INTERFACES_SENSORS_V1_0_DEFAULT_INCLUDE_CONVERT_H_
|
31
android/hardware/interfaces/sensors/1.0/default/service.cpp
Normal file
31
android/hardware/interfaces/sensors/1.0/default/service.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (C) 2016 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.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "android.hardware.sensors@1.0-service"
|
||||
|
||||
#include <android/hardware/sensors/1.0/ISensors.h>
|
||||
#include <hidl/LegacySupport.h>
|
||||
|
||||
using android::hardware::sensors::V1_0::ISensors;
|
||||
using android::hardware::defaultPassthroughServiceImplementation;
|
||||
|
||||
int main() {
|
||||
/* Sensors framework service needs at least two threads.
|
||||
* One thread blocks on a "poll"
|
||||
* The second thread is needed for all other HAL methods.
|
||||
*/
|
||||
return defaultPassthroughServiceImplementation<ISensors>(2);
|
||||
}
|
1296
android/hardware/interfaces/sensors/1.0/types.hal
Normal file
1296
android/hardware/interfaces/sensors/1.0/types.hal
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,23 @@
|
|||
//
|
||||
// Copyright (C) 2016 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.
|
||||
//
|
||||
|
||||
cc_test {
|
||||
name: "VtsHalSensorsV1_0TargetTest",
|
||||
defaults: ["VtsHalTargetTestDefaults"],
|
||||
srcs: ["VtsHalSensorsV1_0TargetTest.cpp"],
|
||||
static_libs: ["android.hardware.sensors@1.0"],
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue