MH2 | Implement ScopeWakelock ctor and dtor
Put the ScopedWakelock class into its own header and its implementation
into its own cpp. Implement the refcounting of the wakelocks. However,
do not incorporate the wakelock handling into post events in halproxy
yet.
Bug: 136511617
Test: No new tests yet. Will add more in a later patchset once more
fleshed out and integrated with postEvents.
Change-Id: I0815c6a6659ec5933b799294956595b11e7bf1b3
diff --git a/sensors/2.0/multihal/include/HalProxy.h b/sensors/2.0/multihal/include/HalProxy.h
index 6c50eef..bdcc1ff 100644
--- a/sensors/2.0/multihal/include/HalProxy.h
+++ b/sensors/2.0/multihal/include/HalProxy.h
@@ -41,7 +41,7 @@
using ::android::hardware::Return;
using ::android::hardware::Void;
-class HalProxy : public ISensors {
+class HalProxy : public ISensors, public IScopedWakelockRefCounter {
public:
using Event = ::android::hardware::sensors::V1_0::Event;
using OperationMode = ::android::hardware::sensors::V1_0::OperationMode;
@@ -95,6 +95,18 @@
Return<void> onDynamicSensorsDisconnected(const hidl_vec<int32_t>& dynamicSensorHandlesRemoved,
int32_t subHalIndex);
+ // Below methods follow IScopedWakelockRefCounter
+
+ /**
+ * Increment ref count and maybe acquire wakelock.
+ */
+ void incrementRefCountAndMaybeAcquireWakelock() override;
+
+ /**
+ * Decrement ref count and maybe release wakelock.
+ */
+ void decrementRefCountAndMaybeReleaseWakelock() override;
+
// Below methods are for HalProxyCallback
/**
@@ -120,6 +132,8 @@
using EventMessageQueue = MessageQueue<Event, kSynchronizedReadWrite>;
using WakeLockMessageQueue = MessageQueue<uint32_t, kSynchronizedReadWrite>;
+ const char* kWakeLockName = "SensorsHAL_WAKEUP";
+
/**
* The Event FMQ where sensor events are written
*/
@@ -165,6 +179,12 @@
//! The mutex for the event queue.
std::mutex mEventQueueMutex;
+ //! The scoped wakelock ref count.
+ size_t mWakelockRefCount = 0;
+
+ //! The mutex guarding the mWakelockRefCount variable
+ std::mutex mWakelockRefCountMutex;
+
//! The bit mask used to get the subhal index from a sensor handle.
static constexpr uint32_t kSensorHandleSubHalIndexMask = 0xFF000000;
@@ -219,11 +239,6 @@
static uint32_t clearSubHalIndex(uint32_t sensorHandle);
};
-// TODO: Use this wake lock name as the prefix to all sensors HAL wake locks acquired.
-// constexpr const char* kWakeLockName = "SensorsHAL_WAKEUP";
-
-// TODO: Use the following class as a starting point for implementing the full HalProxyCallback
-// along with being inspiration for how to implement the ScopedWakelock class.
/**
* Callback class used to provide the HalProxy with the index of which subHal is invoking
*/