Updated multihal to use new sensors AIDL interface.
Test: make android.hardware.sensors@aidl-multihal
Fix: 206867060
Change-Id: I9b78a0f25117d11fdf4beb1e0913393c1c14620d
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