MH2 | Implement dynamic sensors callbacks on HalProxy

Additionally, have HalProxyCallback::processEvents use
HalProxy::setSubHalIndex static method instead of its own helper.
Add unit tests to test the dynamic sensor methods.

Bug: 136511617
Test: New unit tests are passing.
Change-Id: Ib903291a83df2fafa480082f9305c594bd325f79
diff --git a/sensors/2.0/multihal/include/HalProxy.h b/sensors/2.0/multihal/include/HalProxy.h
index ae4b2c5..47571a6 100644
--- a/sensors/2.0/multihal/include/HalProxy.h
+++ b/sensors/2.0/multihal/include/HalProxy.h
@@ -176,6 +176,9 @@
      */
     std::map<uint32_t, SensorInfo> mSensors;
 
+    //! Map of the dynamic sensors that have been added to halproxy.
+    std::map<uint32_t, SensorInfo> mDynamicSensors;
+
     //! The current operation mode for all subhals.
     OperationMode mCurrentOperationMode = OperationMode::NORMAL;
 
@@ -212,6 +215,9 @@
     //! The bool indicating whether to end the pending writes background thread or not
     bool mPendingWritesRun = true;
 
+    //! The mutex protecting access to the dynamic sensors added and removed methods.
+    std::mutex mDynamicSensorsMutex;
+
     /**
      * Initialize the list of SubHal objects in mSubHalList by reading from dynamic libraries
      * listed in a config file.
@@ -271,6 +277,13 @@
      * @return The modified version of the sensor handle.
      */
     static uint32_t clearSubHalIndex(uint32_t sensorHandle);
+
+    /**
+     * @param sensorHandle The sensor handle to modify.
+     *
+     * @return true if subHalIndex byte of sensorHandle is zeroed.
+     */
+    static bool subHalIndexIsClear(uint32_t sensorHandle);
 };
 
 /**
@@ -303,8 +316,6 @@
 
     std::vector<Event> processEvents(const std::vector<Event>& events,
                                      size_t* numWakeupEvents) const;
-
-    uint32_t setSubHalIndex(uint32_t sensorHandle) const;
 };
 
 }  // namespace implementation