Modify SensorDevice to use ISensorsWrapper
Modify the SensorDevice to the use the ISensorsWrapper to abstract
away the version of the currently loaded HAL.
Bug: 111070257
Test: Verified sensor events were received via a_sns_test
Change-Id: I373e6ff2cfe1ea5167b9144e523729b9b0c46fac
diff --git a/services/sensorservice/SensorDevice.cpp b/services/sensorservice/SensorDevice.cpp
index ae3f42f..7237bc8 100644
--- a/services/sensorservice/SensorDevice.cpp
+++ b/services/sensorservice/SensorDevice.cpp
@@ -26,6 +26,7 @@
#include <cinttypes>
#include <thread>
+using namespace android::hardware::sensors;
using namespace android::hardware::sensors::V1_0;
using namespace android::hardware::sensors::V1_0::implementation;
using android::hardware::hidl_vec;
@@ -87,16 +88,25 @@
}
bool SensorDevice::connectHidlService() {
+ bool connected = connectHidlServiceV2_0();
+ if (!connected) {
+ connected = connectHidlServiceV1_0();
+ }
+ return connected;
+}
+
+bool SensorDevice::connectHidlServiceV1_0() {
// SensorDevice will wait for HAL service to start if HAL is declared in device manifest.
size_t retry = 10;
while (retry-- > 0) {
- mSensors = ISensors::getService();
- if (mSensors == nullptr) {
+ sp<V1_0::ISensors> sensors = V1_0::ISensors::getService();
+ if (sensors == nullptr) {
// no sensor hidl service found
break;
}
+ mSensors = new SensorServiceUtil::SensorsWrapperV1_0(sensors);
mRestartWaiter->reset();
// Poke ISensor service. If it has lingering connection from previous generation of
// system server, it will kill itself. There is no intention to handle the poll result,
@@ -114,6 +124,16 @@
return (mSensors != nullptr);
}
+bool SensorDevice::connectHidlServiceV2_0() {
+ sp<V2_0::ISensors> sensors = V2_0::ISensors::getService();
+ if (sensors != nullptr) {
+ mSensors = new SensorServiceUtil::SensorsWrapperV2_0(sensors);
+
+ // TODO: initialize message queues
+ }
+ return (mSensors != nullptr);
+}
+
void SensorDevice::handleDynamicSensorConnection(int handle, bool connected) {
// not need to check mSensors because this is is only called after successful poll()
if (connected) {