diff --git a/sensors/2.0/Android.bp b/sensors/2.0/Android.bp deleted file mode 100644 index 878f2e3..0000000 --- a/sensors/2.0/Android.bp +++ /dev/null @@ -1,67 +0,0 @@ -// -// Copyright (C) 2018 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. - -soong_config_module_type { - name: "senPlugin_cc_defaults", - module_type: "cc_defaults", - config_namespace: "senPlugin", - bool_variables: ["SENSOR_LIST"], - properties: ["cflags", "srcs"], -} - -senPlugin_cc_defaults { - name: "senPlugin_defaults", - soong_config_variables: { - SENSOR_LIST: { cflags: ["-DSENSOR_LIST_ENABLED"],}, - }, -} - -cc_binary { - name: "android.hardware.sensors@2.0-service.intel", - defaults: ["hidl_defaults", "senPlugin_defaults"], - vendor: true, - relative_install_path: "hw", - - local_include_dirs: [ - "iiohal_mediation_v2.0", - "iiohal_mediation_v2.0/libiio_client" - ], - srcs: [ - "service.cpp", - ], - init_rc: ["android.hardware.sensors@2.0-service-intel.rc"], - header_libs: [ - "android.hardware.sensors@2.X-shared-utils", - ], - shared_libs: [ - "android.hardware.sensors@1.0", - "android.hardware.sensors@2.0", - // Needed to compile some shared utilities for both 2.0/2.1 impls, but - // isn't normally needed for a HAL that only supports 2.0. - "android.hardware.sensors@2.1", - "libcutils", - "libfmq", - "libhidlbase", - "liblog", - "libpower", - "libutils", - "libxml2", - ], - static_libs: [ - "android.hardware.sensors@1.0-convert", - "intel.android.iiod.client@2.0-impel" - ], - vintf_fragments: ["android.hardware.sensors@2.0.xml"], -} diff --git a/sensors/2.0/ISensors.hal b/sensors/2.0/ISensors.hal deleted file mode 100644 index a84c56e..0000000 --- a/sensors/2.0/ISensors.hal +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Copyright (C) 2018 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@2.0; - -import @1.0::Event; -import @1.0::OperationMode; -import @1.0::RateLevel; -import @1.0::Result; -import @1.0::SensorInfo; -import @1.0::SharedMemInfo; -import @2.0::ISensorsCallback; - -interface ISensors { - /** - * Enumerate all available (static) sensors. - * - * The SensorInfo for each sensor returned by getSensorsList must be stable - * from the initial call to getSensorsList after a device boot until the - * entire system restarts. The SensorInfo for each sensor must not change - * between subsequent calls to getSensorsList, even across restarts of the - * HAL and its dependencies (for example, the sensor handle for a given - * sensor must not change across HAL restarts). - */ - getSensorsList() generates (vec 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 written to the event queue must be abandoned immediately so that - * subsequent activations do 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); - - /** - * Initialize the Sensors HAL's Fast Message Queues (FMQ) and callback. - * - * The Fast Message Queues (FMQ) that are used to send data between the - * framework and the HAL. The callback is used by the HAL to notify the - * framework of asynchronous events, such as a dynamic sensor connection. - * - * The Event FMQ is used to transport sensor events from the HAL to the - * framework. The Event FMQ is created using the eventQueueDescriptor. - * Data may only be written to the Event FMQ. Data must not be read from - * the Event FMQ since the framework is the only reader. Upon receiving - * sensor events, the HAL writes the sensor events to the Event FMQ. - * - * Once the HAL is finished writing sensor events to the Event FMQ, the HAL - * must notify the framework that sensor events are available to be read and - * processed. This is accomplished by either: - * 1) Calling the Event FMQ’s EventFlag::wake() function with - EventQueueFlagBits::READ_AND_PROCESS - * 2) Setting the write notification in the Event FMQ’s writeBlocking() - * function to EventQueueFlagBits::READ_AND_PROCESS. - * - * If the Event FMQ’s writeBlocking() function is used, the read - * notification must be set to EventQueueFlagBits::EVENTS_READ in order to - * be notified and unblocked when the framework has successfully read events - * from the Event FMQ. - * - * The Wake Lock FMQ is used by the framework to notify the HAL when it is - * safe to release its wake_lock. When the framework receives WAKE_UP events - * from the Event FMQ and the framework has acquired a wake_lock, the - * framework must write the number of WAKE_UP events processed to the Wake - * Lock FMQ. When the HAL reads the data from the Wake Lock FMQ, the HAL - * decrements its current count of unprocessed WAKE_UP events and releases - * its wake_lock if the current count of unprocessed WAKE_UP events is - * zero. It is important to note that the HAL must acquire the wake lock and - * update its internal state regarding the number of outstanding WAKE_UP - * events _before_ posting the event to the Wake Lock FMQ, in order to avoid - * a race condition that can lead to loss of wake lock synchronization with - * the framework. - * - * The framework must use the WakeLockQueueFlagBits::DATA_WRITTEN value to - * notify the HAL that data has been written to the Wake Lock FMQ and must - * be read by HAL. - * - * The ISensorsCallback is used by the HAL to notify the framework of - * asynchronous events, such as a dynamic sensor connection. - * - * The name of any wake_lock acquired by the Sensors HAL for WAKE_UP events - * must begin with "SensorsHAL_WAKEUP". - * - * If WAKE_LOCK_TIMEOUT_SECONDS has elapsed since the most recent WAKE_UP - * event was written to the Event FMQ without receiving a message on the - * Wake Lock FMQ, then any held wake_lock for WAKE_UP events must be - * released. - * - * If either the Event FMQ or the Wake Lock FMQ is already initialized when - * initialize is invoked, then both existing FMQs must be discarded and the - * new descriptors must be used to create new FMQs within the HAL. The - * number of outstanding WAKE_UP events should also be reset to zero, and - * any outstanding wake_locks held as a result of WAKE_UP events should be - * released. - * - * All active sensor requests and direct channels must be closed and - * properly cleaned up when initialize is called in order to ensure that the - * HAL and framework's state is consistent (e.g. after a runtime restart). - * - * initialize must be thread safe and prevent concurrent calls - * to initialize from simultaneously modifying state. - * - * @param eventQueueDescriptor Fast Message Queue descriptor that is used to - * create the Event FMQ which is where sensor events are written. The - * descriptor is obtained from the framework's FMQ that is used to read - * sensor events. - * @param wakeLockDescriptor Fast Message Queue descriptor that is used to - * create the Wake Lock FMQ which is where wake_lock events are read - * from. The descriptor is obtained from the framework's FMQ that is - * used to write wake_lock events. - * @param sensorsCallback sensors callback that receives asynchronous data - * from the Sensors HAL. - * @return result OK on success; BAD_VALUE if descriptor is invalid (such - * as null) - */ - @entry - @callflow(next = {"getSensorsList"}) - initialize(fmq_sync eventQueueDescriptor, - fmq_sync wakeLockDescriptor, - ISensorsCallback sensorsCallback) - generates - (Result result); - - /** - * 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. - * - * @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 the sensor event queue. - * - * @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); -}; diff --git a/sensors/2.0/ISensorsCallback.hal b/sensors/2.0/ISensorsCallback.hal deleted file mode 100644 index e0bd98f..0000000 --- a/sensors/2.0/ISensorsCallback.hal +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2018 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@2.0; - -import @1.0::SensorInfo; - -interface ISensorsCallback { - /** - * Notify the framework that new dynamic sensors have been connected. - * - * If a dynamic sensor was previously connected and has not been - * disconnected, then that sensor must not be included in sensorInfos. - * - * @param sensorInfos vector of SensorInfo for each dynamic sensor that - * was connected. - */ - oneway onDynamicSensorsConnected(vec sensorInfos); - - /** - * Notify the framework that previously connected dynamic sensors have been - * disconnected. - * - * If a dynamic sensor was previously disconnected and has not been - * reconnected, then that sensor must not be included in sensorHandles. - * - * The HAL must ensure that all sensor events from departing dynamic - * sensors have been written to the Event FMQ before calling - * onDynamicSensorsDisconnected. - * - * @param sensorHandles vector of sensor handles for each dynamic sensors - * that was disconnected. - */ - oneway onDynamicSensorsDisconnected(vec sensorHandles); -}; diff --git a/sensors/2.0/OWNERS b/sensors/2.0/OWNERS deleted file mode 100644 index b0db5a9..0000000 --- a/sensors/2.0/OWNERS +++ /dev/null @@ -1,4 +0,0 @@ -arthuri@google.com -bduddie@google.com -stange@google.com -raju.mallikarjun.chegaraddi@intel.com diff --git a/sensors/2.0/SensorsV2_0.h b/sensors/2.0/SensorsV2_0.h deleted file mode 100644 index a6dbeaf..0000000 --- a/sensors/2.0/SensorsV2_0.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2020 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 SENSORS_2_0_SENSORSV2_0_H_ -#define SENSORS_2_0_SENSORSV2_0_H_ - -#include "Sensors.h" - -#include - -namespace android { -namespace hardware { -namespace sensors { -namespace V2_0 { -namespace implementation { - -struct SensorsV2_0 : public ::android::hardware::sensors::V2_X::implementation::Sensors { -}; - -} // namespace implementation -} // namespace V2_0 -} // namespace sensors -} // namespace hardware -} // namespace android - -#endif // SENSORS_2_0_SENSORSV2_0_H_ diff --git a/sensors/2.0/android.hardware.sensors@2.0-service-intel.rc b/sensors/2.0/android.hardware.sensors@2.0-service-intel.rc deleted file mode 100644 index fa4327d..0000000 --- a/sensors/2.0/android.hardware.sensors@2.0-service-intel.rc +++ /dev/null @@ -1,7 +0,0 @@ -service vendor.sensors-hal-2-0-intel /vendor/bin/hw/android.hardware.sensors@2.0-service.intel - interface android.hardware.sensors@2.0::ISensors default - class hal - user system - group system wakelock uhid context_hub - capabilities BLOCK_SUSPEND - rlimit rtprio 10 10 diff --git a/sensors/2.0/android.hardware.sensors@2.0.xml b/sensors/2.0/android.hardware.sensors@2.0.xml deleted file mode 100644 index 1acc8e6..0000000 --- a/sensors/2.0/android.hardware.sensors@2.0.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - android.hardware.sensors - hwbinder - 2.0 - - ISensors - default - - - diff --git a/sensors/2.0/iiohal_mediation_v2.0/Android.bp b/sensors/2.0/iiohal_mediation_v2.0/Android.bp deleted file mode 100644 index f4b2098..0000000 --- a/sensors/2.0/iiohal_mediation_v2.0/Android.bp +++ /dev/null @@ -1,59 +0,0 @@ -// -// Copyright (C) 2018 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_library_static { - name: "intel.android.iiod.client@2.0-impel", - defaults: ["hidl_defaults"], - vendor: true, - local_include_dirs: [".", "libiio_client"], - srcs: [ - "Sensor.cpp", - "iioClient.cpp", - "libiio_client/xml.c", - "libiio_client/buffer.c", - "libiio_client/context.c", - "libiio_client/iiod-client.c", - "libiio_client/lock.c", - "libiio_client/channel.c", - "libiio_client/backend.c", - "libiio_client/device.c", - "libiio_client/utilities.c", - "libiio_client/network.c", - ], - header_libs: [ - "android.hardware.sensors@2.X-shared-utils", - ], - shared_libs: [ - "android.hardware.sensors@1.0", - "android.hardware.sensors@2.0", - "android.hardware.sensors@2.1", - "libcutils", - "libfmq", - "libhidlbase", - "liblog", - "libpower", - "libutils", - "liblog", - "libdl", - "libxml2", - ], - cflags: [ - "-DLOG_TAG=\"SensorsHal2.0\"", - "-Wall", - "-Wno-unused-variable", - "-Wno-unused-parameter", - "-Wno-unused-function", - ], -} diff --git a/sensors/2.0/iiohal_mediation_v2.0/Sensor.cpp b/sensors/2.0/iiohal_mediation_v2.0/Sensor.cpp deleted file mode 100644 index f98071b..0000000 --- a/sensors/2.0/iiohal_mediation_v2.0/Sensor.cpp +++ /dev/null @@ -1,510 +0,0 @@ -/* - * Copyright (C) 2018 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 -#include - -#include -#include - -#include "Sensor.h" - -namespace android { -namespace hardware { -namespace sensors { -namespace V2_X { -namespace implementation { - -using ::android::hardware::sensors::V1_0::MetaDataEventType; -using ::android::hardware::sensors::V1_0::OperationMode; -using ::android::hardware::sensors::V1_0::Result; -using ::android::hardware::sensors::V1_0::SensorFlagBits; -using ::android::hardware::sensors::V1_0::SensorStatus; -using ::android::hardware::sensors::V2_1::Event; -using ::android::hardware::sensors::V2_1::SensorInfo; -using ::android::hardware::sensors::V2_1::SensorType; - -Sensor::Sensor(ISensorsEventCallback* callback) - : mIsEnabled(false), - mSamplingPeriodNs(0), - mLastSampleTimeNs(0), - mCallback(callback), - mMode(OperationMode::NORMAL) { - iioc = iioClient::get_iioClient(); - mRunThread = std::thread(startThread, this); -} - -Sensor::~Sensor() { - std::unique_lock lock(mRunMutex); - mStopThread = true; - mIsEnabled = false; - mWaitCV.notify_all(); - lock.release(); - mRunThread.join(); -} - -const SensorInfo& Sensor::getSensorInfo() const { - return mSensorInfo; -} - -void Sensor::batch(int32_t samplingPeriodNs) { - if (samplingPeriodNs < mSensorInfo.minDelay * 1000) { - samplingPeriodNs = mSensorInfo.minDelay * 1000; - } else if (samplingPeriodNs > mSensorInfo.maxDelay * 1000) { - samplingPeriodNs = mSensorInfo.maxDelay * 1000; - } - - if (mSamplingPeriodNs != samplingPeriodNs) { - mSamplingPeriodNs = samplingPeriodNs; - // Wake up the 'run' thread to check if a new event - // should be generated now - - if (iioc) - iioc->batch(mSensorInfo.sensorHandle, mSamplingPeriodNs); - - mWaitCV.notify_all(); - } -} - -void Sensor::activate(bool enable) { - if (mIsEnabled != enable) { - std::unique_lock lock(mRunMutex); - mIsEnabled = enable; - - if (iioc) - iioc->activate(mSensorInfo.sensorHandle, enable); - - mWaitCV.notify_all(); - } -} - -Result Sensor::flush() { - // Only generate a flush complete event if the sensor is enabled - // and if the sensor is not a one-shot sensor. - if (!mIsEnabled || - (mSensorInfo.flags & - static_cast(SensorFlagBits::ONE_SHOT_MODE))) { - return Result::BAD_VALUE; - } - - // Note: If a sensor supports batching, write all of the - // currently batched events for the sensor to the Event - // FMQ prior to writing the flush complete event. - Event ev{}; - ev.sensorHandle = mSensorInfo.sensorHandle; - ev.sensorType = SensorType::META_DATA; - ev.u.meta.what = MetaDataEventType::META_DATA_FLUSH_COMPLETE; - std::vector evs{ev}; - mCallback->postEvents(evs, isWakeUpSensor()); - - return Result::OK; -} - -void Sensor::startThread(Sensor* sensor) { - sensor->run(); -} - -void Sensor::run() { - std::unique_lock runLock(mRunMutex); - constexpr int64_t kNanosecondsInSeconds = 1000 * 1000 * 1000; - - while (!mStopThread) { - if (!mIsEnabled || mMode == OperationMode::DATA_INJECTION) { - mWaitCV.wait(runLock, [&] { - return ((mIsEnabled && mMode == OperationMode::NORMAL) - || mStopThread); - }); - } else { - timespec curTime; - clock_gettime(CLOCK_REALTIME, &curTime); - int64_t now = (curTime.tv_sec * kNanosecondsInSeconds) + curTime.tv_nsec; - int64_t nextSampleTime = mLastSampleTimeNs + mSamplingPeriodNs; - - if (now >= nextSampleTime) { - mLastSampleTimeNs = now; - nextSampleTime = mLastSampleTimeNs + mSamplingPeriodNs; - mCallback->postEvents(readEvents(), isWakeUpSensor()); - } - - mWaitCV.wait_for(runLock, std::chrono::nanoseconds(nextSampleTime - now)); - } - } -} - -bool Sensor::isWakeUpSensor() { - return mSensorInfo.flags & static_cast(SensorFlagBits::WAKE_UP); -} - -std::vector Sensor::readEvents() { - std::vector events; - Event event; - event.sensorHandle = mSensorInfo.sensorHandle; - event.sensorType = mSensorInfo.type; - event.timestamp = ::android::elapsedRealtimeNano(); - if (iioc && iioc->is_iioc_initialized) { - event.u.vec3.x = iioc->devlist[mSensorInfo.sensorHandle].data[0]; - event.u.vec3.y = iioc->devlist[mSensorInfo.sensorHandle].data[1]; - event.u.vec3.z = iioc->devlist[mSensorInfo.sensorHandle].data[2]; - } else { - if (event.sensorHandle == 1) { - event.u.vec3.x = event.u.vec3.y = 0; - event.u.vec3.z = -9.8; - } - else - event.u.vec3.x = event.u.vec3.y = event.u.vec3.z = 0; - } - event.u.vec3.status = SensorStatus::ACCURACY_HIGH; - events.push_back(event); -#if 0 // Probing data to debug - ALOGD("readEvents: handle(%d) name -> %s data[%f, %f, %f]", - mSensorInfo.sensorHandle, mSensorInfo.name.c_str(), - event.u.vec3.x, event.u.vec3.y, event.u.vec3.z); -#endif - return events; -} - -void Sensor::setOperationMode(OperationMode mode) { - if (mMode != mode) { - std::unique_lock lock(mRunMutex); - mMode = mode; - mWaitCV.notify_all(); - } -} - -bool Sensor::supportsDataInjection() const { - return mSensorInfo.flags & static_cast(SensorFlagBits::DATA_INJECTION); -} - -Result Sensor::injectEvent(const Event& event) { - Result result = Result::OK; - if (event.sensorType == SensorType::ADDITIONAL_INFO) { - // When in OperationMode::NORMAL, SensorType::ADDITIONAL_INFO - // is used to push operation environment data into the device. - } else if (!supportsDataInjection()) { - result = Result::INVALID_OPERATION; - } else if (mMode == OperationMode::DATA_INJECTION) { - mCallback->postEvents(std::vector{event}, isWakeUpSensor()); - } else { - result = Result::BAD_VALUE; - } - return result; -} - -OnChangeSensor::OnChangeSensor(ISensorsEventCallback* callback) - : Sensor(callback), mPreviousEventSet(false) {} - -void OnChangeSensor::activate(bool enable) { - Sensor::activate(enable); - if (!enable) { - mPreviousEventSet = false; - } -} - -std::vector OnChangeSensor::readEvents() { - std::vector events = Sensor::readEvents(); - std::vector outputEvents; - - for (auto iter = events.begin(); iter != events.end(); ++iter) { - Event ev = *iter; - if (ev.u.vec3 != mPreviousEvent.u.vec3 || !mPreviousEventSet) { - outputEvents.push_back(ev); - mPreviousEvent = ev; - mPreviousEventSet = true; - } - } - return outputEvents; -} - -AccelSensor::AccelSensor(int32_t sensorHandle, - ISensorsEventCallback* callback) : Sensor(callback) { - mSensorInfo.sensorHandle = sensorHandle; - mSensorInfo.name = "Accel Sensor"; - mSensorInfo.vendor = "Intel"; - mSensorInfo.version = 1; - mSensorInfo.type = SensorType::ACCELEROMETER; - mSensorInfo.typeAsString = ""; - mSensorInfo.maxRange = 78.4f; // +/- 8g - mSensorInfo.resolution = 1.52e-5; - mSensorInfo.power = 0.001f; // mA - mSensorInfo.minDelay = 10 * 1000; // microseconds - mSensorInfo.maxDelay = 10 * 1000 * 10; // microseconds - mSensorInfo.fifoReservedEventCount = 0; - mSensorInfo.fifoMaxEventCount = 0; - mSensorInfo.requiredPermission = ""; - mSensorInfo.flags = static_cast(SensorFlagBits::DATA_INJECTION); -} - -PressureSensor::PressureSensor(int32_t sensorHandle, - ISensorsEventCallback* callback) - : Sensor(callback) { - mSensorInfo.sensorHandle = sensorHandle; - mSensorInfo.name = "Pressure Sensor"; - mSensorInfo.vendor = "Intel"; - mSensorInfo.version = 1; - mSensorInfo.type = SensorType::PRESSURE; - mSensorInfo.typeAsString = ""; - mSensorInfo.maxRange = 1100.0f; // hPa - mSensorInfo.resolution = 0.005f; // hPa - mSensorInfo.power = 0.001f; // mA - mSensorInfo.minDelay = 100 * 1000; // microseconds - mSensorInfo.maxDelay = 100 * 1000 * 10; // microseconds - mSensorInfo.fifoReservedEventCount = 0; - mSensorInfo.fifoMaxEventCount = 0; - mSensorInfo.requiredPermission = ""; - mSensorInfo.flags = 0; -} - -MagnetometerSensor::MagnetometerSensor(int32_t sensorHandle, - ISensorsEventCallback* callback) - : Sensor(callback) { - mSensorInfo.sensorHandle = sensorHandle; - mSensorInfo.name = "Magnetic Field Sensor"; - mSensorInfo.vendor = "Intel"; - mSensorInfo.version = 1; - mSensorInfo.type = SensorType::MAGNETIC_FIELD; - mSensorInfo.typeAsString = ""; - mSensorInfo.maxRange = 1300.0f; - mSensorInfo.resolution = 0.01f; - mSensorInfo.power = 0.001f; // mA - mSensorInfo.minDelay = 10 * 1000; // microseconds - mSensorInfo.maxDelay = 10 * 1000 * 10; // microseconds - mSensorInfo.fifoReservedEventCount = 0; - mSensorInfo.fifoMaxEventCount = 0; - mSensorInfo.requiredPermission = ""; - mSensorInfo.flags = 0; -} - -LightSensor::LightSensor(int32_t sensorHandle, - ISensorsEventCallback* callback) - : OnChangeSensor(callback) { - mSensorInfo.sensorHandle = sensorHandle; - mSensorInfo.name = "Light Sensor"; - mSensorInfo.vendor = "Intel"; - mSensorInfo.version = 1; - mSensorInfo.type = SensorType::LIGHT; - mSensorInfo.typeAsString = ""; - mSensorInfo.maxRange = 43000.0f; - mSensorInfo.resolution = 10.0f; - mSensorInfo.power = 0.001f; // mA - mSensorInfo.minDelay = 200 * 1000; // microseconds - mSensorInfo.maxDelay = 200 * 1000 * 10; // microseconds - mSensorInfo.fifoReservedEventCount = 0; - mSensorInfo.fifoMaxEventCount = 0; - mSensorInfo.requiredPermission = ""; - mSensorInfo.flags = static_cast(SensorFlagBits::ON_CHANGE_MODE); -} - -ProximitySensor::ProximitySensor(int32_t sensorHandle, - ISensorsEventCallback* callback) - : OnChangeSensor(callback) { - mSensorInfo.sensorHandle = sensorHandle; - mSensorInfo.name = "Proximity Sensor"; - mSensorInfo.vendor = "Intel"; - mSensorInfo.version = 1; - mSensorInfo.type = SensorType::PROXIMITY; - mSensorInfo.typeAsString = ""; - mSensorInfo.maxRange = 5.0f; - mSensorInfo.resolution = 1.0f; - mSensorInfo.power = 0.012f; // mA - mSensorInfo.minDelay = 200 * 1000; // microseconds - mSensorInfo.maxDelay = 200 * 1000 * 10; // microseconds - mSensorInfo.fifoReservedEventCount = 0; - mSensorInfo.fifoMaxEventCount = 0; - mSensorInfo.requiredPermission = ""; - mSensorInfo.flags = - static_cast(SensorFlagBits::ON_CHANGE_MODE | SensorFlagBits::WAKE_UP); -} - -GyroSensor::GyroSensor(int32_t sensorHandle, - ISensorsEventCallback* callback) : Sensor(callback) { - mSensorInfo.sensorHandle = sensorHandle; - mSensorInfo.name = "Gyro Sensor"; - mSensorInfo.vendor = "Intel"; - mSensorInfo.version = 1; - mSensorInfo.type = SensorType::GYROSCOPE_UNCALIBRATED; - mSensorInfo.typeAsString = ""; - mSensorInfo.maxRange = 1000.0f * M_PI / 180.0f; - mSensorInfo.resolution = 1000.0f * M_PI / (180.0f * 32768.0f); - mSensorInfo.power = 0.001f; - mSensorInfo.minDelay = 10 * 1000; // microseconds - mSensorInfo.maxDelay = 10 * 1000 * 10; // microseconds - mSensorInfo.fifoReservedEventCount = 0; - mSensorInfo.fifoMaxEventCount = 0; - mSensorInfo.requiredPermission = ""; - mSensorInfo.flags = 0; -} - -AmbientTempSensor::AmbientTempSensor(int32_t sensorHandle, - ISensorsEventCallback* callback) - : OnChangeSensor(callback) { - mSensorInfo.sensorHandle = sensorHandle; - mSensorInfo.name = "Ambient Temp Sensor"; - mSensorInfo.vendor = "Intel"; - mSensorInfo.version = 1; - mSensorInfo.type = SensorType::AMBIENT_TEMPERATURE; - mSensorInfo.typeAsString = ""; - mSensorInfo.maxRange = 80.0f; - mSensorInfo.resolution = 0.01f; - mSensorInfo.power = 0.001f; - mSensorInfo.minDelay = 40 * 1000; // microseconds - mSensorInfo.maxDelay = 40 * 1000 * 10; // microseconds - mSensorInfo.fifoReservedEventCount = 0; - mSensorInfo.fifoMaxEventCount = 0; - mSensorInfo.requiredPermission = ""; - mSensorInfo.flags = static_cast(SensorFlagBits::ON_CHANGE_MODE); -} - -DeviceTempSensor::DeviceTempSensor(int32_t sensorHandle, - ISensorsEventCallback* callback) - : OnChangeSensor(callback) { - mSensorInfo.sensorHandle = sensorHandle; - mSensorInfo.name = "Device Temp Sensor"; - mSensorInfo.vendor = "Intel"; - mSensorInfo.version = 1; - mSensorInfo.type = SensorType::TEMPERATURE; - mSensorInfo.typeAsString = ""; - mSensorInfo.maxRange = 80.0f; - mSensorInfo.resolution = 0.01f; - mSensorInfo.power = 0.001f; - mSensorInfo.minDelay = 40 * 1000; // microseconds - mSensorInfo.maxDelay = 40 * 1000 * 10; // microseconds - mSensorInfo.fifoReservedEventCount = 0; - mSensorInfo.fifoMaxEventCount = 0; - mSensorInfo.requiredPermission = ""; - mSensorInfo.flags = static_cast(SensorFlagBits::ON_CHANGE_MODE); -} - -RelativeHumiditySensor::RelativeHumiditySensor(int32_t sensorHandle, - ISensorsEventCallback* callback) : OnChangeSensor(callback) { - mSensorInfo.sensorHandle = sensorHandle; - mSensorInfo.name = "Relative Humidity Sensor"; - mSensorInfo.vendor = "Intel"; - mSensorInfo.version = 1; - mSensorInfo.type = SensorType::RELATIVE_HUMIDITY; - mSensorInfo.typeAsString = ""; - mSensorInfo.maxRange = 100.0f; - mSensorInfo.resolution = 0.1f; - mSensorInfo.power = 0.001f; - mSensorInfo.minDelay = 40 * 1000; // microseconds - mSensorInfo.maxDelay = 40 * 1000 * 10; // microseconds - mSensorInfo.fifoReservedEventCount = 0; - mSensorInfo.fifoMaxEventCount = 0; - mSensorInfo.requiredPermission = ""; - mSensorInfo.flags = static_cast(SensorFlagBits::ON_CHANGE_MODE); -} - -GravitySensor::GravitySensor(int32_t sensorHandle, - ISensorsEventCallback* callback) : Sensor(callback) { - mSensorInfo.sensorHandle = sensorHandle; - mSensorInfo.name = "Gravity Sensor"; - mSensorInfo.vendor = "Intel"; - mSensorInfo.version = 1; - mSensorInfo.type = SensorType::GRAVITY; - mSensorInfo.typeAsString = ""; - mSensorInfo.maxRange = 1300.0f; - mSensorInfo.resolution = 0.01f; - mSensorInfo.power = 0.001f; - mSensorInfo.minDelay = 10 * 1000; // microseconds - mSensorInfo.maxDelay = 10 * 1000 * 10; // microseconds - mSensorInfo.fifoReservedEventCount = 0; - mSensorInfo.fifoMaxEventCount = 0; - mSensorInfo.requiredPermission = ""; - mSensorInfo.flags = 0; -} - -RotationVector::RotationVector(int32_t sensorHandle, - ISensorsEventCallback* callback) : Sensor(callback) { - mSensorInfo.sensorHandle = sensorHandle; - mSensorInfo.name = "Rotation Vector"; - mSensorInfo.vendor = "Intel"; - mSensorInfo.version = 1; - mSensorInfo.type = SensorType::ROTATION_VECTOR; - mSensorInfo.typeAsString = ""; - mSensorInfo.maxRange = 1300.0f; - mSensorInfo.resolution = 0.01f; - mSensorInfo.power = 0.001f; - mSensorInfo.minDelay = 10 * 1000; // microseconds - mSensorInfo.maxDelay = 10 * 1000 * 10; // microseconds - mSensorInfo.fifoReservedEventCount = 0; - mSensorInfo.fifoMaxEventCount = 0; - mSensorInfo.requiredPermission = ""; - mSensorInfo.flags = 0; -} - -GeomagnaticRotationVector::GeomagnaticRotationVector(int32_t sensorHandle, - ISensorsEventCallback* callback) : Sensor(callback) { - mSensorInfo.sensorHandle = sensorHandle; - mSensorInfo.name = "Geomagnatic Rotation Vector"; - mSensorInfo.vendor = "Intel"; - mSensorInfo.version = 1; - mSensorInfo.type = SensorType::GEOMAGNETIC_ROTATION_VECTOR; - mSensorInfo.typeAsString = ""; - mSensorInfo.maxRange = 1300.0f; - mSensorInfo.resolution = 0.01f; - mSensorInfo.power = 0.001f; - mSensorInfo.minDelay = 10 * 1000; // microseconds - mSensorInfo.maxDelay = 10 * 1000 * 10; // microseconds - mSensorInfo.fifoReservedEventCount = 0; - mSensorInfo.fifoMaxEventCount = 0; - mSensorInfo.requiredPermission = ""; - mSensorInfo.flags = 0; -} - -OrientationSensor::OrientationSensor(int32_t sensorHandle, - ISensorsEventCallback* callback) : Sensor(callback) { - mSensorInfo.sensorHandle = sensorHandle; - mSensorInfo.name = "Orientation Sensor"; - mSensorInfo.vendor = "Intel"; - mSensorInfo.version = 1; - mSensorInfo.type = SensorType::ORIENTATION; - mSensorInfo.typeAsString = ""; - mSensorInfo.maxRange = 1300.0f; - mSensorInfo.resolution = 0.01f; - mSensorInfo.power = 0.001f; - mSensorInfo.minDelay = 10 * 1000; // microseconds - mSensorInfo.maxDelay = 10 * 1000 * 10; // microseconds - mSensorInfo.fifoReservedEventCount = 0; - mSensorInfo.fifoMaxEventCount = 0; - mSensorInfo.requiredPermission = ""; - mSensorInfo.flags = 0; -} - -InclinometerSensor::InclinometerSensor(int32_t sensorHandle, - ISensorsEventCallback* callback) - : Sensor(callback) { - mSensorInfo.sensorHandle = sensorHandle; - mSensorInfo.name = "Inclinometer 3D Sensor"; - mSensorInfo.vendor = "Intel"; - mSensorInfo.version = 1; - mSensorInfo.type = SensorType::ORIENTATION; - mSensorInfo.typeAsString = ""; - mSensorInfo.maxRange = 1300.0f; - mSensorInfo.resolution = 0.01f; - mSensorInfo.power = 0.001f; // mA - mSensorInfo.minDelay = 10 * 1000; // microseconds - mSensorInfo.maxDelay = 10 * 1000 * 10; // microseconds - mSensorInfo.fifoReservedEventCount = 0; - mSensorInfo.fifoMaxEventCount = 0; - mSensorInfo.requiredPermission = ""; - mSensorInfo.flags = 0; -} - -} // namespace implementation -} // namespace V2_X -} // namespace sensors -} // namespace hardware -} // namespace android diff --git a/sensors/2.0/iiohal_mediation_v2.0/Sensor.h b/sensors/2.0/iiohal_mediation_v2.0/Sensor.h deleted file mode 100644 index 57784ef..0000000 --- a/sensors/2.0/iiohal_mediation_v2.0/Sensor.h +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (C) 2018 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 SENSORS_2_0_IIOHAL_MEDIATION_V2_0_SENSOR_H_ -#define SENSORS_2_0_IIOHAL_MEDIATION_V2_0_SENSOR_H_ - -#include -#include - -#include -#include -#include -#include -#include - -#include "iioClient.h" - -namespace android { -namespace hardware { -namespace sensors { -namespace V2_X { -namespace implementation { - -static constexpr float kDefaultMaxDelayUs = 10 * 1000 * 1000; - -class ISensorsEventCallback { - public: - using Event = ::android::hardware::sensors::V2_1::Event; - - virtual ~ISensorsEventCallback() {} - virtual void postEvents(const std::vector& events, bool wakeup) = 0; -}; - -class Sensor { - public: - using OperationMode = ::android::hardware::sensors::V1_0::OperationMode; - using Result = ::android::hardware::sensors::V1_0::Result; - using Event = ::android::hardware::sensors::V2_1::Event; - using SensorInfo = ::android::hardware::sensors::V2_1::SensorInfo; - using SensorType = ::android::hardware::sensors::V2_1::SensorType; - iioClient *iioc; - - Sensor(ISensorsEventCallback* callback); - virtual ~Sensor(); - - const SensorInfo& getSensorInfo() const; - void batch(int32_t samplingPeriodNs); - virtual void activate(bool enable); - Result flush(); - - void setOperationMode(OperationMode mode); - bool supportsDataInjection() const; - Result injectEvent(const Event& event); - - protected: - void run(); - virtual std::vector readEvents(); - static void startThread(Sensor* sensor); - - bool isWakeUpSensor(); - - bool mIsEnabled; - int64_t mSamplingPeriodNs; - int64_t mLastSampleTimeNs; - SensorInfo mSensorInfo; - - std::atomic_bool mStopThread; - std::condition_variable mWaitCV; - std::mutex mRunMutex; - std::thread mRunThread; - - ISensorsEventCallback* mCallback; - - OperationMode mMode; -}; - -class OnChangeSensor : public Sensor { - public: - OnChangeSensor(ISensorsEventCallback* callback); - - virtual void activate(bool enable) override; - - protected: - virtual std::vector readEvents() override; - - protected: - Event mPreviousEvent; - bool mPreviousEventSet; -}; - -class AccelSensor : public Sensor { - public: - AccelSensor(int32_t sensorHandle, ISensorsEventCallback* callback); -}; - -class GyroSensor : public Sensor { - public: - GyroSensor(int32_t sensorHandle, ISensorsEventCallback* callback); -}; - -class AmbientTempSensor : public OnChangeSensor { - public: - AmbientTempSensor(int32_t sensorHandle, ISensorsEventCallback* callback); -}; - -class DeviceTempSensor : public OnChangeSensor { - public: - DeviceTempSensor(int32_t sensorHandle, ISensorsEventCallback* callback); -}; - -class PressureSensor : public Sensor { - public: - PressureSensor(int32_t sensorHandle, ISensorsEventCallback* callback); -}; - -class MagnetometerSensor : public Sensor { - public: - MagnetometerSensor(int32_t sensorHandle, ISensorsEventCallback* callback); -}; - -class LightSensor : public OnChangeSensor { - public: - LightSensor(int32_t sensorHandle, ISensorsEventCallback* callback); -}; - -class ProximitySensor : public OnChangeSensor { - public: - ProximitySensor(int32_t sensorHandle, ISensorsEventCallback* callback); -}; - -class RelativeHumiditySensor : public OnChangeSensor { - public: - RelativeHumiditySensor(int32_t sensorHandle, ISensorsEventCallback* callback); -}; - -class GravitySensor : public Sensor { - public: - GravitySensor(int32_t sensorHandle, ISensorsEventCallback* callback); -}; - -class RotationVector : public Sensor { - public: - RotationVector(int32_t sensorHandle, ISensorsEventCallback* callback); -}; - -class GeomagnaticRotationVector : public Sensor { - public: - GeomagnaticRotationVector(int32_t sensorHandle, ISensorsEventCallback* callback); -}; - -class OrientationSensor : public Sensor { - public: - OrientationSensor(int32_t sensorHandle, ISensorsEventCallback* callback); -}; - -class InclinometerSensor : public Sensor { - public: - InclinometerSensor(int32_t sensorHandle, ISensorsEventCallback* callback); -}; - -} // namespace implementation -} // namespace V2_X -} // namespace sensors -} // namespace hardware -} // namespace android - -#endif // SENSORS_2_0_IIOHAL_MEDIATION_V2_0_SENSOR_H_ diff --git a/sensors/2.0/iiohal_mediation_v2.0/Sensors.h b/sensors/2.0/iiohal_mediation_v2.0/Sensors.h deleted file mode 100644 index c9e823c..0000000 --- a/sensors/2.0/iiohal_mediation_v2.0/Sensors.h +++ /dev/null @@ -1,384 +0,0 @@ -/* - * Copyright (C) 2018 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 SENSORS_2_0_IIOHAL_MEDIATION_V2_0_SENSORS_H_ -#define SENSORS_2_0_IIOHAL_MEDIATION_V2_0_SENSORS_H_ - -#include "EventMessageQueueWrapper.h" -#include "Sensor.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -namespace android { -namespace hardware { -namespace sensors { -namespace V2_X { -namespace implementation { - -template -struct Sensors : public ISensorsInterface, public ISensorsEventCallback { - using Event = ::android::hardware::sensors::V1_0::Event; - using OperationMode = ::android::hardware::sensors::V1_0::OperationMode; - using RateLevel = ::android::hardware::sensors::V1_0::RateLevel; - using Result = ::android::hardware::sensors::V1_0::Result; - using SharedMemInfo = ::android::hardware::sensors::V1_0::SharedMemInfo; - using EventQueueFlagBits = ::android::hardware::sensors::V2_0::EventQueueFlagBits; - using SensorTimeout = ::android::hardware::sensors::V2_0::SensorTimeout; - using WakeLockQueueFlagBits = ::android::hardware::sensors::V2_0::WakeLockQueueFlagBits; - using ISensorsCallback = ::android::hardware::sensors::V2_0::ISensorsCallback; - using EventMessageQueue = MessageQueue; - using WakeLockMessageQueue = MessageQueue; - - static constexpr const char* kWakeLockName = "SensorsHAL_WAKEUP"; - - Sensors() - : mEventQueueFlag(nullptr), - mNextHandle(1), - mOutstandingWakeUpEvents(0), - mReadWakeLockQueueRun(false), - mAutoReleaseWakeLockTime(0), - mHasWakeLock(false) { -#if SENSOR_LIST_ENABLED - AddSensor(); - AddSensor(); - AddSensor(); - AddSensor(); - AddSensor(); - AddSensor(); - AddSensor(); - AddSensor(); - AddSensor(); -#endif - } - - virtual ~Sensors() { - deleteEventFlag(); - mReadWakeLockQueueRun = false; - mWakeLockThread.join(); - } - - // Methods from ::android::hardware::sensors::V2_0::ISensors follow. - Return getSensorsList(V2_0::ISensors::getSensorsList_cb _hidl_cb) override { - std::vector sensors; - for (const auto& sensor : mSensors) { - sensors.push_back( - V2_1::implementation::convertToOldSensorInfo(sensor.second->getSensorInfo())); - } - - // Call the HIDL callback with the SensorInfo - _hidl_cb(sensors); - - return Void(); - } - - Return setOperationMode(OperationMode mode) override { - for (auto& sensor : mSensors) { - sensor.second->setOperationMode(mode); - } - return Result::OK; - } - - Return activate(int32_t sensorHandle, bool enabled) override { - auto sensor = mSensors.find(sensorHandle); - if (sensor != mSensors.end()) { - sensor->second->activate(enabled); - return Result::OK; - } - return Result::BAD_VALUE; - } - - Return initialize( - const ::android::hardware::MQDescriptorSync& eventQueueDescriptor, - const ::android::hardware::MQDescriptorSync& wakeLockDescriptor, - const sp& sensorsCallback) override { - auto eventQueue = - std::make_unique(eventQueueDescriptor, true /* resetPointers */); - std::unique_ptr wrapper = - std::make_unique(eventQueue); - return initializeBase(wrapper, wakeLockDescriptor, sensorsCallback); - } - - Return initializeBase( - std::unique_ptr& eventQueue, - const ::android::hardware::MQDescriptorSync& wakeLockDescriptor, - const sp& sensorsCallback) { - Result result = Result::OK; - - // Ensure that all sensors are disabled - for (auto& sensor : mSensors) { - sensor.second->activate(false /* enable */); - } - - // Stop the Wake Lock thread if it is currently running - if (mReadWakeLockQueueRun.load()) { - mReadWakeLockQueueRun = false; - mWakeLockThread.join(); - } - - // Save a reference to the callback - mCallback = sensorsCallback; - - // Save the event queue. - mEventQueue = std::move(eventQueue); - - // Ensure that any existing EventFlag is properly deleted - deleteEventFlag(); - - // Create the EventFlag that is used to signal to the framework that sensor events have been - // written to the Event FMQ - if (EventFlag::createEventFlag(mEventQueue->getEventFlagWord(), &mEventQueueFlag) != OK) { - result = Result::BAD_VALUE; - } - - // Create the Wake Lock FMQ that is used by the framework to communicate whenever WAKE_UP - // events have been successfully read and handled by the framework. - mWakeLockQueue = std::make_unique(wakeLockDescriptor, - true /* resetPointers */); - - if (!mCallback || !mEventQueue || !mWakeLockQueue || mEventQueueFlag == nullptr) { - result = Result::BAD_VALUE; - } - - // Start the thread to read events from the Wake Lock FMQ - mReadWakeLockQueueRun = true; - mWakeLockThread = std::thread(startReadWakeLockThread, this); - - return result; - } - - Return batch(int32_t sensorHandle, int64_t samplingPeriodNs, - int64_t /* maxReportLatencyNs */) override { - auto sensor = mSensors.find(sensorHandle); - if (sensor != mSensors.end()) { - sensor->second->batch(samplingPeriodNs); - return Result::OK; - } - return Result::BAD_VALUE; - } - - Return flush(int32_t sensorHandle) override { - auto sensor = mSensors.find(sensorHandle); - if (sensor != mSensors.end()) { - return sensor->second->flush(); - } - return Result::BAD_VALUE; - } - - Return injectSensorData(const Event& event) override { - auto sensor = mSensors.find(event.sensorHandle); - if (sensor != mSensors.end()) { - return sensor->second->injectEvent(V2_1::implementation::convertToNewEvent(event)); - } - - return Result::BAD_VALUE; - } - - Return registerDirectChannel(const SharedMemInfo& /* mem */, - V2_0::ISensors::registerDirectChannel_cb _hidl_cb) override { - _hidl_cb(Result::INVALID_OPERATION, -1 /* channelHandle */); - return Return(); - } - - Return unregisterDirectChannel(int32_t /* channelHandle */) override { - return Result::INVALID_OPERATION; - } - - Return configDirectReport(int32_t /* sensorHandle */, int32_t /* channelHandle */, - RateLevel /* rate */, - V2_0::ISensors::configDirectReport_cb _hidl_cb) override { - _hidl_cb(Result::INVALID_OPERATION, 0 /* reportToken */); - return Return(); - } - - void postEvents(const std::vector& events, bool wakeup) override { - std::lock_guard lock(mWriteLock); - if (mEventQueue->write(events)) { - mEventQueueFlag->wake(static_cast(EventQueueFlagBits::READ_AND_PROCESS)); - - if (wakeup) { - // Keep track of the number of outstanding WAKE_UP events in order to properly hold - // a wake lock until the framework has secured a wake lock - updateWakeLock(events.size(), 0 /* eventsHandled */); - } - } - } - - protected: - /** - * Add a new sensor - */ - template - void AddSensor() { - std::shared_ptr sensor = - std::make_shared(mNextHandle++ /* sensorHandle */, this /* callback */); - mSensors[sensor->getSensorInfo().sensorHandle] = sensor; - } - - /** - * Utility function to delete the Event Flag - */ - void deleteEventFlag() { - if (mEventQueueFlag != nullptr) { - status_t status = EventFlag::deleteEventFlag(&mEventQueueFlag); - if (status != OK) { - ALOGI("Failed to delete event flag: %d", status); - } - } - } - - static void startReadWakeLockThread(Sensors* sensors) { sensors->readWakeLockFMQ(); } - - /** - * Function to read the Wake Lock FMQ and release the wake lock when appropriate - */ - void readWakeLockFMQ() { - while (mReadWakeLockQueueRun.load()) { - constexpr int64_t kReadTimeoutNs = 500 * 1000 * 1000; // 500 ms - uint32_t eventsHandled = 0; - - // Read events from the Wake Lock FMQ. Timeout after a reasonable amount of time to - // ensure that any held wake lock is able to be released if it is held for too long. - mWakeLockQueue->readBlocking(&eventsHandled, 1 /* count */, 0 /* readNotification */, - static_cast(WakeLockQueueFlagBits::DATA_WRITTEN), - kReadTimeoutNs); - updateWakeLock(0 /* eventsWritten */, eventsHandled); - } - } - - /** - * Responsible for acquiring and releasing a wake lock when there are unhandled WAKE_UP events - */ - void updateWakeLock(int32_t eventsWritten, int32_t eventsHandled) { - std::lock_guard lock(mWakeLockLock); - int32_t newVal = mOutstandingWakeUpEvents + eventsWritten - eventsHandled; - if (newVal < 0) { - mOutstandingWakeUpEvents = 0; - } else { - mOutstandingWakeUpEvents = newVal; - } - - if (eventsWritten > 0) { - // Update the time at which the last WAKE_UP event was sent - mAutoReleaseWakeLockTime = - ::android::uptimeMillis() + - static_cast(SensorTimeout::WAKE_LOCK_SECONDS) * 1000; - } - - if (!mHasWakeLock && mOutstandingWakeUpEvents > 0 && - acquire_wake_lock(PARTIAL_WAKE_LOCK, kWakeLockName) == 0) { - mHasWakeLock = true; - } else if (mHasWakeLock) { - // Check if the wake lock should be released automatically if - // SensorTimeout::WAKE_LOCK_SECONDS has elapsed since the last WAKE_UP event was written - // to the Wake Lock FMQ. - if (::android::uptimeMillis() > mAutoReleaseWakeLockTime) { - ALOGD("No events read from wake lock FMQ for %d seconds, auto releasing wake lock", - SensorTimeout::WAKE_LOCK_SECONDS); - mOutstandingWakeUpEvents = 0; - } - - if (mOutstandingWakeUpEvents == 0 && release_wake_lock(kWakeLockName) == 0) { - mHasWakeLock = false; - } - } - } - - /** - * The Event FMQ where sensor events are written - */ - std::unique_ptr mEventQueue; - - /** - * The Wake Lock FMQ that is read to determine when the framework has handled WAKE_UP events - */ - std::unique_ptr mWakeLockQueue; - - /** - * Event Flag to signal to the framework when sensor events are available to be read - */ - EventFlag* mEventQueueFlag; - - /** - * Callback for asynchronous events, such as dynamic sensor connections. - */ - sp mCallback; - - /** - * A map of the available sensors - */ - std::map> mSensors; - - /** - * The next available sensor handle - */ - int32_t mNextHandle; - - /** - * Lock to protect writes to the FMQs - */ - std::mutex mWriteLock; - - /** - * Lock to protect acquiring and releasing the wake lock - */ - std::mutex mWakeLockLock; - - /** - * Track the number of WAKE_UP events that have not been handled by the framework - */ - uint32_t mOutstandingWakeUpEvents; - - /** - * A thread to read the Wake Lock FMQ - */ - std::thread mWakeLockThread; - - /** - * Flag to indicate that the Wake Lock Thread should continue to run - */ - std::atomic_bool mReadWakeLockQueueRun; - - /** - * Track the time when the wake lock should automatically be released - */ - int64_t mAutoReleaseWakeLockTime; - - /** - * Flag to indicate if a wake lock has been acquired - */ - bool mHasWakeLock; -}; - -} // namespace implementation -} // namespace V2_X -} // namespace sensors -} // namespace hardware -} // namespace android - -#endif // SENSORS_2_0_IIOHAL_MEDIATION_V2_0_SENSORS_H_ diff --git a/sensors/2.0/service.cpp b/sensors/2.0/service.cpp deleted file mode 100644 index 1d880b2..0000000 --- a/sensors/2.0/service.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2018 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 -#include -#include -#include -#include "SensorsV2_0.h" - -using android::hardware::configureRpcThreadpool; -using android::hardware::joinRpcThreadpool; -using android::hardware::sensors::V2_0::ISensors; -using android::hardware::sensors::V2_0::implementation::SensorsV2_0; - -int main(int /* argc */, char** /* argv */) { - configureRpcThreadpool(1, true); - - android::sp sensors = new SensorsV2_0(); - if (sensors->registerAsService() != ::android::OK) { - ALOGE("Failed to register Sensors HAL instance"); - return -1; - } - - joinRpcThreadpool(); - return 1; // joinRpcThreadpool shouldn't exit -} diff --git a/sensors/2.0/types.hal b/sensors/2.0/types.hal deleted file mode 100644 index 4457544..0000000 --- a/sensors/2.0/types.hal +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2018 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@2.0; - -enum SensorTimeout : int32_t { - /** - * The maximum number of seconds to wait for a message on the Wake Lock FMQ - * before automatically releasing any wake_lock held for a WAKE_UP event. - */ - WAKE_LOCK_SECONDS = 1, -}; - -enum EventQueueFlagBits : uint32_t { - /** - * Used to notify the Event FMQ that events should be read and processed. - */ - READ_AND_PROCESS = 1 << 0, - - /** - * Used by the framework to signal to the HAL when events have been - * successfully read from the Event FMQ. - * - * If the MessageQueue::writeBlocking function is being used to write sensor - * events to the Event FMQ, then the readNotification parameter must be set - * to EVENTS_READ. - */ - EVENTS_READ = 1 << 1, -}; - -enum WakeLockQueueFlagBits : uint32_t { - /** - * Used to notify the HAL that the framework has written data to the Wake - * Lock FMQ. - */ - DATA_WRITTEN = 1 << 0, -}; diff --git a/sensors/aidl/Android.bp b/sensors/aidl/Android.bp index 49841a4..7ca7dbf 100644 --- a/sensors/aidl/Android.bp +++ b/sensors/aidl/Android.bp @@ -14,17 +14,23 @@ * limitations under the License. */ -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "hardware_interfaces_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["hardware_interfaces_license"], +soong_config_module_type { + name: "senPlugin_cc_defaults", + module_type: "cc_defaults", + config_namespace: "senPlugin", + bool_variables: ["SENSOR_LIST"], + properties: ["cflags", "srcs"], +} + +senPlugin_cc_defaults { + name: "senPlugin_defaults", + soong_config_variables: { + SENSOR_LIST: { cflags: ["-DSENSOR_LIST_ENABLED"],}, + }, } cc_library_static { - name: "libsensorsexampleimpl", + name: "libsensorsaidlimpl", vendor: true, shared_libs: [ "libbase", @@ -44,12 +50,55 @@ cc_library_static { ], } +cc_library_static { + name: "intel.android.iiod.client@aidl-impel", + vendor: true, + local_include_dirs: ["libiio_client"], + srcs: [ + "Sensor.cpp", + "iioClient.cpp", + "libiio_client/xml.c", + "libiio_client/buffer.c", + "libiio_client/context.c", + "libiio_client/iiod-client.c", + "libiio_client/lock.c", + "libiio_client/channel.c", + "libiio_client/backend.c", + "libiio_client/device.c", + "libiio_client/utilities.c", + "libiio_client/network.c", + ], + + shared_libs: [ + "libbase", + "libfmq", + "libpower", + "libbinder_ndk", + "android.hardware.sensors-V1-ndk", + "liblog", + "libdl", + "libxml2", + ], + export_include_dirs: ["include"], + cflags: [ + "-DLOG_TAG=\"SensorsHal2.0\"", + "-Wall", + "-Wno-unused-variable", + "-Wno-unused-parameter", + "-Wno-unused-function", + ], +} + cc_binary { - name: "android.hardware.sensors-service.example", + name: "android.hardware.sensors-service.intel", + defaults: ["senPlugin_defaults"], relative_install_path: "hw", init_rc: ["sensors-default.rc"], vintf_fragments: ["sensors-default.xml"], vendor: true, + local_include_dirs: [ + "libiio_client" + ], shared_libs: [ "libbase", "libbinder_ndk", @@ -59,9 +108,11 @@ cc_binary { "liblog", "libutils", "android.hardware.sensors-V1-ndk", + "libxml2", ], static_libs: [ - "libsensorsexampleimpl", + "libsensorsaidlimpl", + "intel.android.iiod.client@aidl-impel", ], srcs: ["main.cpp"], } diff --git a/sensors/aidl/OWNERS b/sensors/aidl/OWNERS index e955670..6df9542 100644 --- a/sensors/aidl/OWNERS +++ b/sensors/aidl/OWNERS @@ -1,3 +1,4 @@ arthuri@google.com bduddie@google.com -stange@google.com \ No newline at end of file +stange@google.com +rajani.ranjan@intel.com \ No newline at end of file diff --git a/sensors/aidl/Sensor.cpp b/sensors/aidl/Sensor.cpp index 62193d6..746973f 100644 --- a/sensors/aidl/Sensor.cpp +++ b/sensors/aidl/Sensor.cpp @@ -16,6 +16,7 @@ #include "sensors-impl/Sensor.h" +#include #include "utils/SystemClock.h" #include @@ -27,7 +28,7 @@ namespace android { namespace hardware { namespace sensors { -static constexpr int32_t kDefaultMaxDelayUs = 10 * 1000 * 1000; +static constexpr float kDefaultMaxDelayUs = 10 * 1000 * 1000; Sensor::Sensor(ISensorsEventCallback* callback) : mIsEnabled(false), @@ -35,6 +36,7 @@ Sensor::Sensor(ISensorsEventCallback* callback) mLastSampleTimeNs(0), mCallback(callback), mMode(OperationMode::NORMAL) { + iioc = iioClient::get_iioClient(); mRunThread = std::thread(startThread, this); } @@ -51,16 +53,19 @@ const SensorInfo& Sensor::getSensorInfo() const { return mSensorInfo; } -void Sensor::batch(int64_t samplingPeriodNs) { - if (samplingPeriodNs < mSensorInfo.minDelayUs * 1000LL) { - samplingPeriodNs = mSensorInfo.minDelayUs * 1000LL; - } else if (samplingPeriodNs > mSensorInfo.maxDelayUs * 1000LL) { - samplingPeriodNs = mSensorInfo.maxDelayUs * 1000LL; +void Sensor::batch(int32_t samplingPeriodNs) { + if (samplingPeriodNs < mSensorInfo.minDelayUs * 1000) { + samplingPeriodNs = mSensorInfo.minDelayUs * 1000; + } else if (samplingPeriodNs > mSensorInfo.maxDelayUs * 1000) { + samplingPeriodNs = mSensorInfo.maxDelayUs * 1000; } if (mSamplingPeriodNs != samplingPeriodNs) { mSamplingPeriodNs = samplingPeriodNs; // Wake up the 'run' thread to check if a new event should be generated now + + if (iioc) + iioc->batch(mSensorInfo.sensorHandle, mSamplingPeriodNs); mWaitCV.notify_all(); } } @@ -69,6 +74,9 @@ void Sensor::activate(bool enable) { if (mIsEnabled != enable) { std::unique_lock lock(mRunMutex); mIsEnabled = enable; + + if (iioc) + iioc->activate(mSensorInfo.sensorHandle, enable); mWaitCV.notify_all(); } } @@ -138,8 +146,39 @@ std::vector Sensor::readEvents() { event.sensorType = mSensorInfo.type; event.timestamp = ::android::elapsedRealtimeNano(); memset(&event.payload, 0, sizeof(event.payload)); - readEventPayload(event.payload); + EventPayload::Vec3 vec3 ; + if (iioc && iioc->is_iioc_initialized) { + vec3 = { + .x = iioc->devlist[mSensorInfo.sensorHandle].data[0], + .y = iioc->devlist[mSensorInfo.sensorHandle].data[1], + .z = iioc->devlist[mSensorInfo.sensorHandle].data[2], + .status = SensorStatus::ACCURACY_HIGH, + }; + } else { + if (event.sensorHandle == 1) { + vec3 = { + .x = 0, + .y = 0, + .z = -9.8, + .status = SensorStatus::ACCURACY_HIGH, + }; + } + else { + vec3 = { + .x = 0, + .y = 0, + .z = 0, + .status = SensorStatus::ACCURACY_HIGH, + }; + } + } + event.payload.set(vec3); events.push_back(event); +#if 0 // Probing data to debug + ALOGD("readEvents: handle(%d) name -> %s data[%f, %f, %f]", + mSensorInfo.sensorHandle, mSensorInfo.name.c_str(), + event.payload.x, event.payload.y, event.payload.z); +#endif return events; } @@ -192,7 +231,7 @@ std::vector OnChangeSensor::readEvents() { for (auto iter = events.begin(); iter != events.end(); ++iter) { Event ev = *iter; if (!mPreviousEventSet || - memcmp(&mPreviousEvent.payload, &ev.payload, sizeof(ev.payload)) != 0) { + memcmp(&mPreviousEvent.payload, &ev.payload, sizeof(ev.payload)) != 0) { outputEvents.push_back(ev); mPreviousEvent = ev; mPreviousEventSet = true; @@ -204,163 +243,122 @@ std::vector OnChangeSensor::readEvents() { AccelSensor::AccelSensor(int32_t sensorHandle, ISensorsEventCallback* callback) : Sensor(callback) { mSensorInfo.sensorHandle = sensorHandle; mSensorInfo.name = "Accel Sensor"; - mSensorInfo.vendor = "Vendor String"; + mSensorInfo.vendor = "Intel"; mSensorInfo.version = 1; mSensorInfo.type = SensorType::ACCELEROMETER; mSensorInfo.typeAsString = ""; mSensorInfo.maxRange = 78.4f; // +/- 8g mSensorInfo.resolution = 1.52e-5; - mSensorInfo.power = 0.001f; // mA + mSensorInfo.power = 0.001f; // mA mSensorInfo.minDelayUs = 10 * 1000; // microseconds - mSensorInfo.maxDelayUs = kDefaultMaxDelayUs; + mSensorInfo.maxDelayUs = 10 * 1000 * 10; // microseconds mSensorInfo.fifoReservedEventCount = 0; mSensorInfo.fifoMaxEventCount = 0; mSensorInfo.requiredPermission = ""; mSensorInfo.flags = static_cast(SensorInfo::SENSOR_FLAG_BITS_DATA_INJECTION); -}; - -void AccelSensor::readEventPayload(EventPayload& payload) { - EventPayload::Vec3 vec3 = { - .x = 0, - .y = 0, - .z = -9.8, - .status = SensorStatus::ACCURACY_HIGH, - }; - payload.set(vec3); + } PressureSensor::PressureSensor(int32_t sensorHandle, ISensorsEventCallback* callback) : Sensor(callback) { mSensorInfo.sensorHandle = sensorHandle; mSensorInfo.name = "Pressure Sensor"; - mSensorInfo.vendor = "Vendor String"; + mSensorInfo.vendor = "Intel"; mSensorInfo.version = 1; mSensorInfo.type = SensorType::PRESSURE; mSensorInfo.typeAsString = ""; - mSensorInfo.maxRange = 1100.0f; // hPa - mSensorInfo.resolution = 0.005f; // hPa - mSensorInfo.power = 0.001f; // mA + mSensorInfo.maxRange = 1100.0f; // hPa + mSensorInfo.resolution = 0.005f; // hPa + mSensorInfo.power = 0.001f; // mA mSensorInfo.minDelayUs = 100 * 1000; // microseconds - mSensorInfo.maxDelayUs = kDefaultMaxDelayUs; + mSensorInfo.maxDelayUs = 100 * 1000 * 10; // microseconds mSensorInfo.fifoReservedEventCount = 0; mSensorInfo.fifoMaxEventCount = 0; mSensorInfo.requiredPermission = ""; mSensorInfo.flags = 0; -}; - -void PressureSensor::readEventPayload(EventPayload& payload) { - payload.set(1013.25f); } MagnetometerSensor::MagnetometerSensor(int32_t sensorHandle, ISensorsEventCallback* callback) : Sensor(callback) { mSensorInfo.sensorHandle = sensorHandle; mSensorInfo.name = "Magnetic Field Sensor"; - mSensorInfo.vendor = "Vendor String"; + mSensorInfo.vendor = "Intel"; mSensorInfo.version = 1; mSensorInfo.type = SensorType::MAGNETIC_FIELD; mSensorInfo.typeAsString = ""; mSensorInfo.maxRange = 1300.0f; mSensorInfo.resolution = 0.01f; - mSensorInfo.power = 0.001f; // mA - mSensorInfo.minDelayUs = 20 * 1000; // microseconds - mSensorInfo.maxDelayUs = kDefaultMaxDelayUs; + mSensorInfo.power = 0.001f; // mA + mSensorInfo.minDelayUs = 10 * 1000; // microseconds + mSensorInfo.maxDelayUs = 10 * 1000 * 10; // microseconds mSensorInfo.fifoReservedEventCount = 0; mSensorInfo.fifoMaxEventCount = 0; mSensorInfo.requiredPermission = ""; mSensorInfo.flags = 0; -}; - -void MagnetometerSensor::readEventPayload(EventPayload& payload) { - EventPayload::Vec3 vec3 = { - .x = 100.0, - .y = 0, - .z = 50.0, - .status = SensorStatus::ACCURACY_HIGH, - }; - payload.set(vec3); } LightSensor::LightSensor(int32_t sensorHandle, ISensorsEventCallback* callback) : OnChangeSensor(callback) { mSensorInfo.sensorHandle = sensorHandle; mSensorInfo.name = "Light Sensor"; - mSensorInfo.vendor = "Vendor String"; + mSensorInfo.vendor = "Intel"; mSensorInfo.version = 1; mSensorInfo.type = SensorType::LIGHT; mSensorInfo.typeAsString = ""; mSensorInfo.maxRange = 43000.0f; mSensorInfo.resolution = 10.0f; - mSensorInfo.power = 0.001f; // mA + mSensorInfo.power = 0.001f; // mA mSensorInfo.minDelayUs = 200 * 1000; // microseconds - mSensorInfo.maxDelayUs = kDefaultMaxDelayUs; + mSensorInfo.maxDelayUs = 200 * 1000 * 10; // microseconds mSensorInfo.fifoReservedEventCount = 0; mSensorInfo.fifoMaxEventCount = 0; mSensorInfo.requiredPermission = ""; mSensorInfo.flags = static_cast(SensorInfo::SENSOR_FLAG_BITS_ON_CHANGE_MODE); -}; - -void LightSensor::readEventPayload(EventPayload& payload) { - payload.set(80.0f); } ProximitySensor::ProximitySensor(int32_t sensorHandle, ISensorsEventCallback* callback) : OnChangeSensor(callback) { mSensorInfo.sensorHandle = sensorHandle; mSensorInfo.name = "Proximity Sensor"; - mSensorInfo.vendor = "Vendor String"; + mSensorInfo.vendor = "Intel"; mSensorInfo.version = 1; mSensorInfo.type = SensorType::PROXIMITY; mSensorInfo.typeAsString = ""; mSensorInfo.maxRange = 5.0f; mSensorInfo.resolution = 1.0f; - mSensorInfo.power = 0.012f; // mA + mSensorInfo.power = 0.012f; // mA mSensorInfo.minDelayUs = 200 * 1000; // microseconds - mSensorInfo.maxDelayUs = kDefaultMaxDelayUs; + mSensorInfo.maxDelayUs = 200 * 1000 * 10; // microseconds mSensorInfo.fifoReservedEventCount = 0; mSensorInfo.fifoMaxEventCount = 0; mSensorInfo.requiredPermission = ""; mSensorInfo.flags = static_cast(SensorInfo::SENSOR_FLAG_BITS_ON_CHANGE_MODE | SensorInfo::SENSOR_FLAG_BITS_WAKE_UP); -}; - -void ProximitySensor::readEventPayload(EventPayload& payload) { - payload.set(2.5f); } GyroSensor::GyroSensor(int32_t sensorHandle, ISensorsEventCallback* callback) : Sensor(callback) { mSensorInfo.sensorHandle = sensorHandle; mSensorInfo.name = "Gyro Sensor"; - mSensorInfo.vendor = "Vendor String"; + mSensorInfo.vendor = "Intel"; mSensorInfo.version = 1; - mSensorInfo.type = SensorType::GYROSCOPE; + mSensorInfo.type = SensorType::GYROSCOPE_UNCALIBRATED; mSensorInfo.typeAsString = ""; mSensorInfo.maxRange = 1000.0f * M_PI / 180.0f; mSensorInfo.resolution = 1000.0f * M_PI / (180.0f * 32768.0f); mSensorInfo.power = 0.001f; mSensorInfo.minDelayUs = 10 * 1000; // microseconds - mSensorInfo.maxDelayUs = kDefaultMaxDelayUs; + mSensorInfo.maxDelayUs = 10 * 1000 * 10; // microseconds mSensorInfo.fifoReservedEventCount = 0; mSensorInfo.fifoMaxEventCount = 0; mSensorInfo.requiredPermission = ""; mSensorInfo.flags = 0; -}; - -void GyroSensor::readEventPayload(EventPayload& payload) { - EventPayload::Vec3 vec3 = { - .x = 0, - .y = 0, - .z = 0, - .status = SensorStatus::ACCURACY_HIGH, - }; - payload.set(vec3); } AmbientTempSensor::AmbientTempSensor(int32_t sensorHandle, ISensorsEventCallback* callback) : OnChangeSensor(callback) { mSensorInfo.sensorHandle = sensorHandle; mSensorInfo.name = "Ambient Temp Sensor"; - mSensorInfo.vendor = "Vendor String"; + mSensorInfo.vendor = "Intel"; mSensorInfo.version = 1; mSensorInfo.type = SensorType::AMBIENT_TEMPERATURE; mSensorInfo.typeAsString = ""; @@ -368,15 +366,31 @@ AmbientTempSensor::AmbientTempSensor(int32_t sensorHandle, ISensorsEventCallback mSensorInfo.resolution = 0.01f; mSensorInfo.power = 0.001f; mSensorInfo.minDelayUs = 40 * 1000; // microseconds - mSensorInfo.maxDelayUs = kDefaultMaxDelayUs; + mSensorInfo.maxDelayUs = 40 * 1000 * 10; // microseconds mSensorInfo.fifoReservedEventCount = 0; mSensorInfo.fifoMaxEventCount = 0; mSensorInfo.requiredPermission = ""; mSensorInfo.flags = static_cast(SensorInfo::SENSOR_FLAG_BITS_ON_CHANGE_MODE); -}; +} -void AmbientTempSensor::readEventPayload(EventPayload& payload) { - payload.set(40.0f); +DeviceTempSensor::DeviceTempSensor(int32_t sensorHandle, + ISensorsEventCallback* callback) + : OnChangeSensor(callback) { + mSensorInfo.sensorHandle = sensorHandle; + mSensorInfo.name = "Device Temp Sensor"; + mSensorInfo.vendor = "Intel"; + mSensorInfo.version = 1; + mSensorInfo.type = SensorType::AMBIENT_TEMPERATURE; + mSensorInfo.typeAsString = ""; + mSensorInfo.maxRange = 80.0f; + mSensorInfo.resolution = 0.01f; + mSensorInfo.power = 0.001f; + mSensorInfo.minDelayUs = 40 * 1000; // microseconds + mSensorInfo.maxDelayUs = 40 * 1000 * 10; // microseconds + mSensorInfo.fifoReservedEventCount = 0; + mSensorInfo.fifoMaxEventCount = 0; + mSensorInfo.requiredPermission = ""; + mSensorInfo.flags = static_cast(SensorInfo::SENSOR_FLAG_BITS_ON_CHANGE_MODE); } RelativeHumiditySensor::RelativeHumiditySensor(int32_t sensorHandle, @@ -384,7 +398,7 @@ RelativeHumiditySensor::RelativeHumiditySensor(int32_t sensorHandle, : OnChangeSensor(callback) { mSensorInfo.sensorHandle = sensorHandle; mSensorInfo.name = "Relative Humidity Sensor"; - mSensorInfo.vendor = "Vendor String"; + mSensorInfo.vendor = "Intel"; mSensorInfo.version = 1; mSensorInfo.type = SensorType::RELATIVE_HUMIDITY; mSensorInfo.typeAsString = ""; @@ -392,22 +406,114 @@ RelativeHumiditySensor::RelativeHumiditySensor(int32_t sensorHandle, mSensorInfo.resolution = 0.1f; mSensorInfo.power = 0.001f; mSensorInfo.minDelayUs = 40 * 1000; // microseconds - mSensorInfo.maxDelayUs = kDefaultMaxDelayUs; + mSensorInfo.maxDelayUs = 40 * 1000 * 10; // microseconds mSensorInfo.fifoReservedEventCount = 0; mSensorInfo.fifoMaxEventCount = 0; mSensorInfo.requiredPermission = ""; mSensorInfo.flags = static_cast(SensorInfo::SENSOR_FLAG_BITS_ON_CHANGE_MODE); } -void RelativeHumiditySensor::readEventPayload(EventPayload& payload) { - payload.set(50.0f); +GravitySensor::GravitySensor(int32_t sensorHandle, + ISensorsEventCallback* callback) : Sensor(callback) { + mSensorInfo.sensorHandle = sensorHandle; + mSensorInfo.name = "Gravity Sensor"; + mSensorInfo.vendor = "Intel"; + mSensorInfo.version = 1; + mSensorInfo.type = SensorType::GRAVITY; + mSensorInfo.typeAsString = ""; + mSensorInfo.maxRange = 1300.0f; + mSensorInfo.resolution = 0.01f; + mSensorInfo.power = 0.001f; + mSensorInfo.minDelayUs = 10 * 1000; // microseconds + mSensorInfo.maxDelayUs = 10 * 1000 * 10; // microseconds + mSensorInfo.fifoReservedEventCount = 0; + mSensorInfo.fifoMaxEventCount = 0; + mSensorInfo.requiredPermission = ""; + mSensorInfo.flags = 0; +} + +RotationVector::RotationVector(int32_t sensorHandle, + ISensorsEventCallback* callback) : Sensor(callback) { + mSensorInfo.sensorHandle = sensorHandle; + mSensorInfo.name = "Rotation Vector"; + mSensorInfo.vendor = "Intel"; + mSensorInfo.version = 1; + mSensorInfo.type = SensorType::ROTATION_VECTOR; + mSensorInfo.typeAsString = ""; + mSensorInfo.maxRange = 1300.0f; + mSensorInfo.resolution = 0.01f; + mSensorInfo.power = 0.001f; + mSensorInfo.minDelayUs = 10 * 1000; // microseconds + mSensorInfo.maxDelayUs = 10 * 1000 * 10; // microseconds + mSensorInfo.fifoReservedEventCount = 0; + mSensorInfo.fifoMaxEventCount = 0; + mSensorInfo.requiredPermission = ""; + mSensorInfo.flags = 0; +} + +GeomagnaticRotationVector::GeomagnaticRotationVector(int32_t sensorHandle, + ISensorsEventCallback* callback) : Sensor(callback) { + mSensorInfo.sensorHandle = sensorHandle; + mSensorInfo.name = "Geomagnatic Rotation Vector"; + mSensorInfo.vendor = "Intel"; + mSensorInfo.version = 1; + mSensorInfo.type = SensorType::GEOMAGNETIC_ROTATION_VECTOR; + mSensorInfo.typeAsString = ""; + mSensorInfo.maxRange = 1300.0f; + mSensorInfo.resolution = 0.01f; + mSensorInfo.power = 0.001f; + mSensorInfo.minDelayUs = 10 * 1000; // microseconds + mSensorInfo.maxDelayUs = 10 * 1000 * 10; // microseconds + mSensorInfo.fifoReservedEventCount = 0; + mSensorInfo.fifoMaxEventCount = 0; + mSensorInfo.requiredPermission = ""; + mSensorInfo.flags = 0; +} + +OrientationSensor::OrientationSensor(int32_t sensorHandle, + ISensorsEventCallback* callback) : Sensor(callback) { + mSensorInfo.sensorHandle = sensorHandle; + mSensorInfo.name = "Orientation Sensor"; + mSensorInfo.vendor = "Intel"; + mSensorInfo.version = 1; + mSensorInfo.type = SensorType::ORIENTATION; + mSensorInfo.typeAsString = ""; + mSensorInfo.maxRange = 1300.0f; + mSensorInfo.resolution = 0.01f; + mSensorInfo.power = 0.001f; + mSensorInfo.minDelayUs = 10 * 1000; // microseconds + mSensorInfo.maxDelayUs = 10 * 1000 * 10; // microseconds + mSensorInfo.fifoReservedEventCount = 0; + mSensorInfo.fifoMaxEventCount = 0; + mSensorInfo.requiredPermission = ""; + mSensorInfo.flags = 0; +} + +InclinometerSensor::InclinometerSensor(int32_t sensorHandle, + ISensorsEventCallback* callback) + : Sensor(callback) { + mSensorInfo.sensorHandle = sensorHandle; + mSensorInfo.name = "Inclinometer 3D Sensor"; + mSensorInfo.vendor = "Intel"; + mSensorInfo.version = 1; + mSensorInfo.type = SensorType::ORIENTATION; + mSensorInfo.typeAsString = ""; + mSensorInfo.maxRange = 1300.0f; + mSensorInfo.resolution = 0.01f; + mSensorInfo.power = 0.001f; // mA + mSensorInfo.minDelayUs = 10 * 1000; // microseconds + mSensorInfo.maxDelayUs = 10 * 1000 * 10; // microseconds + mSensorInfo.fifoReservedEventCount = 0; + mSensorInfo.fifoMaxEventCount = 0; + mSensorInfo.requiredPermission = ""; + mSensorInfo.flags = 0; } HingeAngleSensor::HingeAngleSensor(int32_t sensorHandle, ISensorsEventCallback* callback) : OnChangeSensor(callback) { mSensorInfo.sensorHandle = sensorHandle; mSensorInfo.name = "Hinge Angle Sensor"; - mSensorInfo.vendor = "Vendor String"; + mSensorInfo.vendor = "Intel"; mSensorInfo.version = 1; mSensorInfo.type = SensorType::HINGE_ANGLE; mSensorInfo.typeAsString = ""; @@ -424,11 +530,8 @@ HingeAngleSensor::HingeAngleSensor(int32_t sensorHandle, ISensorsEventCallback* SensorInfo::SENSOR_FLAG_BITS_DATA_INJECTION); } -void HingeAngleSensor::readEventPayload(EventPayload& payload) { - payload.set(180.0f); -} } // namespace sensors } // namespace hardware } // namespace android -} // namespace aidl +} // namespace aidl \ No newline at end of file diff --git a/sensors/2.0/iiohal_mediation_v2.0/iioClient.cpp b/sensors/aidl/iioClient.cpp similarity index 100% rename from sensors/2.0/iiohal_mediation_v2.0/iioClient.cpp rename to sensors/aidl/iioClient.cpp diff --git a/sensors/2.0/iiohal_mediation_v2.0/iioClient.h b/sensors/aidl/iioClient.h similarity index 93% rename from sensors/2.0/iiohal_mediation_v2.0/iioClient.h rename to sensors/aidl/iioClient.h index 6ecd92d..b84557d 100644 --- a/sensors/2.0/iiohal_mediation_v2.0/iioClient.h +++ b/sensors/aidl/iioClient.h @@ -15,9 +15,6 @@ * */ -#ifndef SENSORS_2_0_IIOHAL_MEDIATION_V2_0_IIO_CLIENT_H_ -#define SENSORS_2_0_IIOHAL_MEDIATION_V2_0_IIO_CLIENT_H_ - #include #include #include @@ -37,7 +34,7 @@ #include #include -#include "iio.h" +#include "libiio_client/iio.h" #define MAX_SENSOR 9 #define MAX_CHANNEL 3 @@ -112,4 +109,3 @@ class iioClient { int activate(int handle, bool enabled); int batch(int handle, int32_t sampling_period_ns); }; -#endif /*SENSORS_2_0_IIOHAL_MEDIATION_V2_0_IIO_CLIENT_H_*/ diff --git a/sensors/aidl/include/sensors-impl/Sensor.h b/sensors/aidl/include/sensors-impl/Sensor.h index e6cd3e6..4c8d286 100644 --- a/sensors/aidl/include/sensors-impl/Sensor.h +++ b/sensors/aidl/include/sensors-impl/Sensor.h @@ -15,7 +15,7 @@ */ #include - +#include "iioClient.h" #include namespace aidl { @@ -40,12 +40,14 @@ class Sensor { using SensorType = ::aidl::android::hardware::sensors::SensorType; using MetaDataEventType = ::aidl::android::hardware::sensors::Event::EventPayload::MetaData::MetaDataEventType; + + iioClient *iioc; Sensor(ISensorsEventCallback* callback); virtual ~Sensor(); const SensorInfo& getSensorInfo() const; - void batch(int64_t samplingPeriodNs); + void batch(int32_t samplingPeriodNs); virtual void activate(bool enable); ndk::ScopedAStatus flush(); @@ -56,7 +58,6 @@ class Sensor { protected: void run(); virtual std::vector readEvents(); - virtual void readEventPayload(EventPayload&) = 0; static void startThread(Sensor* sensor); bool isWakeUpSensor(); @@ -93,76 +94,79 @@ class OnChangeSensor : public Sensor { class AccelSensor : public Sensor { public: AccelSensor(int32_t sensorHandle, ISensorsEventCallback* callback); - - protected: - virtual void readEventPayload(EventPayload& payload) override; }; class GyroSensor : public Sensor { public: GyroSensor(int32_t sensorHandle, ISensorsEventCallback* callback); - - protected: - virtual void readEventPayload(EventPayload& payload) override; }; class AmbientTempSensor : public OnChangeSensor { public: AmbientTempSensor(int32_t sensorHandle, ISensorsEventCallback* callback); +}; - protected: - virtual void readEventPayload(EventPayload& payload) override; +class DeviceTempSensor : public OnChangeSensor { + public: + DeviceTempSensor(int32_t sensorHandle, ISensorsEventCallback* callback); }; class PressureSensor : public Sensor { public: PressureSensor(int32_t sensorHandle, ISensorsEventCallback* callback); - - protected: - virtual void readEventPayload(EventPayload& payload) override; }; class MagnetometerSensor : public Sensor { public: MagnetometerSensor(int32_t sensorHandle, ISensorsEventCallback* callback); - - protected: - virtual void readEventPayload(EventPayload& payload) override; }; class LightSensor : public OnChangeSensor { public: LightSensor(int32_t sensorHandle, ISensorsEventCallback* callback); - - protected: - virtual void readEventPayload(EventPayload& payload) override; }; class ProximitySensor : public OnChangeSensor { public: ProximitySensor(int32_t sensorHandle, ISensorsEventCallback* callback); - - protected: - virtual void readEventPayload(EventPayload& payload) override; }; class RelativeHumiditySensor : public OnChangeSensor { public: RelativeHumiditySensor(int32_t sensorHandle, ISensorsEventCallback* callback); +}; - protected: - virtual void readEventPayload(EventPayload& payload) override; +class GravitySensor : public Sensor { + public: + GravitySensor(int32_t sensorHandle, ISensorsEventCallback* callback); +}; + +class RotationVector : public Sensor { + public: + RotationVector(int32_t sensorHandle, ISensorsEventCallback* callback); +}; + +class GeomagnaticRotationVector : public Sensor { + public: + GeomagnaticRotationVector(int32_t sensorHandle, ISensorsEventCallback* callback); +}; + +class OrientationSensor : public Sensor { + public: + OrientationSensor(int32_t sensorHandle, ISensorsEventCallback* callback); +}; + +class InclinometerSensor : public Sensor { + public: + InclinometerSensor(int32_t sensorHandle, ISensorsEventCallback* callback); }; class HingeAngleSensor : public OnChangeSensor { public: HingeAngleSensor(int32_t sensorHandle, ISensorsEventCallback* callback); - - protected: - virtual void readEventPayload(EventPayload& payload) override; }; } // namespace sensors } // namespace hardware } // namespace android -} // namespace aidl +} // namespace aidl \ No newline at end of file diff --git a/sensors/aidl/include/sensors-impl/Sensors.h b/sensors/aidl/include/sensors-impl/Sensors.h index e270d96..3757608 100644 --- a/sensors/aidl/include/sensors-impl/Sensors.h +++ b/sensors/aidl/include/sensors-impl/Sensors.h @@ -45,15 +45,17 @@ class Sensors : public BnSensors, public ISensorsEventCallback { mReadWakeLockQueueRun(false), mAutoReleaseWakeLockTime(0), mHasWakeLock(false) { +#if SENSOR_LIST_ENABLED AddSensor(); AddSensor(); - AddSensor(); - AddSensor(); AddSensor(); AddSensor(); - AddSensor(); - AddSensor(); - AddSensor(); + AddSensor(); + AddSensor(); + AddSensor(); + AddSensor(); + AddSensor(); +#endif } virtual ~Sensors() { @@ -213,4 +215,4 @@ class Sensors : public BnSensors, public ISensorsEventCallback { } // namespace sensors } // namespace hardware } // namespace android -} // namespace aidl +} // namespace aidl \ No newline at end of file diff --git a/sensors/2.0/iiohal_mediation_v2.0/libiio_client/backend.c b/sensors/aidl/libiio_client/backend.c similarity index 100% rename from sensors/2.0/iiohal_mediation_v2.0/libiio_client/backend.c rename to sensors/aidl/libiio_client/backend.c diff --git a/sensors/2.0/iiohal_mediation_v2.0/libiio_client/buffer.c b/sensors/aidl/libiio_client/buffer.c similarity index 100% rename from sensors/2.0/iiohal_mediation_v2.0/libiio_client/buffer.c rename to sensors/aidl/libiio_client/buffer.c diff --git a/sensors/2.0/iiohal_mediation_v2.0/libiio_client/channel.c b/sensors/aidl/libiio_client/channel.c similarity index 100% rename from sensors/2.0/iiohal_mediation_v2.0/libiio_client/channel.c rename to sensors/aidl/libiio_client/channel.c diff --git a/sensors/2.0/iiohal_mediation_v2.0/libiio_client/context.c b/sensors/aidl/libiio_client/context.c similarity index 100% rename from sensors/2.0/iiohal_mediation_v2.0/libiio_client/context.c rename to sensors/aidl/libiio_client/context.c diff --git a/sensors/2.0/iiohal_mediation_v2.0/libiio_client/debug.h b/sensors/aidl/libiio_client/debug.h similarity index 100% rename from sensors/2.0/iiohal_mediation_v2.0/libiio_client/debug.h rename to sensors/aidl/libiio_client/debug.h diff --git a/sensors/2.0/iiohal_mediation_v2.0/libiio_client/device.c b/sensors/aidl/libiio_client/device.c similarity index 100% rename from sensors/2.0/iiohal_mediation_v2.0/libiio_client/device.c rename to sensors/aidl/libiio_client/device.c diff --git a/sensors/2.0/iiohal_mediation_v2.0/libiio_client/iio-config.h b/sensors/aidl/libiio_client/iio-config.h similarity index 100% rename from sensors/2.0/iiohal_mediation_v2.0/libiio_client/iio-config.h rename to sensors/aidl/libiio_client/iio-config.h diff --git a/sensors/2.0/iiohal_mediation_v2.0/libiio_client/iio-lock.h b/sensors/aidl/libiio_client/iio-lock.h similarity index 100% rename from sensors/2.0/iiohal_mediation_v2.0/libiio_client/iio-lock.h rename to sensors/aidl/libiio_client/iio-lock.h diff --git a/sensors/2.0/iiohal_mediation_v2.0/libiio_client/iio-private.h b/sensors/aidl/libiio_client/iio-private.h similarity index 100% rename from sensors/2.0/iiohal_mediation_v2.0/libiio_client/iio-private.h rename to sensors/aidl/libiio_client/iio-private.h diff --git a/sensors/2.0/iiohal_mediation_v2.0/libiio_client/iio.h b/sensors/aidl/libiio_client/iio.h similarity index 100% rename from sensors/2.0/iiohal_mediation_v2.0/libiio_client/iio.h rename to sensors/aidl/libiio_client/iio.h diff --git a/sensors/2.0/iiohal_mediation_v2.0/libiio_client/iiod-client.c b/sensors/aidl/libiio_client/iiod-client.c similarity index 100% rename from sensors/2.0/iiohal_mediation_v2.0/libiio_client/iiod-client.c rename to sensors/aidl/libiio_client/iiod-client.c diff --git a/sensors/2.0/iiohal_mediation_v2.0/libiio_client/iiod-client.h b/sensors/aidl/libiio_client/iiod-client.h similarity index 100% rename from sensors/2.0/iiohal_mediation_v2.0/libiio_client/iiod-client.h rename to sensors/aidl/libiio_client/iiod-client.h diff --git a/sensors/2.0/iiohal_mediation_v2.0/libiio_client/lock.c b/sensors/aidl/libiio_client/lock.c similarity index 100% rename from sensors/2.0/iiohal_mediation_v2.0/libiio_client/lock.c rename to sensors/aidl/libiio_client/lock.c diff --git a/sensors/2.0/iiohal_mediation_v2.0/libiio_client/network.c b/sensors/aidl/libiio_client/network.c similarity index 100% rename from sensors/2.0/iiohal_mediation_v2.0/libiio_client/network.c rename to sensors/aidl/libiio_client/network.c diff --git a/sensors/2.0/iiohal_mediation_v2.0/libiio_client/sort.h b/sensors/aidl/libiio_client/sort.h similarity index 100% rename from sensors/2.0/iiohal_mediation_v2.0/libiio_client/sort.h rename to sensors/aidl/libiio_client/sort.h diff --git a/sensors/2.0/iiohal_mediation_v2.0/libiio_client/utilities.c b/sensors/aidl/libiio_client/utilities.c similarity index 100% rename from sensors/2.0/iiohal_mediation_v2.0/libiio_client/utilities.c rename to sensors/aidl/libiio_client/utilities.c diff --git a/sensors/2.0/iiohal_mediation_v2.0/libiio_client/xml.c b/sensors/aidl/libiio_client/xml.c similarity index 100% rename from sensors/2.0/iiohal_mediation_v2.0/libiio_client/xml.c rename to sensors/aidl/libiio_client/xml.c diff --git a/sensors/aidl/sensors-default.rc b/sensors/aidl/sensors-default.rc index 96da85d..9f3fec9 100644 --- a/sensors/aidl/sensors-default.rc +++ b/sensors/aidl/sensors-default.rc @@ -1,5 +1,8 @@ -service vendor.sensors-default /vendor/bin/hw/android.hardware.sensors-service.example +service vendor.sensors-default /vendor/bin/hw/android.hardware.sensors-service.intel + interface aidl android.hardware.sensors.ISensors/default class hal user system group system + group system wakelock uhid context_hub + capabilities BLOCK_SUSPEND rlimit rtprio 10 10