Updated multihal to use new sensors AIDL interface.
Test: make android.hardware.sensors@aidl-multihal
Fix: 206867060
Change-Id: I9b78a0f25117d11fdf4beb1e0913393c1c14620d
diff --git a/sensors/aidl/default/multihal/Android.bp b/sensors/aidl/default/multihal/Android.bp
new file mode 100644
index 0000000..a7f6af2
--- /dev/null
+++ b/sensors/aidl/default/multihal/Android.bp
@@ -0,0 +1,57 @@
+//
+// Copyright (C) 2021 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 {
+ // 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"],
+}
+
+cc_library_static {
+ name: "android.hardware.sensors@aidl-multihal",
+ vendor: true,
+ header_libs: [
+ "android.hardware.sensors@2.X-multihal.header",
+ "android.hardware.sensors@2.X-shared-utils",
+ ],
+ shared_libs: [
+ "libfmq",
+ "libpower",
+ "libbase",
+ "libbinder_ndk",
+ "android.hardware.sensors@1.0",
+ "android.hardware.sensors@2.0",
+ "android.hardware.sensors@2.1",
+ "android.hardware.sensors-V1-ndk",
+ ],
+ export_include_dirs: ["include"],
+ srcs: [
+ "HalProxyAidl.cpp",
+ ],
+ visibility: [
+ ":__subpackages__",
+ "//hardware/interfaces/sensors/aidl/multihal:__subpackages__",
+ "//hardware/interfaces/tests/extension/sensors:__subpackages__",
+ ],
+ static_libs: [
+ "android.hardware.sensors@1.0-convert",
+ "android.hardware.sensors@2.X-multihal",
+ "libaidlcommonsupport",
+ ],
+}
diff --git a/sensors/aidl/default/multihal/HalProxyAidl.cpp b/sensors/aidl/default/multihal/HalProxyAidl.cpp
new file mode 100644
index 0000000..64805e6
--- /dev/null
+++ b/sensors/aidl/default/multihal/HalProxyAidl.cpp
@@ -0,0 +1,213 @@
+/*
+ * Copyright (C) 2021 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 "HalProxyAidl.h"
+#include <aidlcommonsupport/NativeHandle.h>
+#include <fmq/AidlMessageQueue.h>
+#include <hidl/Status.h>
+#include "ConvertUtils.h"
+#include "EventMessageQueueWrapperAidl.h"
+#include "ISensorsCallbackWrapperAidl.h"
+#include "WakeLockMessageQueueWrapperAidl.h"
+#include "convertV2_1.h"
+
+using ::aidl::android::hardware::common::fmq::MQDescriptor;
+using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite;
+using ::aidl::android::hardware::sensors::ISensors;
+using ::aidl::android::hardware::sensors::ISensorsCallback;
+using ::android::hardware::sensors::V2_1::implementation::convertToOldEvent;
+
+namespace aidl {
+namespace android {
+namespace hardware {
+namespace sensors {
+namespace implementation {
+
+static binder_status_t resultToBinderStatus(::android::hardware::sensors::V1_0::Result result) {
+ switch (result) {
+ case ::android::hardware::sensors::V1_0::Result::OK:
+ return STATUS_OK;
+ case ::android::hardware::sensors::V1_0::Result::PERMISSION_DENIED:
+ return STATUS_PERMISSION_DENIED;
+ case ::android::hardware::sensors::V1_0::Result::NO_MEMORY:
+ return STATUS_NO_MEMORY;
+ case ::android::hardware::sensors::V1_0::Result::BAD_VALUE:
+ return STATUS_BAD_VALUE;
+ case ::android::hardware::sensors::V1_0::Result::INVALID_OPERATION:
+ return STATUS_INVALID_OPERATION;
+ }
+}
+
+static ::android::hardware::sensors::V1_0::RateLevel convertRateLevel(
+ ISensors::RateLevel rateLevel) {
+ switch (rateLevel) {
+ case ISensors::RateLevel::STOP:
+ return ::android::hardware::sensors::V1_0::RateLevel::STOP;
+ case ISensors::RateLevel::NORMAL:
+ return ::android::hardware::sensors::V1_0::RateLevel::NORMAL;
+ case ISensors::RateLevel::FAST:
+ return ::android::hardware::sensors::V1_0::RateLevel::FAST;
+ case ISensors::RateLevel::VERY_FAST:
+ return ::android::hardware::sensors::V1_0::RateLevel::VERY_FAST;
+ }
+}
+
+static ::android::hardware::sensors::V1_0::OperationMode convertOperationMode(
+ ISensors::OperationMode operationMode) {
+ switch (operationMode) {
+ case ISensors::OperationMode::NORMAL:
+ return ::android::hardware::sensors::V1_0::OperationMode::NORMAL;
+ case ISensors::OperationMode::DATA_INJECTION:
+ return ::android::hardware::sensors::V1_0::OperationMode::DATA_INJECTION;
+ }
+}
+
+static ::android::hardware::sensors::V1_0::SharedMemType convertSharedMemType(
+ ISensors::SharedMemInfo::SharedMemType sharedMemType) {
+ switch (sharedMemType) {
+ case ISensors::SharedMemInfo::SharedMemType::ASHMEM:
+ return ::android::hardware::sensors::V1_0::SharedMemType::ASHMEM;
+ case ISensors::SharedMemInfo::SharedMemType::GRALLOC:
+ return ::android::hardware::sensors::V1_0::SharedMemType::GRALLOC;
+ }
+}
+
+static ::android::hardware::sensors::V1_0::SharedMemFormat convertSharedMemFormat(
+ ISensors::SharedMemInfo::SharedMemFormat sharedMemFormat) {
+ switch (sharedMemFormat) {
+ case ISensors::SharedMemInfo::SharedMemFormat::SENSORS_EVENT:
+ return ::android::hardware::sensors::V1_0::SharedMemFormat::SENSORS_EVENT;
+ }
+}
+
+static ::android::hardware::sensors::V1_0::SharedMemInfo convertSharedMemInfo(
+ const ISensors::SharedMemInfo& sharedMemInfo) {
+ ::android::hardware::sensors::V1_0::SharedMemInfo v1SharedMemInfo;
+ v1SharedMemInfo.type = convertSharedMemType(sharedMemInfo.type);
+ v1SharedMemInfo.format = convertSharedMemFormat(sharedMemInfo.format);
+ v1SharedMemInfo.size = sharedMemInfo.size;
+ v1SharedMemInfo.memoryHandle =
+ ::android::hardware::hidl_handle(::android::makeFromAidl(sharedMemInfo.memoryHandle));
+ return v1SharedMemInfo;
+}
+
+::ndk::ScopedAStatus HalProxyAidl::activate(int32_t in_sensorHandle, bool in_enabled) {
+ return ndk::ScopedAStatus::fromStatus(
+ resultToBinderStatus(HalProxy::activate(in_sensorHandle, in_enabled)));
+}
+
+::ndk::ScopedAStatus HalProxyAidl::batch(int32_t in_sensorHandle, int64_t in_samplingPeriodNs,
+ int64_t in_maxReportLatencyNs) {
+ return ndk::ScopedAStatus::fromStatus(resultToBinderStatus(
+ HalProxy::batch(in_sensorHandle, in_samplingPeriodNs, in_maxReportLatencyNs)));
+}
+
+::ndk::ScopedAStatus HalProxyAidl::configDirectReport(int32_t in_sensorHandle,
+ int32_t in_channelHandle,
+ ISensors::RateLevel in_rate,
+ int32_t* _aidl_return) {
+ binder_status_t binderStatus;
+ HalProxy::configDirectReport(
+ in_sensorHandle, in_channelHandle, convertRateLevel(in_rate),
+ [&binderStatus, _aidl_return](::android::hardware::sensors::V1_0::Result result,
+ int32_t reportToken) {
+ binderStatus = resultToBinderStatus(result);
+ *_aidl_return = reportToken;
+ });
+ return ndk::ScopedAStatus::fromStatus(binderStatus);
+}
+
+::ndk::ScopedAStatus HalProxyAidl::flush(int32_t in_sensorHandle) {
+ return ndk::ScopedAStatus::fromStatus(resultToBinderStatus(HalProxy::flush(in_sensorHandle)));
+}
+
+::ndk::ScopedAStatus HalProxyAidl::getSensorsList(
+ std::vector<::aidl::android::hardware::sensors::SensorInfo>* _aidl_return) {
+ for (const auto& sensor : HalProxy::getSensors()) {
+ _aidl_return->push_back(convertSensorInfo(sensor.second));
+ }
+ return ndk::ScopedAStatus::ok();
+}
+
+::ndk::ScopedAStatus HalProxyAidl::initialize(
+ const MQDescriptor<::aidl::android::hardware::sensors::Event, SynchronizedReadWrite>&
+ in_eventQueueDescriptor,
+ const MQDescriptor<int32_t, SynchronizedReadWrite>& in_wakeLockDescriptor,
+ const std::shared_ptr<ISensorsCallback>& in_sensorsCallback) {
+ ::android::sp<::android::hardware::sensors::V2_1::implementation::ISensorsCallbackWrapperBase>
+ dynamicCallback = new ISensorsCallbackWrapperAidl(in_sensorsCallback);
+
+ auto aidlEventQueue =
+ std::make_unique<::android::AidlMessageQueue<::aidl::android::hardware::sensors::Event,
+ SynchronizedReadWrite>>(
+ in_eventQueueDescriptor, true /* resetPointers */);
+ std::unique_ptr<
+ ::android::hardware::sensors::V2_1::implementation::EventMessageQueueWrapperBase>
+ eventQueue = std::make_unique<EventMessageQueueWrapperAidl>(aidlEventQueue);
+
+ auto aidlWakeLockQueue =
+ std::make_unique<::android::AidlMessageQueue<int32_t, SynchronizedReadWrite>>(
+ in_wakeLockDescriptor, true /* resetPointers */);
+ std::unique_ptr<
+ ::android::hardware::sensors::V2_1::implementation::WakeLockMessageQueueWrapperBase>
+ wakeLockQueue = std::make_unique<WakeLockMessageQueueWrapperAidl>(aidlWakeLockQueue);
+
+ return ndk::ScopedAStatus::fromStatus(
+ resultToBinderStatus(initializeCommon(eventQueue, wakeLockQueue, dynamicCallback)));
+}
+
+::ndk::ScopedAStatus HalProxyAidl::injectSensorData(
+ const ::aidl::android::hardware::sensors::Event& in_event) {
+ ::android::hardware::sensors::V2_1::Event hidlEvent;
+ convertToHidlEvent(in_event, &hidlEvent);
+ return ndk::ScopedAStatus::fromStatus(
+ resultToBinderStatus(HalProxy::injectSensorData(convertToOldEvent(hidlEvent))));
+}
+
+::ndk::ScopedAStatus HalProxyAidl::registerDirectChannel(const ISensors::SharedMemInfo& in_mem,
+ int32_t* _aidl_return) {
+ binder_status_t binderStatus;
+ ::android::hardware::sensors::V1_0::SharedMemInfo sharedMemInfo = convertSharedMemInfo(in_mem);
+
+ HalProxy::registerDirectChannel(
+ sharedMemInfo,
+ [&binderStatus, _aidl_return](::android::hardware::sensors::V1_0::Result result,
+ int32_t reportToken) {
+ binderStatus = resultToBinderStatus(result);
+ *_aidl_return = reportToken;
+ });
+
+ native_handle_delete(
+ const_cast<native_handle_t*>(sharedMemInfo.memoryHandle.getNativeHandle()));
+ return ndk::ScopedAStatus::fromStatus(binderStatus);
+}
+
+::ndk::ScopedAStatus HalProxyAidl::setOperationMode(
+ ::aidl::android::hardware::sensors::ISensors::OperationMode in_mode) {
+ return ndk::ScopedAStatus::fromStatus(
+ resultToBinderStatus(HalProxy::setOperationMode(convertOperationMode(in_mode))));
+}
+
+::ndk::ScopedAStatus HalProxyAidl::unregisterDirectChannel(int32_t in_channelHandle) {
+ return ndk::ScopedAStatus::fromStatus(
+ resultToBinderStatus(HalProxy::unregisterDirectChannel(in_channelHandle)));
+}
+
+} // namespace implementation
+} // namespace sensors
+} // namespace hardware
+} // namespace android
+} // namespace aidl
\ No newline at end of file
diff --git a/sensors/aidl/default/multihal/include/ConvertUtils.h b/sensors/aidl/default/multihal/include/ConvertUtils.h
new file mode 100644
index 0000000..09ec0dc
--- /dev/null
+++ b/sensors/aidl/default/multihal/include/ConvertUtils.h
@@ -0,0 +1,422 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+#pragma once
+
+#include <android-base/logging.h>
+
+namespace aidl {
+namespace android {
+namespace hardware {
+namespace sensors {
+namespace implementation {
+
+static ::aidl::android::hardware::sensors::SensorInfo convertSensorInfo(
+ const ::android::hardware::sensors::V2_1::SensorInfo& sensorInfo) {
+ ::aidl::android::hardware::sensors::SensorInfo aidlSensorInfo;
+ aidlSensorInfo.sensorHandle = sensorInfo.sensorHandle;
+ aidlSensorInfo.name = sensorInfo.name;
+ aidlSensorInfo.vendor = sensorInfo.vendor;
+ aidlSensorInfo.version = sensorInfo.version;
+ aidlSensorInfo.type = (::aidl::android::hardware::sensors::SensorType)sensorInfo.type;
+ aidlSensorInfo.typeAsString = sensorInfo.typeAsString;
+ aidlSensorInfo.maxRange = sensorInfo.maxRange;
+ aidlSensorInfo.resolution = sensorInfo.resolution;
+ aidlSensorInfo.power = sensorInfo.power;
+ aidlSensorInfo.minDelayUs = sensorInfo.minDelay;
+ aidlSensorInfo.fifoReservedEventCount = sensorInfo.fifoReservedEventCount;
+ aidlSensorInfo.fifoMaxEventCount = sensorInfo.fifoMaxEventCount;
+ aidlSensorInfo.requiredPermission = sensorInfo.requiredPermission;
+ aidlSensorInfo.maxDelayUs = sensorInfo.maxDelay;
+ aidlSensorInfo.flags = sensorInfo.flags;
+ return aidlSensorInfo;
+}
+
+static void convertToHidlEvent(const ::aidl::android::hardware::sensors::Event& aidlEvent,
+ ::android::hardware::sensors::V2_1::Event* hidlEvent) {
+ hidlEvent->timestamp = aidlEvent.timestamp;
+ hidlEvent->sensorHandle = aidlEvent.sensorHandle;
+ hidlEvent->sensorType = (::android::hardware::sensors::V2_1::SensorType)aidlEvent.sensorType;
+
+ switch (aidlEvent.sensorType) {
+ case ::aidl::android::hardware::sensors::SensorType::META_DATA:
+ hidlEvent->u.meta.what =
+ (::android::hardware::sensors::V1_0::MetaDataEventType)aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::EventPayload::meta>()
+ .what;
+ break;
+ case ::aidl::android::hardware::sensors::SensorType::ACCELEROMETER:
+ case ::aidl::android::hardware::sensors::SensorType::MAGNETIC_FIELD:
+ case ::aidl::android::hardware::sensors::SensorType::ORIENTATION:
+ case ::aidl::android::hardware::sensors::SensorType::GYROSCOPE:
+ case ::aidl::android::hardware::sensors::SensorType::GRAVITY:
+ case ::aidl::android::hardware::sensors::SensorType::LINEAR_ACCELERATION:
+ hidlEvent->u.vec3.x =
+ aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::EventPayload::vec3>()
+ .x;
+ hidlEvent->u.vec3.y =
+ aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::EventPayload::vec3>()
+ .y;
+ hidlEvent->u.vec3.z =
+ aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::EventPayload::vec3>()
+ .z;
+ break;
+ case ::aidl::android::hardware::sensors::SensorType::GAME_ROTATION_VECTOR:
+ hidlEvent->u.vec4.x =
+ aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::EventPayload::vec4>()
+ .x;
+ hidlEvent->u.vec4.y =
+ aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::EventPayload::vec4>()
+ .y;
+ hidlEvent->u.vec4.z =
+ aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::EventPayload::vec4>()
+ .z;
+ hidlEvent->u.vec4.w =
+ aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::EventPayload::vec4>()
+ .w;
+ break;
+ case ::aidl::android::hardware::sensors::SensorType::ROTATION_VECTOR:
+ case ::aidl::android::hardware::sensors::SensorType::GEOMAGNETIC_ROTATION_VECTOR:
+ std::copy(aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::EventPayload::data>()
+ .values.data(),
+ aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::EventPayload::
+ data>()
+ .values.data() +
+ 5,
+ hidlEvent->u.data.data());
+ break;
+ case ::aidl::android::hardware::sensors::SensorType::ACCELEROMETER_UNCALIBRATED:
+ case ::aidl::android::hardware::sensors::SensorType::MAGNETIC_FIELD_UNCALIBRATED:
+ case ::aidl::android::hardware::sensors::SensorType::GYROSCOPE_UNCALIBRATED:
+ hidlEvent->u.uncal.x =
+ aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::EventPayload::uncal>()
+ .x;
+ hidlEvent->u.uncal.y =
+ aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::EventPayload::uncal>()
+ .y;
+ hidlEvent->u.uncal.z =
+ aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::EventPayload::uncal>()
+ .z;
+ hidlEvent->u.uncal.x_bias =
+ aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::EventPayload::uncal>()
+ .xBias;
+ hidlEvent->u.uncal.y_bias =
+ aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::EventPayload::uncal>()
+ .yBias;
+ hidlEvent->u.uncal.z_bias =
+ aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::EventPayload::uncal>()
+ .zBias;
+ break;
+ case ::aidl::android::hardware::sensors::SensorType::DEVICE_ORIENTATION:
+ case ::aidl::android::hardware::sensors::SensorType::LIGHT:
+ case ::aidl::android::hardware::sensors::SensorType::PRESSURE:
+ case ::aidl::android::hardware::sensors::SensorType::PROXIMITY:
+ case ::aidl::android::hardware::sensors::SensorType::RELATIVE_HUMIDITY:
+ case ::aidl::android::hardware::sensors::SensorType::AMBIENT_TEMPERATURE:
+ case ::aidl::android::hardware::sensors::SensorType::SIGNIFICANT_MOTION:
+ case ::aidl::android::hardware::sensors::SensorType::STEP_DETECTOR:
+ case ::aidl::android::hardware::sensors::SensorType::TILT_DETECTOR:
+ case ::aidl::android::hardware::sensors::SensorType::WAKE_GESTURE:
+ case ::aidl::android::hardware::sensors::SensorType::GLANCE_GESTURE:
+ case ::aidl::android::hardware::sensors::SensorType::PICK_UP_GESTURE:
+ case ::aidl::android::hardware::sensors::SensorType::WRIST_TILT_GESTURE:
+ case ::aidl::android::hardware::sensors::SensorType::STATIONARY_DETECT:
+ case ::aidl::android::hardware::sensors::SensorType::MOTION_DETECT:
+ case ::aidl::android::hardware::sensors::SensorType::HEART_BEAT:
+ case ::aidl::android::hardware::sensors::SensorType::LOW_LATENCY_OFFBODY_DETECT:
+ case ::aidl::android::hardware::sensors::SensorType::HINGE_ANGLE:
+ hidlEvent->u.scalar =
+ aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::EventPayload::scalar>();
+ break;
+ case ::aidl::android::hardware::sensors::SensorType::STEP_COUNTER:
+ hidlEvent->u.stepCount = aidlEvent.payload.get<
+ ::aidl::android::hardware::sensors::Event::EventPayload::stepCount>();
+ break;
+ case ::aidl::android::hardware::sensors::SensorType::HEART_RATE:
+ hidlEvent->u.heartRate.bpm = aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::
+ EventPayload::heartRate>()
+ .bpm;
+ hidlEvent->u.heartRate.status =
+ (::android::hardware::sensors::V1_0::SensorStatus)aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::EventPayload::
+ heartRate>()
+ .status;
+ break;
+ case ::aidl::android::hardware::sensors::SensorType::POSE_6DOF:
+ std::copy(std::begin(aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::
+ EventPayload::pose6DOF>()
+ .values),
+ std::end(aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::
+ EventPayload::data>()
+ .values),
+ hidlEvent->u.pose6DOF.data());
+ break;
+ case ::aidl::android::hardware::sensors::SensorType::DYNAMIC_SENSOR_META:
+ hidlEvent->u.dynamic.connected =
+ aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::EventPayload::dynamic>()
+ .connected;
+ hidlEvent->u.dynamic.sensorHandle =
+ aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::EventPayload::dynamic>()
+ .sensorHandle;
+ std::copy(std::begin(aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::
+ EventPayload::dynamic>()
+ .uuid.values),
+ std::end(aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::
+ EventPayload::dynamic>()
+ .uuid.values),
+ hidlEvent->u.dynamic.uuid.data());
+ break;
+ case ::aidl::android::hardware::sensors::SensorType::ADDITIONAL_INFO: {
+ const AdditionalInfo& additionalInfo = aidlEvent.payload.get<
+ ::aidl::android::hardware::sensors::Event::EventPayload::additional>();
+ hidlEvent->u.additional.type =
+ (::android::hardware::sensors::V1_0::AdditionalInfoType)additionalInfo.type;
+ hidlEvent->u.additional.serial = additionalInfo.serial;
+
+ switch (additionalInfo.payload.getTag()) {
+ case ::aidl::android::hardware::sensors::AdditionalInfo::AdditionalInfoPayload::
+ Tag::dataInt32:
+ std::copy(
+ std::begin(additionalInfo.payload
+ .get<::aidl::android::hardware::sensors::
+ AdditionalInfo::AdditionalInfoPayload::
+ dataInt32>()
+ .values),
+ std::end(additionalInfo.payload
+ .get<::aidl::android::hardware::sensors::
+ AdditionalInfo::AdditionalInfoPayload::
+ dataInt32>()
+ .values),
+ hidlEvent->u.additional.u.data_int32.data());
+ break;
+ case ::aidl::android::hardware::sensors::AdditionalInfo::AdditionalInfoPayload::
+ Tag::dataFloat:
+ std::copy(
+ std::begin(additionalInfo.payload
+ .get<::aidl::android::hardware::sensors::
+ AdditionalInfo::AdditionalInfoPayload::
+ dataFloat>()
+ .values),
+ std::end(additionalInfo.payload
+ .get<::aidl::android::hardware::sensors::
+ AdditionalInfo::AdditionalInfoPayload::
+ dataFloat>()
+ .values),
+ hidlEvent->u.additional.u.data_float.data());
+ break;
+ default:
+ ALOGE("Invalid sensor additioanl info tag: %d",
+ additionalInfo.payload.getTag());
+ break;
+ }
+ break;
+ }
+ default:
+ CHECK_GE((int32_t)aidlEvent.sensorType,
+ (int32_t)::aidl::android::hardware::sensors::SensorType::DEVICE_PRIVATE_BASE);
+ std::copy(std::begin(aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::
+ EventPayload::data>()
+ .values),
+ std::end(aidlEvent.payload
+ .get<::aidl::android::hardware::sensors::Event::
+ EventPayload::data>()
+ .values),
+ hidlEvent->u.data.data());
+ break;
+ }
+}
+
+static void convertToAidlEvent(const ::android::hardware::sensors::V2_1::Event& hidlEvent,
+ ::aidl::android::hardware::sensors::Event* aidlEvent) {
+ aidlEvent->timestamp = hidlEvent.timestamp;
+ aidlEvent->sensorHandle = hidlEvent.sensorHandle;
+ aidlEvent->sensorType = (::aidl::android::hardware::sensors::SensorType)hidlEvent.sensorType;
+ switch (hidlEvent.sensorType) {
+ case ::android::hardware::sensors::V2_1::SensorType::META_DATA: {
+ ::aidl::android::hardware::sensors::Event::EventPayload::MetaData meta;
+ meta.what = (::aidl::android::hardware::sensors::Event::EventPayload::MetaData::
+ MetaDataEventType)hidlEvent.u.meta.what;
+ aidlEvent->payload.set<::aidl::android::hardware::sensors::Event::EventPayload::meta>(
+ meta);
+ break;
+ }
+ case ::android::hardware::sensors::V2_1::SensorType::ACCELEROMETER:
+ case ::android::hardware::sensors::V2_1::SensorType::MAGNETIC_FIELD:
+ case ::android::hardware::sensors::V2_1::SensorType::ORIENTATION:
+ case ::android::hardware::sensors::V2_1::SensorType::GYROSCOPE:
+ case ::android::hardware::sensors::V2_1::SensorType::GRAVITY:
+ case ::android::hardware::sensors::V2_1::SensorType::LINEAR_ACCELERATION: {
+ ::aidl::android::hardware::sensors::Event::EventPayload::Vec3 vec3;
+ vec3.x = hidlEvent.u.vec3.x;
+ vec3.y = hidlEvent.u.vec3.y;
+ vec3.z = hidlEvent.u.vec3.z;
+ aidlEvent->payload.set<::aidl::android::hardware::sensors::Event::EventPayload::vec3>(
+ vec3);
+ break;
+ }
+ case ::android::hardware::sensors::V2_1::SensorType::GAME_ROTATION_VECTOR: {
+ ::aidl::android::hardware::sensors::Event::EventPayload::Vec4 vec4;
+ vec4.x = hidlEvent.u.vec4.x;
+ vec4.y = hidlEvent.u.vec4.y;
+ vec4.z = hidlEvent.u.vec4.z;
+ vec4.w = hidlEvent.u.vec4.w;
+ aidlEvent->payload.set<::aidl::android::hardware::sensors::Event::EventPayload::vec4>(
+ vec4);
+ break;
+ }
+ case ::android::hardware::sensors::V2_1::SensorType::ROTATION_VECTOR:
+ case ::android::hardware::sensors::V2_1::SensorType::GEOMAGNETIC_ROTATION_VECTOR: {
+ ::aidl::android::hardware::sensors::Event::EventPayload::Data data;
+ std::copy(hidlEvent.u.data.data(), hidlEvent.u.data.data() + 5,
+ std::begin(data.values));
+ aidlEvent->payload.set<::aidl::android::hardware::sensors::Event::EventPayload::data>(
+ data);
+ break;
+ }
+ case ::android::hardware::sensors::V2_1::SensorType::MAGNETIC_FIELD_UNCALIBRATED:
+ case ::android::hardware::sensors::V2_1::SensorType::GYROSCOPE_UNCALIBRATED:
+ case ::android::hardware::sensors::V2_1::SensorType::ACCELEROMETER_UNCALIBRATED: {
+ ::aidl::android::hardware::sensors::Event::EventPayload::Uncal uncal;
+ uncal.x = hidlEvent.u.uncal.x;
+ uncal.y = hidlEvent.u.uncal.y;
+ uncal.z = hidlEvent.u.uncal.z;
+ uncal.xBias = hidlEvent.u.uncal.x_bias;
+ uncal.yBias = hidlEvent.u.uncal.y_bias;
+ uncal.zBias = hidlEvent.u.uncal.z_bias;
+ aidlEvent->payload.set<::aidl::android::hardware::sensors::Event::EventPayload::uncal>(
+ uncal);
+ break;
+ }
+ case ::android::hardware::sensors::V2_1::SensorType::DEVICE_ORIENTATION:
+ case ::android::hardware::sensors::V2_1::SensorType::LIGHT:
+ case ::android::hardware::sensors::V2_1::SensorType::PRESSURE:
+ case ::android::hardware::sensors::V2_1::SensorType::PROXIMITY:
+ case ::android::hardware::sensors::V2_1::SensorType::RELATIVE_HUMIDITY:
+ case ::android::hardware::sensors::V2_1::SensorType::AMBIENT_TEMPERATURE:
+ case ::android::hardware::sensors::V2_1::SensorType::SIGNIFICANT_MOTION:
+ case ::android::hardware::sensors::V2_1::SensorType::STEP_DETECTOR:
+ case ::android::hardware::sensors::V2_1::SensorType::TILT_DETECTOR:
+ case ::android::hardware::sensors::V2_1::SensorType::WAKE_GESTURE:
+ case ::android::hardware::sensors::V2_1::SensorType::GLANCE_GESTURE:
+ case ::android::hardware::sensors::V2_1::SensorType::PICK_UP_GESTURE:
+ case ::android::hardware::sensors::V2_1::SensorType::WRIST_TILT_GESTURE:
+ case ::android::hardware::sensors::V2_1::SensorType::STATIONARY_DETECT:
+ case ::android::hardware::sensors::V2_1::SensorType::MOTION_DETECT:
+ case ::android::hardware::sensors::V2_1::SensorType::HEART_BEAT:
+ case ::android::hardware::sensors::V2_1::SensorType::LOW_LATENCY_OFFBODY_DETECT:
+ case ::android::hardware::sensors::V2_1::SensorType::HINGE_ANGLE:
+ aidlEvent->payload.set<::aidl::android::hardware::sensors::Event::EventPayload::scalar>(
+ hidlEvent.u.scalar);
+ break;
+ case ::android::hardware::sensors::V2_1::SensorType::STEP_COUNTER:
+ aidlEvent->payload
+ .set<::aidl::android::hardware::sensors::Event::EventPayload::stepCount>(
+ hidlEvent.u.stepCount);
+ break;
+ case ::android::hardware::sensors::V2_1::SensorType::HEART_RATE: {
+ ::aidl::android::hardware::sensors::Event::EventPayload::HeartRate heartRate;
+ heartRate.bpm = hidlEvent.u.heartRate.bpm;
+ heartRate.status =
+ (::aidl::android::hardware::sensors::SensorStatus)hidlEvent.u.heartRate.status;
+ aidlEvent->payload
+ .set<::aidl::android::hardware::sensors::Event::EventPayload::heartRate>(
+ heartRate);
+ break;
+ }
+ case ::android::hardware::sensors::V2_1::SensorType::POSE_6DOF: {
+ ::aidl::android::hardware::sensors::Event::EventPayload::Pose6Dof pose6Dof;
+ std::copy(hidlEvent.u.pose6DOF.data(),
+ hidlEvent.u.pose6DOF.data() + hidlEvent.u.pose6DOF.size(),
+ std::begin(pose6Dof.values));
+ aidlEvent->payload
+ .set<::aidl::android::hardware::sensors::Event::EventPayload::pose6DOF>(
+ pose6Dof);
+ break;
+ }
+ case ::android::hardware::sensors::V2_1::SensorType::DYNAMIC_SENSOR_META: {
+ ::aidl::android::hardware::sensors::DynamicSensorInfo dynamicSensorInfo;
+ dynamicSensorInfo.connected = hidlEvent.u.dynamic.connected;
+ dynamicSensorInfo.sensorHandle = hidlEvent.u.dynamic.sensorHandle;
+ std::copy(hidlEvent.u.dynamic.uuid.data(),
+ hidlEvent.u.dynamic.uuid.data() + hidlEvent.u.dynamic.uuid.size(),
+ std::begin(dynamicSensorInfo.uuid.values));
+ aidlEvent->payload
+ .set<::aidl::android::hardware::sensors::Event::EventPayload::dynamic>(
+ dynamicSensorInfo);
+ break;
+ }
+ case ::android::hardware::sensors::V2_1::SensorType::ADDITIONAL_INFO: {
+ ::aidl::android::hardware::sensors::AdditionalInfo additionalInfo;
+ additionalInfo.type =
+ (::aidl::android::hardware::sensors::AdditionalInfo::AdditionalInfoType)
+ hidlEvent.u.additional.type;
+ additionalInfo.serial = hidlEvent.u.additional.serial;
+
+ ::aidl::android::hardware::sensors::AdditionalInfo::AdditionalInfoPayload::Int32Values
+ int32Values;
+ std::copy(hidlEvent.u.additional.u.data_int32.data(),
+ hidlEvent.u.additional.u.data_int32.data() +
+ hidlEvent.u.additional.u.data_int32.size(),
+ std::begin(int32Values.values));
+ additionalInfo.payload.set<::aidl::android::hardware::sensors::AdditionalInfo::
+ AdditionalInfoPayload::dataInt32>(int32Values);
+ aidlEvent->payload
+ .set<::aidl::android::hardware::sensors::Event::EventPayload::additional>(
+ additionalInfo);
+ break;
+ }
+ default: {
+ CHECK_GE((int32_t)hidlEvent.sensorType,
+ (int32_t)::android::hardware::sensors::V2_1::SensorType::DEVICE_PRIVATE_BASE);
+ ::aidl::android::hardware::sensors::Event::EventPayload::Data data;
+ std::copy(hidlEvent.u.data.data(), hidlEvent.u.data.data() + hidlEvent.u.data.size(),
+ std::begin(data.values));
+ aidlEvent->payload.set<::aidl::android::hardware::sensors::Event::EventPayload::data>(
+ data);
+ break;
+ }
+ }
+}
+
+} // namespace implementation
+} // namespace sensors
+} // namespace hardware
+} // namespace android
+} // namespace aidl
\ No newline at end of file
diff --git a/sensors/aidl/default/multihal/include/EventMessageQueueWrapperAidl.h b/sensors/aidl/default/multihal/include/EventMessageQueueWrapperAidl.h
new file mode 100644
index 0000000..3eaa1d4
--- /dev/null
+++ b/sensors/aidl/default/multihal/include/EventMessageQueueWrapperAidl.h
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+#pragma once
+
+#include <android/hardware/sensors/2.1/types.h>
+#include <fmq/AidlMessageQueue.h>
+#include "ConvertUtils.h"
+#include "EventMessageQueueWrapper.h"
+#include "ISensorsWrapper.h"
+
+namespace aidl {
+namespace android {
+namespace hardware {
+namespace sensors {
+namespace implementation {
+
+class EventMessageQueueWrapperAidl
+ : public ::android::hardware::sensors::V2_1::implementation::EventMessageQueueWrapperBase {
+ public:
+ EventMessageQueueWrapperAidl(
+ std::unique_ptr<::android::AidlMessageQueue<
+ ::aidl::android::hardware::sensors::Event,
+ ::aidl::android::hardware::common::fmq::SynchronizedReadWrite>>& queue)
+ : mQueue(std::move(queue)) {}
+
+ virtual std::atomic<uint32_t>* getEventFlagWord() override {
+ return mQueue->getEventFlagWord();
+ }
+
+ virtual size_t availableToRead() override { return mQueue->availableToRead(); }
+
+ size_t availableToWrite() override { return mQueue->availableToWrite(); }
+
+ virtual bool read(::android::hardware::sensors::V2_1::Event* events,
+ size_t numToRead) override {
+ bool success = mQueue->read(mIntermediateEventBuffer.data(), numToRead);
+ for (int i = 0; i < numToRead; ++i) {
+ convertToHidlEvent(mIntermediateEventBuffer[i], &events[i]);
+ }
+ return success;
+ }
+
+ bool write(const ::android::hardware::sensors::V2_1::Event* events,
+ size_t numToWrite) override {
+ for (int i = 0; i < numToWrite; ++i) {
+ convertToAidlEvent(events[i], &mIntermediateEventBuffer[i]);
+ }
+ return mQueue->write(mIntermediateEventBuffer.data(), numToWrite);
+ }
+
+ virtual bool write(
+ const std::vector<::android::hardware::sensors::V2_1::Event>& events) override {
+ for (int i = 0; i < events.size(); ++i) {
+ convertToAidlEvent(events[i], &mIntermediateEventBuffer[i]);
+ }
+ return mQueue->write(mIntermediateEventBuffer.data(), events.size());
+ }
+
+ bool writeBlocking(const ::android::hardware::sensors::V2_1::Event* events, size_t count,
+ uint32_t readNotification, uint32_t writeNotification, int64_t timeOutNanos,
+ ::android::hardware::EventFlag* evFlag) override {
+ for (int i = 0; i < count; ++i) {
+ convertToAidlEvent(events[i], &mIntermediateEventBuffer[i]);
+ }
+ return mQueue->writeBlocking(mIntermediateEventBuffer.data(), count, readNotification,
+ writeNotification, timeOutNanos, evFlag);
+ }
+
+ size_t getQuantumCount() override { return mQueue->getQuantumCount(); }
+
+ private:
+ std::unique_ptr<::android::AidlMessageQueue<
+ ::aidl::android::hardware::sensors::Event,
+ ::aidl::android::hardware::common::fmq::SynchronizedReadWrite>>
+ mQueue;
+ std::array<::aidl::android::hardware::sensors::Event,
+ ::android::hardware::sensors::V2_1::implementation::MAX_RECEIVE_BUFFER_EVENT_COUNT>
+ mIntermediateEventBuffer;
+};
+
+} // namespace implementation
+} // namespace sensors
+} // namespace hardware
+} // namespace android
+} // namespace aidl
diff --git a/sensors/aidl/default/multihal/include/HalProxyAidl.h b/sensors/aidl/default/multihal/include/HalProxyAidl.h
new file mode 100644
index 0000000..7401726
--- /dev/null
+++ b/sensors/aidl/default/multihal/include/HalProxyAidl.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+#pragma once
+
+#include <aidl/android/hardware/sensors/BnSensors.h>
+#include "HalProxy.h"
+
+namespace aidl {
+namespace android {
+namespace hardware {
+namespace sensors {
+namespace implementation {
+
+class HalProxyAidl : public ::android::hardware::sensors::V2_1::implementation::HalProxy,
+ public ::aidl::android::hardware::sensors::BnSensors {
+ ::ndk::ScopedAStatus activate(int32_t in_sensorHandle, bool in_enabled) override;
+ ::ndk::ScopedAStatus batch(int32_t in_sensorHandle, int64_t in_samplingPeriodNs,
+ int64_t in_maxReportLatencyNs) override;
+ ::ndk::ScopedAStatus configDirectReport(
+ int32_t in_sensorHandle, int32_t in_channelHandle,
+ ::aidl::android::hardware::sensors::ISensors::RateLevel in_rate,
+ int32_t* _aidl_return) override;
+ ::ndk::ScopedAStatus flush(int32_t in_sensorHandle) override;
+ ::ndk::ScopedAStatus getSensorsList(
+ std::vector<::aidl::android::hardware::sensors::SensorInfo>* _aidl_return) override;
+ ::ndk::ScopedAStatus initialize(
+ const ::aidl::android::hardware::common::fmq::MQDescriptor<
+ ::aidl::android::hardware::sensors::Event,
+ ::aidl::android::hardware::common::fmq::SynchronizedReadWrite>&
+ in_eventQueueDescriptor,
+ const ::aidl::android::hardware::common::fmq::MQDescriptor<
+ int32_t, ::aidl::android::hardware::common::fmq::SynchronizedReadWrite>&
+ in_wakeLockDescriptor,
+ const std::shared_ptr<::aidl::android::hardware::sensors::ISensorsCallback>&
+ in_sensorsCallback) override;
+ ::ndk::ScopedAStatus injectSensorData(
+ const ::aidl::android::hardware::sensors::Event& in_event) override;
+ ::ndk::ScopedAStatus registerDirectChannel(
+ const ::aidl::android::hardware::sensors::ISensors::SharedMemInfo& in_mem,
+ int32_t* _aidl_return) override;
+ ::ndk::ScopedAStatus setOperationMode(
+ ::aidl::android::hardware::sensors::ISensors::OperationMode in_mode) override;
+ ::ndk::ScopedAStatus unregisterDirectChannel(int32_t in_channelHandle) override;
+};
+
+} // namespace implementation
+} // namespace sensors
+} // namespace hardware
+} // namespace android
+} // namespace aidl
diff --git a/sensors/aidl/default/multihal/include/ISensorsCallbackWrapperAidl.h b/sensors/aidl/default/multihal/include/ISensorsCallbackWrapperAidl.h
new file mode 100644
index 0000000..6ef6c63
--- /dev/null
+++ b/sensors/aidl/default/multihal/include/ISensorsCallbackWrapperAidl.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+#pragma once
+
+#include "ConvertUtils.h"
+#include "ISensorsCallbackWrapper.h"
+
+namespace aidl {
+namespace android {
+namespace hardware {
+namespace sensors {
+namespace implementation {
+
+static std::vector<::aidl::android::hardware::sensors::SensorInfo> convertToAidlSensorInfos(
+ const ::android::hardware::hidl_vec<::android::hardware::sensors::V2_1::SensorInfo>&
+ sensorInfos) {
+ std::vector<::aidl::android::hardware::sensors::SensorInfo> aidlSensorInfos;
+ for (const auto& sensorInfo : sensorInfos) {
+ aidlSensorInfos.push_back(convertSensorInfo(sensorInfo));
+ }
+ return aidlSensorInfos;
+}
+
+class ISensorsCallbackWrapperAidl
+ : public ::android::hardware::sensors::V2_1::implementation::ISensorsCallbackWrapperBase {
+ public:
+ ISensorsCallbackWrapperAidl(
+ std::shared_ptr<::aidl::android::hardware::sensors::ISensorsCallback> sensorsCallback)
+ : mSensorsCallback(sensorsCallback) {}
+
+ ::android::hardware::Return<void> onDynamicSensorsConnected(
+ const ::android::hardware::hidl_vec<::android::hardware::sensors::V2_1::SensorInfo>&
+ sensorInfos) override {
+ mSensorsCallback->onDynamicSensorsConnected(convertToAidlSensorInfos(sensorInfos));
+ return ::android::hardware::Void();
+ }
+
+ ::android::hardware::Return<void> onDynamicSensorsDisconnected(
+ const ::android::hardware::hidl_vec<int32_t>& sensorHandles) override {
+ mSensorsCallback->onDynamicSensorsDisconnected(sensorHandles);
+ return ::android::hardware::Void();
+ }
+
+ private:
+ std::shared_ptr<::aidl::android::hardware::sensors::ISensorsCallback> mSensorsCallback;
+};
+
+} // namespace implementation
+} // namespace sensors
+} // namespace hardware
+} // namespace android
+} // namespace aidl
\ No newline at end of file
diff --git a/sensors/aidl/default/multihal/include/WakeLockMessageQueueWrapperAidl.h b/sensors/aidl/default/multihal/include/WakeLockMessageQueueWrapperAidl.h
new file mode 100644
index 0000000..6be0b69
--- /dev/null
+++ b/sensors/aidl/default/multihal/include/WakeLockMessageQueueWrapperAidl.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+#pragma once
+
+#include <android/hardware/sensors/2.1/types.h>
+#include <fmq/AidlMessageQueue.h>
+#include "WakeLockMessageQueueWrapper.h"
+
+namespace aidl {
+namespace android {
+namespace hardware {
+namespace sensors {
+namespace implementation {
+
+class WakeLockMessageQueueWrapperAidl
+ : public ::android::hardware::sensors::V2_1::implementation::WakeLockMessageQueueWrapperBase {
+ public:
+ WakeLockMessageQueueWrapperAidl(
+ std::unique_ptr<::android::AidlMessageQueue<
+ int32_t, ::aidl::android::hardware::common::fmq::SynchronizedReadWrite>>& queue)
+ : mQueue(std::move(queue)) {}
+
+ virtual std::atomic<uint32_t>* getEventFlagWord() override {
+ return mQueue->getEventFlagWord();
+ }
+
+ bool readBlocking(uint32_t* wakeLocks, size_t numToRead, uint32_t readNotification,
+ uint32_t writeNotification, int64_t timeOutNanos,
+ ::android::hardware::EventFlag* evFlag) override {
+ return mQueue->readBlocking(reinterpret_cast<int32_t*>(wakeLocks), numToRead,
+ readNotification, writeNotification, timeOutNanos, evFlag);
+ }
+
+ bool write(const uint32_t* wakeLock) override {
+ return mQueue->write(reinterpret_cast<const int32_t*>(wakeLock));
+ }
+
+ private:
+ std::unique_ptr<::android::AidlMessageQueue<
+ int32_t, ::aidl::android::hardware::common::fmq::SynchronizedReadWrite>>
+ mQueue;
+};
+
+} // namespace implementation
+} // namespace sensors
+} // namespace hardware
+} // namespace android
+} // namespace aidl
diff --git a/sensors/aidl/multihal/Android.bp b/sensors/aidl/multihal/Android.bp
new file mode 100644
index 0000000..6d35daf
--- /dev/null
+++ b/sensors/aidl/multihal/Android.bp
@@ -0,0 +1,59 @@
+//
+// Copyright (C) 2021 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 {
+ // 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"],
+}
+
+cc_binary {
+ name: "android.hardware.sensors-service.multihal",
+ vendor: true,
+ relative_install_path: "hw",
+ srcs: [
+ "service.cpp",
+ ],
+ header_libs: [
+ "android.hardware.sensors@2.X-multihal.header",
+ "android.hardware.sensors@2.X-shared-utils",
+ ],
+ init_rc: ["android.hardware.sensors-service-multihal.rc"],
+ vintf_fragments: ["android.hardware.sensors-multihal.xml"],
+ shared_libs: [
+ "android.hardware.sensors@2.0-ScopedWakelock",
+ "android.hardware.sensors@2.0",
+ "android.hardware.sensors@2.1",
+ "android.hardware.sensors-V1-ndk",
+ "libbase",
+ "libcutils",
+ "libfmq",
+ "liblog",
+ "libpower",
+ "libutils",
+ "libbinder_ndk",
+ "libhidlbase",
+ ],
+ static_libs: [
+ "libaidlcommonsupport",
+ "android.hardware.sensors@1.0-convert",
+ "android.hardware.sensors@2.X-multihal",
+ "android.hardware.sensors@aidl-multihal",
+ ],
+}
diff --git a/sensors/aidl/multihal/OWNERS b/sensors/aidl/multihal/OWNERS
new file mode 100644
index 0000000..e955670
--- /dev/null
+++ b/sensors/aidl/multihal/OWNERS
@@ -0,0 +1,3 @@
+arthuri@google.com
+bduddie@google.com
+stange@google.com
\ No newline at end of file
diff --git a/sensors/aidl/multihal/android.hardware.sensors-multihal.xml b/sensors/aidl/multihal/android.hardware.sensors-multihal.xml
new file mode 100644
index 0000000..d78edff
--- /dev/null
+++ b/sensors/aidl/multihal/android.hardware.sensors-multihal.xml
@@ -0,0 +1,23 @@
+<!--
+ ~ Copyright (C) 2021 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.
+ -->
+
+<manifest version="1.0" type="device">
+ <hal format="aidl">
+ <name>android.hardware.sensors</name>
+ <version>1</version>
+ <fqname>ISensors/default</fqname>
+ </hal>
+</manifest>
diff --git a/sensors/aidl/multihal/android.hardware.sensors-service-multihal.rc b/sensors/aidl/multihal/android.hardware.sensors-service-multihal.rc
new file mode 100644
index 0000000..3f91a0a
--- /dev/null
+++ b/sensors/aidl/multihal/android.hardware.sensors-service-multihal.rc
@@ -0,0 +1,7 @@
+service vendor.sensors-hal-multihal /vendor/bin/hw/android.hardware.sensors-service.multihal
+ class hal
+ user system
+ group system wakelock context_hub
+ task_profiles ServiceCapacityLow
+ capabilities BLOCK_SUSPEND
+ rlimit rtprio 10 10
\ No newline at end of file
diff --git a/sensors/aidl/multihal/service.cpp b/sensors/aidl/multihal/service.cpp
new file mode 100644
index 0000000..11c108a
--- /dev/null
+++ b/sensors/aidl/multihal/service.cpp
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2021 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 <android-base/logging.h>
+#include <android/binder_manager.h>
+#include <android/binder_process.h>
+#include "HalProxyAidl.h"
+
+using ::aidl::android::hardware::sensors::implementation::HalProxyAidl;
+
+int main() {
+ ABinderProcess_setThreadPoolMaxThreadCount(0);
+
+ // Make a default multihal sensors service
+ auto halProxy = ndk::SharedRefBase::make<HalProxyAidl>();
+ const std::string halProxyName = std::string() + HalProxyAidl::descriptor + "/default";
+ binder_status_t status =
+ AServiceManager_addService(halProxy->asBinder().get(), halProxyName.c_str());
+ CHECK_EQ(status, STATUS_OK);
+
+ ABinderProcess_joinThreadPool();
+ return EXIT_FAILURE; // should not reach
+}
diff --git a/sensors/common/default/2.X/multihal/HalProxy.cpp b/sensors/common/default/2.X/multihal/HalProxy.cpp
index f5fc066..73b0594 100644
--- a/sensors/common/default/2.X/multihal/HalProxy.cpp
+++ b/sensors/common/default/2.X/multihal/HalProxy.cpp
@@ -176,7 +176,13 @@
std::unique_ptr<EventMessageQueueWrapperBase> queue =
std::make_unique<EventMessageQueueWrapperV2_1>(eventQueue);
- return initializeCommon(queue, wakeLockDescriptor, dynamicCallback);
+ // Create the Wake Lock FMQ from the wakeLockDescriptor. Reset the read/write positions.
+ auto hidlWakeLockQueue =
+ std::make_unique<WakeLockMessageQueue>(wakeLockDescriptor, true /* resetPointers */);
+ std::unique_ptr<WakeLockMessageQueueWrapperBase> wakeLockQueue =
+ std::make_unique<WakeLockMessageQueueWrapperHidl>(hidlWakeLockQueue);
+
+ return initializeCommon(queue, wakeLockQueue, dynamicCallback);
}
Return<Result> HalProxy::initialize(
@@ -192,12 +198,18 @@
std::unique_ptr<EventMessageQueueWrapperBase> queue =
std::make_unique<EventMessageQueueWrapperV1_0>(eventQueue);
- return initializeCommon(queue, wakeLockDescriptor, dynamicCallback);
+ // Create the Wake Lock FMQ from the wakeLockDescriptor. Reset the read/write positions.
+ auto hidlWakeLockQueue =
+ std::make_unique<WakeLockMessageQueue>(wakeLockDescriptor, true /* resetPointers */);
+ std::unique_ptr<WakeLockMessageQueueWrapperBase> wakeLockQueue =
+ std::make_unique<WakeLockMessageQueueWrapperHidl>(hidlWakeLockQueue);
+
+ return initializeCommon(queue, wakeLockQueue, dynamicCallback);
}
Return<Result> HalProxy::initializeCommon(
std::unique_ptr<EventMessageQueueWrapperBase>& eventQueue,
- const ::android::hardware::MQDescriptorSync<uint32_t>& wakeLockDescriptor,
+ std::unique_ptr<WakeLockMessageQueueWrapperBase>& wakeLockQueue,
const sp<ISensorsCallbackWrapperBase>& sensorsCallback) {
Result result = Result::OK;
@@ -222,8 +234,7 @@
// 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<WakeLockMessageQueue>(wakeLockDescriptor, true /* resetPointers */);
+ mWakeLockQueue = std::move(wakeLockQueue);
if (mEventQueueFlag != nullptr) {
EventFlag::deleteEventFlag(&mEventQueueFlag);
diff --git a/sensors/common/default/2.X/multihal/include/HalProxy.h b/sensors/common/default/2.X/multihal/include/HalProxy.h
index 35d7c8b..6174528 100644
--- a/sensors/common/default/2.X/multihal/include/HalProxy.h
+++ b/sensors/common/default/2.X/multihal/include/HalProxy.h
@@ -23,6 +23,7 @@
#include "V2_0/ScopedWakelock.h"
#include "V2_0/SubHal.h"
#include "V2_1/SubHal.h"
+#include "WakeLockMessageQueueWrapper.h"
#include "convertV2_1.h"
#include <android/hardware/sensors/2.1/ISensors.h>
@@ -98,10 +99,9 @@
const ::android::hardware::MQDescriptorSync<uint32_t>& wakeLockDescriptor,
const sp<V2_0::ISensorsCallback>& sensorsCallback);
- Return<Result> initializeCommon(
- std::unique_ptr<EventMessageQueueWrapperBase>& eventQueue,
- const ::android::hardware::MQDescriptorSync<uint32_t>& wakeLockDescriptor,
- const sp<ISensorsCallbackWrapperBase>& sensorsCallback);
+ Return<Result> initializeCommon(std::unique_ptr<EventMessageQueueWrapperBase>& eventQueue,
+ std::unique_ptr<WakeLockMessageQueueWrapperBase>& wakeLockQueue,
+ const sp<ISensorsCallbackWrapperBase>& sensorsCallback);
Return<Result> batch(int32_t sensorHandle, int64_t samplingPeriodNs,
int64_t maxReportLatencyNs);
@@ -141,6 +141,8 @@
void decrementRefCountAndMaybeReleaseWakelock(size_t delta, int64_t timeoutStart = -1) override;
+ const std::map<int32_t, SensorInfo>& getSensors() { return mSensors; }
+
private:
using EventMessageQueueV2_1 = MessageQueue<V2_1::Event, kSynchronizedReadWrite>;
using EventMessageQueueV2_0 = MessageQueue<V1_0::Event, kSynchronizedReadWrite>;
@@ -154,7 +156,7 @@
/**
* The Wake Lock FMQ that is read to determine when the framework has handled WAKE_UP events
*/
- std::unique_ptr<WakeLockMessageQueue> mWakeLockQueue;
+ std::unique_ptr<WakeLockMessageQueueWrapperBase> mWakeLockQueue;
/**
* Event Flag to signal to the framework when sensor events are available to be read and to
diff --git a/sensors/common/utils/WakeLockMessageQueueWrapper.h b/sensors/common/utils/WakeLockMessageQueueWrapper.h
new file mode 100644
index 0000000..3a219cf
--- /dev/null
+++ b/sensors/common/utils/WakeLockMessageQueueWrapper.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+#pragma once
+
+#include "convertV2_1.h"
+
+#include <android/hardware/sensors/2.1/types.h>
+#include <fmq/MessageQueue.h>
+#include <hidl/MQDescriptor.h>
+#include <hidl/Status.h>
+#include <log/log.h>
+
+#include <atomic>
+
+namespace android {
+namespace hardware {
+namespace sensors {
+namespace V2_1 {
+namespace implementation {
+
+class WakeLockMessageQueueWrapperBase {
+ public:
+ virtual ~WakeLockMessageQueueWrapperBase() {}
+
+ virtual std::atomic<uint32_t>* getEventFlagWord() = 0;
+ virtual bool readBlocking(uint32_t* events, size_t numToRead, uint32_t readNotification,
+ uint32_t writeNotification, int64_t timeOutNanos,
+ ::android::hardware::EventFlag* evFlag = nullptr) = 0;
+ virtual bool write(const uint32_t* wakeLock) = 0;
+};
+
+class WakeLockMessageQueueWrapperHidl : public WakeLockMessageQueueWrapperBase {
+ public:
+ WakeLockMessageQueueWrapperHidl(
+ std::unique_ptr<::android::hardware::MessageQueue<uint32_t, kSynchronizedReadWrite>>&
+ queue)
+ : mQueue(std::move(queue)) {}
+
+ std::atomic<uint32_t>* getEventFlagWord() override { return mQueue->getEventFlagWord(); }
+
+ bool readBlocking(uint32_t* wakeLocks, size_t numToRead, uint32_t readNotification,
+ uint32_t writeNotification, int64_t timeOutNanos,
+ ::android::hardware::EventFlag* evFlag) override {
+ return mQueue->readBlocking(wakeLocks, numToRead, readNotification, writeNotification,
+ timeOutNanos, evFlag);
+ }
+
+ bool write(const uint32_t* wakeLock) override { return mQueue->write(wakeLock); }
+
+ private:
+ std::unique_ptr<::android::hardware::MessageQueue<uint32_t, kSynchronizedReadWrite>> mQueue;
+};
+
+} // namespace implementation
+} // namespace V2_1
+} // namespace sensors
+} // namespace hardware
+} // namespace android