Release dynamic sensor data at the end of process

This makes sure that sensor service has full control of the life time of
the dynamic sensor data, and will not be affected by when the callback
is invoked.

Fixes: 329020894
Fixes: 337741176
Test: Connect a dynamic sensor to phone, rapidly turn on/off bluetooth to
emulate fast connection/disconnection of dynamic sensor. Not seeing
crash anymore

Change-Id: I6c9b4fa06e08dc1bb0b5e578ee2ec10b95fe84c3
diff --git a/services/sensorservice/SensorDevice.h b/services/sensorservice/SensorDevice.h
index 52f7cf2..b7b04b5 100644
--- a/services/sensorservice/SensorDevice.h
+++ b/services/sensorservice/SensorDevice.h
@@ -63,6 +63,14 @@
     std::vector<int32_t> getDynamicSensorHandles();
 
     void handleDynamicSensorConnection(int handle, bool connected);
+    /**
+     * Removes handle from connected dynamic sensor list. Note that this method must be called after
+     * SensorService has done using sensor data.
+     *
+     * @param handle of the disconnected dynamic sensor.
+     */
+    void cleanupDisconnectedDynamicSensor(int handle);
+
     status_t initCheck() const;
     int getHalDeviceVersion() const;