mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 11:36:00 +00:00
Merge changes from topic "multihal_2_1" into rvc-dev am: 89b216690c am: f3660d09f7
Change-Id: I596bcbc3ac680251e031297fd504785e21a98278
This commit is contained in:
@@ -25,6 +25,9 @@ cc_binary {
|
|||||||
],
|
],
|
||||||
init_rc: ["android.hardware.sensors@2.0-service-multihal.rc"],
|
init_rc: ["android.hardware.sensors@2.0-service-multihal.rc"],
|
||||||
vintf_fragments: ["android.hardware.sensors@2.0-multihal.xml"],
|
vintf_fragments: ["android.hardware.sensors@2.0-multihal.xml"],
|
||||||
|
header_libs: [
|
||||||
|
"android.hardware.sensors@2.X-shared-utils",
|
||||||
|
],
|
||||||
shared_libs: [
|
shared_libs: [
|
||||||
"android.hardware.sensors@2.0",
|
"android.hardware.sensors@2.0",
|
||||||
"android.hardware.sensors@2.0-ScopedWakelock",
|
"android.hardware.sensors@2.0-ScopedWakelock",
|
||||||
@@ -37,5 +40,8 @@ cc_binary {
|
|||||||
"libpower",
|
"libpower",
|
||||||
"libutils",
|
"libutils",
|
||||||
],
|
],
|
||||||
static_libs: ["android.hardware.sensors@2.X-multihal"],
|
static_libs: [
|
||||||
|
"android.hardware.sensors@1.0-convert",
|
||||||
|
"android.hardware.sensors@2.X-multihal",
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,12 +23,12 @@
|
|||||||
using android::hardware::configureRpcThreadpool;
|
using android::hardware::configureRpcThreadpool;
|
||||||
using android::hardware::joinRpcThreadpool;
|
using android::hardware::joinRpcThreadpool;
|
||||||
using android::hardware::sensors::V2_0::ISensors;
|
using android::hardware::sensors::V2_0::ISensors;
|
||||||
using android::hardware::sensors::V2_0::implementation::HalProxy;
|
using android::hardware::sensors::V2_1::implementation::HalProxyV2_0;
|
||||||
|
|
||||||
int main(int /* argc */, char** /* argv */) {
|
int main(int /* argc */, char** /* argv */) {
|
||||||
configureRpcThreadpool(1, true);
|
configureRpcThreadpool(1, true);
|
||||||
|
|
||||||
android::sp<ISensors> halProxy = new HalProxy();
|
android::sp<ISensors> halProxy = new HalProxyV2_0();
|
||||||
if (halProxy->registerAsService() != ::android::OK) {
|
if (halProxy->registerAsService() != ::android::OK) {
|
||||||
ALOGE("Failed to register Sensors HAL instance");
|
ALOGE("Failed to register Sensors HAL instance");
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
47
sensors/2.1/multihal/Android.bp
Normal file
47
sensors/2.1/multihal/Android.bp
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
//
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
cc_binary {
|
||||||
|
name: "android.hardware.sensors@2.1-service.multihal",
|
||||||
|
defaults: [
|
||||||
|
"hidl_defaults",
|
||||||
|
],
|
||||||
|
vendor: true,
|
||||||
|
relative_install_path: "hw",
|
||||||
|
srcs: [
|
||||||
|
"service.cpp",
|
||||||
|
],
|
||||||
|
init_rc: ["android.hardware.sensors@2.1-service-multihal.rc"],
|
||||||
|
vintf_fragments: ["android.hardware.sensors@2.1-multihal.xml"],
|
||||||
|
header_libs: [
|
||||||
|
"android.hardware.sensors@2.X-shared-utils",
|
||||||
|
],
|
||||||
|
shared_libs: [
|
||||||
|
"android.hardware.sensors@2.0",
|
||||||
|
"android.hardware.sensors@2.0-ScopedWakelock",
|
||||||
|
"android.hardware.sensors@2.1",
|
||||||
|
"libbase",
|
||||||
|
"libcutils",
|
||||||
|
"libfmq",
|
||||||
|
"libhidlbase",
|
||||||
|
"liblog",
|
||||||
|
"libpower",
|
||||||
|
"libutils",
|
||||||
|
],
|
||||||
|
static_libs: [
|
||||||
|
"android.hardware.sensors@1.0-convert",
|
||||||
|
"android.hardware.sensors@2.X-multihal",
|
||||||
|
],
|
||||||
|
}
|
||||||
3
sensors/2.1/multihal/OWNERS
Normal file
3
sensors/2.1/multihal/OWNERS
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
arthuri@google.com
|
||||||
|
bduddie@google.com
|
||||||
|
stange@google.com
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<manifest version="1.0" type="device">
|
||||||
|
<hal format="hidl">
|
||||||
|
<name>android.hardware.sensors</name>
|
||||||
|
<transport>hwbinder</transport>
|
||||||
|
<version>2.1</version>
|
||||||
|
<interface>
|
||||||
|
<name>ISensors</name>
|
||||||
|
<instance>default</instance>
|
||||||
|
</interface>
|
||||||
|
</hal>
|
||||||
|
</manifest>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
service vendor.sensors-hal-2-1-multihal /vendor/bin/hw/android.hardware.sensors@2.1-service.multihal
|
||||||
|
class hal
|
||||||
|
user system
|
||||||
|
group system wakelock context_hub
|
||||||
|
writepid /dev/cpuset/system-background/tasks
|
||||||
|
capabilities BLOCK_SUSPEND
|
||||||
|
rlimit rtprio 10 10
|
||||||
39
sensors/2.1/multihal/service.cpp
Normal file
39
sensors/2.1/multihal/service.cpp
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <android/hardware/sensors/2.1/ISensors.h>
|
||||||
|
#include <hidl/HidlTransportSupport.h>
|
||||||
|
#include <log/log.h>
|
||||||
|
#include <utils/StrongPointer.h>
|
||||||
|
#include "HalProxy.h"
|
||||||
|
|
||||||
|
using android::hardware::configureRpcThreadpool;
|
||||||
|
using android::hardware::joinRpcThreadpool;
|
||||||
|
using android::hardware::sensors::V2_1::ISensors;
|
||||||
|
using android::hardware::sensors::V2_1::implementation::HalProxyV2_1;
|
||||||
|
|
||||||
|
int main(int /* argc */, char** /* argv */) {
|
||||||
|
configureRpcThreadpool(1, true);
|
||||||
|
|
||||||
|
android::sp<ISensors> halProxy = new HalProxyV2_1();
|
||||||
|
if (halProxy->registerAsService() != ::android::OK) {
|
||||||
|
ALOGE("Failed to register Sensors HAL instance");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
joinRpcThreadpool();
|
||||||
|
return 1; // joinRpcThreadpool shouldn't exit
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ cc_defaults {
|
|||||||
name: "android.hardware.sensors@2.X-multihal-defaults",
|
name: "android.hardware.sensors@2.X-multihal-defaults",
|
||||||
header_libs: [
|
header_libs: [
|
||||||
"android.hardware.sensors@2.X-multihal.header",
|
"android.hardware.sensors@2.X-multihal.header",
|
||||||
|
"android.hardware.sensors@2.X-shared-utils",
|
||||||
],
|
],
|
||||||
shared_libs: [
|
shared_libs: [
|
||||||
"android.hardware.sensors@1.0",
|
"android.hardware.sensors@1.0",
|
||||||
@@ -30,6 +31,9 @@ cc_defaults {
|
|||||||
"libpower",
|
"libpower",
|
||||||
"libutils",
|
"libutils",
|
||||||
],
|
],
|
||||||
|
static_libs: [
|
||||||
|
"android.hardware.sensors@1.0-convert",
|
||||||
|
],
|
||||||
cflags: ["-DLOG_TAG=\"SensorsMultiHal\""],
|
cflags: ["-DLOG_TAG=\"SensorsMultiHal\""],
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,6 +66,7 @@ cc_library_static {
|
|||||||
],
|
],
|
||||||
srcs: [
|
srcs: [
|
||||||
"HalProxy.cpp",
|
"HalProxy.cpp",
|
||||||
|
"HalProxyCallback.cpp",
|
||||||
],
|
],
|
||||||
vendor_available: true,
|
vendor_available: true,
|
||||||
export_header_lib_headers: [
|
export_header_lib_headers: [
|
||||||
|
|||||||
@@ -32,15 +32,17 @@
|
|||||||
namespace android {
|
namespace android {
|
||||||
namespace hardware {
|
namespace hardware {
|
||||||
namespace sensors {
|
namespace sensors {
|
||||||
namespace V2_0 {
|
namespace V2_1 {
|
||||||
namespace implementation {
|
namespace implementation {
|
||||||
|
|
||||||
|
using ::android::hardware::sensors::V1_0::Result;
|
||||||
using ::android::hardware::sensors::V2_0::EventQueueFlagBits;
|
using ::android::hardware::sensors::V2_0::EventQueueFlagBits;
|
||||||
using ::android::hardware::sensors::V2_0::WakeLockQueueFlagBits;
|
using ::android::hardware::sensors::V2_0::WakeLockQueueFlagBits;
|
||||||
using ::android::hardware::sensors::V2_0::implementation::getTimeNow;
|
using ::android::hardware::sensors::V2_0::implementation::getTimeNow;
|
||||||
using ::android::hardware::sensors::V2_0::implementation::kWakelockTimeoutNs;
|
using ::android::hardware::sensors::V2_0::implementation::kWakelockTimeoutNs;
|
||||||
|
|
||||||
typedef ISensorsSubHal*(SensorsHalGetSubHalFunc)(uint32_t*);
|
typedef V2_0::implementation::ISensorsSubHal*(SensorsHalGetSubHalFunc)(uint32_t*);
|
||||||
|
typedef V2_1::implementation::ISensorsSubHal*(SensorsHalGetSubHalV2_1Func)(uint32_t*);
|
||||||
|
|
||||||
static constexpr int32_t kBitsAfterSubHalIndex = 24;
|
static constexpr int32_t kBitsAfterSubHalIndex = 24;
|
||||||
|
|
||||||
@@ -85,7 +87,24 @@ HalProxy::HalProxy() {
|
|||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
HalProxy::HalProxy(std::vector<ISensorsSubHal*>& subHalList) : mSubHalList(subHalList) {
|
HalProxy::HalProxy(std::vector<ISensorsSubHalV2_0*>& subHalList) {
|
||||||
|
for (ISensorsSubHalV2_0* subHal : subHalList) {
|
||||||
|
mSubHalList.push_back(std::make_unique<SubHalWrapperV2_0>(subHal));
|
||||||
|
}
|
||||||
|
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
HalProxy::HalProxy(std::vector<ISensorsSubHalV2_0*>& subHalList,
|
||||||
|
std::vector<ISensorsSubHalV2_1*>& subHalListV2_1) {
|
||||||
|
for (ISensorsSubHalV2_0* subHal : subHalList) {
|
||||||
|
mSubHalList.push_back(std::make_unique<SubHalWrapperV2_0>(subHal));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ISensorsSubHalV2_1* subHal : subHalListV2_1) {
|
||||||
|
mSubHalList.push_back(std::make_unique<SubHalWrapperV2_1>(subHal));
|
||||||
|
}
|
||||||
|
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,8 +112,8 @@ HalProxy::~HalProxy() {
|
|||||||
stopThreads();
|
stopThreads();
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<void> HalProxy::getSensorsList(getSensorsList_cb _hidl_cb) {
|
Return<void> HalProxy::getSensorsList_2_1(ISensorsV2_1::getSensorsList_2_1_cb _hidl_cb) {
|
||||||
std::vector<SensorInfo> sensors;
|
std::vector<V2_1::SensorInfo> sensors;
|
||||||
for (const auto& iter : mSensors) {
|
for (const auto& iter : mSensors) {
|
||||||
sensors.push_back(iter.second);
|
sensors.push_back(iter.second);
|
||||||
}
|
}
|
||||||
@@ -102,22 +121,31 @@ Return<void> HalProxy::getSensorsList(getSensorsList_cb _hidl_cb) {
|
|||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Return<void> HalProxy::getSensorsList(ISensorsV2_0::getSensorsList_cb _hidl_cb) {
|
||||||
|
std::vector<V1_0::SensorInfo> sensors;
|
||||||
|
for (const auto& iter : mSensors) {
|
||||||
|
sensors.push_back(convertToOldSensorInfo(iter.second));
|
||||||
|
}
|
||||||
|
_hidl_cb(sensors);
|
||||||
|
return Void();
|
||||||
|
}
|
||||||
|
|
||||||
Return<Result> HalProxy::setOperationMode(OperationMode mode) {
|
Return<Result> HalProxy::setOperationMode(OperationMode mode) {
|
||||||
Result result = Result::OK;
|
Result result = Result::OK;
|
||||||
size_t subHalIndex;
|
size_t subHalIndex;
|
||||||
for (subHalIndex = 0; subHalIndex < mSubHalList.size(); subHalIndex++) {
|
for (subHalIndex = 0; subHalIndex < mSubHalList.size(); subHalIndex++) {
|
||||||
ISensorsSubHal* subHal = mSubHalList[subHalIndex];
|
result = mSubHalList[subHalIndex]->setOperationMode(mode);
|
||||||
result = subHal->setOperationMode(mode);
|
|
||||||
if (result != Result::OK) {
|
if (result != Result::OK) {
|
||||||
ALOGE("setOperationMode failed for SubHal: %s", subHal->getName().c_str());
|
ALOGE("setOperationMode failed for SubHal: %s",
|
||||||
|
mSubHalList[subHalIndex]->getName().c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result != Result::OK) {
|
if (result != Result::OK) {
|
||||||
// Reset the subhal operation modes that have been flipped
|
// Reset the subhal operation modes that have been flipped
|
||||||
for (size_t i = 0; i < subHalIndex; i++) {
|
for (size_t i = 0; i < subHalIndex; i++) {
|
||||||
ISensorsSubHal* subHal = mSubHalList[i];
|
mSubHalList[i]->setOperationMode(mCurrentOperationMode);
|
||||||
subHal->setOperationMode(mCurrentOperationMode);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mCurrentOperationMode = mode;
|
mCurrentOperationMode = mode;
|
||||||
@@ -133,10 +161,42 @@ Return<Result> HalProxy::activate(int32_t sensorHandle, bool enabled) {
|
|||||||
->activate(clearSubHalIndex(sensorHandle), enabled);
|
->activate(clearSubHalIndex(sensorHandle), enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<Result> HalProxy::initialize(
|
Return<Result> HalProxy::initialize_2_1(
|
||||||
const ::android::hardware::MQDescriptorSync<Event>& eventQueueDescriptor,
|
const ::android::hardware::MQDescriptorSync<V2_1::Event>& eventQueueDescriptor,
|
||||||
const ::android::hardware::MQDescriptorSync<uint32_t>& wakeLockDescriptor,
|
const ::android::hardware::MQDescriptorSync<uint32_t>& wakeLockDescriptor,
|
||||||
const sp<ISensorsCallback>& sensorsCallback) {
|
const sp<V2_1::ISensorsCallback>& sensorsCallback) {
|
||||||
|
sp<ISensorsCallbackWrapperBase> dynamicCallback =
|
||||||
|
new ISensorsCallbackWrapperV2_1(sensorsCallback);
|
||||||
|
|
||||||
|
// Create the Event FMQ from the eventQueueDescriptor. Reset the read/write positions.
|
||||||
|
auto eventQueue =
|
||||||
|
std::make_unique<EventMessageQueueV2_1>(eventQueueDescriptor, true /* resetPointers */);
|
||||||
|
std::unique_ptr<EventMessageQueueWrapperBase> queue =
|
||||||
|
std::make_unique<EventMessageQueueWrapperV2_1>(eventQueue);
|
||||||
|
|
||||||
|
return initializeCommon(queue, wakeLockDescriptor, dynamicCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<Result> HalProxy::initialize(
|
||||||
|
const ::android::hardware::MQDescriptorSync<V1_0::Event>& eventQueueDescriptor,
|
||||||
|
const ::android::hardware::MQDescriptorSync<uint32_t>& wakeLockDescriptor,
|
||||||
|
const sp<V2_0::ISensorsCallback>& sensorsCallback) {
|
||||||
|
sp<ISensorsCallbackWrapperBase> dynamicCallback =
|
||||||
|
new ISensorsCallbackWrapperV2_0(sensorsCallback);
|
||||||
|
|
||||||
|
// Create the Event FMQ from the eventQueueDescriptor. Reset the read/write positions.
|
||||||
|
auto eventQueue =
|
||||||
|
std::make_unique<EventMessageQueueV2_0>(eventQueueDescriptor, true /* resetPointers */);
|
||||||
|
std::unique_ptr<EventMessageQueueWrapperBase> queue =
|
||||||
|
std::make_unique<EventMessageQueueWrapperV1_0>(eventQueue);
|
||||||
|
|
||||||
|
return initializeCommon(queue, wakeLockDescriptor, dynamicCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<Result> HalProxy::initializeCommon(
|
||||||
|
std::unique_ptr<EventMessageQueueWrapperBase>& eventQueue,
|
||||||
|
const ::android::hardware::MQDescriptorSync<uint32_t>& wakeLockDescriptor,
|
||||||
|
const sp<ISensorsCallbackWrapperBase>& sensorsCallback) {
|
||||||
Result result = Result::OK;
|
Result result = Result::OK;
|
||||||
|
|
||||||
stopThreads();
|
stopThreads();
|
||||||
@@ -147,7 +207,7 @@ Return<Result> HalProxy::initialize(
|
|||||||
disableAllSensors();
|
disableAllSensors();
|
||||||
|
|
||||||
// Clears the queue if any events were pending write before.
|
// Clears the queue if any events were pending write before.
|
||||||
mPendingWriteEventsQueue = std::queue<std::pair<std::vector<Event>, size_t>>();
|
mPendingWriteEventsQueue = std::queue<std::pair<std::vector<V2_1::Event>, size_t>>();
|
||||||
mSizePendingWriteEventsQueue = 0;
|
mSizePendingWriteEventsQueue = 0;
|
||||||
|
|
||||||
// Clears previously connected dynamic sensors
|
// Clears previously connected dynamic sensors
|
||||||
@@ -156,8 +216,7 @@ Return<Result> HalProxy::initialize(
|
|||||||
mDynamicSensorsCallback = sensorsCallback;
|
mDynamicSensorsCallback = sensorsCallback;
|
||||||
|
|
||||||
// Create the Event FMQ from the eventQueueDescriptor. Reset the read/write positions.
|
// Create the Event FMQ from the eventQueueDescriptor. Reset the read/write positions.
|
||||||
mEventQueue =
|
mEventQueue = std::move(eventQueue);
|
||||||
std::make_unique<EventMessageQueue>(eventQueueDescriptor, true /* resetPointers */);
|
|
||||||
|
|
||||||
// Create the Wake Lock FMQ that is used by the framework to communicate whenever WAKE_UP
|
// 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.
|
// events have been successfully read and handled by the framework.
|
||||||
@@ -186,12 +245,10 @@ Return<Result> HalProxy::initialize(
|
|||||||
mWakelockThread = std::thread(startWakelockThread, this);
|
mWakelockThread = std::thread(startWakelockThread, this);
|
||||||
|
|
||||||
for (size_t i = 0; i < mSubHalList.size(); i++) {
|
for (size_t i = 0; i < mSubHalList.size(); i++) {
|
||||||
auto subHal = mSubHalList[i];
|
Result currRes = mSubHalList[i]->initialize(this, this, i);
|
||||||
const auto& subHalCallback = mSubHalCallbacks[i];
|
|
||||||
Result currRes = subHal->initialize(subHalCallback);
|
|
||||||
if (currRes != Result::OK) {
|
if (currRes != Result::OK) {
|
||||||
result = currRes;
|
result = currRes;
|
||||||
ALOGE("Subhal '%s' failed to initialize.", subHal->getName().c_str());
|
ALOGE("Subhal '%s' failed to initialize.", mSubHalList[i]->getName().c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -217,7 +274,11 @@ Return<Result> HalProxy::flush(int32_t sensorHandle) {
|
|||||||
return getSubHalForSensorHandle(sensorHandle)->flush(clearSubHalIndex(sensorHandle));
|
return getSubHalForSensorHandle(sensorHandle)->flush(clearSubHalIndex(sensorHandle));
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<Result> HalProxy::injectSensorData(const Event& event) {
|
Return<Result> HalProxy::injectSensorData_2_1(const V2_1::Event& event) {
|
||||||
|
return injectSensorData(convertToOldEvent(event));
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<Result> HalProxy::injectSensorData(const V1_0::Event& event) {
|
||||||
Result result = Result::OK;
|
Result result = Result::OK;
|
||||||
if (mCurrentOperationMode == OperationMode::NORMAL &&
|
if (mCurrentOperationMode == OperationMode::NORMAL &&
|
||||||
event.sensorType != V1_0::SensorType::ADDITIONAL_INFO) {
|
event.sensorType != V1_0::SensorType::ADDITIONAL_INFO) {
|
||||||
@@ -226,18 +287,19 @@ Return<Result> HalProxy::injectSensorData(const Event& event) {
|
|||||||
result = Result::BAD_VALUE;
|
result = Result::BAD_VALUE;
|
||||||
}
|
}
|
||||||
if (result == Result::OK) {
|
if (result == Result::OK) {
|
||||||
Event subHalEvent = event;
|
V1_0::Event subHalEvent = event;
|
||||||
if (!isSubHalIndexValid(event.sensorHandle)) {
|
if (!isSubHalIndexValid(event.sensorHandle)) {
|
||||||
return Result::BAD_VALUE;
|
return Result::BAD_VALUE;
|
||||||
}
|
}
|
||||||
subHalEvent.sensorHandle = clearSubHalIndex(event.sensorHandle);
|
subHalEvent.sensorHandle = clearSubHalIndex(event.sensorHandle);
|
||||||
result = getSubHalForSensorHandle(event.sensorHandle)->injectSensorData(subHalEvent);
|
result = getSubHalForSensorHandle(event.sensorHandle)
|
||||||
|
->injectSensorData(convertToNewEvent(subHalEvent));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<void> HalProxy::registerDirectChannel(const SharedMemInfo& mem,
|
Return<void> HalProxy::registerDirectChannel(const SharedMemInfo& mem,
|
||||||
registerDirectChannel_cb _hidl_cb) {
|
ISensorsV2_0::registerDirectChannel_cb _hidl_cb) {
|
||||||
if (mDirectChannelSubHal == nullptr) {
|
if (mDirectChannelSubHal == nullptr) {
|
||||||
_hidl_cb(Result::INVALID_OPERATION, -1 /* channelHandle */);
|
_hidl_cb(Result::INVALID_OPERATION, -1 /* channelHandle */);
|
||||||
} else {
|
} else {
|
||||||
@@ -257,7 +319,8 @@ Return<Result> HalProxy::unregisterDirectChannel(int32_t channelHandle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Return<void> HalProxy::configDirectReport(int32_t sensorHandle, int32_t channelHandle,
|
Return<void> HalProxy::configDirectReport(int32_t sensorHandle, int32_t channelHandle,
|
||||||
RateLevel rate, configDirectReport_cb _hidl_cb) {
|
RateLevel rate,
|
||||||
|
ISensorsV2_0::configDirectReport_cb _hidl_cb) {
|
||||||
if (mDirectChannelSubHal == nullptr) {
|
if (mDirectChannelSubHal == nullptr) {
|
||||||
_hidl_cb(Result::INVALID_OPERATION, -1 /* reportToken */);
|
_hidl_cb(Result::INVALID_OPERATION, -1 /* reportToken */);
|
||||||
} else if (sensorHandle == -1 && rate != RateLevel::STOP) {
|
} else if (sensorHandle == -1 && rate != RateLevel::STOP) {
|
||||||
@@ -302,7 +365,7 @@ Return<void> HalProxy::debug(const hidl_handle& fd, const hidl_vec<hidl_string>&
|
|||||||
stream << " # of non-dynamic sensors across all subhals: " << mSensors.size() << std::endl;
|
stream << " # of non-dynamic sensors across all subhals: " << mSensors.size() << std::endl;
|
||||||
stream << " # of dynamic sensors across all subhals: " << mDynamicSensors.size() << std::endl;
|
stream << " # of dynamic sensors across all subhals: " << mDynamicSensors.size() << std::endl;
|
||||||
stream << "SubHals (" << mSubHalList.size() << "):" << std::endl;
|
stream << "SubHals (" << mSubHalList.size() << "):" << std::endl;
|
||||||
for (ISensorsSubHal* subHal : mSubHalList) {
|
for (auto& subHal : mSubHalList) {
|
||||||
stream << " Name: " << subHal->getName() << std::endl;
|
stream << " Name: " << subHal->getName() << std::endl;
|
||||||
stream << " Debug dump: " << std::endl;
|
stream << " Debug dump: " << std::endl;
|
||||||
android::base::WriteStringToFd(stream.str(), writeFd);
|
android::base::WriteStringToFd(stream.str(), writeFd);
|
||||||
@@ -369,20 +432,37 @@ void HalProxy::initializeSubHalListFromConfigFile(const char* configFileName) {
|
|||||||
} else {
|
} else {
|
||||||
SensorsHalGetSubHalFunc* sensorsHalGetSubHalPtr =
|
SensorsHalGetSubHalFunc* sensorsHalGetSubHalPtr =
|
||||||
(SensorsHalGetSubHalFunc*)dlsym(handle, "sensorsHalGetSubHal");
|
(SensorsHalGetSubHalFunc*)dlsym(handle, "sensorsHalGetSubHal");
|
||||||
if (sensorsHalGetSubHalPtr == nullptr) {
|
if (sensorsHalGetSubHalPtr != nullptr) {
|
||||||
ALOGE("Failed to locate sensorsHalGetSubHal function for library: %s",
|
|
||||||
subHalLibraryFile.c_str());
|
|
||||||
} else {
|
|
||||||
std::function<SensorsHalGetSubHalFunc> sensorsHalGetSubHal =
|
std::function<SensorsHalGetSubHalFunc> sensorsHalGetSubHal =
|
||||||
*sensorsHalGetSubHalPtr;
|
*sensorsHalGetSubHalPtr;
|
||||||
uint32_t version;
|
uint32_t version;
|
||||||
ISensorsSubHal* subHal = sensorsHalGetSubHal(&version);
|
ISensorsSubHalV2_0* subHal = sensorsHalGetSubHal(&version);
|
||||||
if (version != SUB_HAL_2_0_VERSION) {
|
if (version != SUB_HAL_2_0_VERSION) {
|
||||||
ALOGE("SubHal version was not 2.0 for library: %s",
|
ALOGE("SubHal version was not 2.0 for library: %s",
|
||||||
subHalLibraryFile.c_str());
|
subHalLibraryFile.c_str());
|
||||||
} else {
|
} else {
|
||||||
ALOGV("Loaded SubHal from library: %s", subHalLibraryFile.c_str());
|
ALOGV("Loaded SubHal from library: %s", subHalLibraryFile.c_str());
|
||||||
mSubHalList.push_back(subHal);
|
mSubHalList.push_back(std::make_unique<SubHalWrapperV2_0>(subHal));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
SensorsHalGetSubHalV2_1Func* getSubHalV2_1Ptr =
|
||||||
|
(SensorsHalGetSubHalV2_1Func*)dlsym(handle, "sensorsHalGetSubHal_2_1");
|
||||||
|
|
||||||
|
if (getSubHalV2_1Ptr == nullptr) {
|
||||||
|
ALOGE("Failed to locate sensorsHalGetSubHal function for library: %s",
|
||||||
|
subHalLibraryFile.c_str());
|
||||||
|
} else {
|
||||||
|
std::function<SensorsHalGetSubHalV2_1Func> sensorsHalGetSubHal_2_1 =
|
||||||
|
*getSubHalV2_1Ptr;
|
||||||
|
uint32_t version;
|
||||||
|
ISensorsSubHalV2_1* subHal = sensorsHalGetSubHal_2_1(&version);
|
||||||
|
if (version != SUB_HAL_2_1_VERSION) {
|
||||||
|
ALOGE("SubHal version was not 2.1 for library: %s",
|
||||||
|
subHalLibraryFile.c_str());
|
||||||
|
} else {
|
||||||
|
ALOGV("Loaded SubHal from library: %s", subHalLibraryFile.c_str());
|
||||||
|
mSubHalList.push_back(std::make_unique<SubHalWrapperV2_1>(subHal));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -390,36 +470,28 @@ void HalProxy::initializeSubHalListFromConfigFile(const char* configFileName) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HalProxy::initializeSubHalCallbacks() {
|
|
||||||
for (size_t subHalIndex = 0; subHalIndex < mSubHalList.size(); subHalIndex++) {
|
|
||||||
sp<IHalProxyCallback> callback = new HalProxyCallback(this, subHalIndex);
|
|
||||||
mSubHalCallbacks.push_back(callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void HalProxy::initializeSensorList() {
|
void HalProxy::initializeSensorList() {
|
||||||
for (size_t subHalIndex = 0; subHalIndex < mSubHalList.size(); subHalIndex++) {
|
for (size_t subHalIndex = 0; subHalIndex < mSubHalList.size(); subHalIndex++) {
|
||||||
ISensorsSubHal* subHal = mSubHalList[subHalIndex];
|
auto result = mSubHalList[subHalIndex]->getSensorsList([&](const auto& list) {
|
||||||
auto result = subHal->getSensorsList([&](const auto& list) {
|
|
||||||
for (SensorInfo sensor : list) {
|
for (SensorInfo sensor : list) {
|
||||||
if (!subHalIndexIsClear(sensor.sensorHandle)) {
|
if (!subHalIndexIsClear(sensor.sensorHandle)) {
|
||||||
ALOGE("SubHal sensorHandle's first byte was not 0");
|
ALOGE("SubHal sensorHandle's first byte was not 0");
|
||||||
} else {
|
} else {
|
||||||
ALOGV("Loaded sensor: %s", sensor.name.c_str());
|
ALOGV("Loaded sensor: %s", sensor.name.c_str());
|
||||||
sensor.sensorHandle = setSubHalIndex(sensor.sensorHandle, subHalIndex);
|
sensor.sensorHandle = setSubHalIndex(sensor.sensorHandle, subHalIndex);
|
||||||
setDirectChannelFlags(&sensor, subHal);
|
setDirectChannelFlags(&sensor, mSubHalList[subHalIndex]);
|
||||||
mSensors[sensor.sensorHandle] = sensor;
|
mSensors[sensor.sensorHandle] = sensor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!result.isOk()) {
|
if (!result.isOk()) {
|
||||||
ALOGE("getSensorsList call failed for SubHal: %s", subHal->getName().c_str());
|
ALOGE("getSensorsList call failed for SubHal: %s",
|
||||||
|
mSubHalList[subHalIndex]->getName().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HalProxy::init() {
|
void HalProxy::init() {
|
||||||
initializeSubHalCallbacks();
|
|
||||||
initializeSensorList();
|
initializeSensorList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -552,7 +624,7 @@ void HalProxy::resetSharedWakelock() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HalProxy::postEventsToMessageQueue(const std::vector<Event>& events, size_t numWakeupEvents,
|
void HalProxy::postEventsToMessageQueue(const std::vector<Event>& events, size_t numWakeupEvents,
|
||||||
ScopedWakelock wakelock) {
|
V2_0::implementation::ScopedWakelock wakelock) {
|
||||||
size_t numToWrite = 0;
|
size_t numToWrite = 0;
|
||||||
std::lock_guard<std::mutex> lock(mEventQueueWriteMutex);
|
std::lock_guard<std::mutex> lock(mEventQueueWriteMutex);
|
||||||
if (wakelock.isLocked()) {
|
if (wakelock.isLocked()) {
|
||||||
@@ -610,7 +682,8 @@ void HalProxy::decrementRefCountAndMaybeReleaseWakelock(size_t delta,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HalProxy::setDirectChannelFlags(SensorInfo* sensorInfo, ISensorsSubHal* subHal) {
|
void HalProxy::setDirectChannelFlags(SensorInfo* sensorInfo,
|
||||||
|
std::shared_ptr<ISubHalWrapperBase> subHal) {
|
||||||
bool sensorSupportsDirectChannel =
|
bool sensorSupportsDirectChannel =
|
||||||
(sensorInfo->flags & (V1_0::SensorFlagBits::MASK_DIRECT_REPORT |
|
(sensorInfo->flags & (V1_0::SensorFlagBits::MASK_DIRECT_REPORT |
|
||||||
V1_0::SensorFlagBits::MASK_DIRECT_CHANNEL)) != 0;
|
V1_0::SensorFlagBits::MASK_DIRECT_CHANNEL)) != 0;
|
||||||
@@ -624,7 +697,7 @@ void HalProxy::setDirectChannelFlags(SensorInfo* sensorInfo, ISensorsSubHal* sub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ISensorsSubHal* HalProxy::getSubHalForSensorHandle(int32_t sensorHandle) {
|
std::shared_ptr<ISubHalWrapperBase> HalProxy::getSubHalForSensorHandle(int32_t sensorHandle) {
|
||||||
return mSubHalList[extractSubHalIndex(sensorHandle)];
|
return mSubHalList[extractSubHalIndex(sensorHandle)];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -651,46 +724,8 @@ bool HalProxy::subHalIndexIsClear(int32_t sensorHandle) {
|
|||||||
return (sensorHandle & kSensorHandleSubHalIndexMask) == 0;
|
return (sensorHandle & kSensorHandleSubHalIndexMask) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HalProxyCallback::postEvents(const std::vector<Event>& events, ScopedWakelock wakelock) {
|
|
||||||
if (events.empty() || !mHalProxy->areThreadsRunning()) return;
|
|
||||||
size_t numWakeupEvents;
|
|
||||||
std::vector<Event> processedEvents = processEvents(events, &numWakeupEvents);
|
|
||||||
if (numWakeupEvents > 0) {
|
|
||||||
ALOG_ASSERT(wakelock.isLocked(),
|
|
||||||
"Wakeup events posted while wakelock unlocked for subhal"
|
|
||||||
" w/ index %" PRId32 ".",
|
|
||||||
mSubHalIndex);
|
|
||||||
} else {
|
|
||||||
ALOG_ASSERT(!wakelock.isLocked(),
|
|
||||||
"No Wakeup events posted but wakelock locked for subhal"
|
|
||||||
" w/ index %" PRId32 ".",
|
|
||||||
mSubHalIndex);
|
|
||||||
}
|
|
||||||
mHalProxy->postEventsToMessageQueue(processedEvents, numWakeupEvents, std::move(wakelock));
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedWakelock HalProxyCallback::createScopedWakelock(bool lock) {
|
|
||||||
ScopedWakelock wakelock(mHalProxy, lock);
|
|
||||||
return wakelock;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<Event> HalProxyCallback::processEvents(const std::vector<Event>& events,
|
|
||||||
size_t* numWakeupEvents) const {
|
|
||||||
*numWakeupEvents = 0;
|
|
||||||
std::vector<Event> eventsOut;
|
|
||||||
for (Event event : events) {
|
|
||||||
event.sensorHandle = setSubHalIndex(event.sensorHandle, mSubHalIndex);
|
|
||||||
eventsOut.push_back(event);
|
|
||||||
const SensorInfo& sensor = mHalProxy->getSensorInfo(event.sensorHandle);
|
|
||||||
if ((sensor.flags & V1_0::SensorFlagBits::WAKE_UP) != 0) {
|
|
||||||
(*numWakeupEvents)++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return eventsOut;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace implementation
|
} // namespace implementation
|
||||||
} // namespace V2_0
|
} // namespace V2_1
|
||||||
} // namespace sensors
|
} // namespace sensors
|
||||||
} // namespace hardware
|
} // namespace hardware
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|||||||
82
sensors/common/default/2.X/multihal/HalProxyCallback.cpp
Normal file
82
sensors/common/default/2.X/multihal/HalProxyCallback.cpp
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 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 "HalProxyCallback.h"
|
||||||
|
|
||||||
|
namespace android {
|
||||||
|
namespace hardware {
|
||||||
|
namespace sensors {
|
||||||
|
namespace V2_0 {
|
||||||
|
namespace implementation {
|
||||||
|
|
||||||
|
static constexpr int32_t kBitsAfterSubHalIndex = 24;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the subhal index as first byte of sensor handle and return this modified version.
|
||||||
|
*
|
||||||
|
* @param sensorHandle The sensor handle to modify.
|
||||||
|
* @param subHalIndex The index in the hal proxy of the sub hal this sensor belongs to.
|
||||||
|
*
|
||||||
|
* @return The modified sensor handle.
|
||||||
|
*/
|
||||||
|
int32_t setSubHalIndex(int32_t sensorHandle, size_t subHalIndex) {
|
||||||
|
return sensorHandle | (static_cast<int32_t>(subHalIndex) << kBitsAfterSubHalIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HalProxyCallbackBase::postEvents(const std::vector<V2_1::Event>& events,
|
||||||
|
ScopedWakelock wakelock) {
|
||||||
|
if (events.empty() || !mCallback->areThreadsRunning()) return;
|
||||||
|
size_t numWakeupEvents;
|
||||||
|
std::vector<V2_1::Event> processedEvents = processEvents(events, &numWakeupEvents);
|
||||||
|
if (numWakeupEvents > 0) {
|
||||||
|
ALOG_ASSERT(wakelock.isLocked(),
|
||||||
|
"Wakeup events posted while wakelock unlocked for subhal"
|
||||||
|
" w/ index %" PRId32 ".",
|
||||||
|
mSubHalIndex);
|
||||||
|
} else {
|
||||||
|
ALOG_ASSERT(!wakelock.isLocked(),
|
||||||
|
"No Wakeup events posted but wakelock locked for subhal"
|
||||||
|
" w/ index %" PRId32 ".",
|
||||||
|
mSubHalIndex);
|
||||||
|
}
|
||||||
|
mCallback->postEventsToMessageQueue(processedEvents, numWakeupEvents, std::move(wakelock));
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedWakelock HalProxyCallbackBase::createScopedWakelock(bool lock) {
|
||||||
|
ScopedWakelock wakelock(mRefCounter, lock);
|
||||||
|
return wakelock;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<V2_1::Event> HalProxyCallbackBase::processEvents(const std::vector<V2_1::Event>& events,
|
||||||
|
size_t* numWakeupEvents) const {
|
||||||
|
*numWakeupEvents = 0;
|
||||||
|
std::vector<V2_1::Event> eventsOut;
|
||||||
|
for (V2_1::Event event : events) {
|
||||||
|
event.sensorHandle = setSubHalIndex(event.sensorHandle, mSubHalIndex);
|
||||||
|
eventsOut.push_back(event);
|
||||||
|
const V2_1::SensorInfo& sensor = mCallback->getSensorInfo(event.sensorHandle);
|
||||||
|
if ((sensor.flags & V1_0::SensorFlagBits::WAKE_UP) != 0) {
|
||||||
|
(*numWakeupEvents)++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return eventsOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace implementation
|
||||||
|
} // namespace V2_0
|
||||||
|
} // namespace sensors
|
||||||
|
} // namespace hardware
|
||||||
|
} // namespace android
|
||||||
@@ -16,12 +16,17 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "EventMessageQueueWrapper.h"
|
||||||
|
#include "HalProxyCallback.h"
|
||||||
|
#include "ISensorsCallbackWrapper.h"
|
||||||
|
#include "SubHalWrapper.h"
|
||||||
#include "V2_0/ScopedWakelock.h"
|
#include "V2_0/ScopedWakelock.h"
|
||||||
#include "V2_0/SubHal.h"
|
#include "V2_0/SubHal.h"
|
||||||
#include "V2_1/SubHal.h"
|
#include "V2_1/SubHal.h"
|
||||||
|
#include "convertV2_1.h"
|
||||||
|
|
||||||
#include <android/hardware/sensors/2.0/ISensors.h>
|
#include <android/hardware/sensors/2.1/ISensors.h>
|
||||||
#include <android/hardware/sensors/2.0/types.h>
|
#include <android/hardware/sensors/2.1/types.h>
|
||||||
#include <fmq/MessageQueue.h>
|
#include <fmq/MessageQueue.h>
|
||||||
#include <hardware_legacy/power.h>
|
#include <hardware_legacy/power.h>
|
||||||
#include <hidl/MQDescriptor.h>
|
#include <hidl/MQDescriptor.h>
|
||||||
@@ -38,96 +43,97 @@
|
|||||||
namespace android {
|
namespace android {
|
||||||
namespace hardware {
|
namespace hardware {
|
||||||
namespace sensors {
|
namespace sensors {
|
||||||
namespace V2_0 {
|
namespace V2_1 {
|
||||||
namespace implementation {
|
namespace implementation {
|
||||||
|
|
||||||
using ::android::sp;
|
/**
|
||||||
using ::android::hardware::EventFlag;
|
* HalProxy is the main interface for Multi-HAL. It is responsible for managing subHALs and
|
||||||
using ::android::hardware::hidl_string;
|
* proxying function calls to/from the subHAL APIs from the sensors framework. It also manages any
|
||||||
using ::android::hardware::hidl_vec;
|
* wakelocks allocated through the IHalProxyCallback and manages posting events to the sensors
|
||||||
using ::android::hardware::MessageQueue;
|
* framework.
|
||||||
using ::android::hardware::MQDescriptor;
|
*/
|
||||||
using ::android::hardware::Return;
|
class HalProxy : public V2_0::implementation::IScopedWakelockRefCounter,
|
||||||
using ::android::hardware::Void;
|
public V2_0::implementation::ISubHalCallback {
|
||||||
|
|
||||||
class HalProxy : public ISensors, public IScopedWakelockRefCounter {
|
|
||||||
public:
|
public:
|
||||||
using Event = ::android::hardware::sensors::V1_0::Event;
|
using Event = ::android::hardware::sensors::V2_1::Event;
|
||||||
using OperationMode = ::android::hardware::sensors::V1_0::OperationMode;
|
using OperationMode = ::android::hardware::sensors::V1_0::OperationMode;
|
||||||
using RateLevel = ::android::hardware::sensors::V1_0::RateLevel;
|
using RateLevel = ::android::hardware::sensors::V1_0::RateLevel;
|
||||||
using Result = ::android::hardware::sensors::V1_0::Result;
|
using Result = ::android::hardware::sensors::V1_0::Result;
|
||||||
using SensorInfo = ::android::hardware::sensors::V1_0::SensorInfo;
|
using SensorInfo = ::android::hardware::sensors::V2_1::SensorInfo;
|
||||||
using SharedMemInfo = ::android::hardware::sensors::V1_0::SharedMemInfo;
|
using SharedMemInfo = ::android::hardware::sensors::V1_0::SharedMemInfo;
|
||||||
using ISensorsSubHal = ::android::hardware::sensors::V2_0::implementation::ISensorsSubHal;
|
using IHalProxyCallbackV2_0 = V2_0::implementation::IHalProxyCallback;
|
||||||
|
using IHalProxyCallbackV2_1 = V2_1::implementation::IHalProxyCallback;
|
||||||
|
using ISensorsSubHalV2_0 = V2_0::implementation::ISensorsSubHal;
|
||||||
|
using ISensorsSubHalV2_1 = V2_1::implementation::ISensorsSubHal;
|
||||||
|
using ISensorsV2_0 = V2_0::ISensors;
|
||||||
|
using ISensorsV2_1 = V2_1::ISensors;
|
||||||
|
using HalProxyCallbackBase = V2_0::implementation::HalProxyCallbackBase;
|
||||||
|
|
||||||
explicit HalProxy();
|
explicit HalProxy();
|
||||||
// Test only constructor.
|
// Test only constructor.
|
||||||
explicit HalProxy(std::vector<ISensorsSubHal*>& subHalList);
|
explicit HalProxy(std::vector<ISensorsSubHalV2_0*>& subHalList);
|
||||||
|
explicit HalProxy(std::vector<ISensorsSubHalV2_0*>& subHalList,
|
||||||
|
std::vector<ISensorsSubHalV2_1*>& subHalListV2_1);
|
||||||
~HalProxy();
|
~HalProxy();
|
||||||
|
|
||||||
|
// Methods from ::android::hardware::sensors::V2_1::ISensors follow.
|
||||||
|
Return<void> getSensorsList_2_1(ISensorsV2_1::getSensorsList_2_1_cb _hidl_cb);
|
||||||
|
|
||||||
|
Return<Result> initialize_2_1(
|
||||||
|
const ::android::hardware::MQDescriptorSync<V2_1::Event>& eventQueueDescriptor,
|
||||||
|
const ::android::hardware::MQDescriptorSync<uint32_t>& wakeLockDescriptor,
|
||||||
|
const sp<V2_1::ISensorsCallback>& sensorsCallback);
|
||||||
|
|
||||||
|
Return<Result> injectSensorData_2_1(const Event& event);
|
||||||
|
|
||||||
// Methods from ::android::hardware::sensors::V2_0::ISensors follow.
|
// Methods from ::android::hardware::sensors::V2_0::ISensors follow.
|
||||||
Return<void> getSensorsList(getSensorsList_cb _hidl_cb) override;
|
Return<void> getSensorsList(ISensorsV2_0::getSensorsList_cb _hidl_cb);
|
||||||
|
|
||||||
Return<Result> setOperationMode(OperationMode mode) override;
|
Return<Result> setOperationMode(OperationMode mode);
|
||||||
|
|
||||||
Return<Result> activate(int32_t sensorHandle, bool enabled) override;
|
Return<Result> activate(int32_t sensorHandle, bool enabled);
|
||||||
|
|
||||||
Return<Result> initialize(
|
Return<Result> initialize(
|
||||||
const ::android::hardware::MQDescriptorSync<Event>& eventQueueDescriptor,
|
const ::android::hardware::MQDescriptorSync<V1_0::Event>& eventQueueDescriptor,
|
||||||
const ::android::hardware::MQDescriptorSync<uint32_t>& wakeLockDescriptor,
|
const ::android::hardware::MQDescriptorSync<uint32_t>& wakeLockDescriptor,
|
||||||
const sp<ISensorsCallback>& sensorsCallback) override;
|
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> batch(int32_t sensorHandle, int64_t samplingPeriodNs,
|
Return<Result> batch(int32_t sensorHandle, int64_t samplingPeriodNs,
|
||||||
int64_t maxReportLatencyNs) override;
|
int64_t maxReportLatencyNs);
|
||||||
|
|
||||||
Return<Result> flush(int32_t sensorHandle) override;
|
Return<Result> flush(int32_t sensorHandle);
|
||||||
|
|
||||||
Return<Result> injectSensorData(const Event& event) override;
|
Return<Result> injectSensorData(const V1_0::Event& event);
|
||||||
|
|
||||||
Return<void> registerDirectChannel(const SharedMemInfo& mem,
|
Return<void> registerDirectChannel(const SharedMemInfo& mem,
|
||||||
registerDirectChannel_cb _hidl_cb) override;
|
ISensorsV2_0::registerDirectChannel_cb _hidl_cb);
|
||||||
|
|
||||||
Return<Result> unregisterDirectChannel(int32_t channelHandle) override;
|
Return<Result> unregisterDirectChannel(int32_t channelHandle);
|
||||||
|
|
||||||
Return<void> configDirectReport(int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
|
Return<void> configDirectReport(int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
|
||||||
configDirectReport_cb _hidl_cb) override;
|
ISensorsV2_0::configDirectReport_cb _hidl_cb);
|
||||||
|
|
||||||
Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& args) override;
|
Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& args);
|
||||||
|
|
||||||
// Below methods from ::android::hardware::sensors::V2_0::ISensorsCallback with a minor change
|
|
||||||
// to pass in the sub-HAL index. While the above methods are invoked from the sensors framework
|
|
||||||
// via the binder, these methods are invoked from a callback provided to sub-HALs inside the
|
|
||||||
// same process as the HalProxy, but potentially running on different threads.
|
|
||||||
Return<void> onDynamicSensorsConnected(const hidl_vec<SensorInfo>& dynamicSensorsAdded,
|
Return<void> onDynamicSensorsConnected(const hidl_vec<SensorInfo>& dynamicSensorsAdded,
|
||||||
int32_t subHalIndex);
|
int32_t subHalIndex) override;
|
||||||
|
|
||||||
Return<void> onDynamicSensorsDisconnected(const hidl_vec<int32_t>& dynamicSensorHandlesRemoved,
|
Return<void> onDynamicSensorsDisconnected(const hidl_vec<int32_t>& dynamicSensorHandlesRemoved,
|
||||||
int32_t subHalIndex);
|
int32_t subHalIndex) override;
|
||||||
|
|
||||||
// Below methods are for HalProxyCallback
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Post events to the event message queue if there is room to write them. Otherwise post the
|
|
||||||
* remaining events to a background thread for a blocking write with a kPendingWriteTimeoutNs
|
|
||||||
* timeout.
|
|
||||||
*
|
|
||||||
* @param events The list of events to post to the message queue.
|
|
||||||
* @param numWakeupEvents The number of wakeup events in events.
|
|
||||||
* @param wakelock The wakelock associated with this post of events.
|
|
||||||
*/
|
|
||||||
void postEventsToMessageQueue(const std::vector<Event>& events, size_t numWakeupEvents,
|
void postEventsToMessageQueue(const std::vector<Event>& events, size_t numWakeupEvents,
|
||||||
ScopedWakelock wakelock);
|
V2_0::implementation::ScopedWakelock wakelock) override;
|
||||||
|
|
||||||
/**
|
const SensorInfo& getSensorInfo(int32_t sensorHandle) override {
|
||||||
* Get the sensor info associated with that sensorHandle.
|
return mSensors[sensorHandle];
|
||||||
*
|
}
|
||||||
* @param sensorHandle The sensor handle.
|
|
||||||
*
|
|
||||||
* @return The sensor info object in the mapping.
|
|
||||||
*/
|
|
||||||
const SensorInfo& getSensorInfo(int32_t sensorHandle) { return mSensors[sensorHandle]; }
|
|
||||||
|
|
||||||
bool areThreadsRunning() { return mThreadsRun.load(); }
|
bool areThreadsRunning() override { return mThreadsRun.load(); }
|
||||||
|
|
||||||
// Below methods are from IScopedWakelockRefCounter interface
|
// Below methods are from IScopedWakelockRefCounter interface
|
||||||
bool incrementRefCountAndMaybeAcquireWakelock(size_t delta,
|
bool incrementRefCountAndMaybeAcquireWakelock(size_t delta,
|
||||||
@@ -136,13 +142,14 @@ class HalProxy : public ISensors, public IScopedWakelockRefCounter {
|
|||||||
void decrementRefCountAndMaybeReleaseWakelock(size_t delta, int64_t timeoutStart = -1) override;
|
void decrementRefCountAndMaybeReleaseWakelock(size_t delta, int64_t timeoutStart = -1) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using EventMessageQueue = MessageQueue<Event, kSynchronizedReadWrite>;
|
using EventMessageQueueV2_1 = MessageQueue<V2_1::Event, kSynchronizedReadWrite>;
|
||||||
|
using EventMessageQueueV2_0 = MessageQueue<V1_0::Event, kSynchronizedReadWrite>;
|
||||||
using WakeLockMessageQueue = MessageQueue<uint32_t, kSynchronizedReadWrite>;
|
using WakeLockMessageQueue = MessageQueue<uint32_t, kSynchronizedReadWrite>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Event FMQ where sensor events are written
|
* The Event FMQ where sensor events are written
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<EventMessageQueue> mEventQueue;
|
std::unique_ptr<EventMessageQueueWrapperBase> mEventQueue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Wake Lock FMQ that is read to determine when the framework has handled WAKE_UP events
|
* The Wake Lock FMQ that is read to determine when the framework has handled WAKE_UP events
|
||||||
@@ -161,15 +168,12 @@ class HalProxy : public ISensors, public IScopedWakelockRefCounter {
|
|||||||
/**
|
/**
|
||||||
* Callback to the sensors framework to inform it that new sensors have been added or removed.
|
* Callback to the sensors framework to inform it that new sensors have been added or removed.
|
||||||
*/
|
*/
|
||||||
sp<ISensorsCallback> mDynamicSensorsCallback;
|
sp<ISensorsCallbackWrapperBase> mDynamicSensorsCallback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SubHal object pointers that have been saved from vendor dynamic libraries.
|
* SubHal objects that have been saved from vendor dynamic libraries.
|
||||||
*/
|
*/
|
||||||
std::vector<ISensorsSubHal*> mSubHalList;
|
std::vector<std::shared_ptr<ISubHalWrapperBase>> mSubHalList;
|
||||||
|
|
||||||
//! The list of subhal callbacks for each subhal where the indices correlate with mSubHalList
|
|
||||||
std::vector<const sp<IHalProxyCallback>> mSubHalCallbacks;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map of sensor handles to SensorInfo objects that contains the sensor info from subhals as
|
* Map of sensor handles to SensorInfo objects that contains the sensor info from subhals as
|
||||||
@@ -187,7 +191,7 @@ class HalProxy : public ISensors, public IScopedWakelockRefCounter {
|
|||||||
OperationMode mCurrentOperationMode = OperationMode::NORMAL;
|
OperationMode mCurrentOperationMode = OperationMode::NORMAL;
|
||||||
|
|
||||||
//! The single subHal that supports directChannel reporting.
|
//! The single subHal that supports directChannel reporting.
|
||||||
ISensorsSubHal* mDirectChannelSubHal = nullptr;
|
std::shared_ptr<ISubHalWrapperBase> mDirectChannelSubHal;
|
||||||
|
|
||||||
//! The timeout for each pending write on background thread for events.
|
//! The timeout for each pending write on background thread for events.
|
||||||
static const int64_t kPendingWriteTimeoutNs = 5 * INT64_C(1000000000) /* 5 seconds */;
|
static const int64_t kPendingWriteTimeoutNs = 5 * INT64_C(1000000000) /* 5 seconds */;
|
||||||
@@ -239,9 +243,9 @@ class HalProxy : public ISensors, public IScopedWakelockRefCounter {
|
|||||||
//! The refcount of how many ScopedWakelocks and pending wakeup events are active
|
//! The refcount of how many ScopedWakelocks and pending wakeup events are active
|
||||||
size_t mWakelockRefCount = 0;
|
size_t mWakelockRefCount = 0;
|
||||||
|
|
||||||
int64_t mWakelockTimeoutStartTime = getTimeNow();
|
int64_t mWakelockTimeoutStartTime = V2_0::implementation::getTimeNow();
|
||||||
|
|
||||||
int64_t mWakelockTimeoutResetTime = getTimeNow();
|
int64_t mWakelockTimeoutResetTime = V2_0::implementation::getTimeNow();
|
||||||
|
|
||||||
const char* kWakelockName = "SensorsHAL_WAKEUP";
|
const char* kWakelockName = "SensorsHAL_WAKEUP";
|
||||||
|
|
||||||
@@ -321,7 +325,7 @@ class HalProxy : public ISensors, public IScopedWakelockRefCounter {
|
|||||||
* disabled.
|
* disabled.
|
||||||
* @param subHal The subhal pointer that the current sensorInfo object came from.
|
* @param subHal The subhal pointer that the current sensorInfo object came from.
|
||||||
*/
|
*/
|
||||||
void setDirectChannelFlags(SensorInfo* sensorInfo, ISensorsSubHal* subHal);
|
void setDirectChannelFlags(SensorInfo* sensorInfo, std::shared_ptr<ISubHalWrapperBase> subHal);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the subhal pointer which can be found by indexing into the mSubHalList vector
|
* Get the subhal pointer which can be found by indexing into the mSubHalList vector
|
||||||
@@ -329,7 +333,7 @@ class HalProxy : public ISensors, public IScopedWakelockRefCounter {
|
|||||||
*
|
*
|
||||||
* @param sensorHandle The handle used to identify a sensor in one of the subhals.
|
* @param sensorHandle The handle used to identify a sensor in one of the subhals.
|
||||||
*/
|
*/
|
||||||
ISensorsSubHal* getSubHalForSensorHandle(int32_t sensorHandle);
|
std::shared_ptr<ISubHalWrapperBase> getSubHalForSensorHandle(int32_t sensorHandle);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks that sensorHandle's subhal index byte is within bounds of mSubHalList.
|
* Checks that sensorHandle's subhal index byte is within bounds of mSubHalList.
|
||||||
@@ -368,39 +372,81 @@ class HalProxy : public ISensors, public IScopedWakelockRefCounter {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback class used to provide the HalProxy with the index of which subHal is invoking
|
* Since a newer HAL can't masquerade as a older HAL, IHalProxy enables the HalProxy to be compiled
|
||||||
|
* either for HAL 2.0 or HAL 2.1 depending on the build configuration.
|
||||||
*/
|
*/
|
||||||
class HalProxyCallback : public IHalProxyCallback {
|
template <class ISensorsVersion>
|
||||||
using SensorInfo = ::android::hardware::sensors::V1_0::SensorInfo;
|
class IHalProxy : public HalProxy, public ISensorsVersion {
|
||||||
|
Return<void> getSensorsList(ISensorsV2_0::getSensorsList_cb _hidl_cb) override {
|
||||||
public:
|
return HalProxy::getSensorsList(_hidl_cb);
|
||||||
HalProxyCallback(HalProxy* halProxy, int32_t subHalIndex)
|
|
||||||
: mHalProxy(halProxy), mSubHalIndex(subHalIndex) {}
|
|
||||||
|
|
||||||
Return<void> onDynamicSensorsConnected(
|
|
||||||
const hidl_vec<SensorInfo>& dynamicSensorsAdded) override {
|
|
||||||
return mHalProxy->onDynamicSensorsConnected(dynamicSensorsAdded, mSubHalIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<void> onDynamicSensorsDisconnected(
|
Return<Result> setOperationMode(OperationMode mode) override {
|
||||||
const hidl_vec<int32_t>& dynamicSensorHandlesRemoved) override {
|
return HalProxy::setOperationMode(mode);
|
||||||
return mHalProxy->onDynamicSensorsDisconnected(dynamicSensorHandlesRemoved, mSubHalIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void postEvents(const std::vector<Event>& events, ScopedWakelock wakelock);
|
Return<Result> activate(int32_t sensorHandle, bool enabled) override {
|
||||||
|
return HalProxy::activate(sensorHandle, enabled);
|
||||||
|
}
|
||||||
|
|
||||||
ScopedWakelock createScopedWakelock(bool lock);
|
Return<Result> initialize(
|
||||||
|
const ::android::hardware::MQDescriptorSync<V1_0::Event>& eventQueueDescriptor,
|
||||||
|
const ::android::hardware::MQDescriptorSync<uint32_t>& wakeLockDescriptor,
|
||||||
|
const sp<V2_0::ISensorsCallback>& sensorsCallback) override {
|
||||||
|
return HalProxy::initialize(eventQueueDescriptor, wakeLockDescriptor, sensorsCallback);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
Return<Result> batch(int32_t sensorHandle, int64_t samplingPeriodNs,
|
||||||
HalProxy* mHalProxy;
|
int64_t maxReportLatencyNs) override {
|
||||||
int32_t mSubHalIndex;
|
return HalProxy::batch(sensorHandle, samplingPeriodNs, maxReportLatencyNs);
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Event> processEvents(const std::vector<Event>& events,
|
Return<Result> flush(int32_t sensorHandle) override { return HalProxy::flush(sensorHandle); }
|
||||||
size_t* numWakeupEvents) const;
|
|
||||||
|
Return<Result> injectSensorData(const V1_0::Event& event) override {
|
||||||
|
return HalProxy::injectSensorData(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> registerDirectChannel(const SharedMemInfo& mem,
|
||||||
|
ISensorsV2_0::registerDirectChannel_cb _hidl_cb) override {
|
||||||
|
return HalProxy::registerDirectChannel(mem, _hidl_cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<Result> unregisterDirectChannel(int32_t channelHandle) override {
|
||||||
|
return HalProxy::unregisterDirectChannel(channelHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> configDirectReport(int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
|
||||||
|
ISensorsV2_0::configDirectReport_cb _hidl_cb) override {
|
||||||
|
return HalProxy::configDirectReport(sensorHandle, channelHandle, rate, _hidl_cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& args) override {
|
||||||
|
return HalProxy::debug(fd, args);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class HalProxyV2_0 : public IHalProxy<V2_0::ISensors> {};
|
||||||
|
|
||||||
|
class HalProxyV2_1 : public IHalProxy<V2_1::ISensors> {
|
||||||
|
Return<void> getSensorsList_2_1(ISensorsV2_1::getSensorsList_2_1_cb _hidl_cb) override {
|
||||||
|
return HalProxy::getSensorsList_2_1(_hidl_cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<Result> initialize_2_1(
|
||||||
|
const ::android::hardware::MQDescriptorSync<V2_1::Event>& eventQueueDescriptor,
|
||||||
|
const ::android::hardware::MQDescriptorSync<uint32_t>& wakeLockDescriptor,
|
||||||
|
const sp<V2_1::ISensorsCallback>& sensorsCallback) override {
|
||||||
|
return HalProxy::initialize_2_1(eventQueueDescriptor, wakeLockDescriptor, sensorsCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<Result> injectSensorData_2_1(const Event& event) override {
|
||||||
|
return HalProxy::injectSensorData_2_1(event);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace implementation
|
} // namespace implementation
|
||||||
} // namespace V2_0
|
} // namespace V2_1
|
||||||
} // namespace sensors
|
} // namespace sensors
|
||||||
} // namespace hardware
|
} // namespace hardware
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|||||||
171
sensors/common/default/2.X/multihal/include/HalProxyCallback.h
Normal file
171
sensors/common/default/2.X/multihal/include/HalProxyCallback.h
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 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 "V2_0/ScopedWakelock.h"
|
||||||
|
#include "V2_0/SubHal.h"
|
||||||
|
#include "V2_1/SubHal.h"
|
||||||
|
#include "convertV2_1.h"
|
||||||
|
|
||||||
|
#include <android/hardware/sensors/2.1/ISensors.h>
|
||||||
|
#include <android/hardware/sensors/2.1/types.h>
|
||||||
|
#include <log/log.h>
|
||||||
|
|
||||||
|
namespace android {
|
||||||
|
namespace hardware {
|
||||||
|
namespace sensors {
|
||||||
|
namespace V2_0 {
|
||||||
|
namespace implementation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface used to communicate with the HalProxy when subHals interact with their provided
|
||||||
|
* callback.
|
||||||
|
*/
|
||||||
|
class ISubHalCallback {
|
||||||
|
public:
|
||||||
|
virtual ~ISubHalCallback() {}
|
||||||
|
|
||||||
|
// Below methods from ::android::hardware::sensors::V2_0::ISensorsCallback with a minor change
|
||||||
|
// to pass in the sub-HAL index. While the above methods are invoked from the sensors framework
|
||||||
|
// via the binder, these methods are invoked from a callback provided to sub-HALs inside the
|
||||||
|
// same process as the HalProxy, but potentially running on different threads.
|
||||||
|
virtual Return<void> onDynamicSensorsConnected(
|
||||||
|
const hidl_vec<V2_1::SensorInfo>& dynamicSensorsAdded, int32_t subHalIndex) = 0;
|
||||||
|
|
||||||
|
virtual Return<void> onDynamicSensorsDisconnected(
|
||||||
|
const hidl_vec<int32_t>& dynamicSensorHandlesRemoved, int32_t subHalIndex) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post events to the event message queue if there is room to write them. Otherwise post the
|
||||||
|
* remaining events to a background thread for a blocking write with a kPendingWriteTimeoutNs
|
||||||
|
* timeout.
|
||||||
|
*
|
||||||
|
* @param events The list of events to post to the message queue.
|
||||||
|
* @param numWakeupEvents The number of wakeup events in events.
|
||||||
|
* @param wakelock The wakelock associated with this post of events.
|
||||||
|
*/
|
||||||
|
virtual void postEventsToMessageQueue(const std::vector<V2_1::Event>& events,
|
||||||
|
size_t numWakeupEvents,
|
||||||
|
V2_0::implementation::ScopedWakelock wakelock) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the sensor info associated with that sensorHandle.
|
||||||
|
*
|
||||||
|
* @param sensorHandle The sensor handle.
|
||||||
|
*
|
||||||
|
* @return The sensor info object in the mapping.
|
||||||
|
*/
|
||||||
|
virtual const V2_1::SensorInfo& getSensorInfo(int32_t sensorHandle) = 0;
|
||||||
|
|
||||||
|
virtual bool areThreadsRunning() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback class given to subhals that allows the HalProxy to know which subhal a given invocation
|
||||||
|
* is coming from.
|
||||||
|
*/
|
||||||
|
class HalProxyCallbackBase : public VirtualLightRefBase {
|
||||||
|
public:
|
||||||
|
HalProxyCallbackBase(ISubHalCallback* callback,
|
||||||
|
V2_0::implementation::IScopedWakelockRefCounter* refCounter,
|
||||||
|
int32_t subHalIndex)
|
||||||
|
: mCallback(callback), mRefCounter(refCounter), mSubHalIndex(subHalIndex) {}
|
||||||
|
|
||||||
|
void postEvents(const std::vector<V2_1::Event>& events,
|
||||||
|
V2_0::implementation::ScopedWakelock wakelock);
|
||||||
|
|
||||||
|
V2_0::implementation::ScopedWakelock createScopedWakelock(bool lock);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
ISubHalCallback* mCallback;
|
||||||
|
V2_0::implementation::IScopedWakelockRefCounter* mRefCounter;
|
||||||
|
int32_t mSubHalIndex;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<V2_1::Event> processEvents(const std::vector<V2_1::Event>& events,
|
||||||
|
size_t* numWakeupEvents) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
class HalProxyCallbackV2_0 : public HalProxyCallbackBase,
|
||||||
|
public V2_0::implementation::IHalProxyCallback {
|
||||||
|
public:
|
||||||
|
HalProxyCallbackV2_0(ISubHalCallback* callback,
|
||||||
|
V2_0::implementation::IScopedWakelockRefCounter* refCounter,
|
||||||
|
int32_t subHalIndex)
|
||||||
|
: HalProxyCallbackBase(callback, refCounter, subHalIndex) {}
|
||||||
|
|
||||||
|
Return<void> onDynamicSensorsConnected(
|
||||||
|
const hidl_vec<V1_0::SensorInfo>& dynamicSensorsAdded) override {
|
||||||
|
return mCallback->onDynamicSensorsConnected(
|
||||||
|
V2_1::implementation::convertToNewSensorInfos(dynamicSensorsAdded), mSubHalIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> onDynamicSensorsDisconnected(
|
||||||
|
const hidl_vec<int32_t>& dynamicSensorHandlesRemoved) override {
|
||||||
|
return mCallback->onDynamicSensorsDisconnected(dynamicSensorHandlesRemoved, mSubHalIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void postEvents(const std::vector<V1_0::Event>& events,
|
||||||
|
V2_0::implementation::ScopedWakelock wakelock) override {
|
||||||
|
HalProxyCallbackBase::postEvents(V2_1::implementation::convertToNewEvents(events),
|
||||||
|
std::move(wakelock));
|
||||||
|
}
|
||||||
|
|
||||||
|
V2_0::implementation::ScopedWakelock createScopedWakelock(bool lock) override {
|
||||||
|
return HalProxyCallbackBase::createScopedWakelock(lock);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class HalProxyCallbackV2_1 : public HalProxyCallbackBase,
|
||||||
|
public V2_1::implementation::IHalProxyCallback {
|
||||||
|
public:
|
||||||
|
HalProxyCallbackV2_1(ISubHalCallback* callback,
|
||||||
|
V2_0::implementation::IScopedWakelockRefCounter* refCounter,
|
||||||
|
int32_t subHalIndex)
|
||||||
|
: HalProxyCallbackBase(callback, refCounter, subHalIndex) {}
|
||||||
|
|
||||||
|
Return<void> onDynamicSensorsConnected_2_1(
|
||||||
|
const hidl_vec<V2_1::SensorInfo>& dynamicSensorsAdded) override {
|
||||||
|
return mCallback->onDynamicSensorsConnected(dynamicSensorsAdded, mSubHalIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> onDynamicSensorsConnected(
|
||||||
|
const hidl_vec<V1_0::SensorInfo>& /* dynamicSensorsAdded */) override {
|
||||||
|
LOG_ALWAYS_FATAL("Old dynamic sensors method can't be used");
|
||||||
|
return Void();
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> onDynamicSensorsDisconnected(
|
||||||
|
const hidl_vec<int32_t>& dynamicSensorHandlesRemoved) override {
|
||||||
|
return mCallback->onDynamicSensorsDisconnected(dynamicSensorHandlesRemoved, mSubHalIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void postEvents(const std::vector<V2_1::Event>& events,
|
||||||
|
V2_0::implementation::ScopedWakelock wakelock) override {
|
||||||
|
return HalProxyCallbackBase::postEvents(events, std::move(wakelock));
|
||||||
|
}
|
||||||
|
|
||||||
|
V2_0::implementation::ScopedWakelock createScopedWakelock(bool lock) override {
|
||||||
|
return HalProxyCallbackBase::createScopedWakelock(lock);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace implementation
|
||||||
|
} // namespace V2_0
|
||||||
|
} // namespace sensors
|
||||||
|
} // namespace hardware
|
||||||
|
} // namespace android
|
||||||
188
sensors/common/default/2.X/multihal/include/SubHalWrapper.h
Normal file
188
sensors/common/default/2.X/multihal/include/SubHalWrapper.h
Normal file
@@ -0,0 +1,188 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "HalProxyCallback.h"
|
||||||
|
#include "V2_0/SubHal.h"
|
||||||
|
#include "V2_1/SubHal.h"
|
||||||
|
|
||||||
|
#include "android/hardware/sensors/1.0/ISensors.h"
|
||||||
|
#include "android/hardware/sensors/1.0/types.h"
|
||||||
|
#include "android/hardware/sensors/2.0/ISensors.h"
|
||||||
|
#include "android/hardware/sensors/2.0/ISensorsCallback.h"
|
||||||
|
#include "android/hardware/sensors/2.1/ISensors.h"
|
||||||
|
#include "android/hardware/sensors/2.1/ISensorsCallback.h"
|
||||||
|
#include "android/hardware/sensors/2.1/types.h"
|
||||||
|
|
||||||
|
#include <utils/LightRefBase.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
namespace android {
|
||||||
|
namespace hardware {
|
||||||
|
namespace sensors {
|
||||||
|
namespace V2_1 {
|
||||||
|
namespace implementation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The following subHal wrapper classes abstract away common functionality across V2.0 and V2.1
|
||||||
|
* subHal interfaces. Much of the logic is common between the two versions and this allows users of
|
||||||
|
* the classes to only care about the type used at initialization and then interact with either
|
||||||
|
* version of the subHal interface without worrying about the type.
|
||||||
|
*/
|
||||||
|
class ISubHalWrapperBase {
|
||||||
|
protected:
|
||||||
|
using Event = ::android::hardware::sensors::V2_1::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 SensorInfo = ::android::hardware::sensors::V2_1::SensorInfo;
|
||||||
|
using SharedMemInfo = ::android::hardware::sensors::V1_0::SharedMemInfo;
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~ISubHalWrapperBase() {}
|
||||||
|
|
||||||
|
virtual bool supportsNewEvents() = 0;
|
||||||
|
|
||||||
|
virtual Return<Result> initialize(V2_0::implementation::ISubHalCallback* callback,
|
||||||
|
V2_0::implementation::IScopedWakelockRefCounter* refCounter,
|
||||||
|
int32_t subHalIndex) = 0;
|
||||||
|
|
||||||
|
virtual Return<void> getSensorsList(
|
||||||
|
::android::hardware::sensors::V2_1::ISensors::getSensorsList_2_1_cb _hidl_cb) = 0;
|
||||||
|
|
||||||
|
virtual Return<Result> setOperationMode(OperationMode mode) = 0;
|
||||||
|
|
||||||
|
virtual Return<Result> activate(int32_t sensorHandle, bool enabled) = 0;
|
||||||
|
|
||||||
|
virtual Return<Result> batch(int32_t sensorHandle, int64_t samplingPeriodNs,
|
||||||
|
int64_t maxReportLatencyNs) = 0;
|
||||||
|
|
||||||
|
virtual Return<Result> flush(int32_t sensorHandle) = 0;
|
||||||
|
|
||||||
|
virtual Return<Result> injectSensorData(const Event& event) = 0;
|
||||||
|
|
||||||
|
virtual Return<void> registerDirectChannel(const SharedMemInfo& mem,
|
||||||
|
ISensors::registerDirectChannel_cb _hidl_cb) = 0;
|
||||||
|
|
||||||
|
virtual Return<Result> unregisterDirectChannel(int32_t channelHandle) = 0;
|
||||||
|
|
||||||
|
virtual Return<void> configDirectReport(int32_t sensorHandle, int32_t channelHandle,
|
||||||
|
RateLevel rate,
|
||||||
|
ISensors::configDirectReport_cb _hidl_cb) = 0;
|
||||||
|
|
||||||
|
virtual Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& args) = 0;
|
||||||
|
|
||||||
|
virtual const std::string getName() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class SubHalWrapperBase : public ISubHalWrapperBase {
|
||||||
|
public:
|
||||||
|
SubHalWrapperBase(T* subHal) : mSubHal(subHal){};
|
||||||
|
|
||||||
|
virtual bool supportsNewEvents() override { return false; }
|
||||||
|
|
||||||
|
virtual Return<void> getSensorsList(
|
||||||
|
::android::hardware::sensors::V2_1::ISensors::getSensorsList_2_1_cb _hidl_cb) override {
|
||||||
|
return mSubHal->getSensorsList(
|
||||||
|
[&](const auto& list) { _hidl_cb(convertToNewSensorInfos(list)); });
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<Result> setOperationMode(OperationMode mode) override {
|
||||||
|
return mSubHal->setOperationMode(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<Result> activate(int32_t sensorHandle, bool enabled) override {
|
||||||
|
return mSubHal->activate(sensorHandle, enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<Result> batch(int32_t sensorHandle, int64_t samplingPeriodNs,
|
||||||
|
int64_t maxReportLatencyNs) override {
|
||||||
|
return mSubHal->batch(sensorHandle, samplingPeriodNs, maxReportLatencyNs);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<Result> flush(int32_t sensorHandle) override { return mSubHal->flush(sensorHandle); }
|
||||||
|
|
||||||
|
virtual Return<Result> injectSensorData(const Event& event) override {
|
||||||
|
return mSubHal->injectSensorData(convertToOldEvent(event));
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> registerDirectChannel(const SharedMemInfo& mem,
|
||||||
|
ISensors::registerDirectChannel_cb _hidl_cb) override {
|
||||||
|
return mSubHal->registerDirectChannel(mem, _hidl_cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<Result> unregisterDirectChannel(int32_t channelHandle) override {
|
||||||
|
return mSubHal->unregisterDirectChannel(channelHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> configDirectReport(int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
|
||||||
|
ISensors::configDirectReport_cb _hidl_cb) override {
|
||||||
|
return mSubHal->configDirectReport(sensorHandle, channelHandle, rate, _hidl_cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& args) override {
|
||||||
|
return mSubHal->debug(fd, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string getName() override { return mSubHal->getName(); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
T* mSubHal;
|
||||||
|
};
|
||||||
|
|
||||||
|
class SubHalWrapperV2_0 : public SubHalWrapperBase<V2_0::implementation::ISensorsSubHal> {
|
||||||
|
public:
|
||||||
|
SubHalWrapperV2_0(V2_0::implementation::ISensorsSubHal* subHal) : SubHalWrapperBase(subHal){};
|
||||||
|
|
||||||
|
Return<Result> initialize(V2_0::implementation::ISubHalCallback* callback,
|
||||||
|
V2_0::implementation::IScopedWakelockRefCounter* refCounter,
|
||||||
|
int32_t subHalIndex) override {
|
||||||
|
return mSubHal->initialize(
|
||||||
|
new V2_0::implementation::HalProxyCallbackV2_0(callback, refCounter, subHalIndex));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class SubHalWrapperV2_1 : public SubHalWrapperBase<V2_1::implementation::ISensorsSubHal> {
|
||||||
|
public:
|
||||||
|
SubHalWrapperV2_1(V2_1::implementation::ISensorsSubHal* subHal) : SubHalWrapperBase(subHal) {}
|
||||||
|
|
||||||
|
bool supportsNewEvents() override { return true; }
|
||||||
|
|
||||||
|
virtual Return<void> getSensorsList(
|
||||||
|
::android::hardware::sensors::V2_1::ISensors::getSensorsList_2_1_cb _hidl_cb) override {
|
||||||
|
return mSubHal->getSensorsList_2_1([&](const auto& list) { _hidl_cb(list); });
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual Return<Result> injectSensorData(const Event& event) override {
|
||||||
|
return mSubHal->injectSensorData_2_1(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<Result> initialize(V2_0::implementation::ISubHalCallback* callback,
|
||||||
|
V2_0::implementation::IScopedWakelockRefCounter* refCounter,
|
||||||
|
int32_t subHalIndex) override {
|
||||||
|
return mSubHal->initialize(
|
||||||
|
new V2_0::implementation::HalProxyCallbackV2_1(callback, refCounter, subHalIndex));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace implementation
|
||||||
|
} // namespace V2_1
|
||||||
|
} // namespace sensors
|
||||||
|
} // namespace hardware
|
||||||
|
} // namespace android
|
||||||
@@ -88,7 +88,7 @@ class ScopedWakelock {
|
|||||||
bool isLocked() const { return mLocked; }
|
bool isLocked() const { return mLocked; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class HalProxyCallback;
|
friend class HalProxyCallbackBase;
|
||||||
IScopedWakelockRefCounter* mRefCounter;
|
IScopedWakelockRefCounter* mRefCounter;
|
||||||
int64_t mCreatedAtTimeNs;
|
int64_t mCreatedAtTimeNs;
|
||||||
bool mLocked;
|
bool mLocked;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ cc_defaults {
|
|||||||
],
|
],
|
||||||
header_libs: [
|
header_libs: [
|
||||||
"android.hardware.sensors@2.0-multihal.header",
|
"android.hardware.sensors@2.0-multihal.header",
|
||||||
|
"android.hardware.sensors@2.X-shared-utils",
|
||||||
],
|
],
|
||||||
export_include_dirs: ["fake_subhal"],
|
export_include_dirs: ["fake_subhal"],
|
||||||
shared_libs: [
|
shared_libs: [
|
||||||
@@ -36,6 +37,7 @@ cc_defaults {
|
|||||||
"libutils",
|
"libutils",
|
||||||
],
|
],
|
||||||
static_libs: [
|
static_libs: [
|
||||||
|
"android.hardware.sensors@1.0-convert",
|
||||||
"android.hardware.sensors@2.X-multihal",
|
"android.hardware.sensors@2.X-multihal",
|
||||||
],
|
],
|
||||||
cflags: [
|
cflags: [
|
||||||
@@ -48,6 +50,7 @@ cc_library {
|
|||||||
vendor: true,
|
vendor: true,
|
||||||
defaults: ["android.hardware.sensors@2.X-fakesubhal-defaults"],
|
defaults: ["android.hardware.sensors@2.X-fakesubhal-defaults"],
|
||||||
cflags: [
|
cflags: [
|
||||||
|
"-DSUB_HAL_VERSION_2_0",
|
||||||
"-DSUPPORT_CONTINUOUS_SENSORS",
|
"-DSUPPORT_CONTINUOUS_SENSORS",
|
||||||
"-DSUB_HAL_NAME=\"FakeSubHal-Continuous\"",
|
"-DSUB_HAL_NAME=\"FakeSubHal-Continuous\"",
|
||||||
],
|
],
|
||||||
@@ -57,6 +60,17 @@ cc_library {
|
|||||||
name: "android.hardware.sensors@2.X-fakesubhal-config2",
|
name: "android.hardware.sensors@2.X-fakesubhal-config2",
|
||||||
vendor: true,
|
vendor: true,
|
||||||
defaults: ["android.hardware.sensors@2.X-fakesubhal-defaults"],
|
defaults: ["android.hardware.sensors@2.X-fakesubhal-defaults"],
|
||||||
|
cflags: [
|
||||||
|
"-DSUB_HAL_VERSION_2_0",
|
||||||
|
"-DSUPPORT_ON_CHANGE_SENSORS",
|
||||||
|
"-DSUB_HAL_NAME=\"FakeSubHal-OnChange\"",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_library {
|
||||||
|
name: "android.hardware.sensors@2.X-fakesubhal-config3",
|
||||||
|
vendor: true,
|
||||||
|
defaults: ["android.hardware.sensors@2.X-fakesubhal-defaults"],
|
||||||
cflags: [
|
cflags: [
|
||||||
"-DSUPPORT_ON_CHANGE_SENSORS",
|
"-DSUPPORT_ON_CHANGE_SENSORS",
|
||||||
"-DSUB_HAL_NAME=\"FakeSubHal-OnChange\"",
|
"-DSUB_HAL_NAME=\"FakeSubHal-OnChange\"",
|
||||||
@@ -78,7 +92,11 @@ cc_test {
|
|||||||
name: "android.hardware.sensors@2.X-halproxy-unit-tests",
|
name: "android.hardware.sensors@2.X-halproxy-unit-tests",
|
||||||
srcs: ["HalProxy_test.cpp"],
|
srcs: ["HalProxy_test.cpp"],
|
||||||
vendor: true,
|
vendor: true,
|
||||||
|
header_libs: [
|
||||||
|
"android.hardware.sensors@2.X-shared-utils",
|
||||||
|
],
|
||||||
static_libs: [
|
static_libs: [
|
||||||
|
"android.hardware.sensors@1.0-convert",
|
||||||
"android.hardware.sensors@2.0-ScopedWakelock.testlib",
|
"android.hardware.sensors@2.0-ScopedWakelock.testlib",
|
||||||
"android.hardware.sensors@2.X-multihal",
|
"android.hardware.sensors@2.X-multihal",
|
||||||
"android.hardware.sensors@2.X-fakesubhal-unittest",
|
"android.hardware.sensors@2.X-fakesubhal-unittest",
|
||||||
|
|||||||
@@ -15,12 +15,15 @@
|
|||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <android/hardware/sensors/1.0/types.h>
|
||||||
#include <android/hardware/sensors/2.0/types.h>
|
#include <android/hardware/sensors/2.0/types.h>
|
||||||
|
#include <android/hardware/sensors/2.1/types.h>
|
||||||
#include <fmq/MessageQueue.h>
|
#include <fmq/MessageQueue.h>
|
||||||
|
|
||||||
#include "HalProxy.h"
|
#include "HalProxy.h"
|
||||||
#include "SensorsSubHal.h"
|
#include "SensorsSubHal.h"
|
||||||
#include "V2_0/ScopedWakelock.h"
|
#include "V2_0/ScopedWakelock.h"
|
||||||
|
#include "convertV2_1.h"
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <set>
|
#include <set>
|
||||||
@@ -38,27 +41,35 @@ using ::android::hardware::sensors::V1_0::SensorFlagBits;
|
|||||||
using ::android::hardware::sensors::V1_0::SensorInfo;
|
using ::android::hardware::sensors::V1_0::SensorInfo;
|
||||||
using ::android::hardware::sensors::V1_0::SensorType;
|
using ::android::hardware::sensors::V1_0::SensorType;
|
||||||
using ::android::hardware::sensors::V2_0::EventQueueFlagBits;
|
using ::android::hardware::sensors::V2_0::EventQueueFlagBits;
|
||||||
using ::android::hardware::sensors::V2_0::ISensorsCallback;
|
|
||||||
using ::android::hardware::sensors::V2_0::WakeLockQueueFlagBits;
|
using ::android::hardware::sensors::V2_0::WakeLockQueueFlagBits;
|
||||||
using ::android::hardware::sensors::V2_0::implementation::HalProxy;
|
using ::android::hardware::sensors::V2_0::implementation::HalProxyCallbackBase;
|
||||||
using ::android::hardware::sensors::V2_0::implementation::HalProxyCallback;
|
using ::android::hardware::sensors::V2_0::implementation::ScopedWakelock;
|
||||||
using ::android::hardware::sensors::V2_0::subhal::implementation::AddAndRemoveDynamicSensorsSubHal;
|
using ::android::hardware::sensors::V2_1::implementation::convertToNewEvents;
|
||||||
using ::android::hardware::sensors::V2_0::subhal::implementation::AllSensorsSubHal;
|
using ::android::hardware::sensors::V2_1::implementation::convertToNewSensorInfos;
|
||||||
using ::android::hardware::sensors::V2_0::subhal::implementation::
|
using ::android::hardware::sensors::V2_1::implementation::HalProxy;
|
||||||
|
using ::android::hardware::sensors::V2_1::subhal::implementation::AddAndRemoveDynamicSensorsSubHal;
|
||||||
|
using ::android::hardware::sensors::V2_1::subhal::implementation::AllSensorsSubHal;
|
||||||
|
using ::android::hardware::sensors::V2_1::subhal::implementation::
|
||||||
AllSupportDirectChannelSensorsSubHal;
|
AllSupportDirectChannelSensorsSubHal;
|
||||||
using ::android::hardware::sensors::V2_0::subhal::implementation::ContinuousSensorsSubHal;
|
using ::android::hardware::sensors::V2_1::subhal::implementation::ContinuousSensorsSubHal;
|
||||||
using ::android::hardware::sensors::V2_0::subhal::implementation::
|
using ::android::hardware::sensors::V2_1::subhal::implementation::
|
||||||
DoesNotSupportDirectChannelSensorsSubHal;
|
DoesNotSupportDirectChannelSensorsSubHal;
|
||||||
using ::android::hardware::sensors::V2_0::subhal::implementation::OnChangeSensorsSubHal;
|
using ::android::hardware::sensors::V2_1::subhal::implementation::OnChangeSensorsSubHal;
|
||||||
using ::android::hardware::sensors::V2_0::subhal::implementation::SensorsSubHal;
|
using ::android::hardware::sensors::V2_1::subhal::implementation::SensorsSubHalV2_0;
|
||||||
using ::android::hardware::sensors::V2_0::subhal::implementation::
|
using ::android::hardware::sensors::V2_1::subhal::implementation::SensorsSubHalV2_1;
|
||||||
|
using ::android::hardware::sensors::V2_1::subhal::implementation::
|
||||||
SetOperationModeFailingSensorsSubHal;
|
SetOperationModeFailingSensorsSubHal;
|
||||||
|
|
||||||
using EventMessageQueue = MessageQueue<Event, ::android::hardware::kSynchronizedReadWrite>;
|
using ISensorsCallbackV2_0 = ::android::hardware::sensors::V2_0::ISensorsCallback;
|
||||||
|
using ISensorsCallbackV2_1 = ::android::hardware::sensors::V2_1::ISensorsCallback;
|
||||||
|
using EventV1_0 = ::android::hardware::sensors::V1_0::Event;
|
||||||
|
using EventV2_1 = ::android::hardware::sensors::V2_1::Event;
|
||||||
|
using EventMessageQueueV2_1 = MessageQueue<EventV2_1, ::android::hardware::kSynchronizedReadWrite>;
|
||||||
|
using EventMessageQueueV2_0 = MessageQueue<EventV1_0, ::android::hardware::kSynchronizedReadWrite>;
|
||||||
using WakeupMessageQueue = MessageQueue<uint32_t, ::android::hardware::kSynchronizedReadWrite>;
|
using WakeupMessageQueue = MessageQueue<uint32_t, ::android::hardware::kSynchronizedReadWrite>;
|
||||||
|
|
||||||
// The barebones sensors callback class passed into halproxy initialize calls
|
// The barebones sensors callback class passed into halproxy initialize calls
|
||||||
class SensorsCallback : public ISensorsCallback {
|
class SensorsCallback : public ISensorsCallbackV2_0 {
|
||||||
public:
|
public:
|
||||||
Return<void> onDynamicSensorsConnected(
|
Return<void> onDynamicSensorsConnected(
|
||||||
const hidl_vec<SensorInfo>& /*dynamicSensorsAdded*/) override {
|
const hidl_vec<SensorInfo>& /*dynamicSensorsAdded*/) override {
|
||||||
@@ -73,8 +84,30 @@ class SensorsCallback : public ISensorsCallback {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class SensorsCallbackV2_1 : public ISensorsCallbackV2_1 {
|
||||||
|
public:
|
||||||
|
Return<void> onDynamicSensorsConnected_2_1(
|
||||||
|
const hidl_vec<::android::hardware::sensors::V2_1::SensorInfo>& /*dynamicSensorsAdded*/)
|
||||||
|
override {
|
||||||
|
// Nothing yet
|
||||||
|
return Return<void>();
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> onDynamicSensorsConnected(
|
||||||
|
const hidl_vec<SensorInfo>& /*dynamicSensorsAdded*/) override {
|
||||||
|
// Nothing yet
|
||||||
|
return Return<void>();
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> onDynamicSensorsDisconnected(
|
||||||
|
const hidl_vec<int32_t>& /*dynamicSensorHandlesRemoved*/) override {
|
||||||
|
// Nothing yet
|
||||||
|
return Return<void>();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// The sensors callback that expects a variable list of sensors to be added
|
// The sensors callback that expects a variable list of sensors to be added
|
||||||
class TestSensorsCallback : public ISensorsCallback {
|
class TestSensorsCallback : public ISensorsCallbackV2_0 {
|
||||||
public:
|
public:
|
||||||
Return<void> onDynamicSensorsConnected(
|
Return<void> onDynamicSensorsConnected(
|
||||||
const hidl_vec<SensorInfo>& dynamicSensorsAdded) override {
|
const hidl_vec<SensorInfo>& dynamicSensorsAdded) override {
|
||||||
@@ -129,10 +162,10 @@ void testSensorsListForOneDirectChannelEnabledSubHal(const std::vector<SensorInf
|
|||||||
void ackWakeupEventsToHalProxy(size_t numEvents, std::unique_ptr<WakeupMessageQueue>& wakelockQueue,
|
void ackWakeupEventsToHalProxy(size_t numEvents, std::unique_ptr<WakeupMessageQueue>& wakelockQueue,
|
||||||
EventFlag* wakelockQueueFlag);
|
EventFlag* wakelockQueueFlag);
|
||||||
|
|
||||||
bool readEventsOutOfQueue(size_t numEvents, std::unique_ptr<EventMessageQueue>& eventQueue,
|
bool readEventsOutOfQueue(size_t numEvents, std::unique_ptr<EventMessageQueueV2_0>& eventQueue,
|
||||||
EventFlag* eventQueueFlag);
|
EventFlag* eventQueueFlag);
|
||||||
|
|
||||||
std::unique_ptr<EventMessageQueue> makeEventFMQ(size_t size);
|
std::unique_ptr<EventMessageQueueV2_0> makeEventFMQ(size_t size);
|
||||||
|
|
||||||
std::unique_ptr<WakeupMessageQueue> makeWakelockFMQ(size_t size);
|
std::unique_ptr<WakeupMessageQueue> makeWakelockFMQ(size_t size);
|
||||||
|
|
||||||
@@ -142,7 +175,7 @@ std::unique_ptr<WakeupMessageQueue> makeWakelockFMQ(size_t size);
|
|||||||
*
|
*
|
||||||
* @return A proximity event.
|
* @return A proximity event.
|
||||||
*/
|
*/
|
||||||
Event makeProximityEvent();
|
EventV1_0 makeProximityEvent();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct and return a HIDL Event type thats sensorHandle refers to a proximity sensor
|
* Construct and return a HIDL Event type thats sensorHandle refers to a proximity sensor
|
||||||
@@ -150,7 +183,7 @@ Event makeProximityEvent();
|
|||||||
*
|
*
|
||||||
* @return A proximity event.
|
* @return A proximity event.
|
||||||
*/
|
*/
|
||||||
Event makeAccelerometerEvent();
|
EventV1_0 makeAccelerometerEvent();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a certain number of proximity type events with the sensorHandle field set to
|
* Make a certain number of proximity type events with the sensorHandle field set to
|
||||||
@@ -160,7 +193,7 @@ Event makeAccelerometerEvent();
|
|||||||
*
|
*
|
||||||
* @return The created list of events.
|
* @return The created list of events.
|
||||||
*/
|
*/
|
||||||
std::vector<Event> makeMultipleProximityEvents(size_t numEvents);
|
std::vector<EventV1_0> makeMultipleProximityEvents(size_t numEvents);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a certain number of accelerometer type events with the sensorHandle field set to
|
* Make a certain number of accelerometer type events with the sensorHandle field set to
|
||||||
@@ -170,7 +203,7 @@ std::vector<Event> makeMultipleProximityEvents(size_t numEvents);
|
|||||||
*
|
*
|
||||||
* @return The created list of events.
|
* @return The created list of events.
|
||||||
*/
|
*/
|
||||||
std::vector<Event> makeMultipleAccelerometerEvents(size_t numEvents);
|
std::vector<EventV1_0> makeMultipleAccelerometerEvents(size_t numEvents);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a SensorInfo vector and a sensor handles vector populate 'sensors' with SensorInfo
|
* Given a SensorInfo vector and a sensor handles vector populate 'sensors' with SensorInfo
|
||||||
@@ -188,7 +221,7 @@ void makeSensorsAndSensorHandlesStartingAndOfSize(int32_t start, size_t size,
|
|||||||
|
|
||||||
// Tests follow
|
// Tests follow
|
||||||
TEST(HalProxyTest, GetSensorsListOneSubHalTest) {
|
TEST(HalProxyTest, GetSensorsListOneSubHalTest) {
|
||||||
AllSensorsSubHal subHal;
|
AllSensorsSubHal<SensorsSubHalV2_0> subHal;
|
||||||
std::vector<ISensorsSubHal*> fakeSubHals{&subHal};
|
std::vector<ISensorsSubHal*> fakeSubHals{&subHal};
|
||||||
HalProxy proxy(fakeSubHals);
|
HalProxy proxy(fakeSubHals);
|
||||||
|
|
||||||
@@ -200,8 +233,8 @@ TEST(HalProxyTest, GetSensorsListOneSubHalTest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(HalProxyTest, GetSensorsListTwoSubHalTest) {
|
TEST(HalProxyTest, GetSensorsListTwoSubHalTest) {
|
||||||
ContinuousSensorsSubHal continuousSubHal;
|
ContinuousSensorsSubHal<SensorsSubHalV2_0> continuousSubHal;
|
||||||
OnChangeSensorsSubHal onChangeSubHal;
|
OnChangeSensorsSubHal<SensorsSubHalV2_0> onChangeSubHal;
|
||||||
std::vector<ISensorsSubHal*> fakeSubHals;
|
std::vector<ISensorsSubHal*> fakeSubHals;
|
||||||
fakeSubHals.push_back(&continuousSubHal);
|
fakeSubHals.push_back(&continuousSubHal);
|
||||||
fakeSubHals.push_back(&onChangeSubHal);
|
fakeSubHals.push_back(&onChangeSubHal);
|
||||||
@@ -221,8 +254,8 @@ TEST(HalProxyTest, GetSensorsListTwoSubHalTest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(HalProxyTest, SetOperationModeTwoSubHalSuccessTest) {
|
TEST(HalProxyTest, SetOperationModeTwoSubHalSuccessTest) {
|
||||||
ContinuousSensorsSubHal subHal1;
|
ContinuousSensorsSubHal<SensorsSubHalV2_0> subHal1;
|
||||||
OnChangeSensorsSubHal subHal2;
|
OnChangeSensorsSubHal<SensorsSubHalV2_0> subHal2;
|
||||||
|
|
||||||
std::vector<ISensorsSubHal*> fakeSubHals{&subHal1, &subHal2};
|
std::vector<ISensorsSubHal*> fakeSubHals{&subHal1, &subHal2};
|
||||||
HalProxy proxy(fakeSubHals);
|
HalProxy proxy(fakeSubHals);
|
||||||
@@ -238,7 +271,7 @@ TEST(HalProxyTest, SetOperationModeTwoSubHalSuccessTest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(HalProxyTest, SetOperationModeTwoSubHalFailTest) {
|
TEST(HalProxyTest, SetOperationModeTwoSubHalFailTest) {
|
||||||
AllSensorsSubHal subHal1;
|
AllSensorsSubHal<SensorsSubHalV2_0> subHal1;
|
||||||
SetOperationModeFailingSensorsSubHal subHal2;
|
SetOperationModeFailingSensorsSubHal subHal2;
|
||||||
|
|
||||||
std::vector<ISensorsSubHal*> fakeSubHals{&subHal1, &subHal2};
|
std::vector<ISensorsSubHal*> fakeSubHals{&subHal1, &subHal2};
|
||||||
@@ -279,16 +312,16 @@ TEST(HalProxyTest, InitDirectChannelThreeSubHalsUnitTest) {
|
|||||||
|
|
||||||
TEST(HalProxyTest, PostSingleNonWakeupEvent) {
|
TEST(HalProxyTest, PostSingleNonWakeupEvent) {
|
||||||
constexpr size_t kQueueSize = 5;
|
constexpr size_t kQueueSize = 5;
|
||||||
AllSensorsSubHal subHal;
|
AllSensorsSubHal<SensorsSubHalV2_0> subHal;
|
||||||
std::vector<ISensorsSubHal*> subHals{&subHal};
|
std::vector<ISensorsSubHal*> subHals{&subHal};
|
||||||
HalProxy proxy(subHals);
|
HalProxy proxy(subHals);
|
||||||
std::unique_ptr<EventMessageQueue> eventQueue = makeEventFMQ(kQueueSize);
|
std::unique_ptr<EventMessageQueueV2_0> eventQueue = makeEventFMQ(kQueueSize);
|
||||||
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
||||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||||
|
|
||||||
std::vector<Event> events{makeAccelerometerEvent()};
|
std::vector<EventV1_0> events{makeAccelerometerEvent()};
|
||||||
subHal.postEvents(events, false /* wakeup */);
|
subHal.postEvents(convertToNewEvents(events), false /* wakeup */);
|
||||||
|
|
||||||
EXPECT_EQ(eventQueue->availableToRead(), 1);
|
EXPECT_EQ(eventQueue->availableToRead(), 1);
|
||||||
}
|
}
|
||||||
@@ -296,28 +329,28 @@ TEST(HalProxyTest, PostSingleNonWakeupEvent) {
|
|||||||
TEST(HalProxyTest, PostMultipleNonWakeupEvent) {
|
TEST(HalProxyTest, PostMultipleNonWakeupEvent) {
|
||||||
constexpr size_t kQueueSize = 5;
|
constexpr size_t kQueueSize = 5;
|
||||||
constexpr size_t kNumEvents = 3;
|
constexpr size_t kNumEvents = 3;
|
||||||
AllSensorsSubHal subHal;
|
AllSensorsSubHal<SensorsSubHalV2_0> subHal;
|
||||||
std::vector<ISensorsSubHal*> subHals{&subHal};
|
std::vector<ISensorsSubHal*> subHals{&subHal};
|
||||||
HalProxy proxy(subHals);
|
HalProxy proxy(subHals);
|
||||||
std::unique_ptr<EventMessageQueue> eventQueue = makeEventFMQ(kQueueSize);
|
std::unique_ptr<EventMessageQueueV2_0> eventQueue = makeEventFMQ(kQueueSize);
|
||||||
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
||||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||||
|
|
||||||
std::vector<Event> events = makeMultipleAccelerometerEvents(kNumEvents);
|
std::vector<EventV1_0> events = makeMultipleAccelerometerEvents(kNumEvents);
|
||||||
subHal.postEvents(events, false /* wakeup */);
|
subHal.postEvents(convertToNewEvents(events), false /* wakeup */);
|
||||||
|
|
||||||
EXPECT_EQ(eventQueue->availableToRead(), kNumEvents);
|
EXPECT_EQ(eventQueue->availableToRead(), kNumEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(HalProxyTest, PostSingleWakeupEvent) {
|
TEST(HalProxyTest, PostSingleWakeupEvent) {
|
||||||
constexpr size_t kQueueSize = 5;
|
constexpr size_t kQueueSize = 5;
|
||||||
AllSensorsSubHal subHal;
|
AllSensorsSubHal<SensorsSubHalV2_0> subHal;
|
||||||
std::vector<ISensorsSubHal*> subHals{&subHal};
|
std::vector<ISensorsSubHal*> subHals{&subHal};
|
||||||
HalProxy proxy(subHals);
|
HalProxy proxy(subHals);
|
||||||
std::unique_ptr<EventMessageQueue> eventQueue = makeEventFMQ(kQueueSize);
|
std::unique_ptr<EventMessageQueueV2_0> eventQueue = makeEventFMQ(kQueueSize);
|
||||||
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
||||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||||
|
|
||||||
EventFlag* eventQueueFlag;
|
EventFlag* eventQueueFlag;
|
||||||
@@ -326,8 +359,8 @@ TEST(HalProxyTest, PostSingleWakeupEvent) {
|
|||||||
EventFlag* wakelockQueueFlag;
|
EventFlag* wakelockQueueFlag;
|
||||||
EventFlag::createEventFlag(wakeLockQueue->getEventFlagWord(), &wakelockQueueFlag);
|
EventFlag::createEventFlag(wakeLockQueue->getEventFlagWord(), &wakelockQueueFlag);
|
||||||
|
|
||||||
std::vector<Event> events{makeProximityEvent()};
|
std::vector<EventV1_0> events{makeProximityEvent()};
|
||||||
subHal.postEvents(events, true /* wakeup */);
|
subHal.postEvents(convertToNewEvents(events), true /* wakeup */);
|
||||||
|
|
||||||
EXPECT_EQ(eventQueue->availableToRead(), 1);
|
EXPECT_EQ(eventQueue->availableToRead(), 1);
|
||||||
|
|
||||||
@@ -338,12 +371,12 @@ TEST(HalProxyTest, PostSingleWakeupEvent) {
|
|||||||
TEST(HalProxyTest, PostMultipleWakeupEvents) {
|
TEST(HalProxyTest, PostMultipleWakeupEvents) {
|
||||||
constexpr size_t kQueueSize = 5;
|
constexpr size_t kQueueSize = 5;
|
||||||
constexpr size_t kNumEvents = 3;
|
constexpr size_t kNumEvents = 3;
|
||||||
AllSensorsSubHal subHal;
|
AllSensorsSubHal<SensorsSubHalV2_0> subHal;
|
||||||
std::vector<ISensorsSubHal*> subHals{&subHal};
|
std::vector<ISensorsSubHal*> subHals{&subHal};
|
||||||
HalProxy proxy(subHals);
|
HalProxy proxy(subHals);
|
||||||
std::unique_ptr<EventMessageQueue> eventQueue = makeEventFMQ(kQueueSize);
|
std::unique_ptr<EventMessageQueueV2_0> eventQueue = makeEventFMQ(kQueueSize);
|
||||||
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
||||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||||
|
|
||||||
EventFlag* eventQueueFlag;
|
EventFlag* eventQueueFlag;
|
||||||
@@ -352,8 +385,8 @@ TEST(HalProxyTest, PostMultipleWakeupEvents) {
|
|||||||
EventFlag* wakelockQueueFlag;
|
EventFlag* wakelockQueueFlag;
|
||||||
EventFlag::createEventFlag(wakeLockQueue->getEventFlagWord(), &wakelockQueueFlag);
|
EventFlag::createEventFlag(wakeLockQueue->getEventFlagWord(), &wakelockQueueFlag);
|
||||||
|
|
||||||
std::vector<Event> events = makeMultipleProximityEvents(kNumEvents);
|
std::vector<EventV1_0> events = makeMultipleProximityEvents(kNumEvents);
|
||||||
subHal.postEvents(events, true /* wakeup */);
|
subHal.postEvents(convertToNewEvents(events), true /* wakeup */);
|
||||||
|
|
||||||
EXPECT_EQ(eventQueue->availableToRead(), kNumEvents);
|
EXPECT_EQ(eventQueue->availableToRead(), kNumEvents);
|
||||||
|
|
||||||
@@ -364,20 +397,20 @@ TEST(HalProxyTest, PostMultipleWakeupEvents) {
|
|||||||
TEST(HalProxyTest, PostEventsMultipleSubhals) {
|
TEST(HalProxyTest, PostEventsMultipleSubhals) {
|
||||||
constexpr size_t kQueueSize = 5;
|
constexpr size_t kQueueSize = 5;
|
||||||
constexpr size_t kNumEvents = 2;
|
constexpr size_t kNumEvents = 2;
|
||||||
AllSensorsSubHal subHal1, subHal2;
|
AllSensorsSubHal<SensorsSubHalV2_0> subHal1, subHal2;
|
||||||
std::vector<ISensorsSubHal*> subHals{&subHal1, &subHal2};
|
std::vector<ISensorsSubHal*> subHals{&subHal1, &subHal2};
|
||||||
HalProxy proxy(subHals);
|
HalProxy proxy(subHals);
|
||||||
std::unique_ptr<EventMessageQueue> eventQueue = makeEventFMQ(kQueueSize);
|
std::unique_ptr<EventMessageQueueV2_0> eventQueue = makeEventFMQ(kQueueSize);
|
||||||
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
||||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||||
|
|
||||||
std::vector<Event> events = makeMultipleAccelerometerEvents(kNumEvents);
|
std::vector<EventV1_0> events = makeMultipleAccelerometerEvents(kNumEvents);
|
||||||
subHal1.postEvents(events, false /* wakeup */);
|
subHal1.postEvents(convertToNewEvents(events), false /* wakeup */);
|
||||||
|
|
||||||
EXPECT_EQ(eventQueue->availableToRead(), kNumEvents);
|
EXPECT_EQ(eventQueue->availableToRead(), kNumEvents);
|
||||||
|
|
||||||
subHal2.postEvents(events, false /* wakeup */);
|
subHal2.postEvents(convertToNewEvents(events), false /* wakeup */);
|
||||||
|
|
||||||
EXPECT_EQ(eventQueue->availableToRead(), kNumEvents * 2);
|
EXPECT_EQ(eventQueue->availableToRead(), kNumEvents * 2);
|
||||||
}
|
}
|
||||||
@@ -385,19 +418,19 @@ TEST(HalProxyTest, PostEventsMultipleSubhals) {
|
|||||||
TEST(HalProxyTest, PostEventsDelayedWrite) {
|
TEST(HalProxyTest, PostEventsDelayedWrite) {
|
||||||
constexpr size_t kQueueSize = 5;
|
constexpr size_t kQueueSize = 5;
|
||||||
constexpr size_t kNumEvents = 6;
|
constexpr size_t kNumEvents = 6;
|
||||||
AllSensorsSubHal subHal1, subHal2;
|
AllSensorsSubHal<SensorsSubHalV2_0> subHal1, subHal2;
|
||||||
std::vector<ISensorsSubHal*> subHals{&subHal1, &subHal2};
|
std::vector<ISensorsSubHal*> subHals{&subHal1, &subHal2};
|
||||||
HalProxy proxy(subHals);
|
HalProxy proxy(subHals);
|
||||||
std::unique_ptr<EventMessageQueue> eventQueue = makeEventFMQ(kQueueSize);
|
std::unique_ptr<EventMessageQueueV2_0> eventQueue = makeEventFMQ(kQueueSize);
|
||||||
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
||||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||||
|
|
||||||
EventFlag* eventQueueFlag;
|
EventFlag* eventQueueFlag;
|
||||||
EventFlag::createEventFlag(eventQueue->getEventFlagWord(), &eventQueueFlag);
|
EventFlag::createEventFlag(eventQueue->getEventFlagWord(), &eventQueueFlag);
|
||||||
|
|
||||||
std::vector<Event> events = makeMultipleAccelerometerEvents(kNumEvents);
|
std::vector<EventV1_0> events = makeMultipleAccelerometerEvents(kNumEvents);
|
||||||
subHal1.postEvents(events, false /* wakeup */);
|
subHal1.postEvents(convertToNewEvents(events), false /* wakeup */);
|
||||||
|
|
||||||
EXPECT_EQ(eventQueue->availableToRead(), kQueueSize);
|
EXPECT_EQ(eventQueue->availableToRead(), kQueueSize);
|
||||||
|
|
||||||
@@ -413,18 +446,20 @@ TEST(HalProxyTest, PostEventsDelayedWrite) {
|
|||||||
TEST(HalProxyTest, PostEventsMultipleSubhalsThreaded) {
|
TEST(HalProxyTest, PostEventsMultipleSubhalsThreaded) {
|
||||||
constexpr size_t kQueueSize = 5;
|
constexpr size_t kQueueSize = 5;
|
||||||
constexpr size_t kNumEvents = 2;
|
constexpr size_t kNumEvents = 2;
|
||||||
AllSensorsSubHal subHal1, subHal2;
|
AllSensorsSubHal<SensorsSubHalV2_0> subHal1, subHal2;
|
||||||
std::vector<ISensorsSubHal*> subHals{&subHal1, &subHal2};
|
std::vector<ISensorsSubHal*> subHals{&subHal1, &subHal2};
|
||||||
HalProxy proxy(subHals);
|
HalProxy proxy(subHals);
|
||||||
std::unique_ptr<EventMessageQueue> eventQueue = makeEventFMQ(kQueueSize);
|
std::unique_ptr<EventMessageQueueV2_0> eventQueue = makeEventFMQ(kQueueSize);
|
||||||
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
||||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||||
|
|
||||||
std::vector<Event> events = makeMultipleAccelerometerEvents(kNumEvents);
|
std::vector<EventV1_0> events = makeMultipleAccelerometerEvents(kNumEvents);
|
||||||
|
|
||||||
std::thread t1(&AllSensorsSubHal::postEvents, &subHal1, events, false);
|
std::thread t1(&AllSensorsSubHal<SensorsSubHalV2_0>::postEvents, &subHal1,
|
||||||
std::thread t2(&AllSensorsSubHal::postEvents, &subHal2, events, false);
|
convertToNewEvents(events), false);
|
||||||
|
std::thread t2(&AllSensorsSubHal<SensorsSubHalV2_0>::postEvents, &subHal2,
|
||||||
|
convertToNewEvents(events), false);
|
||||||
|
|
||||||
t1.join();
|
t1.join();
|
||||||
t2.join();
|
t2.join();
|
||||||
@@ -435,34 +470,34 @@ TEST(HalProxyTest, PostEventsMultipleSubhalsThreaded) {
|
|||||||
TEST(HalProxyTest, DestructingWithEventsPendingOnBackgroundThread) {
|
TEST(HalProxyTest, DestructingWithEventsPendingOnBackgroundThread) {
|
||||||
constexpr size_t kQueueSize = 5;
|
constexpr size_t kQueueSize = 5;
|
||||||
constexpr size_t kNumEvents = 6;
|
constexpr size_t kNumEvents = 6;
|
||||||
AllSensorsSubHal subHal;
|
AllSensorsSubHal<SensorsSubHalV2_0> subHal;
|
||||||
std::vector<ISensorsSubHal*> subHals{&subHal};
|
std::vector<ISensorsSubHal*> subHals{&subHal};
|
||||||
|
|
||||||
std::unique_ptr<EventMessageQueue> eventQueue = makeEventFMQ(kQueueSize);
|
std::unique_ptr<EventMessageQueueV2_0> eventQueue = makeEventFMQ(kQueueSize);
|
||||||
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
||||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||||
HalProxy proxy(subHals);
|
HalProxy proxy(subHals);
|
||||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||||
|
|
||||||
std::vector<Event> events = makeMultipleAccelerometerEvents(kNumEvents);
|
std::vector<EventV1_0> events = makeMultipleAccelerometerEvents(kNumEvents);
|
||||||
subHal.postEvents(events, false /* wakeup */);
|
subHal.postEvents(convertToNewEvents(events), false /* wakeup */);
|
||||||
|
|
||||||
// Destructing HalProxy object with events on the background thread
|
// Destructing HalProxy object with events on the background thread
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(HalProxyTest, DestructingWithUnackedWakeupEventsPosted) {
|
TEST(HalProxyTest, DestructingWithUnackedWakeupEventsPosted) {
|
||||||
constexpr size_t kQueueSize = 5;
|
constexpr size_t kQueueSize = 5;
|
||||||
AllSensorsSubHal subHal;
|
AllSensorsSubHal<SensorsSubHalV2_0> subHal;
|
||||||
std::vector<ISensorsSubHal*> subHals{&subHal};
|
std::vector<ISensorsSubHal*> subHals{&subHal};
|
||||||
|
|
||||||
std::unique_ptr<EventMessageQueue> eventQueue = makeEventFMQ(kQueueSize);
|
std::unique_ptr<EventMessageQueueV2_0> eventQueue = makeEventFMQ(kQueueSize);
|
||||||
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
||||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||||
HalProxy proxy(subHals);
|
HalProxy proxy(subHals);
|
||||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||||
|
|
||||||
std::vector<Event> events{makeProximityEvent()};
|
std::vector<EventV1_0> events{makeProximityEvent()};
|
||||||
subHal.postEvents(events, true /* wakeup */);
|
subHal.postEvents(convertToNewEvents(events), true /* wakeup */);
|
||||||
|
|
||||||
// Not sending any acks back through wakeLockQueue
|
// Not sending any acks back through wakeLockQueue
|
||||||
|
|
||||||
@@ -472,17 +507,17 @@ TEST(HalProxyTest, DestructingWithUnackedWakeupEventsPosted) {
|
|||||||
TEST(HalProxyTest, ReinitializeWithEventsPendingOnBackgroundThread) {
|
TEST(HalProxyTest, ReinitializeWithEventsPendingOnBackgroundThread) {
|
||||||
constexpr size_t kQueueSize = 5;
|
constexpr size_t kQueueSize = 5;
|
||||||
constexpr size_t kNumEvents = 10;
|
constexpr size_t kNumEvents = 10;
|
||||||
AllSensorsSubHal subHal;
|
AllSensorsSubHal<SensorsSubHalV2_0> subHal;
|
||||||
std::vector<ISensorsSubHal*> subHals{&subHal};
|
std::vector<ISensorsSubHal*> subHals{&subHal};
|
||||||
|
|
||||||
std::unique_ptr<EventMessageQueue> eventQueue = makeEventFMQ(kQueueSize);
|
std::unique_ptr<EventMessageQueueV2_0> eventQueue = makeEventFMQ(kQueueSize);
|
||||||
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
||||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||||
HalProxy proxy(subHals);
|
HalProxy proxy(subHals);
|
||||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||||
|
|
||||||
std::vector<Event> events = makeMultipleAccelerometerEvents(kNumEvents);
|
std::vector<EventV1_0> events = makeMultipleAccelerometerEvents(kNumEvents);
|
||||||
subHal.postEvents(events, false /* wakeup */);
|
subHal.postEvents(convertToNewEvents(events), false /* wakeup */);
|
||||||
|
|
||||||
eventQueue = makeEventFMQ(kQueueSize);
|
eventQueue = makeEventFMQ(kQueueSize);
|
||||||
wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
||||||
@@ -492,23 +527,23 @@ TEST(HalProxyTest, ReinitializeWithEventsPendingOnBackgroundThread) {
|
|||||||
EXPECT_EQ(secondInitResult, Result::OK);
|
EXPECT_EQ(secondInitResult, Result::OK);
|
||||||
// Small sleep so that pending writes thread has a change to hit writeBlocking call.
|
// Small sleep so that pending writes thread has a change to hit writeBlocking call.
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
||||||
Event eventOut;
|
EventV1_0 eventOut;
|
||||||
EXPECT_FALSE(eventQueue->read(&eventOut));
|
EXPECT_FALSE(eventQueue->read(&eventOut));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(HalProxyTest, ReinitializingWithUnackedWakeupEventsPosted) {
|
TEST(HalProxyTest, ReinitializingWithUnackedWakeupEventsPosted) {
|
||||||
constexpr size_t kQueueSize = 5;
|
constexpr size_t kQueueSize = 5;
|
||||||
AllSensorsSubHal subHal;
|
AllSensorsSubHal<SensorsSubHalV2_0> subHal;
|
||||||
std::vector<ISensorsSubHal*> subHals{&subHal};
|
std::vector<ISensorsSubHal*> subHals{&subHal};
|
||||||
|
|
||||||
std::unique_ptr<EventMessageQueue> eventQueue = makeEventFMQ(kQueueSize);
|
std::unique_ptr<EventMessageQueueV2_0> eventQueue = makeEventFMQ(kQueueSize);
|
||||||
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
||||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||||
HalProxy proxy(subHals);
|
HalProxy proxy(subHals);
|
||||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||||
|
|
||||||
std::vector<Event> events{makeProximityEvent()};
|
std::vector<EventV1_0> events{makeProximityEvent()};
|
||||||
subHal.postEvents(events, true /* wakeup */);
|
subHal.postEvents(convertToNewEvents(events), true /* wakeup */);
|
||||||
|
|
||||||
// Not sending any acks back through wakeLockQueue
|
// Not sending any acks back through wakeLockQueue
|
||||||
|
|
||||||
@@ -523,12 +558,12 @@ TEST(HalProxyTest, ReinitializingWithUnackedWakeupEventsPosted) {
|
|||||||
TEST(HalProxyTest, InitializeManyTimesInARow) {
|
TEST(HalProxyTest, InitializeManyTimesInARow) {
|
||||||
constexpr size_t kQueueSize = 5;
|
constexpr size_t kQueueSize = 5;
|
||||||
constexpr size_t kNumTimesToInit = 100;
|
constexpr size_t kNumTimesToInit = 100;
|
||||||
AllSensorsSubHal subHal;
|
AllSensorsSubHal<SensorsSubHalV2_0> subHal;
|
||||||
std::vector<ISensorsSubHal*> subHals{&subHal};
|
std::vector<ISensorsSubHal*> subHals{&subHal};
|
||||||
|
|
||||||
std::unique_ptr<EventMessageQueue> eventQueue = makeEventFMQ(kQueueSize);
|
std::unique_ptr<EventMessageQueueV2_0> eventQueue = makeEventFMQ(kQueueSize);
|
||||||
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
||||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||||
HalProxy proxy(subHals);
|
HalProxy proxy(subHals);
|
||||||
|
|
||||||
for (size_t i = 0; i < kNumTimesToInit; i++) {
|
for (size_t i = 0; i < kNumTimesToInit; i++) {
|
||||||
@@ -540,15 +575,15 @@ TEST(HalProxyTest, InitializeManyTimesInARow) {
|
|||||||
|
|
||||||
TEST(HalProxyTest, OperationModeResetOnInitialize) {
|
TEST(HalProxyTest, OperationModeResetOnInitialize) {
|
||||||
constexpr size_t kQueueSize = 5;
|
constexpr size_t kQueueSize = 5;
|
||||||
AllSensorsSubHal subHal;
|
AllSensorsSubHal<SensorsSubHalV2_0> subHal;
|
||||||
std::vector<ISensorsSubHal*> subHals{&subHal};
|
std::vector<ISensorsSubHal*> subHals{&subHal};
|
||||||
std::unique_ptr<EventMessageQueue> eventQueue = makeEventFMQ(kQueueSize);
|
std::unique_ptr<EventMessageQueueV2_0> eventQueue = makeEventFMQ(kQueueSize);
|
||||||
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
||||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||||
HalProxy proxy(subHals);
|
HalProxy proxy(subHals);
|
||||||
proxy.setOperationMode(OperationMode::DATA_INJECTION);
|
proxy.setOperationMode(OperationMode::DATA_INJECTION);
|
||||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||||
Event event = makeAccelerometerEvent();
|
EventV1_0 event = makeAccelerometerEvent();
|
||||||
// Should not be able to inject a non AdditionInfo type event because operation mode should
|
// Should not be able to inject a non AdditionInfo type event because operation mode should
|
||||||
// have been reset to NORMAL
|
// have been reset to NORMAL
|
||||||
EXPECT_EQ(proxy.injectSensorData(event), Result::BAD_VALUE);
|
EXPECT_EQ(proxy.injectSensorData(event), Result::BAD_VALUE);
|
||||||
@@ -559,7 +594,7 @@ TEST(HalProxyTest, DynamicSensorsDiscardedOnInitialize) {
|
|||||||
constexpr size_t kNumSensors = 5;
|
constexpr size_t kNumSensors = 5;
|
||||||
AddAndRemoveDynamicSensorsSubHal subHal;
|
AddAndRemoveDynamicSensorsSubHal subHal;
|
||||||
std::vector<ISensorsSubHal*> subHals{&subHal};
|
std::vector<ISensorsSubHal*> subHals{&subHal};
|
||||||
std::unique_ptr<EventMessageQueue> eventQueue = makeEventFMQ(kQueueSize);
|
std::unique_ptr<EventMessageQueueV2_0> eventQueue = makeEventFMQ(kQueueSize);
|
||||||
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
||||||
HalProxy proxy(subHals);
|
HalProxy proxy(subHals);
|
||||||
|
|
||||||
@@ -574,9 +609,9 @@ TEST(HalProxyTest, DynamicSensorsDiscardedOnInitialize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TestSensorsCallback* callback = new TestSensorsCallback();
|
TestSensorsCallback* callback = new TestSensorsCallback();
|
||||||
::android::sp<ISensorsCallback> callbackPtr = callback;
|
::android::sp<ISensorsCallbackV2_0> callbackPtr = callback;
|
||||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callbackPtr);
|
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callbackPtr);
|
||||||
subHal.addDynamicSensors(sensorsToConnect);
|
subHal.addDynamicSensors(convertToNewSensorInfos(sensorsToConnect));
|
||||||
|
|
||||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callbackPtr);
|
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callbackPtr);
|
||||||
subHal.removeDynamicSensors(sensorHandlesToAttemptToRemove);
|
subHal.removeDynamicSensors(sensorHandlesToAttemptToRemove);
|
||||||
@@ -593,7 +628,7 @@ TEST(HalProxyTest, DynamicSensorsConnectedTest) {
|
|||||||
AddAndRemoveDynamicSensorsSubHal subHal;
|
AddAndRemoveDynamicSensorsSubHal subHal;
|
||||||
std::vector<ISensorsSubHal*> subHals{&subHal};
|
std::vector<ISensorsSubHal*> subHals{&subHal};
|
||||||
HalProxy proxy(subHals);
|
HalProxy proxy(subHals);
|
||||||
std::unique_ptr<EventMessageQueue> eventQueue = makeEventFMQ(0);
|
std::unique_ptr<EventMessageQueueV2_0> eventQueue = makeEventFMQ(0);
|
||||||
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(0);
|
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(0);
|
||||||
|
|
||||||
std::vector<SensorInfo> sensorsToConnect;
|
std::vector<SensorInfo> sensorsToConnect;
|
||||||
@@ -602,9 +637,9 @@ TEST(HalProxyTest, DynamicSensorsConnectedTest) {
|
|||||||
sensorHandlesToExpect);
|
sensorHandlesToExpect);
|
||||||
|
|
||||||
TestSensorsCallback* callback = new TestSensorsCallback();
|
TestSensorsCallback* callback = new TestSensorsCallback();
|
||||||
::android::sp<ISensorsCallback> callbackPtr = callback;
|
::android::sp<ISensorsCallbackV2_0> callbackPtr = callback;
|
||||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callbackPtr);
|
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callbackPtr);
|
||||||
subHal.addDynamicSensors(sensorsToConnect);
|
subHal.addDynamicSensors(convertToNewSensorInfos(sensorsToConnect));
|
||||||
|
|
||||||
std::vector<SensorInfo> sensorsSeen = callback->getSensorsConnected();
|
std::vector<SensorInfo> sensorsSeen = callback->getSensorsConnected();
|
||||||
EXPECT_EQ(kNumSensors, sensorsSeen.size());
|
EXPECT_EQ(kNumSensors, sensorsSeen.size());
|
||||||
@@ -621,7 +656,7 @@ TEST(HalProxyTest, DynamicSensorsDisconnectedTest) {
|
|||||||
AddAndRemoveDynamicSensorsSubHal subHal;
|
AddAndRemoveDynamicSensorsSubHal subHal;
|
||||||
std::vector<ISensorsSubHal*> subHals{&subHal};
|
std::vector<ISensorsSubHal*> subHals{&subHal};
|
||||||
HalProxy proxy(subHals);
|
HalProxy proxy(subHals);
|
||||||
std::unique_ptr<EventMessageQueue> eventQueue = makeEventFMQ(0);
|
std::unique_ptr<EventMessageQueueV2_0> eventQueue = makeEventFMQ(0);
|
||||||
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(0);
|
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(0);
|
||||||
|
|
||||||
std::vector<SensorInfo> sensorsToConnect;
|
std::vector<SensorInfo> sensorsToConnect;
|
||||||
@@ -646,9 +681,9 @@ TEST(HalProxyTest, DynamicSensorsDisconnectedTest) {
|
|||||||
nonDynamicSensorHandles.end());
|
nonDynamicSensorHandles.end());
|
||||||
|
|
||||||
TestSensorsCallback* callback = new TestSensorsCallback();
|
TestSensorsCallback* callback = new TestSensorsCallback();
|
||||||
::android::sp<ISensorsCallback> callbackPtr = callback;
|
::android::sp<ISensorsCallbackV2_0> callbackPtr = callback;
|
||||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callbackPtr);
|
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callbackPtr);
|
||||||
subHal.addDynamicSensors(sensorsToConnect);
|
subHal.addDynamicSensors(convertToNewSensorInfos(sensorsToConnect));
|
||||||
subHal.removeDynamicSensors(sensorHandlesToAttemptToRemove);
|
subHal.removeDynamicSensors(sensorHandlesToAttemptToRemove);
|
||||||
|
|
||||||
std::vector<int32_t> sensorHandlesSeen = callback->getSensorHandlesDisconnected();
|
std::vector<int32_t> sensorHandlesSeen = callback->getSensorHandlesDisconnected();
|
||||||
@@ -667,15 +702,15 @@ TEST(HalProxyTest, InvalidSensorHandleSubHalIndexProxyCalls) {
|
|||||||
constexpr size_t kNumSubHals = 3;
|
constexpr size_t kNumSubHals = 3;
|
||||||
constexpr size_t kQueueSize = 5;
|
constexpr size_t kQueueSize = 5;
|
||||||
int32_t kNumSubHalsInt32 = static_cast<int32_t>(kNumSubHals);
|
int32_t kNumSubHalsInt32 = static_cast<int32_t>(kNumSubHals);
|
||||||
std::vector<AllSensorsSubHal> subHalObjs(kNumSubHals);
|
std::vector<AllSensorsSubHal<SensorsSubHalV2_0>> subHalObjs(kNumSubHals);
|
||||||
std::vector<ISensorsSubHal*> subHals;
|
std::vector<ISensorsSubHal*> subHals;
|
||||||
for (const auto& subHal : subHalObjs) {
|
for (const auto& subHal : subHalObjs) {
|
||||||
subHals.push_back((ISensorsSubHal*)(&subHal));
|
subHals.push_back((ISensorsSubHal*)(&subHal));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<EventMessageQueue> eventQueue = makeEventFMQ(kQueueSize);
|
std::unique_ptr<EventMessageQueueV2_0> eventQueue = makeEventFMQ(kQueueSize);
|
||||||
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
||||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||||
HalProxy proxy(subHals);
|
HalProxy proxy(subHals);
|
||||||
// Initialize for the injectSensorData call so callback postEvents is valid
|
// Initialize for the injectSensorData call so callback postEvents is valid
|
||||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||||
@@ -687,7 +722,7 @@ TEST(HalProxyTest, InvalidSensorHandleSubHalIndexProxyCalls) {
|
|||||||
EXPECT_EQ(proxy.activate(0x00000001 | (kNumSubHalsInt32 << 24), true), Result::BAD_VALUE);
|
EXPECT_EQ(proxy.activate(0x00000001 | (kNumSubHalsInt32 << 24), true), Result::BAD_VALUE);
|
||||||
EXPECT_EQ(proxy.batch(0x00000001 | (kNumSubHalsInt32 << 24), 0, 0), Result::BAD_VALUE);
|
EXPECT_EQ(proxy.batch(0x00000001 | (kNumSubHalsInt32 << 24), 0, 0), Result::BAD_VALUE);
|
||||||
EXPECT_EQ(proxy.flush(0x00000001 | (kNumSubHalsInt32 << 24)), Result::BAD_VALUE);
|
EXPECT_EQ(proxy.flush(0x00000001 | (kNumSubHalsInt32 << 24)), Result::BAD_VALUE);
|
||||||
Event event;
|
EventV1_0 event;
|
||||||
event.sensorHandle = 0x00000001 | (kNumSubHalsInt32 << 24);
|
event.sensorHandle = 0x00000001 | (kNumSubHalsInt32 << 24);
|
||||||
EXPECT_EQ(proxy.injectSensorData(event), Result::BAD_VALUE);
|
EXPECT_EQ(proxy.injectSensorData(event), Result::BAD_VALUE);
|
||||||
}
|
}
|
||||||
@@ -696,28 +731,28 @@ TEST(HalProxyTest, PostedEventSensorHandleSubHalIndexValid) {
|
|||||||
constexpr size_t kQueueSize = 5;
|
constexpr size_t kQueueSize = 5;
|
||||||
constexpr int32_t subhal1Index = 0;
|
constexpr int32_t subhal1Index = 0;
|
||||||
constexpr int32_t subhal2Index = 1;
|
constexpr int32_t subhal2Index = 1;
|
||||||
AllSensorsSubHal subhal1;
|
AllSensorsSubHal<SensorsSubHalV2_0> subhal1;
|
||||||
AllSensorsSubHal subhal2;
|
AllSensorsSubHal<SensorsSubHalV2_0> subhal2;
|
||||||
std::vector<ISensorsSubHal*> subHals{&subhal1, &subhal2};
|
std::vector<ISensorsSubHal*> subHals{&subhal1, &subhal2};
|
||||||
|
|
||||||
std::unique_ptr<EventMessageQueue> eventQueue = makeEventFMQ(kQueueSize);
|
std::unique_ptr<EventMessageQueueV2_0> eventQueue = makeEventFMQ(kQueueSize);
|
||||||
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
||||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||||
HalProxy proxy(subHals);
|
HalProxy proxy(subHals);
|
||||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||||
|
|
||||||
int32_t sensorHandleToPost = 0x00000001;
|
int32_t sensorHandleToPost = 0x00000001;
|
||||||
Event eventIn = makeAccelerometerEvent();
|
EventV1_0 eventIn = makeAccelerometerEvent();
|
||||||
eventIn.sensorHandle = sensorHandleToPost;
|
eventIn.sensorHandle = sensorHandleToPost;
|
||||||
std::vector<Event> eventsToPost{eventIn};
|
std::vector<EventV1_0> eventsToPost{eventIn};
|
||||||
subhal1.postEvents(eventsToPost, false);
|
subhal1.postEvents(convertToNewEvents(eventsToPost), false);
|
||||||
|
|
||||||
Event eventOut;
|
EventV1_0 eventOut;
|
||||||
EXPECT_TRUE(eventQueue->read(&eventOut));
|
EXPECT_TRUE(eventQueue->read(&eventOut));
|
||||||
|
|
||||||
EXPECT_EQ(eventOut.sensorHandle, (subhal1Index << 24) | sensorHandleToPost);
|
EXPECT_EQ(eventOut.sensorHandle, (subhal1Index << 24) | sensorHandleToPost);
|
||||||
|
|
||||||
subhal2.postEvents(eventsToPost, false);
|
subhal2.postEvents(convertToNewEvents(eventsToPost), false);
|
||||||
|
|
||||||
EXPECT_TRUE(eventQueue->read(&eventOut));
|
EXPECT_TRUE(eventQueue->read(&eventOut));
|
||||||
|
|
||||||
@@ -728,22 +763,22 @@ TEST(HalProxyTest, FillAndDrainPendingQueueTest) {
|
|||||||
constexpr size_t kQueueSize = 5;
|
constexpr size_t kQueueSize = 5;
|
||||||
// TODO: Make this constant linked to same limit in HalProxy.h
|
// TODO: Make this constant linked to same limit in HalProxy.h
|
||||||
constexpr size_t kMaxPendingQueueSize = 100000;
|
constexpr size_t kMaxPendingQueueSize = 100000;
|
||||||
AllSensorsSubHal subhal;
|
AllSensorsSubHal<SensorsSubHalV2_0> subhal;
|
||||||
std::vector<ISensorsSubHal*> subHals{&subhal};
|
std::vector<ISensorsSubHal*> subHals{&subhal};
|
||||||
|
|
||||||
std::unique_ptr<EventMessageQueue> eventQueue = makeEventFMQ(kQueueSize);
|
std::unique_ptr<EventMessageQueueV2_0> eventQueue = makeEventFMQ(kQueueSize);
|
||||||
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
||||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||||
EventFlag* eventQueueFlag;
|
EventFlag* eventQueueFlag;
|
||||||
EventFlag::createEventFlag(eventQueue->getEventFlagWord(), &eventQueueFlag);
|
EventFlag::createEventFlag(eventQueue->getEventFlagWord(), &eventQueueFlag);
|
||||||
HalProxy proxy(subHals);
|
HalProxy proxy(subHals);
|
||||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||||
|
|
||||||
// Fill pending queue
|
// Fill pending queue
|
||||||
std::vector<Event> events = makeMultipleAccelerometerEvents(kQueueSize);
|
std::vector<EventV1_0> events = makeMultipleAccelerometerEvents(kQueueSize);
|
||||||
subhal.postEvents(events, false);
|
subhal.postEvents(convertToNewEvents(events), false);
|
||||||
events = makeMultipleAccelerometerEvents(kMaxPendingQueueSize);
|
events = makeMultipleAccelerometerEvents(kMaxPendingQueueSize);
|
||||||
subhal.postEvents(events, false);
|
subhal.postEvents(convertToNewEvents(events), false);
|
||||||
|
|
||||||
// Drain pending queue
|
// Drain pending queue
|
||||||
for (int i = 0; i < kMaxPendingQueueSize + kQueueSize; i += kQueueSize) {
|
for (int i = 0; i < kMaxPendingQueueSize + kQueueSize; i += kQueueSize) {
|
||||||
@@ -752,9 +787,9 @@ TEST(HalProxyTest, FillAndDrainPendingQueueTest) {
|
|||||||
|
|
||||||
// Put one event on pending queue
|
// Put one event on pending queue
|
||||||
events = makeMultipleAccelerometerEvents(kQueueSize);
|
events = makeMultipleAccelerometerEvents(kQueueSize);
|
||||||
subhal.postEvents(events, false);
|
subhal.postEvents(convertToNewEvents(events), false);
|
||||||
events = {makeAccelerometerEvent()};
|
events = {makeAccelerometerEvent()};
|
||||||
subhal.postEvents(events, false);
|
subhal.postEvents(convertToNewEvents(events), false);
|
||||||
|
|
||||||
// Read out to make room for one event on pending queue to write to FMQ
|
// Read out to make room for one event on pending queue to write to FMQ
|
||||||
ASSERT_TRUE(readEventsOutOfQueue(kQueueSize, eventQueue, eventQueueFlag));
|
ASSERT_TRUE(readEventsOutOfQueue(kQueueSize, eventQueue, eventQueueFlag));
|
||||||
@@ -763,6 +798,35 @@ TEST(HalProxyTest, FillAndDrainPendingQueueTest) {
|
|||||||
EXPECT_TRUE(readEventsOutOfQueue(1, eventQueue, eventQueueFlag));
|
EXPECT_TRUE(readEventsOutOfQueue(1, eventQueue, eventQueueFlag));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(HalProxyTest, PostEventsMultipleSubhalsThreadedV2_1) {
|
||||||
|
constexpr size_t kQueueSize = 5;
|
||||||
|
constexpr size_t kNumEvents = 2;
|
||||||
|
AllSensorsSubHal<SensorsSubHalV2_0> subHal1;
|
||||||
|
AllSensorsSubHal<SensorsSubHalV2_1> subHal2;
|
||||||
|
std::vector<::android::hardware::sensors::V2_0::implementation::ISensorsSubHal*> subHalsV2_0{
|
||||||
|
&subHal1};
|
||||||
|
std::vector<::android::hardware::sensors::V2_1::implementation::ISensorsSubHal*> subHalsV2_1{
|
||||||
|
&subHal2};
|
||||||
|
HalProxy proxy(subHalsV2_0, subHalsV2_1);
|
||||||
|
std::unique_ptr<EventMessageQueueV2_1> eventQueue =
|
||||||
|
std::make_unique<EventMessageQueueV2_1>(kQueueSize, true);
|
||||||
|
std::unique_ptr<WakeupMessageQueue> wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
||||||
|
::android::sp<ISensorsCallbackV2_1> callback = new SensorsCallbackV2_1();
|
||||||
|
proxy.initialize_2_1(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||||
|
|
||||||
|
std::vector<EventV1_0> events = makeMultipleAccelerometerEvents(kNumEvents);
|
||||||
|
|
||||||
|
std::thread t1(&AllSensorsSubHal<SensorsSubHalV2_0>::postEvents, &subHal1,
|
||||||
|
convertToNewEvents(events), false);
|
||||||
|
std::thread t2(&AllSensorsSubHal<SensorsSubHalV2_1>::postEvents, &subHal2,
|
||||||
|
convertToNewEvents(events), false);
|
||||||
|
|
||||||
|
t1.join();
|
||||||
|
t2.join();
|
||||||
|
|
||||||
|
EXPECT_EQ(eventQueue->availableToRead(), kNumEvents * 2);
|
||||||
|
}
|
||||||
|
|
||||||
// Helper implementations follow
|
// Helper implementations follow
|
||||||
void testSensorsListFromProxyAndSubHal(const std::vector<SensorInfo>& proxySensorsList,
|
void testSensorsListFromProxyAndSubHal(const std::vector<SensorInfo>& proxySensorsList,
|
||||||
const std::vector<SensorInfo>& subHalSensorsList) {
|
const std::vector<SensorInfo>& subHalSensorsList) {
|
||||||
@@ -801,26 +865,26 @@ void ackWakeupEventsToHalProxy(size_t numEvents, std::unique_ptr<WakeupMessageQu
|
|||||||
wakelockQueueFlag->wake(static_cast<uint32_t>(WakeLockQueueFlagBits::DATA_WRITTEN));
|
wakelockQueueFlag->wake(static_cast<uint32_t>(WakeLockQueueFlagBits::DATA_WRITTEN));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool readEventsOutOfQueue(size_t numEvents, std::unique_ptr<EventMessageQueue>& eventQueue,
|
bool readEventsOutOfQueue(size_t numEvents, std::unique_ptr<EventMessageQueueV2_0>& eventQueue,
|
||||||
EventFlag* eventQueueFlag) {
|
EventFlag* eventQueueFlag) {
|
||||||
constexpr int64_t kReadBlockingTimeout = INT64_C(500000000);
|
constexpr int64_t kReadBlockingTimeout = INT64_C(500000000);
|
||||||
std::vector<Event> events(numEvents);
|
std::vector<EventV1_0> events(numEvents);
|
||||||
return eventQueue->readBlocking(events.data(), numEvents,
|
return eventQueue->readBlocking(events.data(), numEvents,
|
||||||
static_cast<uint32_t>(EventQueueFlagBits::EVENTS_READ),
|
static_cast<uint32_t>(EventQueueFlagBits::EVENTS_READ),
|
||||||
static_cast<uint32_t>(EventQueueFlagBits::READ_AND_PROCESS),
|
static_cast<uint32_t>(EventQueueFlagBits::READ_AND_PROCESS),
|
||||||
kReadBlockingTimeout, eventQueueFlag);
|
kReadBlockingTimeout, eventQueueFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<EventMessageQueue> makeEventFMQ(size_t size) {
|
std::unique_ptr<EventMessageQueueV2_0> makeEventFMQ(size_t size) {
|
||||||
return std::make_unique<EventMessageQueue>(size, true);
|
return std::make_unique<EventMessageQueueV2_0>(size, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<WakeupMessageQueue> makeWakelockFMQ(size_t size) {
|
std::unique_ptr<WakeupMessageQueue> makeWakelockFMQ(size_t size) {
|
||||||
return std::make_unique<WakeupMessageQueue>(size, true);
|
return std::make_unique<WakeupMessageQueue>(size, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Event makeProximityEvent() {
|
EventV1_0 makeProximityEvent() {
|
||||||
Event event;
|
EventV1_0 event;
|
||||||
event.timestamp = 0xFF00FF00;
|
event.timestamp = 0xFF00FF00;
|
||||||
// This is the sensorhandle of proximity, which is wakeup type
|
// This is the sensorhandle of proximity, which is wakeup type
|
||||||
event.sensorHandle = 0x00000008;
|
event.sensorHandle = 0x00000008;
|
||||||
@@ -829,8 +893,8 @@ Event makeProximityEvent() {
|
|||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
Event makeAccelerometerEvent() {
|
EventV1_0 makeAccelerometerEvent() {
|
||||||
Event event;
|
EventV1_0 event;
|
||||||
event.timestamp = 0xFF00FF00;
|
event.timestamp = 0xFF00FF00;
|
||||||
// This is the sensorhandle of proximity, which is wakeup type
|
// This is the sensorhandle of proximity, which is wakeup type
|
||||||
event.sensorHandle = 0x00000001;
|
event.sensorHandle = 0x00000001;
|
||||||
@@ -839,16 +903,16 @@ Event makeAccelerometerEvent() {
|
|||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Event> makeMultipleProximityEvents(size_t numEvents) {
|
std::vector<EventV1_0> makeMultipleProximityEvents(size_t numEvents) {
|
||||||
std::vector<Event> events;
|
std::vector<EventV1_0> events;
|
||||||
for (size_t i = 0; i < numEvents; i++) {
|
for (size_t i = 0; i < numEvents; i++) {
|
||||||
events.push_back(makeProximityEvent());
|
events.push_back(makeProximityEvent());
|
||||||
}
|
}
|
||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Event> makeMultipleAccelerometerEvents(size_t numEvents) {
|
std::vector<EventV1_0> makeMultipleAccelerometerEvents(size_t numEvents) {
|
||||||
std::vector<Event> events;
|
std::vector<EventV1_0> events;
|
||||||
for (size_t i = 0; i < numEvents; i++) {
|
for (size_t i = 0; i < numEvents; i++) {
|
||||||
events.push_back(makeAccelerometerEvent());
|
events.push_back(makeAccelerometerEvent());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "V2_0/SubHal.h"
|
||||||
|
#include "V2_1/SubHal.h"
|
||||||
|
#include "convertV2_1.h"
|
||||||
|
|
||||||
|
namespace android {
|
||||||
|
namespace hardware {
|
||||||
|
namespace sensors {
|
||||||
|
namespace V2_1 {
|
||||||
|
namespace subhal {
|
||||||
|
namespace implementation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The following callback wrapper classes abstract away common functionality across V2.0 and V2.1
|
||||||
|
* interfaces. Much of the logic is common between the two versions and this allows users of the
|
||||||
|
* classes to only care about the type used at initialization and then interact with either version
|
||||||
|
* of the callback interface without worrying about the type.
|
||||||
|
*/
|
||||||
|
class IHalProxyCallbackWrapperBase {
|
||||||
|
protected:
|
||||||
|
using ScopedWakelock = V2_0::implementation::ScopedWakelock;
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~IHalProxyCallbackWrapperBase() {}
|
||||||
|
|
||||||
|
virtual Return<void> onDynamicSensorsConnected(
|
||||||
|
const hidl_vec<V2_1::SensorInfo>& sensorInfos) = 0;
|
||||||
|
|
||||||
|
virtual Return<void> onDynamicSensorsDisconnected(const hidl_vec<int32_t>& sensorHandles) = 0;
|
||||||
|
|
||||||
|
virtual void postEvents(const std::vector<V2_1::Event>& events, ScopedWakelock wakelock) = 0;
|
||||||
|
|
||||||
|
virtual ScopedWakelock createScopedWakelock(bool lock) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class HalProxyCallbackWrapperBase : public IHalProxyCallbackWrapperBase {
|
||||||
|
public:
|
||||||
|
HalProxyCallbackWrapperBase(sp<T> callback) : mCallback(callback){};
|
||||||
|
|
||||||
|
Return<void> onDynamicSensorsDisconnected(const hidl_vec<int32_t>& sensorHandles) override {
|
||||||
|
return mCallback->onDynamicSensorsDisconnected(sensorHandles);
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedWakelock createScopedWakelock(bool lock) override {
|
||||||
|
return mCallback->createScopedWakelock(lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
sp<T> mCallback;
|
||||||
|
};
|
||||||
|
|
||||||
|
class HalProxyCallbackWrapperV2_0
|
||||||
|
: public HalProxyCallbackWrapperBase<V2_0::implementation::IHalProxyCallback> {
|
||||||
|
public:
|
||||||
|
HalProxyCallbackWrapperV2_0(sp<V2_0::implementation::IHalProxyCallback> callback)
|
||||||
|
: HalProxyCallbackWrapperBase(callback){};
|
||||||
|
|
||||||
|
Return<void> onDynamicSensorsConnected(const hidl_vec<V2_1::SensorInfo>& sensorInfos) override {
|
||||||
|
return mCallback->onDynamicSensorsConnected(
|
||||||
|
V2_1::implementation::convertToOldSensorInfos(sensorInfos));
|
||||||
|
}
|
||||||
|
|
||||||
|
void postEvents(const std::vector<V2_1::Event>& events, ScopedWakelock wakelock) override {
|
||||||
|
return mCallback->postEvents(V2_1::implementation::convertToOldEvents(events),
|
||||||
|
std::move(wakelock));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class HalProxyCallbackWrapperV2_1
|
||||||
|
: public HalProxyCallbackWrapperBase<V2_1::implementation::IHalProxyCallback> {
|
||||||
|
public:
|
||||||
|
HalProxyCallbackWrapperV2_1(sp<V2_1::implementation::IHalProxyCallback> callback)
|
||||||
|
: HalProxyCallbackWrapperBase(callback){};
|
||||||
|
|
||||||
|
Return<void> onDynamicSensorsConnected(const hidl_vec<V2_1::SensorInfo>& sensorInfos) override {
|
||||||
|
return mCallback->onDynamicSensorsConnected_2_1(sensorInfos);
|
||||||
|
}
|
||||||
|
|
||||||
|
void postEvents(const std::vector<V2_1::Event>& events, ScopedWakelock wakelock) {
|
||||||
|
return mCallback->postEvents(events, std::move(wakelock));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace implementation
|
||||||
|
} // namespace subhal
|
||||||
|
} // namespace V2_1
|
||||||
|
} // namespace sensors
|
||||||
|
} // namespace hardware
|
||||||
|
} // namespace android
|
||||||
@@ -24,13 +24,18 @@
|
|||||||
namespace android {
|
namespace android {
|
||||||
namespace hardware {
|
namespace hardware {
|
||||||
namespace sensors {
|
namespace sensors {
|
||||||
namespace V2_0 {
|
namespace V2_1 {
|
||||||
namespace subhal {
|
namespace subhal {
|
||||||
namespace implementation {
|
namespace implementation {
|
||||||
|
|
||||||
using ::android::hardware::sensors::V1_0::MetaDataEventType;
|
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::SensorFlagBits;
|
||||||
using ::android::hardware::sensors::V1_0::SensorStatus;
|
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(int32_t sensorHandle, ISensorsEventCallback* callback)
|
Sensor::Sensor(int32_t sensorHandle, ISensorsEventCallback* callback)
|
||||||
: mIsEnabled(false),
|
: mIsEnabled(false),
|
||||||
@@ -343,7 +348,7 @@ RelativeHumiditySensor::RelativeHumiditySensor(int32_t sensorHandle,
|
|||||||
|
|
||||||
} // namespace implementation
|
} // namespace implementation
|
||||||
} // namespace subhal
|
} // namespace subhal
|
||||||
} // namespace V2_0
|
} // namespace V2_1
|
||||||
} // namespace sensors
|
} // namespace sensors
|
||||||
} // namespace hardware
|
} // namespace hardware
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <android/hardware/sensors/1.0/types.h>
|
#include <android/hardware/sensors/2.1/types.h>
|
||||||
|
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -24,16 +24,16 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using ::android::hardware::sensors::V1_0::Event;
|
|
||||||
using ::android::hardware::sensors::V1_0::OperationMode;
|
using ::android::hardware::sensors::V1_0::OperationMode;
|
||||||
using ::android::hardware::sensors::V1_0::Result;
|
using ::android::hardware::sensors::V1_0::Result;
|
||||||
using ::android::hardware::sensors::V1_0::SensorInfo;
|
using ::android::hardware::sensors::V2_1::Event;
|
||||||
using ::android::hardware::sensors::V1_0::SensorType;
|
using ::android::hardware::sensors::V2_1::SensorInfo;
|
||||||
|
using ::android::hardware::sensors::V2_1::SensorType;
|
||||||
|
|
||||||
namespace android {
|
namespace android {
|
||||||
namespace hardware {
|
namespace hardware {
|
||||||
namespace sensors {
|
namespace sensors {
|
||||||
namespace V2_0 {
|
namespace V2_1 {
|
||||||
namespace subhal {
|
namespace subhal {
|
||||||
namespace implementation {
|
namespace implementation {
|
||||||
|
|
||||||
@@ -151,7 +151,7 @@ class RelativeHumiditySensor : public OnChangeSensor {
|
|||||||
|
|
||||||
} // namespace implementation
|
} // namespace implementation
|
||||||
} // namespace subhal
|
} // namespace subhal
|
||||||
} // namespace V2_0
|
} // namespace V2_1
|
||||||
} // namespace sensors
|
} // namespace sensors
|
||||||
} // namespace hardware
|
} // namespace hardware
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|||||||
@@ -16,33 +16,66 @@
|
|||||||
|
|
||||||
#include "SensorsSubHal.h"
|
#include "SensorsSubHal.h"
|
||||||
|
|
||||||
#include <android/hardware/sensors/2.0/types.h>
|
#include <android/hardware/sensors/2.1/types.h>
|
||||||
#include <log/log.h>
|
#include <log/log.h>
|
||||||
|
|
||||||
ISensorsSubHal* sensorsHalGetSubHal(uint32_t* version) {
|
#ifdef SUB_HAL_VERSION_2_0
|
||||||
|
::android::hardware::sensors::V2_0::implementation::ISensorsSubHal* sensorsHalGetSubHal(
|
||||||
|
uint32_t* version) {
|
||||||
#if defined SUPPORT_CONTINUOUS_SENSORS && defined SUPPORT_ON_CHANGE_SENSORS
|
#if defined SUPPORT_CONTINUOUS_SENSORS && defined SUPPORT_ON_CHANGE_SENSORS
|
||||||
static ::android::hardware::sensors::V2_0::subhal::implementation::AllSensorsSubHal subHal;
|
static ::android::hardware::sensors::V2_1::subhal::implementation::AllSensorsSubHal<
|
||||||
|
::android::hardware::sensors::V2_1::subhal::implementation::SensorsSubHalV2_0>
|
||||||
|
subHal;
|
||||||
#elif defined SUPPORT_CONTINUOUS_SENSORS
|
#elif defined SUPPORT_CONTINUOUS_SENSORS
|
||||||
static ::android::hardware::sensors::V2_0::subhal::implementation::ContinuousSensorsSubHal
|
static ::android::hardware::sensors::V2_1::subhal::implementation::ContinuousSensorsSubHal<
|
||||||
|
::android::hardware::sensors::V2_1::subhal::implementation::SensorsSubHalV2_0>
|
||||||
subHal;
|
subHal;
|
||||||
#elif defined SUPPORT_ON_CHANGE_SENSORS
|
#elif defined SUPPORT_ON_CHANGE_SENSORS
|
||||||
static ::android::hardware::sensors::V2_0::subhal::implementation::OnChangeSensorsSubHal subHal;
|
static ::android::hardware::sensors::V2_1::subhal::implementation::OnChangeSensorsSubHal<
|
||||||
|
::android::hardware::sensors::V2_1::subhal::implementation::SensorsSubHalV2_0>
|
||||||
|
subHal;
|
||||||
#else
|
#else
|
||||||
static ::android::hardware::sensors::V2_0::subhal::implementation::SensorsSubHal subHal;
|
static ::android::hardware::sensors::V2_1::subhal::implementation::SensorsSubHal<
|
||||||
|
::android::hardware::sensors::V2_1::subhal::implementation::SensorsSubHalV2_0>
|
||||||
|
subHal;
|
||||||
#endif // defined SUPPORT_CONTINUOUS_SENSORS && defined SUPPORT_ON_CHANGE_SENSORS
|
#endif // defined SUPPORT_CONTINUOUS_SENSORS && defined SUPPORT_ON_CHANGE_SENSORS
|
||||||
*version = SUB_HAL_2_0_VERSION;
|
*version = SUB_HAL_2_0_VERSION;
|
||||||
return &subHal;
|
return &subHal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else // SUB_HAL_VERSION_2_0
|
||||||
|
|
||||||
|
::android::hardware::sensors::V2_1::implementation::ISensorsSubHal* sensorsHalGetSubHal_2_1(
|
||||||
|
uint32_t* version) {
|
||||||
|
#if defined SUPPORT_CONTINUOUS_SENSORS && defined SUPPORT_ON_CHANGE_SENSORS
|
||||||
|
static ::android::hardware::sensors::V2_1::subhal::implementation::AllSensorsSubHal<
|
||||||
|
::android::hardware::sensors::V2_1::subhal::implementation::SensorsSubHalV2_1>
|
||||||
|
subHal;
|
||||||
|
#elif defined SUPPORT_CONTINUOUS_SENSORS
|
||||||
|
static ::android::hardware::sensors::V2_1::subhal::implementation::ContinuousSensorsSubHal<
|
||||||
|
::android::hardware::sensors::V2_1::subhal::implementation::SensorsSubHalV2_1>
|
||||||
|
subHal;
|
||||||
|
#elif defined SUPPORT_ON_CHANGE_SENSORS
|
||||||
|
static ::android::hardware::sensors::V2_1::subhal::implementation::OnChangeSensorsSubHal<
|
||||||
|
::android::hardware::sensors::V2_1::subhal::implementation::SensorsSubHalV2_1>
|
||||||
|
subHal;
|
||||||
|
#else
|
||||||
|
static ::android::hardware::sensors::V2_1::subhal::implementation::SensorsSubHalV2_1 subHal;
|
||||||
|
#endif // defined SUPPORT_CONTINUOUS_SENSORS && defined SUPPORT_ON_CHANGE_SENSORS
|
||||||
|
*version = SUB_HAL_2_1_VERSION;
|
||||||
|
return &subHal;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SUB_HAL_VERSION_2_0
|
||||||
|
|
||||||
namespace android {
|
namespace android {
|
||||||
namespace hardware {
|
namespace hardware {
|
||||||
namespace sensors {
|
namespace sensors {
|
||||||
namespace V2_0 {
|
namespace V2_1 {
|
||||||
namespace subhal {
|
namespace subhal {
|
||||||
namespace implementation {
|
namespace implementation {
|
||||||
|
|
||||||
using ::android::hardware::Void;
|
using ::android::hardware::Void;
|
||||||
using ::android::hardware::sensors::V1_0::Event;
|
|
||||||
using ::android::hardware::sensors::V1_0::OperationMode;
|
using ::android::hardware::sensors::V1_0::OperationMode;
|
||||||
using ::android::hardware::sensors::V1_0::RateLevel;
|
using ::android::hardware::sensors::V1_0::RateLevel;
|
||||||
using ::android::hardware::sensors::V1_0::Result;
|
using ::android::hardware::sensors::V1_0::Result;
|
||||||
@@ -50,11 +83,12 @@ using ::android::hardware::sensors::V1_0::SharedMemInfo;
|
|||||||
using ::android::hardware::sensors::V2_0::SensorTimeout;
|
using ::android::hardware::sensors::V2_0::SensorTimeout;
|
||||||
using ::android::hardware::sensors::V2_0::WakeLockQueueFlagBits;
|
using ::android::hardware::sensors::V2_0::WakeLockQueueFlagBits;
|
||||||
using ::android::hardware::sensors::V2_0::implementation::ScopedWakelock;
|
using ::android::hardware::sensors::V2_0::implementation::ScopedWakelock;
|
||||||
|
using ::android::hardware::sensors::V2_1::Event;
|
||||||
|
|
||||||
SensorsSubHal::SensorsSubHal() : mCallback(nullptr), mNextHandle(1) {}
|
ISensorsSubHalBase::ISensorsSubHalBase() : mCallback(nullptr), mNextHandle(1) {}
|
||||||
|
|
||||||
// Methods from ::android::hardware::sensors::V2_0::ISensors follow.
|
// Methods from ::android::hardware::sensors::V2_0::ISensors follow.
|
||||||
Return<void> SensorsSubHal::getSensorsList(getSensorsList_cb _hidl_cb) {
|
Return<void> ISensorsSubHalBase::getSensorsList(V2_1::ISensors::getSensorsList_2_1_cb _hidl_cb) {
|
||||||
std::vector<SensorInfo> sensors;
|
std::vector<SensorInfo> sensors;
|
||||||
for (const auto& sensor : mSensors) {
|
for (const auto& sensor : mSensors) {
|
||||||
sensors.push_back(sensor.second->getSensorInfo());
|
sensors.push_back(sensor.second->getSensorInfo());
|
||||||
@@ -64,7 +98,7 @@ Return<void> SensorsSubHal::getSensorsList(getSensorsList_cb _hidl_cb) {
|
|||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<Result> SensorsSubHal::setOperationMode(OperationMode mode) {
|
Return<Result> ISensorsSubHalBase::setOperationMode(OperationMode mode) {
|
||||||
for (auto sensor : mSensors) {
|
for (auto sensor : mSensors) {
|
||||||
sensor.second->setOperationMode(mode);
|
sensor.second->setOperationMode(mode);
|
||||||
}
|
}
|
||||||
@@ -72,7 +106,7 @@ Return<Result> SensorsSubHal::setOperationMode(OperationMode mode) {
|
|||||||
return Result::OK;
|
return Result::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<Result> SensorsSubHal::activate(int32_t sensorHandle, bool enabled) {
|
Return<Result> ISensorsSubHalBase::activate(int32_t sensorHandle, bool enabled) {
|
||||||
auto sensor = mSensors.find(sensorHandle);
|
auto sensor = mSensors.find(sensorHandle);
|
||||||
if (sensor != mSensors.end()) {
|
if (sensor != mSensors.end()) {
|
||||||
sensor->second->activate(enabled);
|
sensor->second->activate(enabled);
|
||||||
@@ -81,8 +115,8 @@ Return<Result> SensorsSubHal::activate(int32_t sensorHandle, bool enabled) {
|
|||||||
return Result::BAD_VALUE;
|
return Result::BAD_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<Result> SensorsSubHal::batch(int32_t sensorHandle, int64_t samplingPeriodNs,
|
Return<Result> ISensorsSubHalBase::batch(int32_t sensorHandle, int64_t samplingPeriodNs,
|
||||||
int64_t /* maxReportLatencyNs */) {
|
int64_t /* maxReportLatencyNs */) {
|
||||||
auto sensor = mSensors.find(sensorHandle);
|
auto sensor = mSensors.find(sensorHandle);
|
||||||
if (sensor != mSensors.end()) {
|
if (sensor != mSensors.end()) {
|
||||||
sensor->second->batch(samplingPeriodNs);
|
sensor->second->batch(samplingPeriodNs);
|
||||||
@@ -91,7 +125,7 @@ Return<Result> SensorsSubHal::batch(int32_t sensorHandle, int64_t samplingPeriod
|
|||||||
return Result::BAD_VALUE;
|
return Result::BAD_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<Result> SensorsSubHal::flush(int32_t sensorHandle) {
|
Return<Result> ISensorsSubHalBase::flush(int32_t sensorHandle) {
|
||||||
auto sensor = mSensors.find(sensorHandle);
|
auto sensor = mSensors.find(sensorHandle);
|
||||||
if (sensor != mSensors.end()) {
|
if (sensor != mSensors.end()) {
|
||||||
return sensor->second->flush();
|
return sensor->second->flush();
|
||||||
@@ -99,7 +133,7 @@ Return<Result> SensorsSubHal::flush(int32_t sensorHandle) {
|
|||||||
return Result::BAD_VALUE;
|
return Result::BAD_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<Result> SensorsSubHal::injectSensorData(const Event& event) {
|
Return<Result> ISensorsSubHalBase::injectSensorData(const Event& event) {
|
||||||
auto sensor = mSensors.find(event.sensorHandle);
|
auto sensor = mSensors.find(event.sensorHandle);
|
||||||
if (sensor != mSensors.end()) {
|
if (sensor != mSensors.end()) {
|
||||||
return sensor->second->injectEvent(event);
|
return sensor->second->injectEvent(event);
|
||||||
@@ -108,24 +142,24 @@ Return<Result> SensorsSubHal::injectSensorData(const Event& event) {
|
|||||||
return Result::BAD_VALUE;
|
return Result::BAD_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<void> SensorsSubHal::registerDirectChannel(const SharedMemInfo& /* mem */,
|
Return<void> ISensorsSubHalBase::registerDirectChannel(
|
||||||
registerDirectChannel_cb _hidl_cb) {
|
const SharedMemInfo& /* mem */, V2_0::ISensors::registerDirectChannel_cb _hidl_cb) {
|
||||||
_hidl_cb(Result::INVALID_OPERATION, -1 /* channelHandle */);
|
_hidl_cb(Result::INVALID_OPERATION, -1 /* channelHandle */);
|
||||||
return Return<void>();
|
return Return<void>();
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<Result> SensorsSubHal::unregisterDirectChannel(int32_t /* channelHandle */) {
|
Return<Result> ISensorsSubHalBase::unregisterDirectChannel(int32_t /* channelHandle */) {
|
||||||
return Result::INVALID_OPERATION;
|
return Result::INVALID_OPERATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<void> SensorsSubHal::configDirectReport(int32_t /* sensorHandle */,
|
Return<void> ISensorsSubHalBase::configDirectReport(
|
||||||
int32_t /* channelHandle */, RateLevel /* rate */,
|
int32_t /* sensorHandle */, int32_t /* channelHandle */, RateLevel /* rate */,
|
||||||
configDirectReport_cb _hidl_cb) {
|
V2_0::ISensors::configDirectReport_cb _hidl_cb) {
|
||||||
_hidl_cb(Result::INVALID_OPERATION, 0 /* reportToken */);
|
_hidl_cb(Result::INVALID_OPERATION, 0 /* reportToken */);
|
||||||
return Return<void>();
|
return Return<void>();
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<void> SensorsSubHal::debug(const hidl_handle& fd, const hidl_vec<hidl_string>& args) {
|
Return<void> ISensorsSubHalBase::debug(const hidl_handle& fd, const hidl_vec<hidl_string>& args) {
|
||||||
if (fd.getNativeHandle() == nullptr || fd->numFds < 1) {
|
if (fd.getNativeHandle() == nullptr || fd->numFds < 1) {
|
||||||
ALOGE("%s: missing fd for writing", __FUNCTION__);
|
ALOGE("%s: missing fd for writing", __FUNCTION__);
|
||||||
return Void();
|
return Void();
|
||||||
@@ -156,44 +190,18 @@ Return<void> SensorsSubHal::debug(const hidl_handle& fd, const hidl_vec<hidl_str
|
|||||||
return Return<void>();
|
return Return<void>();
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<Result> SensorsSubHal::initialize(const sp<IHalProxyCallback>& halProxyCallback) {
|
Return<Result> ISensorsSubHalBase::initialize(
|
||||||
mCallback = halProxyCallback;
|
std::unique_ptr<IHalProxyCallbackWrapperBase>& halProxyCallback) {
|
||||||
|
mCallback = std::move(halProxyCallback);
|
||||||
setOperationMode(OperationMode::NORMAL);
|
setOperationMode(OperationMode::NORMAL);
|
||||||
return Result::OK;
|
return Result::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SensorsSubHal::postEvents(const std::vector<Event>& events, bool wakeup) {
|
void ISensorsSubHalBase::postEvents(const std::vector<Event>& events, bool wakeup) {
|
||||||
ScopedWakelock wakelock = mCallback->createScopedWakelock(wakeup);
|
ScopedWakelock wakelock = mCallback->createScopedWakelock(wakeup);
|
||||||
mCallback->postEvents(events, std::move(wakelock));
|
mCallback->postEvents(events, std::move(wakelock));
|
||||||
}
|
}
|
||||||
|
|
||||||
ContinuousSensorsSubHal::ContinuousSensorsSubHal() {
|
|
||||||
AddSensor<AccelSensor>();
|
|
||||||
AddSensor<GyroSensor>();
|
|
||||||
AddSensor<MagnetometerSensor>();
|
|
||||||
AddSensor<PressureSensor>();
|
|
||||||
AddSensor<DeviceTempSensor>();
|
|
||||||
}
|
|
||||||
|
|
||||||
OnChangeSensorsSubHal::OnChangeSensorsSubHal() {
|
|
||||||
AddSensor<AmbientTempSensor>();
|
|
||||||
AddSensor<LightSensor>();
|
|
||||||
AddSensor<ProximitySensor>();
|
|
||||||
AddSensor<RelativeHumiditySensor>();
|
|
||||||
}
|
|
||||||
|
|
||||||
AllSensorsSubHal::AllSensorsSubHal() {
|
|
||||||
AddSensor<AccelSensor>();
|
|
||||||
AddSensor<GyroSensor>();
|
|
||||||
AddSensor<MagnetometerSensor>();
|
|
||||||
AddSensor<PressureSensor>();
|
|
||||||
AddSensor<DeviceTempSensor>();
|
|
||||||
AddSensor<AmbientTempSensor>();
|
|
||||||
AddSensor<LightSensor>();
|
|
||||||
AddSensor<ProximitySensor>();
|
|
||||||
AddSensor<RelativeHumiditySensor>();
|
|
||||||
}
|
|
||||||
|
|
||||||
Return<Result> SetOperationModeFailingSensorsSubHal::setOperationMode(OperationMode /*mode*/) {
|
Return<Result> SetOperationModeFailingSensorsSubHal::setOperationMode(OperationMode /*mode*/) {
|
||||||
return Result::BAD_VALUE;
|
return Result::BAD_VALUE;
|
||||||
}
|
}
|
||||||
@@ -206,7 +214,7 @@ Return<void> AllSupportDirectChannelSensorsSubHal::getSensorsList(getSensorsList
|
|||||||
sensorInfo.flags |= V1_0::SensorFlagBits::MASK_DIRECT_REPORT;
|
sensorInfo.flags |= V1_0::SensorFlagBits::MASK_DIRECT_REPORT;
|
||||||
sensors.push_back(sensorInfo);
|
sensors.push_back(sensorInfo);
|
||||||
}
|
}
|
||||||
_hidl_cb(sensors);
|
_hidl_cb(V2_1::implementation::convertToOldSensorInfos(sensors));
|
||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,7 +226,7 @@ Return<void> DoesNotSupportDirectChannelSensorsSubHal::getSensorsList(getSensors
|
|||||||
sensorInfo.flags &= ~static_cast<uint32_t>(V1_0::SensorFlagBits::MASK_DIRECT_REPORT);
|
sensorInfo.flags &= ~static_cast<uint32_t>(V1_0::SensorFlagBits::MASK_DIRECT_REPORT);
|
||||||
sensors.push_back(sensorInfo);
|
sensors.push_back(sensorInfo);
|
||||||
}
|
}
|
||||||
_hidl_cb(sensors);
|
_hidl_cb(V2_1::implementation::convertToOldSensorInfos(sensors));
|
||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,7 +242,7 @@ void AddAndRemoveDynamicSensorsSubHal::removeDynamicSensors(
|
|||||||
|
|
||||||
} // namespace implementation
|
} // namespace implementation
|
||||||
} // namespace subhal
|
} // namespace subhal
|
||||||
} // namespace V2_0
|
} // namespace V2_1
|
||||||
} // namespace sensors
|
} // namespace sensors
|
||||||
} // namespace hardware
|
} // namespace hardware
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|||||||
@@ -17,7 +17,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "V2_0/SubHal.h"
|
#include "V2_0/SubHal.h"
|
||||||
|
#include "V2_1/SubHal.h"
|
||||||
|
|
||||||
|
#include "IHalProxyCallbackWrapper.h"
|
||||||
#include "Sensor.h"
|
#include "Sensor.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -25,54 +27,54 @@
|
|||||||
namespace android {
|
namespace android {
|
||||||
namespace hardware {
|
namespace hardware {
|
||||||
namespace sensors {
|
namespace sensors {
|
||||||
namespace V2_0 {
|
namespace V2_1 {
|
||||||
namespace subhal {
|
namespace subhal {
|
||||||
namespace implementation {
|
namespace implementation {
|
||||||
|
|
||||||
using ::android::hardware::sensors::V1_0::OperationMode;
|
using ::android::hardware::sensors::V1_0::OperationMode;
|
||||||
using ::android::hardware::sensors::V1_0::Result;
|
using ::android::hardware::sensors::V1_0::Result;
|
||||||
using ::android::hardware::sensors::V2_0::implementation::IHalProxyCallback;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of a ISensorsSubHal that can be used to test the implementation of multihal 2.0.
|
* Implementation of a ISensorsSubHal that can be used to test the implementation of multihal 2.0.
|
||||||
* See the README file for more details on how this class can be used for testing.
|
* See the README file for more details on how this class can be used for testing.
|
||||||
*/
|
*/
|
||||||
class SensorsSubHal : public ISensorsSubHal, public ISensorsEventCallback {
|
class ISensorsSubHalBase : public ISensorsEventCallback {
|
||||||
using Event = ::android::hardware::sensors::V1_0::Event;
|
protected:
|
||||||
|
using Event = ::android::hardware::sensors::V2_1::Event;
|
||||||
using RateLevel = ::android::hardware::sensors::V1_0::RateLevel;
|
using RateLevel = ::android::hardware::sensors::V1_0::RateLevel;
|
||||||
using SharedMemInfo = ::android::hardware::sensors::V1_0::SharedMemInfo;
|
using SharedMemInfo = ::android::hardware::sensors::V1_0::SharedMemInfo;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SensorsSubHal();
|
ISensorsSubHalBase();
|
||||||
|
|
||||||
|
Return<void> getSensorsList(V2_1::ISensors::getSensorsList_2_1_cb _hidl_cb);
|
||||||
|
Return<Result> injectSensorData(const Event& event);
|
||||||
|
Return<Result> initialize(std::unique_ptr<IHalProxyCallbackWrapperBase>& halProxyCallback);
|
||||||
|
|
||||||
// Methods from ::android::hardware::sensors::V2_0::ISensors follow.
|
// Methods from ::android::hardware::sensors::V2_0::ISensors follow.
|
||||||
virtual Return<void> getSensorsList(getSensorsList_cb _hidl_cb) override;
|
virtual Return<Result> setOperationMode(OperationMode mode);
|
||||||
|
|
||||||
virtual Return<Result> setOperationMode(OperationMode mode) override;
|
|
||||||
|
|
||||||
OperationMode getOperationMode() const { return mCurrentOperationMode; }
|
OperationMode getOperationMode() const { return mCurrentOperationMode; }
|
||||||
|
|
||||||
Return<Result> activate(int32_t sensorHandle, bool enabled) override;
|
Return<Result> activate(int32_t sensorHandle, bool enabled);
|
||||||
|
|
||||||
Return<Result> batch(int32_t sensorHandle, int64_t samplingPeriodNs,
|
Return<Result> batch(int32_t sensorHandle, int64_t samplingPeriodNs,
|
||||||
int64_t maxReportLatencyNs) override;
|
int64_t maxReportLatencyNs);
|
||||||
|
|
||||||
Return<Result> flush(int32_t sensorHandle) override;
|
Return<Result> flush(int32_t sensorHandle);
|
||||||
|
|
||||||
Return<Result> injectSensorData(const Event& event) override;
|
|
||||||
|
|
||||||
Return<void> registerDirectChannel(const SharedMemInfo& mem,
|
Return<void> registerDirectChannel(const SharedMemInfo& mem,
|
||||||
registerDirectChannel_cb _hidl_cb) override;
|
V2_0::ISensors::registerDirectChannel_cb _hidl_cb);
|
||||||
|
|
||||||
Return<Result> unregisterDirectChannel(int32_t channelHandle) override;
|
Return<Result> unregisterDirectChannel(int32_t channelHandle);
|
||||||
|
|
||||||
Return<void> configDirectReport(int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
|
Return<void> configDirectReport(int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
|
||||||
configDirectReport_cb _hidl_cb) override;
|
V2_0::ISensors::configDirectReport_cb _hidl_cb);
|
||||||
|
|
||||||
Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& args) override;
|
Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& args);
|
||||||
|
|
||||||
// Methods from ::android::hardware::sensors::V2_0::implementation::ISensorsSubHal follow.
|
// Methods from ::android::hardware::sensors::V2_0::implementation::ISensorsSubHal follow.
|
||||||
const std::string getName() override {
|
const std::string getName() {
|
||||||
#ifdef SUB_HAL_NAME
|
#ifdef SUB_HAL_NAME
|
||||||
return SUB_HAL_NAME;
|
return SUB_HAL_NAME;
|
||||||
#else // SUB_HAL_NAME
|
#else // SUB_HAL_NAME
|
||||||
@@ -80,8 +82,6 @@ class SensorsSubHal : public ISensorsSubHal, public ISensorsEventCallback {
|
|||||||
#endif // SUB_HAL_NAME
|
#endif // SUB_HAL_NAME
|
||||||
}
|
}
|
||||||
|
|
||||||
Return<Result> initialize(const sp<IHalProxyCallback>& halProxyCallback) override;
|
|
||||||
|
|
||||||
// Method from ISensorsEventCallback.
|
// Method from ISensorsEventCallback.
|
||||||
void postEvents(const std::vector<Event>& events, bool wakeup) override;
|
void postEvents(const std::vector<Event>& events, bool wakeup) override;
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ class SensorsSubHal : public ISensorsSubHal, public ISensorsEventCallback {
|
|||||||
* disconnected, sensor events need to be sent to the framework, and when a wakelock should be
|
* disconnected, sensor events need to be sent to the framework, and when a wakelock should be
|
||||||
* acquired.
|
* acquired.
|
||||||
*/
|
*/
|
||||||
sp<IHalProxyCallback> mCallback;
|
std::unique_ptr<IHalProxyCallbackWrapperBase> mCallback;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
@@ -118,40 +118,143 @@ class SensorsSubHal : public ISensorsSubHal, public ISensorsEventCallback {
|
|||||||
int32_t mNextHandle;
|
int32_t mNextHandle;
|
||||||
};
|
};
|
||||||
|
|
||||||
// SubHal that has continuous sensors for testing purposes.
|
template <class SubHalClass>
|
||||||
class ContinuousSensorsSubHal : public SensorsSubHal {
|
class SensorsSubHalBase : public ISensorsSubHalBase, public SubHalClass {
|
||||||
public:
|
public:
|
||||||
ContinuousSensorsSubHal();
|
Return<Result> setOperationMode(OperationMode mode) override {
|
||||||
|
return ISensorsSubHalBase::setOperationMode(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<Result> activate(int32_t sensorHandle, bool enabled) override {
|
||||||
|
return ISensorsSubHalBase::activate(sensorHandle, enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<Result> batch(int32_t sensorHandle, int64_t samplingPeriodNs,
|
||||||
|
int64_t maxReportLatencyNs) override {
|
||||||
|
return ISensorsSubHalBase::batch(sensorHandle, samplingPeriodNs, maxReportLatencyNs);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<Result> flush(int32_t sensorHandle) override {
|
||||||
|
return ISensorsSubHalBase::flush(sensorHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> registerDirectChannel(const SharedMemInfo& mem,
|
||||||
|
V2_0::ISensors::registerDirectChannel_cb _hidl_cb) override {
|
||||||
|
return ISensorsSubHalBase::registerDirectChannel(mem, _hidl_cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<Result> unregisterDirectChannel(int32_t channelHandle) override {
|
||||||
|
return ISensorsSubHalBase::unregisterDirectChannel(channelHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> configDirectReport(int32_t sensorHandle, int32_t channelHandle, RateLevel rate,
|
||||||
|
V2_0::ISensors::configDirectReport_cb _hidl_cb) override {
|
||||||
|
return ISensorsSubHalBase::configDirectReport(sensorHandle, channelHandle, rate, _hidl_cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& args) override {
|
||||||
|
return ISensorsSubHalBase::debug(fd, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string getName() override { return ISensorsSubHalBase::getName(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
class SensorsSubHalV2_0 : public SensorsSubHalBase<V2_0::implementation::ISensorsSubHal> {
|
||||||
|
public:
|
||||||
|
virtual Return<void> getSensorsList(V2_0::ISensors::getSensorsList_cb _hidl_cb) override {
|
||||||
|
return ISensorsSubHalBase::getSensorsList([&](const auto& list) {
|
||||||
|
_hidl_cb(V2_1::implementation::convertToOldSensorInfos(list));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<Result> injectSensorData(const V1_0::Event& event) override {
|
||||||
|
return ISensorsSubHalBase::injectSensorData(V2_1::implementation::convertToNewEvent(event));
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<Result> initialize(
|
||||||
|
const sp<V2_0::implementation::IHalProxyCallback>& halProxyCallback) override {
|
||||||
|
std::unique_ptr<IHalProxyCallbackWrapperBase> wrapper =
|
||||||
|
std::make_unique<HalProxyCallbackWrapperV2_0>(halProxyCallback);
|
||||||
|
return ISensorsSubHalBase::initialize(wrapper);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class SensorsSubHalV2_1 : public SensorsSubHalBase<V2_1::implementation::ISensorsSubHal> {
|
||||||
|
public:
|
||||||
|
Return<void> getSensorsList_2_1(V2_1::ISensors::getSensorsList_2_1_cb _hidl_cb) override {
|
||||||
|
return ISensorsSubHalBase::getSensorsList(_hidl_cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<Result> injectSensorData_2_1(const V2_1::Event& event) override {
|
||||||
|
return ISensorsSubHalBase::injectSensorData(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<Result> initialize(
|
||||||
|
const sp<V2_1::implementation::IHalProxyCallback>& halProxyCallback) override {
|
||||||
|
std::unique_ptr<IHalProxyCallbackWrapperBase> wrapper =
|
||||||
|
std::make_unique<HalProxyCallbackWrapperV2_1>(halProxyCallback);
|
||||||
|
return ISensorsSubHalBase::initialize(wrapper);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// SubHal that has continuous sensors for testing purposes.
|
||||||
|
template <class SubHalVersion>
|
||||||
|
class ContinuousSensorsSubHal : public SubHalVersion {
|
||||||
|
public:
|
||||||
|
ContinuousSensorsSubHal() {
|
||||||
|
ISensorsSubHalBase::AddSensor<AccelSensor>();
|
||||||
|
ISensorsSubHalBase::AddSensor<GyroSensor>();
|
||||||
|
ISensorsSubHalBase::AddSensor<MagnetometerSensor>();
|
||||||
|
ISensorsSubHalBase::AddSensor<PressureSensor>();
|
||||||
|
ISensorsSubHalBase::AddSensor<DeviceTempSensor>();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// SubHal that has on-change sensors for testing purposes.
|
// SubHal that has on-change sensors for testing purposes.
|
||||||
class OnChangeSensorsSubHal : public SensorsSubHal {
|
template <class SubHalVersion>
|
||||||
|
class OnChangeSensorsSubHal : public SubHalVersion {
|
||||||
public:
|
public:
|
||||||
OnChangeSensorsSubHal();
|
OnChangeSensorsSubHal() {
|
||||||
|
ISensorsSubHalBase::AddSensor<AmbientTempSensor>();
|
||||||
|
ISensorsSubHalBase::AddSensor<LightSensor>();
|
||||||
|
ISensorsSubHalBase::AddSensor<ProximitySensor>();
|
||||||
|
ISensorsSubHalBase::AddSensor<RelativeHumiditySensor>();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// SubHal that has both continuous and on-change sensors for testing purposes.
|
// SubHal that has both continuous and on-change sensors for testing purposes.
|
||||||
class AllSensorsSubHal : public SensorsSubHal {
|
template <class SubHalVersion>
|
||||||
|
class AllSensorsSubHal : public SubHalVersion {
|
||||||
public:
|
public:
|
||||||
AllSensorsSubHal();
|
AllSensorsSubHal() {
|
||||||
|
ISensorsSubHalBase::AddSensor<AccelSensor>();
|
||||||
|
ISensorsSubHalBase::AddSensor<GyroSensor>();
|
||||||
|
ISensorsSubHalBase::AddSensor<MagnetometerSensor>();
|
||||||
|
ISensorsSubHalBase::AddSensor<PressureSensor>();
|
||||||
|
ISensorsSubHalBase::AddSensor<DeviceTempSensor>();
|
||||||
|
ISensorsSubHalBase::AddSensor<AmbientTempSensor>();
|
||||||
|
ISensorsSubHalBase::AddSensor<LightSensor>();
|
||||||
|
ISensorsSubHalBase::AddSensor<ProximitySensor>();
|
||||||
|
ISensorsSubHalBase::AddSensor<RelativeHumiditySensor>();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class SetOperationModeFailingSensorsSubHal : public AllSensorsSubHal {
|
class SetOperationModeFailingSensorsSubHal : public AllSensorsSubHal<SensorsSubHalV2_0> {
|
||||||
public:
|
public:
|
||||||
Return<Result> setOperationMode(OperationMode mode) override;
|
Return<Result> setOperationMode(OperationMode mode) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AllSupportDirectChannelSensorsSubHal : public AllSensorsSubHal {
|
class AllSupportDirectChannelSensorsSubHal : public AllSensorsSubHal<SensorsSubHalV2_0> {
|
||||||
public:
|
public:
|
||||||
Return<void> getSensorsList(getSensorsList_cb _hidl_cb) override;
|
Return<void> getSensorsList(V2_0::ISensors::getSensorsList_cb _hidl_cb) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DoesNotSupportDirectChannelSensorsSubHal : public AllSensorsSubHal {
|
class DoesNotSupportDirectChannelSensorsSubHal : public AllSensorsSubHal<SensorsSubHalV2_0> {
|
||||||
public:
|
public:
|
||||||
Return<void> getSensorsList(getSensorsList_cb _hidl_cb) override;
|
Return<void> getSensorsList(V2_0::ISensors::getSensorsList_cb _hidl_cb) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AddAndRemoveDynamicSensorsSubHal : public AllSensorsSubHal {
|
class AddAndRemoveDynamicSensorsSubHal : public AllSensorsSubHal<SensorsSubHalV2_0> {
|
||||||
public:
|
public:
|
||||||
void addDynamicSensors(const std::vector<SensorInfo>& sensorsAdded);
|
void addDynamicSensors(const std::vector<SensorInfo>& sensorsAdded);
|
||||||
void removeDynamicSensors(const std::vector<int32_t>& sensorHandlesAdded);
|
void removeDynamicSensors(const std::vector<int32_t>& sensorHandlesAdded);
|
||||||
@@ -159,7 +262,7 @@ class AddAndRemoveDynamicSensorsSubHal : public AllSensorsSubHal {
|
|||||||
|
|
||||||
} // namespace implementation
|
} // namespace implementation
|
||||||
} // namespace subhal
|
} // namespace subhal
|
||||||
} // namespace V2_0
|
} // namespace V2_1
|
||||||
} // namespace sensors
|
} // namespace sensors
|
||||||
} // namespace hardware
|
} // namespace hardware
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|||||||
@@ -39,8 +39,14 @@ class EventMessageQueueWrapperBase : public RefBase {
|
|||||||
|
|
||||||
virtual std::atomic<uint32_t>* getEventFlagWord() = 0;
|
virtual std::atomic<uint32_t>* getEventFlagWord() = 0;
|
||||||
virtual size_t availableToRead() = 0;
|
virtual size_t availableToRead() = 0;
|
||||||
|
virtual size_t availableToWrite() = 0;
|
||||||
virtual bool read(V2_1::Event* events, size_t numToRead) = 0;
|
virtual bool read(V2_1::Event* events, size_t numToRead) = 0;
|
||||||
|
virtual bool write(const V2_1::Event* events, size_t numToWrite) = 0;
|
||||||
virtual bool write(const std::vector<V2_1::Event>& events) = 0;
|
virtual bool write(const std::vector<V2_1::Event>& events) = 0;
|
||||||
|
virtual bool writeBlocking(const V2_1::Event* events, size_t count, uint32_t readNotification,
|
||||||
|
uint32_t writeNotification, int64_t timeOutNanos,
|
||||||
|
android::hardware::EventFlag* evFlag) = 0;
|
||||||
|
virtual size_t getQuantumCount() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class EventMessageQueueWrapperV1_0 : public EventMessageQueueWrapperBase {
|
class EventMessageQueueWrapperV1_0 : public EventMessageQueueWrapperBase {
|
||||||
@@ -60,15 +66,30 @@ class EventMessageQueueWrapperV1_0 : public EventMessageQueueWrapperBase {
|
|||||||
|
|
||||||
virtual size_t availableToRead() override { return mQueue->availableToRead(); }
|
virtual size_t availableToRead() override { return mQueue->availableToRead(); }
|
||||||
|
|
||||||
|
size_t availableToWrite() override { return mQueue->availableToWrite(); }
|
||||||
|
|
||||||
virtual bool read(V2_1::Event* events, size_t numToRead) override {
|
virtual bool read(V2_1::Event* events, size_t numToRead) override {
|
||||||
return mQueue->read(reinterpret_cast<V1_0::Event*>(events), numToRead);
|
return mQueue->read(reinterpret_cast<V1_0::Event*>(events), numToRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool write(const V2_1::Event* events, size_t numToWrite) override {
|
||||||
|
return mQueue->write(reinterpret_cast<const V1_0::Event*>(events), numToWrite);
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool write(const std::vector<V2_1::Event>& events) override {
|
virtual bool write(const std::vector<V2_1::Event>& events) override {
|
||||||
const std::vector<V1_0::Event>& oldEvents = convertToOldEvents(events);
|
const std::vector<V1_0::Event>& oldEvents = convertToOldEvents(events);
|
||||||
return mQueue->write(oldEvents.data(), oldEvents.size());
|
return mQueue->write(oldEvents.data(), oldEvents.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool writeBlocking(const V2_1::Event* events, size_t count, uint32_t readNotification,
|
||||||
|
uint32_t writeNotification, int64_t timeOutNanos,
|
||||||
|
android::hardware::EventFlag* evFlag) override {
|
||||||
|
return mQueue->writeBlocking(reinterpret_cast<const V1_0::Event*>(events), count,
|
||||||
|
readNotification, writeNotification, timeOutNanos, evFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t getQuantumCount() override { return mQueue->getQuantumCount(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<EventMessageQueue> mQueue;
|
std::unique_ptr<EventMessageQueue> mQueue;
|
||||||
};
|
};
|
||||||
@@ -88,14 +109,29 @@ class EventMessageQueueWrapperV2_1 : public EventMessageQueueWrapperBase {
|
|||||||
|
|
||||||
virtual size_t availableToRead() override { return mQueue->availableToRead(); }
|
virtual size_t availableToRead() override { return mQueue->availableToRead(); }
|
||||||
|
|
||||||
|
size_t availableToWrite() override { return mQueue->availableToWrite(); }
|
||||||
|
|
||||||
virtual bool read(V2_1::Event* events, size_t numToRead) override {
|
virtual bool read(V2_1::Event* events, size_t numToRead) override {
|
||||||
return mQueue->read(events, numToRead);
|
return mQueue->read(events, numToRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool write(const V2_1::Event* events, size_t numToWrite) override {
|
||||||
|
return mQueue->write(events, numToWrite);
|
||||||
|
}
|
||||||
|
|
||||||
bool write(const std::vector<V2_1::Event>& events) override {
|
bool write(const std::vector<V2_1::Event>& events) override {
|
||||||
return mQueue->write(events.data(), events.size());
|
return mQueue->write(events.data(), events.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool writeBlocking(const V2_1::Event* events, size_t count, uint32_t readNotification,
|
||||||
|
uint32_t writeNotification, int64_t timeOutNanos,
|
||||||
|
android::hardware::EventFlag* evFlag) override {
|
||||||
|
return mQueue->writeBlocking(events, count, readNotification, writeNotification,
|
||||||
|
timeOutNanos, evFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t getQuantumCount() override { return mQueue->getQuantumCount(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<EventMessageQueue> mQueue;
|
std::unique_ptr<EventMessageQueue> mQueue;
|
||||||
};
|
};
|
||||||
|
|||||||
96
sensors/common/utils/ISensorsCallbackWrapper.h
Normal file
96
sensors/common/utils/ISensorsCallbackWrapper.h
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* 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 ANDROID_HARDWARE_SENSORS_V2_1_ISENSORSCALLBACKWRAPPER_H
|
||||||
|
#define ANDROID_HARDWARE_SENSORS_V2_1_ISENSORSCALLBACKWRAPPER_H
|
||||||
|
|
||||||
|
#include "convertV2_1.h"
|
||||||
|
|
||||||
|
#include "android/hardware/sensors/1.0/ISensors.h"
|
||||||
|
#include "android/hardware/sensors/1.0/types.h"
|
||||||
|
#include "android/hardware/sensors/2.0/ISensors.h"
|
||||||
|
#include "android/hardware/sensors/2.0/ISensorsCallback.h"
|
||||||
|
#include "android/hardware/sensors/2.1/ISensors.h"
|
||||||
|
#include "android/hardware/sensors/2.1/ISensorsCallback.h"
|
||||||
|
#include "android/hardware/sensors/2.1/types.h"
|
||||||
|
|
||||||
|
#include <utils/LightRefBase.h>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
namespace android {
|
||||||
|
namespace hardware {
|
||||||
|
namespace sensors {
|
||||||
|
namespace V2_1 {
|
||||||
|
namespace implementation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ISensorsCallbackWrapper classes below abstract away the common logic between both the V2.0
|
||||||
|
* and V2.1 versions of the Sensors HAL interface. This allows users of these classes to only care
|
||||||
|
* about the HAL version at init time and then interact with either version of the callback without
|
||||||
|
* worrying about the class type by utilizing the base class.
|
||||||
|
*/
|
||||||
|
class ISensorsCallbackWrapperBase : public VirtualLightRefBase {
|
||||||
|
public:
|
||||||
|
virtual Return<void> onDynamicSensorsConnected(
|
||||||
|
const hidl_vec<V2_1::SensorInfo>& sensorInfos) = 0;
|
||||||
|
|
||||||
|
virtual Return<void> onDynamicSensorsDisconnected(const hidl_vec<int32_t>& sensorHandles) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class SensorsCallbackWrapperBase : public ISensorsCallbackWrapperBase {
|
||||||
|
public:
|
||||||
|
SensorsCallbackWrapperBase(sp<T> sensorsCallback) : mSensorsCallback(sensorsCallback){};
|
||||||
|
|
||||||
|
virtual Return<void> onDynamicSensorsConnected(
|
||||||
|
const hidl_vec<V2_1::SensorInfo>& sensorInfos) override {
|
||||||
|
return mSensorsCallback->onDynamicSensorsConnected(convertToOldSensorInfos(sensorInfos));
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> onDynamicSensorsDisconnected(const hidl_vec<int32_t>& sensorHandles) {
|
||||||
|
return mSensorsCallback->onDynamicSensorsDisconnected(sensorHandles);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
sp<T> mSensorsCallback;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ISensorsCallbackWrapperV2_0
|
||||||
|
: public SensorsCallbackWrapperBase<hardware::sensors::V2_0::ISensorsCallback> {
|
||||||
|
public:
|
||||||
|
ISensorsCallbackWrapperV2_0(sp<hardware::sensors::V2_0::ISensorsCallback> sensorsCallback)
|
||||||
|
: SensorsCallbackWrapperBase(sensorsCallback){};
|
||||||
|
};
|
||||||
|
|
||||||
|
class ISensorsCallbackWrapperV2_1
|
||||||
|
: public SensorsCallbackWrapperBase<hardware::sensors::V2_1::ISensorsCallback> {
|
||||||
|
public:
|
||||||
|
ISensorsCallbackWrapperV2_1(sp<hardware::sensors::V2_1::ISensorsCallback> sensorsCallback)
|
||||||
|
: SensorsCallbackWrapperBase(sensorsCallback) {}
|
||||||
|
|
||||||
|
Return<void> onDynamicSensorsConnected(const hidl_vec<V2_1::SensorInfo>& sensorInfos) override {
|
||||||
|
return mSensorsCallback->onDynamicSensorsConnected_2_1(sensorInfos);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace implementation
|
||||||
|
} // namespace V2_1
|
||||||
|
} // namespace sensors
|
||||||
|
} // namespace hardware
|
||||||
|
} // namespace android
|
||||||
|
|
||||||
|
#endif // ANDROID_HARDWARE_SENSORS_V2_1_ISENSORSCALLBACKWRAPPER_H
|
||||||
Reference in New Issue
Block a user