V2: Update tests for multihal to test HAL 2.1
Updates tests and fake subhals to support Multi-HAL 2.1 to make on-device testing feasible. Bug: 149758467 Test: Verify that the new unit tests and subhals in this topic load and run on a Pixel device Change-Id: I7a9d7c1678826bb1956119e8b76f591c7bc213e1
This commit is contained in:
parent
199b5ff96a
commit
7a21c53268
7 changed files with 531 additions and 233 deletions
|
@ -50,6 +50,7 @@ cc_library {
|
|||
vendor: true,
|
||||
defaults: ["android.hardware.sensors@2.X-fakesubhal-defaults"],
|
||||
cflags: [
|
||||
"-DSUB_HAL_VERSION_2_0",
|
||||
"-DSUPPORT_CONTINUOUS_SENSORS",
|
||||
"-DSUB_HAL_NAME=\"FakeSubHal-Continuous\"",
|
||||
],
|
||||
|
@ -59,6 +60,17 @@ cc_library {
|
|||
name: "android.hardware.sensors@2.X-fakesubhal-config2",
|
||||
vendor: true,
|
||||
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: [
|
||||
"-DSUPPORT_ON_CHANGE_SENSORS",
|
||||
"-DSUB_HAL_NAME=\"FakeSubHal-OnChange\"",
|
||||
|
|
|
@ -15,12 +15,15 @@
|
|||
|
||||
#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.1/types.h>
|
||||
#include <fmq/MessageQueue.h>
|
||||
|
||||
#include "HalProxy.h"
|
||||
#include "SensorsSubHal.h"
|
||||
#include "V2_0/ScopedWakelock.h"
|
||||
#include "convertV2_1.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <set>
|
||||
|
@ -38,28 +41,35 @@ using ::android::hardware::sensors::V1_0::SensorFlagBits;
|
|||
using ::android::hardware::sensors::V1_0::SensorInfo;
|
||||
using ::android::hardware::sensors::V1_0::SensorType;
|
||||
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::implementation::HalProxyCallbackBase;
|
||||
using ::android::hardware::sensors::V2_0::implementation::ScopedWakelock;
|
||||
using ::android::hardware::sensors::V2_0::subhal::implementation::AddAndRemoveDynamicSensorsSubHal;
|
||||
using ::android::hardware::sensors::V2_0::subhal::implementation::AllSensorsSubHal;
|
||||
using ::android::hardware::sensors::V2_0::subhal::implementation::
|
||||
AllSupportDirectChannelSensorsSubHal;
|
||||
using ::android::hardware::sensors::V2_0::subhal::implementation::ContinuousSensorsSubHal;
|
||||
using ::android::hardware::sensors::V2_0::subhal::implementation::
|
||||
DoesNotSupportDirectChannelSensorsSubHal;
|
||||
using ::android::hardware::sensors::V2_0::subhal::implementation::OnChangeSensorsSubHal;
|
||||
using ::android::hardware::sensors::V2_0::subhal::implementation::SensorsSubHal;
|
||||
using ::android::hardware::sensors::V2_0::subhal::implementation::
|
||||
SetOperationModeFailingSensorsSubHal;
|
||||
using ::android::hardware::sensors::V2_1::implementation::convertToNewEvents;
|
||||
using ::android::hardware::sensors::V2_1::implementation::convertToNewSensorInfos;
|
||||
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;
|
||||
using ::android::hardware::sensors::V2_1::subhal::implementation::ContinuousSensorsSubHal;
|
||||
using ::android::hardware::sensors::V2_1::subhal::implementation::
|
||||
DoesNotSupportDirectChannelSensorsSubHal;
|
||||
using ::android::hardware::sensors::V2_1::subhal::implementation::OnChangeSensorsSubHal;
|
||||
using ::android::hardware::sensors::V2_1::subhal::implementation::SensorsSubHalV2_0;
|
||||
using ::android::hardware::sensors::V2_1::subhal::implementation::SensorsSubHalV2_1;
|
||||
using ::android::hardware::sensors::V2_1::subhal::implementation::
|
||||
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>;
|
||||
|
||||
// The barebones sensors callback class passed into halproxy initialize calls
|
||||
class SensorsCallback : public ISensorsCallback {
|
||||
class SensorsCallback : public ISensorsCallbackV2_0 {
|
||||
public:
|
||||
Return<void> onDynamicSensorsConnected(
|
||||
const hidl_vec<SensorInfo>& /*dynamicSensorsAdded*/) override {
|
||||
|
@ -74,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
|
||||
class TestSensorsCallback : public ISensorsCallback {
|
||||
class TestSensorsCallback : public ISensorsCallbackV2_0 {
|
||||
public:
|
||||
Return<void> onDynamicSensorsConnected(
|
||||
const hidl_vec<SensorInfo>& dynamicSensorsAdded) override {
|
||||
|
@ -130,10 +162,10 @@ void testSensorsListForOneDirectChannelEnabledSubHal(const std::vector<SensorInf
|
|||
void ackWakeupEventsToHalProxy(size_t numEvents, std::unique_ptr<WakeupMessageQueue>& wakelockQueue,
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
|
@ -143,7 +175,7 @@ std::unique_ptr<WakeupMessageQueue> makeWakelockFMQ(size_t size);
|
|||
*
|
||||
* @return A proximity event.
|
||||
*/
|
||||
Event makeProximityEvent();
|
||||
EventV1_0 makeProximityEvent();
|
||||
|
||||
/**
|
||||
* Construct and return a HIDL Event type thats sensorHandle refers to a proximity sensor
|
||||
|
@ -151,7 +183,7 @@ Event makeProximityEvent();
|
|||
*
|
||||
* @return A proximity event.
|
||||
*/
|
||||
Event makeAccelerometerEvent();
|
||||
EventV1_0 makeAccelerometerEvent();
|
||||
|
||||
/**
|
||||
* Make a certain number of proximity type events with the sensorHandle field set to
|
||||
|
@ -161,7 +193,7 @@ Event makeAccelerometerEvent();
|
|||
*
|
||||
* @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
|
||||
|
@ -171,7 +203,7 @@ std::vector<Event> makeMultipleProximityEvents(size_t numEvents);
|
|||
*
|
||||
* @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
|
||||
|
@ -189,7 +221,7 @@ void makeSensorsAndSensorHandlesStartingAndOfSize(int32_t start, size_t size,
|
|||
|
||||
// Tests follow
|
||||
TEST(HalProxyTest, GetSensorsListOneSubHalTest) {
|
||||
AllSensorsSubHal subHal;
|
||||
AllSensorsSubHal<SensorsSubHalV2_0> subHal;
|
||||
std::vector<ISensorsSubHal*> fakeSubHals{&subHal};
|
||||
HalProxy proxy(fakeSubHals);
|
||||
|
||||
|
@ -201,8 +233,8 @@ TEST(HalProxyTest, GetSensorsListOneSubHalTest) {
|
|||
}
|
||||
|
||||
TEST(HalProxyTest, GetSensorsListTwoSubHalTest) {
|
||||
ContinuousSensorsSubHal continuousSubHal;
|
||||
OnChangeSensorsSubHal onChangeSubHal;
|
||||
ContinuousSensorsSubHal<SensorsSubHalV2_0> continuousSubHal;
|
||||
OnChangeSensorsSubHal<SensorsSubHalV2_0> onChangeSubHal;
|
||||
std::vector<ISensorsSubHal*> fakeSubHals;
|
||||
fakeSubHals.push_back(&continuousSubHal);
|
||||
fakeSubHals.push_back(&onChangeSubHal);
|
||||
|
@ -222,8 +254,8 @@ TEST(HalProxyTest, GetSensorsListTwoSubHalTest) {
|
|||
}
|
||||
|
||||
TEST(HalProxyTest, SetOperationModeTwoSubHalSuccessTest) {
|
||||
ContinuousSensorsSubHal subHal1;
|
||||
OnChangeSensorsSubHal subHal2;
|
||||
ContinuousSensorsSubHal<SensorsSubHalV2_0> subHal1;
|
||||
OnChangeSensorsSubHal<SensorsSubHalV2_0> subHal2;
|
||||
|
||||
std::vector<ISensorsSubHal*> fakeSubHals{&subHal1, &subHal2};
|
||||
HalProxy proxy(fakeSubHals);
|
||||
|
@ -239,7 +271,7 @@ TEST(HalProxyTest, SetOperationModeTwoSubHalSuccessTest) {
|
|||
}
|
||||
|
||||
TEST(HalProxyTest, SetOperationModeTwoSubHalFailTest) {
|
||||
AllSensorsSubHal subHal1;
|
||||
AllSensorsSubHal<SensorsSubHalV2_0> subHal1;
|
||||
SetOperationModeFailingSensorsSubHal subHal2;
|
||||
|
||||
std::vector<ISensorsSubHal*> fakeSubHals{&subHal1, &subHal2};
|
||||
|
@ -280,16 +312,16 @@ TEST(HalProxyTest, InitDirectChannelThreeSubHalsUnitTest) {
|
|||
|
||||
TEST(HalProxyTest, PostSingleNonWakeupEvent) {
|
||||
constexpr size_t kQueueSize = 5;
|
||||
AllSensorsSubHal subHal;
|
||||
AllSensorsSubHal<SensorsSubHalV2_0> subHal;
|
||||
std::vector<ISensorsSubHal*> subHals{&subHal};
|
||||
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);
|
||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
||||
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||
|
||||
std::vector<Event> events{makeAccelerometerEvent()};
|
||||
subHal.postEvents(events, false /* wakeup */);
|
||||
std::vector<EventV1_0> events{makeAccelerometerEvent()};
|
||||
subHal.postEvents(convertToNewEvents(events), false /* wakeup */);
|
||||
|
||||
EXPECT_EQ(eventQueue->availableToRead(), 1);
|
||||
}
|
||||
|
@ -297,28 +329,28 @@ TEST(HalProxyTest, PostSingleNonWakeupEvent) {
|
|||
TEST(HalProxyTest, PostMultipleNonWakeupEvent) {
|
||||
constexpr size_t kQueueSize = 5;
|
||||
constexpr size_t kNumEvents = 3;
|
||||
AllSensorsSubHal subHal;
|
||||
AllSensorsSubHal<SensorsSubHalV2_0> subHal;
|
||||
std::vector<ISensorsSubHal*> subHals{&subHal};
|
||||
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);
|
||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
||||
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||
|
||||
std::vector<Event> events = makeMultipleAccelerometerEvents(kNumEvents);
|
||||
subHal.postEvents(events, false /* wakeup */);
|
||||
std::vector<EventV1_0> events = makeMultipleAccelerometerEvents(kNumEvents);
|
||||
subHal.postEvents(convertToNewEvents(events), false /* wakeup */);
|
||||
|
||||
EXPECT_EQ(eventQueue->availableToRead(), kNumEvents);
|
||||
}
|
||||
|
||||
TEST(HalProxyTest, PostSingleWakeupEvent) {
|
||||
constexpr size_t kQueueSize = 5;
|
||||
AllSensorsSubHal subHal;
|
||||
AllSensorsSubHal<SensorsSubHalV2_0> subHal;
|
||||
std::vector<ISensorsSubHal*> subHals{&subHal};
|
||||
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);
|
||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
||||
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||
|
||||
EventFlag* eventQueueFlag;
|
||||
|
@ -327,8 +359,8 @@ TEST(HalProxyTest, PostSingleWakeupEvent) {
|
|||
EventFlag* wakelockQueueFlag;
|
||||
EventFlag::createEventFlag(wakeLockQueue->getEventFlagWord(), &wakelockQueueFlag);
|
||||
|
||||
std::vector<Event> events{makeProximityEvent()};
|
||||
subHal.postEvents(events, true /* wakeup */);
|
||||
std::vector<EventV1_0> events{makeProximityEvent()};
|
||||
subHal.postEvents(convertToNewEvents(events), true /* wakeup */);
|
||||
|
||||
EXPECT_EQ(eventQueue->availableToRead(), 1);
|
||||
|
||||
|
@ -339,12 +371,12 @@ TEST(HalProxyTest, PostSingleWakeupEvent) {
|
|||
TEST(HalProxyTest, PostMultipleWakeupEvents) {
|
||||
constexpr size_t kQueueSize = 5;
|
||||
constexpr size_t kNumEvents = 3;
|
||||
AllSensorsSubHal subHal;
|
||||
AllSensorsSubHal<SensorsSubHalV2_0> subHal;
|
||||
std::vector<ISensorsSubHal*> subHals{&subHal};
|
||||
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);
|
||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
||||
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||
|
||||
EventFlag* eventQueueFlag;
|
||||
|
@ -353,8 +385,8 @@ TEST(HalProxyTest, PostMultipleWakeupEvents) {
|
|||
EventFlag* wakelockQueueFlag;
|
||||
EventFlag::createEventFlag(wakeLockQueue->getEventFlagWord(), &wakelockQueueFlag);
|
||||
|
||||
std::vector<Event> events = makeMultipleProximityEvents(kNumEvents);
|
||||
subHal.postEvents(events, true /* wakeup */);
|
||||
std::vector<EventV1_0> events = makeMultipleProximityEvents(kNumEvents);
|
||||
subHal.postEvents(convertToNewEvents(events), true /* wakeup */);
|
||||
|
||||
EXPECT_EQ(eventQueue->availableToRead(), kNumEvents);
|
||||
|
||||
|
@ -365,20 +397,20 @@ TEST(HalProxyTest, PostMultipleWakeupEvents) {
|
|||
TEST(HalProxyTest, PostEventsMultipleSubhals) {
|
||||
constexpr size_t kQueueSize = 5;
|
||||
constexpr size_t kNumEvents = 2;
|
||||
AllSensorsSubHal subHal1, subHal2;
|
||||
AllSensorsSubHal<SensorsSubHalV2_0> subHal1, subHal2;
|
||||
std::vector<ISensorsSubHal*> subHals{&subHal1, &subHal2};
|
||||
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);
|
||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
||||
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||
|
||||
std::vector<Event> events = makeMultipleAccelerometerEvents(kNumEvents);
|
||||
subHal1.postEvents(events, false /* wakeup */);
|
||||
std::vector<EventV1_0> events = makeMultipleAccelerometerEvents(kNumEvents);
|
||||
subHal1.postEvents(convertToNewEvents(events), false /* wakeup */);
|
||||
|
||||
EXPECT_EQ(eventQueue->availableToRead(), kNumEvents);
|
||||
|
||||
subHal2.postEvents(events, false /* wakeup */);
|
||||
subHal2.postEvents(convertToNewEvents(events), false /* wakeup */);
|
||||
|
||||
EXPECT_EQ(eventQueue->availableToRead(), kNumEvents * 2);
|
||||
}
|
||||
|
@ -386,19 +418,19 @@ TEST(HalProxyTest, PostEventsMultipleSubhals) {
|
|||
TEST(HalProxyTest, PostEventsDelayedWrite) {
|
||||
constexpr size_t kQueueSize = 5;
|
||||
constexpr size_t kNumEvents = 6;
|
||||
AllSensorsSubHal subHal1, subHal2;
|
||||
AllSensorsSubHal<SensorsSubHalV2_0> subHal1, subHal2;
|
||||
std::vector<ISensorsSubHal*> subHals{&subHal1, &subHal2};
|
||||
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);
|
||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
||||
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||
|
||||
EventFlag* eventQueueFlag;
|
||||
EventFlag::createEventFlag(eventQueue->getEventFlagWord(), &eventQueueFlag);
|
||||
|
||||
std::vector<Event> events = makeMultipleAccelerometerEvents(kNumEvents);
|
||||
subHal1.postEvents(events, false /* wakeup */);
|
||||
std::vector<EventV1_0> events = makeMultipleAccelerometerEvents(kNumEvents);
|
||||
subHal1.postEvents(convertToNewEvents(events), false /* wakeup */);
|
||||
|
||||
EXPECT_EQ(eventQueue->availableToRead(), kQueueSize);
|
||||
|
||||
|
@ -414,18 +446,20 @@ TEST(HalProxyTest, PostEventsDelayedWrite) {
|
|||
TEST(HalProxyTest, PostEventsMultipleSubhalsThreaded) {
|
||||
constexpr size_t kQueueSize = 5;
|
||||
constexpr size_t kNumEvents = 2;
|
||||
AllSensorsSubHal subHal1, subHal2;
|
||||
AllSensorsSubHal<SensorsSubHalV2_0> subHal1, subHal2;
|
||||
std::vector<ISensorsSubHal*> subHals{&subHal1, &subHal2};
|
||||
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);
|
||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
||||
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||
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 t2(&AllSensorsSubHal::postEvents, &subHal2, events, false);
|
||||
std::thread t1(&AllSensorsSubHal<SensorsSubHalV2_0>::postEvents, &subHal1,
|
||||
convertToNewEvents(events), false);
|
||||
std::thread t2(&AllSensorsSubHal<SensorsSubHalV2_0>::postEvents, &subHal2,
|
||||
convertToNewEvents(events), false);
|
||||
|
||||
t1.join();
|
||||
t2.join();
|
||||
|
@ -436,34 +470,34 @@ TEST(HalProxyTest, PostEventsMultipleSubhalsThreaded) {
|
|||
TEST(HalProxyTest, DestructingWithEventsPendingOnBackgroundThread) {
|
||||
constexpr size_t kQueueSize = 5;
|
||||
constexpr size_t kNumEvents = 6;
|
||||
AllSensorsSubHal subHal;
|
||||
AllSensorsSubHal<SensorsSubHalV2_0> 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);
|
||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
||||
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||
HalProxy proxy(subHals);
|
||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||
|
||||
std::vector<Event> events = makeMultipleAccelerometerEvents(kNumEvents);
|
||||
subHal.postEvents(events, false /* wakeup */);
|
||||
std::vector<EventV1_0> events = makeMultipleAccelerometerEvents(kNumEvents);
|
||||
subHal.postEvents(convertToNewEvents(events), false /* wakeup */);
|
||||
|
||||
// Destructing HalProxy object with events on the background thread
|
||||
}
|
||||
|
||||
TEST(HalProxyTest, DestructingWithUnackedWakeupEventsPosted) {
|
||||
constexpr size_t kQueueSize = 5;
|
||||
AllSensorsSubHal subHal;
|
||||
AllSensorsSubHal<SensorsSubHalV2_0> 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);
|
||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
||||
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||
HalProxy proxy(subHals);
|
||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||
|
||||
std::vector<Event> events{makeProximityEvent()};
|
||||
subHal.postEvents(events, true /* wakeup */);
|
||||
std::vector<EventV1_0> events{makeProximityEvent()};
|
||||
subHal.postEvents(convertToNewEvents(events), true /* wakeup */);
|
||||
|
||||
// Not sending any acks back through wakeLockQueue
|
||||
|
||||
|
@ -473,17 +507,17 @@ TEST(HalProxyTest, DestructingWithUnackedWakeupEventsPosted) {
|
|||
TEST(HalProxyTest, ReinitializeWithEventsPendingOnBackgroundThread) {
|
||||
constexpr size_t kQueueSize = 5;
|
||||
constexpr size_t kNumEvents = 10;
|
||||
AllSensorsSubHal subHal;
|
||||
AllSensorsSubHal<SensorsSubHalV2_0> 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);
|
||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
||||
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||
HalProxy proxy(subHals);
|
||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||
|
||||
std::vector<Event> events = makeMultipleAccelerometerEvents(kNumEvents);
|
||||
subHal.postEvents(events, false /* wakeup */);
|
||||
std::vector<EventV1_0> events = makeMultipleAccelerometerEvents(kNumEvents);
|
||||
subHal.postEvents(convertToNewEvents(events), false /* wakeup */);
|
||||
|
||||
eventQueue = makeEventFMQ(kQueueSize);
|
||||
wakeLockQueue = makeWakelockFMQ(kQueueSize);
|
||||
|
@ -493,23 +527,23 @@ TEST(HalProxyTest, ReinitializeWithEventsPendingOnBackgroundThread) {
|
|||
EXPECT_EQ(secondInitResult, Result::OK);
|
||||
// Small sleep so that pending writes thread has a change to hit writeBlocking call.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
||||
Event eventOut;
|
||||
EventV1_0 eventOut;
|
||||
EXPECT_FALSE(eventQueue->read(&eventOut));
|
||||
}
|
||||
|
||||
TEST(HalProxyTest, ReinitializingWithUnackedWakeupEventsPosted) {
|
||||
constexpr size_t kQueueSize = 5;
|
||||
AllSensorsSubHal subHal;
|
||||
AllSensorsSubHal<SensorsSubHalV2_0> 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);
|
||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
||||
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||
HalProxy proxy(subHals);
|
||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||
|
||||
std::vector<Event> events{makeProximityEvent()};
|
||||
subHal.postEvents(events, true /* wakeup */);
|
||||
std::vector<EventV1_0> events{makeProximityEvent()};
|
||||
subHal.postEvents(convertToNewEvents(events), true /* wakeup */);
|
||||
|
||||
// Not sending any acks back through wakeLockQueue
|
||||
|
||||
|
@ -524,12 +558,12 @@ TEST(HalProxyTest, ReinitializingWithUnackedWakeupEventsPosted) {
|
|||
TEST(HalProxyTest, InitializeManyTimesInARow) {
|
||||
constexpr size_t kQueueSize = 5;
|
||||
constexpr size_t kNumTimesToInit = 100;
|
||||
AllSensorsSubHal subHal;
|
||||
AllSensorsSubHal<SensorsSubHalV2_0> 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);
|
||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
||||
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||
HalProxy proxy(subHals);
|
||||
|
||||
for (size_t i = 0; i < kNumTimesToInit; i++) {
|
||||
|
@ -541,15 +575,15 @@ TEST(HalProxyTest, InitializeManyTimesInARow) {
|
|||
|
||||
TEST(HalProxyTest, OperationModeResetOnInitialize) {
|
||||
constexpr size_t kQueueSize = 5;
|
||||
AllSensorsSubHal subHal;
|
||||
AllSensorsSubHal<SensorsSubHalV2_0> 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);
|
||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
||||
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||
HalProxy proxy(subHals);
|
||||
proxy.setOperationMode(OperationMode::DATA_INJECTION);
|
||||
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
|
||||
// have been reset to NORMAL
|
||||
EXPECT_EQ(proxy.injectSensorData(event), Result::BAD_VALUE);
|
||||
|
@ -560,7 +594,7 @@ TEST(HalProxyTest, DynamicSensorsDiscardedOnInitialize) {
|
|||
constexpr size_t kNumSensors = 5;
|
||||
AddAndRemoveDynamicSensorsSubHal 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);
|
||||
HalProxy proxy(subHals);
|
||||
|
||||
|
@ -575,9 +609,9 @@ TEST(HalProxyTest, DynamicSensorsDiscardedOnInitialize) {
|
|||
}
|
||||
|
||||
TestSensorsCallback* callback = new TestSensorsCallback();
|
||||
::android::sp<ISensorsCallback> callbackPtr = callback;
|
||||
::android::sp<ISensorsCallbackV2_0> callbackPtr = callback;
|
||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callbackPtr);
|
||||
subHal.addDynamicSensors(sensorsToConnect);
|
||||
subHal.addDynamicSensors(convertToNewSensorInfos(sensorsToConnect));
|
||||
|
||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callbackPtr);
|
||||
subHal.removeDynamicSensors(sensorHandlesToAttemptToRemove);
|
||||
|
@ -594,7 +628,7 @@ TEST(HalProxyTest, DynamicSensorsConnectedTest) {
|
|||
AddAndRemoveDynamicSensorsSubHal subHal;
|
||||
std::vector<ISensorsSubHal*> subHals{&subHal};
|
||||
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::vector<SensorInfo> sensorsToConnect;
|
||||
|
@ -603,9 +637,9 @@ TEST(HalProxyTest, DynamicSensorsConnectedTest) {
|
|||
sensorHandlesToExpect);
|
||||
|
||||
TestSensorsCallback* callback = new TestSensorsCallback();
|
||||
::android::sp<ISensorsCallback> callbackPtr = callback;
|
||||
::android::sp<ISensorsCallbackV2_0> callbackPtr = callback;
|
||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callbackPtr);
|
||||
subHal.addDynamicSensors(sensorsToConnect);
|
||||
subHal.addDynamicSensors(convertToNewSensorInfos(sensorsToConnect));
|
||||
|
||||
std::vector<SensorInfo> sensorsSeen = callback->getSensorsConnected();
|
||||
EXPECT_EQ(kNumSensors, sensorsSeen.size());
|
||||
|
@ -622,7 +656,7 @@ TEST(HalProxyTest, DynamicSensorsDisconnectedTest) {
|
|||
AddAndRemoveDynamicSensorsSubHal subHal;
|
||||
std::vector<ISensorsSubHal*> subHals{&subHal};
|
||||
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::vector<SensorInfo> sensorsToConnect;
|
||||
|
@ -647,9 +681,9 @@ TEST(HalProxyTest, DynamicSensorsDisconnectedTest) {
|
|||
nonDynamicSensorHandles.end());
|
||||
|
||||
TestSensorsCallback* callback = new TestSensorsCallback();
|
||||
::android::sp<ISensorsCallback> callbackPtr = callback;
|
||||
::android::sp<ISensorsCallbackV2_0> callbackPtr = callback;
|
||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callbackPtr);
|
||||
subHal.addDynamicSensors(sensorsToConnect);
|
||||
subHal.addDynamicSensors(convertToNewSensorInfos(sensorsToConnect));
|
||||
subHal.removeDynamicSensors(sensorHandlesToAttemptToRemove);
|
||||
|
||||
std::vector<int32_t> sensorHandlesSeen = callback->getSensorHandlesDisconnected();
|
||||
|
@ -668,15 +702,15 @@ TEST(HalProxyTest, InvalidSensorHandleSubHalIndexProxyCalls) {
|
|||
constexpr size_t kNumSubHals = 3;
|
||||
constexpr size_t kQueueSize = 5;
|
||||
int32_t kNumSubHalsInt32 = static_cast<int32_t>(kNumSubHals);
|
||||
std::vector<AllSensorsSubHal> subHalObjs(kNumSubHals);
|
||||
std::vector<AllSensorsSubHal<SensorsSubHalV2_0>> subHalObjs(kNumSubHals);
|
||||
std::vector<ISensorsSubHal*> subHals;
|
||||
for (const auto& subHal : subHalObjs) {
|
||||
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);
|
||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
||||
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||
HalProxy proxy(subHals);
|
||||
// Initialize for the injectSensorData call so callback postEvents is valid
|
||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||
|
@ -688,7 +722,7 @@ TEST(HalProxyTest, InvalidSensorHandleSubHalIndexProxyCalls) {
|
|||
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.flush(0x00000001 | (kNumSubHalsInt32 << 24)), Result::BAD_VALUE);
|
||||
Event event;
|
||||
EventV1_0 event;
|
||||
event.sensorHandle = 0x00000001 | (kNumSubHalsInt32 << 24);
|
||||
EXPECT_EQ(proxy.injectSensorData(event), Result::BAD_VALUE);
|
||||
}
|
||||
|
@ -697,28 +731,28 @@ TEST(HalProxyTest, PostedEventSensorHandleSubHalIndexValid) {
|
|||
constexpr size_t kQueueSize = 5;
|
||||
constexpr int32_t subhal1Index = 0;
|
||||
constexpr int32_t subhal2Index = 1;
|
||||
AllSensorsSubHal subhal1;
|
||||
AllSensorsSubHal subhal2;
|
||||
AllSensorsSubHal<SensorsSubHalV2_0> subhal1;
|
||||
AllSensorsSubHal<SensorsSubHalV2_0> 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);
|
||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
||||
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||
HalProxy proxy(subHals);
|
||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||
|
||||
int32_t sensorHandleToPost = 0x00000001;
|
||||
Event eventIn = makeAccelerometerEvent();
|
||||
EventV1_0 eventIn = makeAccelerometerEvent();
|
||||
eventIn.sensorHandle = sensorHandleToPost;
|
||||
std::vector<Event> eventsToPost{eventIn};
|
||||
subhal1.postEvents(eventsToPost, false);
|
||||
std::vector<EventV1_0> eventsToPost{eventIn};
|
||||
subhal1.postEvents(convertToNewEvents(eventsToPost), false);
|
||||
|
||||
Event eventOut;
|
||||
EventV1_0 eventOut;
|
||||
EXPECT_TRUE(eventQueue->read(&eventOut));
|
||||
|
||||
EXPECT_EQ(eventOut.sensorHandle, (subhal1Index << 24) | sensorHandleToPost);
|
||||
|
||||
subhal2.postEvents(eventsToPost, false);
|
||||
subhal2.postEvents(convertToNewEvents(eventsToPost), false);
|
||||
|
||||
EXPECT_TRUE(eventQueue->read(&eventOut));
|
||||
|
||||
|
@ -729,22 +763,22 @@ TEST(HalProxyTest, FillAndDrainPendingQueueTest) {
|
|||
constexpr size_t kQueueSize = 5;
|
||||
// TODO: Make this constant linked to same limit in HalProxy.h
|
||||
constexpr size_t kMaxPendingQueueSize = 100000;
|
||||
AllSensorsSubHal subhal;
|
||||
AllSensorsSubHal<SensorsSubHalV2_0> 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);
|
||||
::android::sp<ISensorsCallback> callback = new SensorsCallback();
|
||||
::android::sp<ISensorsCallbackV2_0> callback = new SensorsCallback();
|
||||
EventFlag* eventQueueFlag;
|
||||
EventFlag::createEventFlag(eventQueue->getEventFlagWord(), &eventQueueFlag);
|
||||
HalProxy proxy(subHals);
|
||||
proxy.initialize(*eventQueue->getDesc(), *wakeLockQueue->getDesc(), callback);
|
||||
|
||||
// Fill pending queue
|
||||
std::vector<Event> events = makeMultipleAccelerometerEvents(kQueueSize);
|
||||
subhal.postEvents(events, false);
|
||||
std::vector<EventV1_0> events = makeMultipleAccelerometerEvents(kQueueSize);
|
||||
subhal.postEvents(convertToNewEvents(events), false);
|
||||
events = makeMultipleAccelerometerEvents(kMaxPendingQueueSize);
|
||||
subhal.postEvents(events, false);
|
||||
subhal.postEvents(convertToNewEvents(events), false);
|
||||
|
||||
// Drain pending queue
|
||||
for (int i = 0; i < kMaxPendingQueueSize + kQueueSize; i += kQueueSize) {
|
||||
|
@ -753,9 +787,9 @@ TEST(HalProxyTest, FillAndDrainPendingQueueTest) {
|
|||
|
||||
// Put one event on pending queue
|
||||
events = makeMultipleAccelerometerEvents(kQueueSize);
|
||||
subhal.postEvents(events, false);
|
||||
subhal.postEvents(convertToNewEvents(events), false);
|
||||
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
|
||||
ASSERT_TRUE(readEventsOutOfQueue(kQueueSize, eventQueue, eventQueueFlag));
|
||||
|
@ -764,6 +798,35 @@ TEST(HalProxyTest, FillAndDrainPendingQueueTest) {
|
|||
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
|
||||
void testSensorsListFromProxyAndSubHal(const std::vector<SensorInfo>& proxySensorsList,
|
||||
const std::vector<SensorInfo>& subHalSensorsList) {
|
||||
|
@ -802,26 +865,26 @@ void ackWakeupEventsToHalProxy(size_t numEvents, std::unique_ptr<WakeupMessageQu
|
|||
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) {
|
||||
constexpr int64_t kReadBlockingTimeout = INT64_C(500000000);
|
||||
std::vector<Event> events(numEvents);
|
||||
std::vector<EventV1_0> events(numEvents);
|
||||
return eventQueue->readBlocking(events.data(), numEvents,
|
||||
static_cast<uint32_t>(EventQueueFlagBits::EVENTS_READ),
|
||||
static_cast<uint32_t>(EventQueueFlagBits::READ_AND_PROCESS),
|
||||
kReadBlockingTimeout, eventQueueFlag);
|
||||
}
|
||||
|
||||
std::unique_ptr<EventMessageQueue> makeEventFMQ(size_t size) {
|
||||
return std::make_unique<EventMessageQueue>(size, true);
|
||||
std::unique_ptr<EventMessageQueueV2_0> makeEventFMQ(size_t size) {
|
||||
return std::make_unique<EventMessageQueueV2_0>(size, true);
|
||||
}
|
||||
|
||||
std::unique_ptr<WakeupMessageQueue> makeWakelockFMQ(size_t size) {
|
||||
return std::make_unique<WakeupMessageQueue>(size, true);
|
||||
}
|
||||
|
||||
Event makeProximityEvent() {
|
||||
Event event;
|
||||
EventV1_0 makeProximityEvent() {
|
||||
EventV1_0 event;
|
||||
event.timestamp = 0xFF00FF00;
|
||||
// This is the sensorhandle of proximity, which is wakeup type
|
||||
event.sensorHandle = 0x00000008;
|
||||
|
@ -830,8 +893,8 @@ Event makeProximityEvent() {
|
|||
return event;
|
||||
}
|
||||
|
||||
Event makeAccelerometerEvent() {
|
||||
Event event;
|
||||
EventV1_0 makeAccelerometerEvent() {
|
||||
EventV1_0 event;
|
||||
event.timestamp = 0xFF00FF00;
|
||||
// This is the sensorhandle of proximity, which is wakeup type
|
||||
event.sensorHandle = 0x00000001;
|
||||
|
@ -840,16 +903,16 @@ Event makeAccelerometerEvent() {
|
|||
return event;
|
||||
}
|
||||
|
||||
std::vector<Event> makeMultipleProximityEvents(size_t numEvents) {
|
||||
std::vector<Event> events;
|
||||
std::vector<EventV1_0> makeMultipleProximityEvents(size_t numEvents) {
|
||||
std::vector<EventV1_0> events;
|
||||
for (size_t i = 0; i < numEvents; i++) {
|
||||
events.push_back(makeProximityEvent());
|
||||
}
|
||||
return events;
|
||||
}
|
||||
|
||||
std::vector<Event> makeMultipleAccelerometerEvents(size_t numEvents) {
|
||||
std::vector<Event> events;
|
||||
std::vector<EventV1_0> makeMultipleAccelerometerEvents(size_t numEvents) {
|
||||
std::vector<EventV1_0> events;
|
||||
for (size_t i = 0; i < numEvents; i++) {
|
||||
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 hardware {
|
||||
namespace sensors {
|
||||
namespace V2_0 {
|
||||
namespace V2_1 {
|
||||
namespace subhal {
|
||||
namespace implementation {
|
||||
|
||||
using ::android::hardware::sensors::V1_0::MetaDataEventType;
|
||||
using ::android::hardware::sensors::V1_0::OperationMode;
|
||||
using ::android::hardware::sensors::V1_0::Result;
|
||||
using ::android::hardware::sensors::V1_0::SensorFlagBits;
|
||||
using ::android::hardware::sensors::V1_0::SensorStatus;
|
||||
using ::android::hardware::sensors::V2_1::Event;
|
||||
using ::android::hardware::sensors::V2_1::SensorInfo;
|
||||
using ::android::hardware::sensors::V2_1::SensorType;
|
||||
|
||||
Sensor::Sensor(int32_t sensorHandle, ISensorsEventCallback* callback)
|
||||
: mIsEnabled(false),
|
||||
|
@ -343,7 +348,7 @@ RelativeHumiditySensor::RelativeHumiditySensor(int32_t sensorHandle,
|
|||
|
||||
} // namespace implementation
|
||||
} // namespace subhal
|
||||
} // namespace V2_0
|
||||
} // namespace V2_1
|
||||
} // namespace sensors
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <android/hardware/sensors/1.0/types.h>
|
||||
#include <android/hardware/sensors/2.1/types.h>
|
||||
|
||||
#include <condition_variable>
|
||||
#include <memory>
|
||||
|
@ -24,16 +24,16 @@
|
|||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
using ::android::hardware::sensors::V1_0::Event;
|
||||
using ::android::hardware::sensors::V1_0::OperationMode;
|
||||
using ::android::hardware::sensors::V1_0::Result;
|
||||
using ::android::hardware::sensors::V1_0::SensorInfo;
|
||||
using ::android::hardware::sensors::V1_0::SensorType;
|
||||
using ::android::hardware::sensors::V2_1::Event;
|
||||
using ::android::hardware::sensors::V2_1::SensorInfo;
|
||||
using ::android::hardware::sensors::V2_1::SensorType;
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace sensors {
|
||||
namespace V2_0 {
|
||||
namespace V2_1 {
|
||||
namespace subhal {
|
||||
namespace implementation {
|
||||
|
||||
|
@ -151,7 +151,7 @@ class RelativeHumiditySensor : public OnChangeSensor {
|
|||
|
||||
} // namespace implementation
|
||||
} // namespace subhal
|
||||
} // namespace V2_0
|
||||
} // namespace V2_1
|
||||
} // namespace sensors
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
|
|
@ -16,33 +16,66 @@
|
|||
|
||||
#include "SensorsSubHal.h"
|
||||
|
||||
#include <android/hardware/sensors/2.0/types.h>
|
||||
#include <android/hardware/sensors/2.1/types.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
|
||||
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
|
||||
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;
|
||||
#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
|
||||
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
|
||||
*version = SUB_HAL_2_0_VERSION;
|
||||
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 hardware {
|
||||
namespace sensors {
|
||||
namespace V2_0 {
|
||||
namespace V2_1 {
|
||||
namespace subhal {
|
||||
namespace implementation {
|
||||
|
||||
using ::android::hardware::Void;
|
||||
using ::android::hardware::sensors::V1_0::Event;
|
||||
using ::android::hardware::sensors::V1_0::OperationMode;
|
||||
using ::android::hardware::sensors::V1_0::RateLevel;
|
||||
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::WakeLockQueueFlagBits;
|
||||
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.
|
||||
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;
|
||||
for (const auto& sensor : mSensors) {
|
||||
sensors.push_back(sensor.second->getSensorInfo());
|
||||
|
@ -64,7 +98,7 @@ Return<void> SensorsSubHal::getSensorsList(getSensorsList_cb _hidl_cb) {
|
|||
return Void();
|
||||
}
|
||||
|
||||
Return<Result> SensorsSubHal::setOperationMode(OperationMode mode) {
|
||||
Return<Result> ISensorsSubHalBase::setOperationMode(OperationMode mode) {
|
||||
for (auto sensor : mSensors) {
|
||||
sensor.second->setOperationMode(mode);
|
||||
}
|
||||
|
@ -72,7 +106,7 @@ Return<Result> SensorsSubHal::setOperationMode(OperationMode mode) {
|
|||
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);
|
||||
if (sensor != mSensors.end()) {
|
||||
sensor->second->activate(enabled);
|
||||
|
@ -81,8 +115,8 @@ Return<Result> SensorsSubHal::activate(int32_t sensorHandle, bool enabled) {
|
|||
return Result::BAD_VALUE;
|
||||
}
|
||||
|
||||
Return<Result> SensorsSubHal::batch(int32_t sensorHandle, int64_t samplingPeriodNs,
|
||||
int64_t /* maxReportLatencyNs */) {
|
||||
Return<Result> ISensorsSubHalBase::batch(int32_t sensorHandle, int64_t samplingPeriodNs,
|
||||
int64_t /* maxReportLatencyNs */) {
|
||||
auto sensor = mSensors.find(sensorHandle);
|
||||
if (sensor != mSensors.end()) {
|
||||
sensor->second->batch(samplingPeriodNs);
|
||||
|
@ -91,7 +125,7 @@ Return<Result> SensorsSubHal::batch(int32_t sensorHandle, int64_t samplingPeriod
|
|||
return Result::BAD_VALUE;
|
||||
}
|
||||
|
||||
Return<Result> SensorsSubHal::flush(int32_t sensorHandle) {
|
||||
Return<Result> ISensorsSubHalBase::flush(int32_t sensorHandle) {
|
||||
auto sensor = mSensors.find(sensorHandle);
|
||||
if (sensor != mSensors.end()) {
|
||||
return sensor->second->flush();
|
||||
|
@ -99,7 +133,7 @@ Return<Result> SensorsSubHal::flush(int32_t sensorHandle) {
|
|||
return Result::BAD_VALUE;
|
||||
}
|
||||
|
||||
Return<Result> SensorsSubHal::injectSensorData(const Event& event) {
|
||||
Return<Result> ISensorsSubHalBase::injectSensorData(const Event& event) {
|
||||
auto sensor = mSensors.find(event.sensorHandle);
|
||||
if (sensor != mSensors.end()) {
|
||||
return sensor->second->injectEvent(event);
|
||||
|
@ -108,24 +142,24 @@ Return<Result> SensorsSubHal::injectSensorData(const Event& event) {
|
|||
return Result::BAD_VALUE;
|
||||
}
|
||||
|
||||
Return<void> SensorsSubHal::registerDirectChannel(const SharedMemInfo& /* mem */,
|
||||
registerDirectChannel_cb _hidl_cb) {
|
||||
Return<void> ISensorsSubHalBase::registerDirectChannel(
|
||||
const SharedMemInfo& /* mem */, V2_0::ISensors::registerDirectChannel_cb _hidl_cb) {
|
||||
_hidl_cb(Result::INVALID_OPERATION, -1 /* channelHandle */);
|
||||
return Return<void>();
|
||||
}
|
||||
|
||||
Return<Result> SensorsSubHal::unregisterDirectChannel(int32_t /* channelHandle */) {
|
||||
Return<Result> ISensorsSubHalBase::unregisterDirectChannel(int32_t /* channelHandle */) {
|
||||
return Result::INVALID_OPERATION;
|
||||
}
|
||||
|
||||
Return<void> SensorsSubHal::configDirectReport(int32_t /* sensorHandle */,
|
||||
int32_t /* channelHandle */, RateLevel /* rate */,
|
||||
configDirectReport_cb _hidl_cb) {
|
||||
Return<void> ISensorsSubHalBase::configDirectReport(
|
||||
int32_t /* sensorHandle */, int32_t /* channelHandle */, RateLevel /* rate */,
|
||||
V2_0::ISensors::configDirectReport_cb _hidl_cb) {
|
||||
_hidl_cb(Result::INVALID_OPERATION, 0 /* reportToken */);
|
||||
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) {
|
||||
ALOGE("%s: missing fd for writing", __FUNCTION__);
|
||||
return Void();
|
||||
|
@ -156,44 +190,18 @@ Return<void> SensorsSubHal::debug(const hidl_handle& fd, const hidl_vec<hidl_str
|
|||
return Return<void>();
|
||||
}
|
||||
|
||||
Return<Result> SensorsSubHal::initialize(const sp<IHalProxyCallback>& halProxyCallback) {
|
||||
mCallback = halProxyCallback;
|
||||
Return<Result> ISensorsSubHalBase::initialize(
|
||||
std::unique_ptr<IHalProxyCallbackWrapperBase>& halProxyCallback) {
|
||||
mCallback = std::move(halProxyCallback);
|
||||
setOperationMode(OperationMode::NORMAL);
|
||||
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);
|
||||
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::BAD_VALUE;
|
||||
}
|
||||
|
@ -206,7 +214,7 @@ Return<void> AllSupportDirectChannelSensorsSubHal::getSensorsList(getSensorsList
|
|||
sensorInfo.flags |= V1_0::SensorFlagBits::MASK_DIRECT_REPORT;
|
||||
sensors.push_back(sensorInfo);
|
||||
}
|
||||
_hidl_cb(sensors);
|
||||
_hidl_cb(V2_1::implementation::convertToOldSensorInfos(sensors));
|
||||
return Void();
|
||||
}
|
||||
|
||||
|
@ -218,7 +226,7 @@ Return<void> DoesNotSupportDirectChannelSensorsSubHal::getSensorsList(getSensors
|
|||
sensorInfo.flags &= ~static_cast<uint32_t>(V1_0::SensorFlagBits::MASK_DIRECT_REPORT);
|
||||
sensors.push_back(sensorInfo);
|
||||
}
|
||||
_hidl_cb(sensors);
|
||||
_hidl_cb(V2_1::implementation::convertToOldSensorInfos(sensors));
|
||||
return Void();
|
||||
}
|
||||
|
||||
|
@ -234,7 +242,7 @@ void AddAndRemoveDynamicSensorsSubHal::removeDynamicSensors(
|
|||
|
||||
} // namespace implementation
|
||||
} // namespace subhal
|
||||
} // namespace V2_0
|
||||
} // namespace V2_1
|
||||
} // namespace sensors
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
|
|
@ -17,7 +17,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "V2_0/SubHal.h"
|
||||
#include "V2_1/SubHal.h"
|
||||
|
||||
#include "IHalProxyCallbackWrapper.h"
|
||||
#include "Sensor.h"
|
||||
|
||||
#include <vector>
|
||||
|
@ -25,54 +27,54 @@
|
|||
namespace android {
|
||||
namespace hardware {
|
||||
namespace sensors {
|
||||
namespace V2_0 {
|
||||
namespace V2_1 {
|
||||
namespace subhal {
|
||||
namespace implementation {
|
||||
|
||||
using ::android::hardware::sensors::V1_0::OperationMode;
|
||||
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.
|
||||
* See the README file for more details on how this class can be used for testing.
|
||||
*/
|
||||
class SensorsSubHal : public ISensorsSubHal, public ISensorsEventCallback {
|
||||
using Event = ::android::hardware::sensors::V1_0::Event;
|
||||
class ISensorsSubHalBase : public ISensorsEventCallback {
|
||||
protected:
|
||||
using Event = ::android::hardware::sensors::V2_1::Event;
|
||||
using RateLevel = ::android::hardware::sensors::V1_0::RateLevel;
|
||||
using SharedMemInfo = ::android::hardware::sensors::V1_0::SharedMemInfo;
|
||||
|
||||
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.
|
||||
virtual Return<void> getSensorsList(getSensorsList_cb _hidl_cb) override;
|
||||
|
||||
virtual Return<Result> setOperationMode(OperationMode mode) override;
|
||||
virtual Return<Result> setOperationMode(OperationMode mode);
|
||||
|
||||
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,
|
||||
int64_t maxReportLatencyNs) override;
|
||||
int64_t maxReportLatencyNs);
|
||||
|
||||
Return<Result> flush(int32_t sensorHandle) override;
|
||||
|
||||
Return<Result> injectSensorData(const Event& event) override;
|
||||
Return<Result> flush(int32_t sensorHandle);
|
||||
|
||||
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,
|
||||
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.
|
||||
const std::string getName() override {
|
||||
const std::string getName() {
|
||||
#ifdef SUB_HAL_NAME
|
||||
return SUB_HAL_NAME;
|
||||
#else // SUB_HAL_NAME
|
||||
|
@ -80,8 +82,6 @@ class SensorsSubHal : public ISensorsSubHal, public ISensorsEventCallback {
|
|||
#endif // SUB_HAL_NAME
|
||||
}
|
||||
|
||||
Return<Result> initialize(const sp<IHalProxyCallback>& halProxyCallback) override;
|
||||
|
||||
// Method from ISensorsEventCallback.
|
||||
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
|
||||
* acquired.
|
||||
*/
|
||||
sp<IHalProxyCallback> mCallback;
|
||||
std::unique_ptr<IHalProxyCallbackWrapperBase> mCallback;
|
||||
|
||||
private:
|
||||
/**
|
||||
|
@ -118,40 +118,143 @@ class SensorsSubHal : public ISensorsSubHal, public ISensorsEventCallback {
|
|||
int32_t mNextHandle;
|
||||
};
|
||||
|
||||
// SubHal that has continuous sensors for testing purposes.
|
||||
class ContinuousSensorsSubHal : public SensorsSubHal {
|
||||
template <class SubHalClass>
|
||||
class SensorsSubHalBase : public ISensorsSubHalBase, public SubHalClass {
|
||||
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.
|
||||
class OnChangeSensorsSubHal : public SensorsSubHal {
|
||||
template <class SubHalVersion>
|
||||
class OnChangeSensorsSubHal : public SubHalVersion {
|
||||
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.
|
||||
class AllSensorsSubHal : public SensorsSubHal {
|
||||
template <class SubHalVersion>
|
||||
class AllSensorsSubHal : public SubHalVersion {
|
||||
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:
|
||||
Return<Result> setOperationMode(OperationMode mode) override;
|
||||
};
|
||||
|
||||
class AllSupportDirectChannelSensorsSubHal : public AllSensorsSubHal {
|
||||
class AllSupportDirectChannelSensorsSubHal : public AllSensorsSubHal<SensorsSubHalV2_0> {
|
||||
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:
|
||||
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:
|
||||
void addDynamicSensors(const std::vector<SensorInfo>& sensorsAdded);
|
||||
void removeDynamicSensors(const std::vector<int32_t>& sensorHandlesAdded);
|
||||
|
@ -159,7 +262,7 @@ class AddAndRemoveDynamicSensorsSubHal : public AllSensorsSubHal {
|
|||
|
||||
} // namespace implementation
|
||||
} // namespace subhal
|
||||
} // namespace V2_0
|
||||
} // namespace V2_1
|
||||
} // namespace sensors
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
|
Loading…
Reference in a new issue