Loading services/sensorservice/SensorDevice.cpp +34 −15 Original line number Original line Diff line number Diff line Loading @@ -34,6 +34,7 @@ using namespace android::hardware::sensors::V1_0; using namespace android::hardware::sensors::V1_0::implementation; using namespace android::hardware::sensors::V1_0::implementation; using android::hardware::sensors::V2_0::EventQueueFlagBits; using android::hardware::sensors::V2_0::EventQueueFlagBits; using android::hardware::hidl_vec; using android::hardware::hidl_vec; using android::hardware::Return; using android::SensorDeviceUtils::HidlServiceRegistrationWaiter; using android::SensorDeviceUtils::HidlServiceRegistrationWaiter; namespace android { namespace android { Loading Loading @@ -162,13 +163,14 @@ SensorDevice::HalConnectionStatus SensorDevice::connectHidlServiceV2_0() { CHECK(mSensors != nullptr && mEventQueue != nullptr && CHECK(mSensors != nullptr && mEventQueue != nullptr && mWakeLockQueue != nullptr && mEventQueueFlag != nullptr); mWakeLockQueue != nullptr && mEventQueueFlag != nullptr); status_t status = StatusFromResult(checkReturn(mSensors->initializeMessageQueues( status_t status = StatusFromResult(checkReturn(mSensors->initialize( *mEventQueue->getDesc(), *mEventQueue->getDesc(), *mWakeLockQueue->getDesc()))); *mWakeLockQueue->getDesc(), this))); if (status != NO_ERROR) { if (status != NO_ERROR) { connectionStatus = HalConnectionStatus::FAILED_TO_CONNECT; connectionStatus = HalConnectionStatus::FAILED_TO_CONNECT; ALOGE("Failed to initialize message queues (%s)", strerror(-status)); ALOGE("Failed to initialize Sensors HAL (%s)", strerror(-status)); } else { } else { connectionStatus = HalConnectionStatus::CONNECTED; connectionStatus = HalConnectionStatus::CONNECTED; } } Loading Loading @@ -332,6 +334,33 @@ ssize_t SensorDevice::pollFmq(sensors_event_t* buffer, size_t maxNumEventsToRead return eventsRead; return eventsRead; } } Return<void> SensorDevice::onDynamicSensorsConnected( const hidl_vec<SensorInfo> &dynamicSensorsAdded) { // Allocate a sensor_t structure for each dynamic sensor added and insert // it into the dictionary of connected dynamic sensors keyed by handle. for (size_t i = 0; i < dynamicSensorsAdded.size(); ++i) { const SensorInfo &info = dynamicSensorsAdded[i]; auto it = mConnectedDynamicSensors.find(info.sensorHandle); CHECK(it == mConnectedDynamicSensors.end()); sensor_t *sensor = new sensor_t(); convertToSensor(info, sensor); mConnectedDynamicSensors.insert( std::make_pair(sensor->handle, sensor)); } return Return<void>(); } Return<void> SensorDevice::onDynamicSensorsDisconnected( const hidl_vec<int32_t> &dynamicSensorHandlesRemoved) { (void) dynamicSensorHandlesRemoved; // TODO: Currently dynamic sensors do not seem to be removed return Return<void>(); } void SensorDevice::autoDisable(void *ident, int handle) { void SensorDevice::autoDisable(void *ident, int handle) { Mutex::Autolock _l(mLock); Mutex::Autolock _l(mLock); ssize_t activationIndex = mActivationCount.indexOfKey(handle); ssize_t activationIndex = mActivationCount.indexOfKey(handle); Loading Loading @@ -767,19 +796,9 @@ void SensorDevice::convertToSensorEvents( const hidl_vec<Event> &src, const hidl_vec<Event> &src, const hidl_vec<SensorInfo> &dynamicSensorsAdded, const hidl_vec<SensorInfo> &dynamicSensorsAdded, sensors_event_t *dst) { sensors_event_t *dst) { // Allocate a sensor_t structure for each dynamic sensor added and insert // it into the dictionary of connected dynamic sensors keyed by handle. for (size_t i = 0; i < dynamicSensorsAdded.size(); ++i) { const SensorInfo &info = dynamicSensorsAdded[i]; auto it = mConnectedDynamicSensors.find(info.sensorHandle); if (dynamicSensorsAdded.size() > 0) { CHECK(it == mConnectedDynamicSensors.end()); onDynamicSensorsConnected(dynamicSensorsAdded); sensor_t *sensor = new sensor_t; convertToSensor(info, sensor); mConnectedDynamicSensors.insert( std::make_pair(sensor->handle, sensor)); } } for (size_t i = 0; i < src.size(); ++i) { for (size_t i = 0; i < src.size(); ++i) { Loading services/sensorservice/SensorDevice.h +9 −1 Original line number Original line Diff line number Diff line Loading @@ -43,7 +43,9 @@ namespace android { // --------------------------------------------------------------------------- // --------------------------------------------------------------------------- class SensorDevice : public Singleton<SensorDevice>, public SensorServiceUtil::Dumpable { class SensorDevice : public Singleton<SensorDevice>, public android::hardware::sensors::V2_0::ISensorsCallback, public SensorServiceUtil::Dumpable { public: public: class HidlTransportErrorLog { class HidlTransportErrorLog { public: public: Loading Loading @@ -102,6 +104,12 @@ public: status_t injectSensorData(const sensors_event_t *event); status_t injectSensorData(const sensors_event_t *event); void notifyConnectionDestroyed(void *ident); void notifyConnectionDestroyed(void *ident); using Result = ::android::hardware::sensors::V1_0::Result; hardware::Return<void> onDynamicSensorsConnected( const hardware::hidl_vec<hardware::sensors::V1_0::SensorInfo> &dynamicSensorsAdded) override; hardware::Return<void> onDynamicSensorsDisconnected( const hardware::hidl_vec<int32_t> &dynamicSensorHandlesRemoved) override; // Dumpable // Dumpable virtual std::string dump() const; virtual std::string dump() const; private: private: Loading services/sensorservice/SensorsWrapper.h +10 −6 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,7 @@ #include "android/hardware/sensors/1.0/ISensors.h" #include "android/hardware/sensors/1.0/ISensors.h" #include "android/hardware/sensors/2.0/ISensors.h" #include "android/hardware/sensors/2.0/ISensors.h" #include "android/hardware/sensors/2.0/ISensorsCallback.h" #include <utils/LightRefBase.h> #include <utils/LightRefBase.h> Loading @@ -33,6 +34,7 @@ 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; using ::android::hardware::sensors::V1_0::SharedMemInfo; using ::android::hardware::sensors::V1_0::SharedMemInfo; using ::android::hardware::sensors::V2_0::ISensorsCallback; /* /* * The ISensorsWrapper interface includes all function from supported Sensors HAL versions. This * The ISensorsWrapper interface includes all function from supported Sensors HAL versions. This Loading Loading @@ -85,10 +87,12 @@ public: return Return<void>(); return Return<void>(); } } virtual Return<Result> initializeMessageQueues(const MQDescriptorSync<Event>& eventQueueDesc, virtual Return<Result> initialize(const MQDescriptorSync<Event>& eventQueueDesc, const MQDescriptorSync<uint32_t>& wakeLockDesc) { const MQDescriptorSync<uint32_t>& wakeLockDesc, const ::android::sp<ISensorsCallback>& callback) { (void)eventQueueDesc; (void)eventQueueDesc; (void)wakeLockDesc; (void)wakeLockDesc; (void)callback; // TODO (b/111070257): Generate an assert-level error since this should never be called // TODO (b/111070257): Generate an assert-level error since this should never be called // directly // directly return Result::INVALID_OPERATION; return Result::INVALID_OPERATION; Loading Loading @@ -177,10 +181,10 @@ public: return true; return true; } } Return<Result> initializeMessageQueues( Return<Result> initialize(const MQDescriptorSync<Event>& eventQueueDesc, const MQDescriptorSync<Event>& eventQueueDesc, const MQDescriptorSync<uint32_t>& wakeLockDesc, const MQDescriptorSync<uint32_t>& wakeLockDesc) override { const ::android::sp<ISensorsCallback>& callback) override { return mSensors->initializeMessageQueues(eventQueueDesc, wakeLockDesc); return mSensors->initialize(eventQueueDesc, wakeLockDesc, callback); } } }; }; Loading Loading
services/sensorservice/SensorDevice.cpp +34 −15 Original line number Original line Diff line number Diff line Loading @@ -34,6 +34,7 @@ using namespace android::hardware::sensors::V1_0; using namespace android::hardware::sensors::V1_0::implementation; using namespace android::hardware::sensors::V1_0::implementation; using android::hardware::sensors::V2_0::EventQueueFlagBits; using android::hardware::sensors::V2_0::EventQueueFlagBits; using android::hardware::hidl_vec; using android::hardware::hidl_vec; using android::hardware::Return; using android::SensorDeviceUtils::HidlServiceRegistrationWaiter; using android::SensorDeviceUtils::HidlServiceRegistrationWaiter; namespace android { namespace android { Loading Loading @@ -162,13 +163,14 @@ SensorDevice::HalConnectionStatus SensorDevice::connectHidlServiceV2_0() { CHECK(mSensors != nullptr && mEventQueue != nullptr && CHECK(mSensors != nullptr && mEventQueue != nullptr && mWakeLockQueue != nullptr && mEventQueueFlag != nullptr); mWakeLockQueue != nullptr && mEventQueueFlag != nullptr); status_t status = StatusFromResult(checkReturn(mSensors->initializeMessageQueues( status_t status = StatusFromResult(checkReturn(mSensors->initialize( *mEventQueue->getDesc(), *mEventQueue->getDesc(), *mWakeLockQueue->getDesc()))); *mWakeLockQueue->getDesc(), this))); if (status != NO_ERROR) { if (status != NO_ERROR) { connectionStatus = HalConnectionStatus::FAILED_TO_CONNECT; connectionStatus = HalConnectionStatus::FAILED_TO_CONNECT; ALOGE("Failed to initialize message queues (%s)", strerror(-status)); ALOGE("Failed to initialize Sensors HAL (%s)", strerror(-status)); } else { } else { connectionStatus = HalConnectionStatus::CONNECTED; connectionStatus = HalConnectionStatus::CONNECTED; } } Loading Loading @@ -332,6 +334,33 @@ ssize_t SensorDevice::pollFmq(sensors_event_t* buffer, size_t maxNumEventsToRead return eventsRead; return eventsRead; } } Return<void> SensorDevice::onDynamicSensorsConnected( const hidl_vec<SensorInfo> &dynamicSensorsAdded) { // Allocate a sensor_t structure for each dynamic sensor added and insert // it into the dictionary of connected dynamic sensors keyed by handle. for (size_t i = 0; i < dynamicSensorsAdded.size(); ++i) { const SensorInfo &info = dynamicSensorsAdded[i]; auto it = mConnectedDynamicSensors.find(info.sensorHandle); CHECK(it == mConnectedDynamicSensors.end()); sensor_t *sensor = new sensor_t(); convertToSensor(info, sensor); mConnectedDynamicSensors.insert( std::make_pair(sensor->handle, sensor)); } return Return<void>(); } Return<void> SensorDevice::onDynamicSensorsDisconnected( const hidl_vec<int32_t> &dynamicSensorHandlesRemoved) { (void) dynamicSensorHandlesRemoved; // TODO: Currently dynamic sensors do not seem to be removed return Return<void>(); } void SensorDevice::autoDisable(void *ident, int handle) { void SensorDevice::autoDisable(void *ident, int handle) { Mutex::Autolock _l(mLock); Mutex::Autolock _l(mLock); ssize_t activationIndex = mActivationCount.indexOfKey(handle); ssize_t activationIndex = mActivationCount.indexOfKey(handle); Loading Loading @@ -767,19 +796,9 @@ void SensorDevice::convertToSensorEvents( const hidl_vec<Event> &src, const hidl_vec<Event> &src, const hidl_vec<SensorInfo> &dynamicSensorsAdded, const hidl_vec<SensorInfo> &dynamicSensorsAdded, sensors_event_t *dst) { sensors_event_t *dst) { // Allocate a sensor_t structure for each dynamic sensor added and insert // it into the dictionary of connected dynamic sensors keyed by handle. for (size_t i = 0; i < dynamicSensorsAdded.size(); ++i) { const SensorInfo &info = dynamicSensorsAdded[i]; auto it = mConnectedDynamicSensors.find(info.sensorHandle); if (dynamicSensorsAdded.size() > 0) { CHECK(it == mConnectedDynamicSensors.end()); onDynamicSensorsConnected(dynamicSensorsAdded); sensor_t *sensor = new sensor_t; convertToSensor(info, sensor); mConnectedDynamicSensors.insert( std::make_pair(sensor->handle, sensor)); } } for (size_t i = 0; i < src.size(); ++i) { for (size_t i = 0; i < src.size(); ++i) { Loading
services/sensorservice/SensorDevice.h +9 −1 Original line number Original line Diff line number Diff line Loading @@ -43,7 +43,9 @@ namespace android { // --------------------------------------------------------------------------- // --------------------------------------------------------------------------- class SensorDevice : public Singleton<SensorDevice>, public SensorServiceUtil::Dumpable { class SensorDevice : public Singleton<SensorDevice>, public android::hardware::sensors::V2_0::ISensorsCallback, public SensorServiceUtil::Dumpable { public: public: class HidlTransportErrorLog { class HidlTransportErrorLog { public: public: Loading Loading @@ -102,6 +104,12 @@ public: status_t injectSensorData(const sensors_event_t *event); status_t injectSensorData(const sensors_event_t *event); void notifyConnectionDestroyed(void *ident); void notifyConnectionDestroyed(void *ident); using Result = ::android::hardware::sensors::V1_0::Result; hardware::Return<void> onDynamicSensorsConnected( const hardware::hidl_vec<hardware::sensors::V1_0::SensorInfo> &dynamicSensorsAdded) override; hardware::Return<void> onDynamicSensorsDisconnected( const hardware::hidl_vec<int32_t> &dynamicSensorHandlesRemoved) override; // Dumpable // Dumpable virtual std::string dump() const; virtual std::string dump() const; private: private: Loading
services/sensorservice/SensorsWrapper.h +10 −6 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,7 @@ #include "android/hardware/sensors/1.0/ISensors.h" #include "android/hardware/sensors/1.0/ISensors.h" #include "android/hardware/sensors/2.0/ISensors.h" #include "android/hardware/sensors/2.0/ISensors.h" #include "android/hardware/sensors/2.0/ISensorsCallback.h" #include <utils/LightRefBase.h> #include <utils/LightRefBase.h> Loading @@ -33,6 +34,7 @@ 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; using ::android::hardware::sensors::V1_0::SharedMemInfo; using ::android::hardware::sensors::V1_0::SharedMemInfo; using ::android::hardware::sensors::V2_0::ISensorsCallback; /* /* * The ISensorsWrapper interface includes all function from supported Sensors HAL versions. This * The ISensorsWrapper interface includes all function from supported Sensors HAL versions. This Loading Loading @@ -85,10 +87,12 @@ public: return Return<void>(); return Return<void>(); } } virtual Return<Result> initializeMessageQueues(const MQDescriptorSync<Event>& eventQueueDesc, virtual Return<Result> initialize(const MQDescriptorSync<Event>& eventQueueDesc, const MQDescriptorSync<uint32_t>& wakeLockDesc) { const MQDescriptorSync<uint32_t>& wakeLockDesc, const ::android::sp<ISensorsCallback>& callback) { (void)eventQueueDesc; (void)eventQueueDesc; (void)wakeLockDesc; (void)wakeLockDesc; (void)callback; // TODO (b/111070257): Generate an assert-level error since this should never be called // TODO (b/111070257): Generate an assert-level error since this should never be called // directly // directly return Result::INVALID_OPERATION; return Result::INVALID_OPERATION; Loading Loading @@ -177,10 +181,10 @@ public: return true; return true; } } Return<Result> initializeMessageQueues( Return<Result> initialize(const MQDescriptorSync<Event>& eventQueueDesc, const MQDescriptorSync<Event>& eventQueueDesc, const MQDescriptorSync<uint32_t>& wakeLockDesc, const MQDescriptorSync<uint32_t>& wakeLockDesc) override { const ::android::sp<ISensorsCallback>& callback) override { return mSensors->initializeMessageQueues(eventQueueDesc, wakeLockDesc); return mSensors->initialize(eventQueueDesc, wakeLockDesc, callback); } } }; }; Loading