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) {
diff --git a/services/sensorservice/SensorDevice.h b/services/sensorservice/SensorDevice.h
index 6d75051..595a627 100644
--- a/services/sensorservice/SensorDevice.h
+++ b/services/sensorservice/SensorDevice.h
@@ -19,6 +19,7 @@
#include "SensorDeviceUtils.h"
#include "SensorServiceUtils.h"
+#include "SensorsWrapper.h"
#include <sensor/Sensor.h>
#include <stdint.h>
@@ -31,8 +32,6 @@
#include <unordered_map>
#include <algorithm> //std::max std::min
-#include "android/hardware/sensors/1.0/ISensors.h"
-
#include "RingBuffer.h"
// ---------------------------------------------------------------------------
@@ -103,7 +102,7 @@
private:
friend class Singleton<SensorDevice>;
- sp<hardware::sensors::V1_0::ISensors> mSensors;
+ sp<SensorServiceUtil::ISensorsWrapper> mSensors;
Vector<sensor_t> mSensorList;
std::unordered_map<int32_t, sensor_t*> mConnectedDynamicSensors;
@@ -163,6 +162,8 @@
SortedVector<void *> mDisabledClients;
SensorDevice();
bool connectHidlService();
+ bool connectHidlServiceV1_0();
+ bool connectHidlServiceV2_0();
static void handleHidlDeath(const std::string &detail);
template<typename T>