MH2 | Add restart logic in HalProxy::initialize method.
Bug: 136511617
Test: None yet
Change-Id: I389a7243d3612586aae4e8a802afda92af8dcc6d
diff --git a/sensors/2.0/multihal/include/HalProxy.h b/sensors/2.0/multihal/include/HalProxy.h
index 6592afe..26bc644 100644
--- a/sensors/2.0/multihal/include/HalProxy.h
+++ b/sensors/2.0/multihal/include/HalProxy.h
@@ -149,9 +149,13 @@
std::unique_ptr<WakeLockMessageQueue> mWakeLockQueue;
/**
- * Event Flag to signal to the framework when sensor events are available to be read
+ * Event Flag to signal to the framework when sensor events are available to be read and to
+ * interrupt event queue blocking write.
*/
- EventFlag* mEventQueueFlag;
+ EventFlag* mEventQueueFlag = nullptr;
+
+ //! Event Flag to signal internally that the wakelock queue should stop its blocking read.
+ EventFlag* mWakelockQueueFlag = nullptr;
/**
* Callback to the sensors framework to inform it that new sensors have been added or removed.
@@ -254,6 +258,16 @@
void init();
/**
+ * Stops all threads by setting the threads running flag to false and joining to them.
+ */
+ void stopThreads();
+
+ /**
+ * Disable all the sensors observed by the HalProxy.
+ */
+ void disableAllSensors();
+
+ /**
* Starts the thread that handles pending writes to event fmq.
*
* @param halProxy The HalProxy object pointer.
diff --git a/sensors/2.0/multihal/include/SubHal.h b/sensors/2.0/multihal/include/SubHal.h
index e7eedaa..92ae3a6 100644
--- a/sensors/2.0/multihal/include/SubHal.h
+++ b/sensors/2.0/multihal/include/SubHal.h
@@ -130,11 +130,13 @@
virtual const std::string getName() = 0;
/**
- * First method invoked on the sub-HAL after it's allocated through sensorsHalGetSubHal() by the
- * HalProxy. Sub-HALs should use this to initialize any state and retain the callback given in
- * order to communicate with the HalProxy. Method will be called anytime the sensors framework
- * restarts. Therefore, this method will be responsible for reseting the state of the subhal and
- * cleaning up and reallocating any previously allocated data.
+ * This is the first method invoked on the sub-HAL after it's allocated through
+ * sensorsHalGetSubHal() by the HalProxy. Sub-HALs should use this to initialize any state and
+ * retain the callback given in order to communicate with the HalProxy. Method will be called
+ * anytime the sensors framework restarts. Therefore, this method will be responsible for
+ * reseting the state of the subhal and cleaning up and reallocating any previously allocated
+ * data. Initialize should ensure that the subhal has reset its operation mode to NORMAL state
+ * as well.
*
* @param halProxyCallback callback used to inform the HalProxy when a dynamic sensor's state
* changes, new sensor events should be sent to the framework, and when a new ScopedWakelock