Loading services/sensorservice/SensorDevice.cpp +22 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -87,16 +88,25 @@ SensorDevice::SensorDevice() } 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, Loading @@ -114,6 +124,16 @@ bool SensorDevice::connectHidlService() { 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) { Loading services/sensorservice/SensorDevice.h +4 −3 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ #include "SensorDeviceUtils.h" #include "SensorServiceUtils.h" #include "SensorsWrapper.h" #include <sensor/Sensor.h> #include <stdint.h> Loading @@ -31,8 +32,6 @@ #include <unordered_map> #include <algorithm> //std::max std::min #include "android/hardware/sensors/1.0/ISensors.h" #include "RingBuffer.h" // --------------------------------------------------------------------------- Loading Loading @@ -103,7 +102,7 @@ public: 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; Loading Loading @@ -163,6 +162,8 @@ private: SortedVector<void *> mDisabledClients; SensorDevice(); bool connectHidlService(); bool connectHidlServiceV1_0(); bool connectHidlServiceV2_0(); static void handleHidlDeath(const std::string &detail); template<typename T> Loading Loading
services/sensorservice/SensorDevice.cpp +22 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -87,16 +88,25 @@ SensorDevice::SensorDevice() } 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, Loading @@ -114,6 +124,16 @@ bool SensorDevice::connectHidlService() { 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) { Loading
services/sensorservice/SensorDevice.h +4 −3 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ #include "SensorDeviceUtils.h" #include "SensorServiceUtils.h" #include "SensorsWrapper.h" #include <sensor/Sensor.h> #include <stdint.h> Loading @@ -31,8 +32,6 @@ #include <unordered_map> #include <algorithm> //std::max std::min #include "android/hardware/sensors/1.0/ISensors.h" #include "RingBuffer.h" // --------------------------------------------------------------------------- Loading Loading @@ -103,7 +102,7 @@ public: 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; Loading Loading @@ -163,6 +162,8 @@ private: SortedVector<void *> mDisabledClients; SensorDevice(); bool connectHidlService(); bool connectHidlServiceV1_0(); bool connectHidlServiceV2_0(); static void handleHidlDeath(const std::string &detail); template<typename T> Loading