Loading sensors/aidl/default/Sensors.cpp +19 −13 Original line number Diff line number Diff line Loading @@ -82,6 +82,7 @@ ScopedAStatus Sensors::initialize( const MQDescriptor<int32_t, SynchronizedReadWrite>& in_wakeLockDescriptor, const std::shared_ptr<::aidl::android::hardware::sensors::ISensorsCallback>& in_sensorsCallback) { ALOGI("Sensors initializing"); ScopedAStatus result = ScopedAStatus::ok(); mEventQueue = std::make_unique<AidlMessageQueue<Event, SynchronizedReadWrite>>( Loading @@ -101,8 +102,12 @@ ScopedAStatus Sensors::initialize( // Save a reference to the callback mCallback = in_sensorsCallback; { // Hold the lock to ensure that re-creation of event flag is atomic std::lock_guard<std::mutex> lock(mWriteLock); // Ensure that any existing EventFlag is properly deleted deleteEventFlag(); deleteEventFlagLocked(); // Create the EventFlag that is used to signal to the framework that sensor events have been // written to the Event FMQ Loading @@ -118,6 +123,7 @@ ScopedAStatus Sensors::initialize( if (!mCallback || !mEventQueue || !mWakeLockQueue || mEventQueueFlag == nullptr) { result = ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); } } // Start the thread to read events from the Wake Lock FMQ mReadWakeLockQueueRun = true; Loading sensors/aidl/default/include/sensors-impl/Sensors.h +8 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ #include <map> #include "Sensor.h" #include <android-base/thread_annotations.h> namespace aidl { namespace android { namespace hardware { Loading Loading @@ -125,6 +127,11 @@ class Sensors : public BnSensors, public ISensorsEventCallback { void deleteEventFlag() { // Hold the lock to ensure we don't delete the flag while it's being used in postEvents() std::lock_guard<std::mutex> lock(mWriteLock); deleteEventFlagLocked(); } // Expects mWriteLock to be locked prior to invocation void deleteEventFlagLocked() { if (mEventQueueFlag != nullptr) { status_t status = EventFlag::deleteEventFlag(&mEventQueueFlag); if (status != OK) { Loading Loading @@ -193,7 +200,7 @@ class Sensors : public BnSensors, public ISensorsEventCallback { // The Wake Lock FMQ that is read to determine when the framework has handled WAKE_UP events std::unique_ptr<AidlMessageQueue<int32_t, SynchronizedReadWrite>> mWakeLockQueue; // Event Flag to signal to the framework when sensor events are available to be read EventFlag* mEventQueueFlag; EventFlag* mEventQueueFlag GUARDED_BY(mWriteLock); // Callback for asynchronous events, such as dynamic sensor connections. std::shared_ptr<::aidl::android::hardware::sensors::ISensorsCallback> mCallback; // A map of the available sensors. Loading Loading
sensors/aidl/default/Sensors.cpp +19 −13 Original line number Diff line number Diff line Loading @@ -82,6 +82,7 @@ ScopedAStatus Sensors::initialize( const MQDescriptor<int32_t, SynchronizedReadWrite>& in_wakeLockDescriptor, const std::shared_ptr<::aidl::android::hardware::sensors::ISensorsCallback>& in_sensorsCallback) { ALOGI("Sensors initializing"); ScopedAStatus result = ScopedAStatus::ok(); mEventQueue = std::make_unique<AidlMessageQueue<Event, SynchronizedReadWrite>>( Loading @@ -101,8 +102,12 @@ ScopedAStatus Sensors::initialize( // Save a reference to the callback mCallback = in_sensorsCallback; { // Hold the lock to ensure that re-creation of event flag is atomic std::lock_guard<std::mutex> lock(mWriteLock); // Ensure that any existing EventFlag is properly deleted deleteEventFlag(); deleteEventFlagLocked(); // Create the EventFlag that is used to signal to the framework that sensor events have been // written to the Event FMQ Loading @@ -118,6 +123,7 @@ ScopedAStatus Sensors::initialize( if (!mCallback || !mEventQueue || !mWakeLockQueue || mEventQueueFlag == nullptr) { result = ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); } } // Start the thread to read events from the Wake Lock FMQ mReadWakeLockQueueRun = true; Loading
sensors/aidl/default/include/sensors-impl/Sensors.h +8 −1 Original line number Diff line number Diff line Loading @@ -23,6 +23,8 @@ #include <map> #include "Sensor.h" #include <android-base/thread_annotations.h> namespace aidl { namespace android { namespace hardware { Loading Loading @@ -125,6 +127,11 @@ class Sensors : public BnSensors, public ISensorsEventCallback { void deleteEventFlag() { // Hold the lock to ensure we don't delete the flag while it's being used in postEvents() std::lock_guard<std::mutex> lock(mWriteLock); deleteEventFlagLocked(); } // Expects mWriteLock to be locked prior to invocation void deleteEventFlagLocked() { if (mEventQueueFlag != nullptr) { status_t status = EventFlag::deleteEventFlag(&mEventQueueFlag); if (status != OK) { Loading Loading @@ -193,7 +200,7 @@ class Sensors : public BnSensors, public ISensorsEventCallback { // The Wake Lock FMQ that is read to determine when the framework has handled WAKE_UP events std::unique_ptr<AidlMessageQueue<int32_t, SynchronizedReadWrite>> mWakeLockQueue; // Event Flag to signal to the framework when sensor events are available to be read EventFlag* mEventQueueFlag; EventFlag* mEventQueueFlag GUARDED_BY(mWriteLock); // Callback for asynchronous events, such as dynamic sensor connections. std::shared_ptr<::aidl::android::hardware::sensors::ISensorsCallback> mCallback; // A map of the available sensors. Loading