Adds sensors HAL AIDL interface
Bug: 195593357
Test: Compile
Change-Id: I6c63a6ba2dc3fbe5b25f401728d0724df2620bef
diff --git a/sensors/aidl/default/Android.bp b/sensors/aidl/default/Android.bp
new file mode 100644
index 0000000..487387d
--- /dev/null
+++ b/sensors/aidl/default/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_library_static {
+ name: "libsensorsexampleimpl",
+ vendor: true,
+ shared_libs: [
+ "libbase",
+ "libbinder_ndk",
+ "android.hardware.sensors-V1-ndk",
+ ],
+ export_include_dirs: ["include"],
+ srcs: [
+ "Sensors.cpp",
+ ],
+ visibility: [
+ ":__subpackages__",
+ "//hardware/interfaces/tests/extension/sensors:__subpackages__",
+ ],
+}
+
+cc_binary {
+ name: "android.hardware.sensors-service.example",
+ relative_install_path: "hw",
+ init_rc: ["sensors-default.rc"],
+ vintf_fragments: ["sensors-default.xml"],
+ vendor: true,
+ shared_libs: [
+ "libbase",
+ "libbinder_ndk",
+ "android.hardware.sensors-V1-ndk",
+ ],
+ static_libs: [
+ "libsensorsexampleimpl",
+ ],
+ srcs: ["main.cpp"],
+}
diff --git a/sensors/aidl/default/Sensors.cpp b/sensors/aidl/default/Sensors.cpp
new file mode 100644
index 0000000..14bbbbf
--- /dev/null
+++ b/sensors/aidl/default/Sensors.cpp
@@ -0,0 +1,84 @@
+/*
+ * 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 "sensors-impl/Sensors.h"
+
+using ::aidl::android::hardware::common::fmq::MQDescriptor;
+using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite;
+using ::aidl::android::hardware::sensors::Event;
+using ::aidl::android::hardware::sensors::ISensors;
+using ::aidl::android::hardware::sensors::ISensorsCallback;
+using ::aidl::android::hardware::sensors::SensorInfo;
+
+namespace aidl {
+namespace android {
+namespace hardware {
+namespace sensors {
+
+// TODO(b/195593357): Implement AIDL HAL
+::ndk::ScopedAStatus Sensors::activate(int32_t /* in_sensorHandle */, bool /* in_enabled */) {
+ return ndk::ScopedAStatus::ok();
+}
+
+::ndk::ScopedAStatus Sensors::batch(int32_t /* in_sensorHandle */,
+ int64_t /* in_samplingPeriodNs */,
+ int64_t /* in_maxReportLatencyNs */) {
+ return ndk::ScopedAStatus::ok();
+}
+
+::ndk::ScopedAStatus Sensors::configDirectReport(int32_t /* in_sensorHandle */,
+ int32_t /* in_channelHandle */,
+ ISensors::RateLevel /* in_rate */,
+ int32_t* /* _aidl_return */) {
+ return ndk::ScopedAStatus::ok();
+}
+
+::ndk::ScopedAStatus Sensors::flush(int32_t /* in_sensorHandle */) {
+ return ndk::ScopedAStatus::ok();
+}
+
+::ndk::ScopedAStatus Sensors::getSensorsList(std::vector<SensorInfo>* /* _aidl_return */) {
+ return ndk::ScopedAStatus::ok();
+}
+
+::ndk::ScopedAStatus Sensors::initialize(
+ const MQDescriptor<Event, SynchronizedReadWrite>& /* in_eventQueueDescriptor */,
+ const MQDescriptor<int32_t, SynchronizedReadWrite>& /* in_wakeLockDescriptor */,
+ const std::shared_ptr<ISensorsCallback>& /* in_sensorsCallback */) {
+ return ndk::ScopedAStatus::ok();
+}
+
+::ndk::ScopedAStatus Sensors::injectSensorData(const Event& /* in_event */) {
+ return ndk::ScopedAStatus::ok();
+}
+
+::ndk::ScopedAStatus Sensors::registerDirectChannel(const ISensors::SharedMemInfo& /* in_mem */,
+ int32_t* /* _aidl_return */) {
+ return ndk::ScopedAStatus::ok();
+}
+
+::ndk::ScopedAStatus Sensors::setOperationMode(OperationMode /* in_mode */) {
+ return ndk::ScopedAStatus::ok();
+}
+
+::ndk::ScopedAStatus Sensors::unregisterDirectChannel(int32_t /* in_channelHandle */) {
+ return ndk::ScopedAStatus::ok();
+}
+
+} // namespace sensors
+} // namespace hardware
+} // namespace android
+} // namespace aidl
diff --git a/sensors/aidl/default/include/sensors-impl/Sensors.h b/sensors/aidl/default/include/sensors-impl/Sensors.h
new file mode 100644
index 0000000..b6be4a5
--- /dev/null
+++ b/sensors/aidl/default/include/sensors-impl/Sensors.h
@@ -0,0 +1,60 @@
+/*
+ * 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>
+
+namespace aidl {
+namespace android {
+namespace hardware {
+namespace sensors {
+
+class Sensors : public 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 sensors
+} // namespace hardware
+} // namespace android
+} // namespace aidl
diff --git a/sensors/aidl/default/main.cpp b/sensors/aidl/default/main.cpp
new file mode 100644
index 0000000..8a5a7de
--- /dev/null
+++ b/sensors/aidl/default/main.cpp
@@ -0,0 +1,37 @@
+/*
+ * 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 "sensors-impl/Sensors.h"
+
+#include <android-base/logging.h>
+#include <android/binder_manager.h>
+#include <android/binder_process.h>
+
+using aidl::android::hardware::sensors::Sensors;
+
+int main() {
+ ABinderProcess_setThreadPoolMaxThreadCount(0);
+
+ // Make a default sensors service
+ auto sensor = ndk::SharedRefBase::make<Sensors>();
+ const std::string sensorName = std::string() + Sensors::descriptor + "/default";
+ binder_status_t status =
+ AServiceManager_addService(sensor->asBinder().get(), sensorName.c_str());
+ CHECK_EQ(status, STATUS_OK);
+
+ ABinderProcess_joinThreadPool();
+ return EXIT_FAILURE; // should not reach
+}
diff --git a/sensors/aidl/default/sensors-default.rc b/sensors/aidl/default/sensors-default.rc
new file mode 100644
index 0000000..96da85d
--- /dev/null
+++ b/sensors/aidl/default/sensors-default.rc
@@ -0,0 +1,5 @@
+service vendor.sensors-default /vendor/bin/hw/android.hardware.sensors-service.example
+ class hal
+ user system
+ group system
+ rlimit rtprio 10 10
diff --git a/sensors/aidl/default/sensors-default.xml b/sensors/aidl/default/sensors-default.xml
new file mode 100644
index 0000000..7898a6b
--- /dev/null
+++ b/sensors/aidl/default/sensors-default.xml
@@ -0,0 +1,7 @@
+<manifest version="1.0" type="device">
+ <hal format="aidl">
+ <name>android.hardware.sensors</name>
+ <version>1</version>
+ <fqname>ISensors/default</fqname>
+ </hal>
+</manifest>