Track if sensor is active

Keep track of if a sensor has been activated within the Sensor Device.
This prevents a possible race-condition if the Sensors NDK API is used
incorrectly by calling setEventRate prior to enabling a sensor causing
the SensorDevice and SensorService to become out of sync with each
other. In such a situation, the Sensor Device could end up with two
sets of batch parameters for a sensor before activating the sensor.

Previously, if there is more than one set of batch parameters, the
SensorDevice assumes that the device has been activated and will not
activate the sensor. This patch modifies that logic to check if the
sensor is actually activated, and the sensor will be activated if it
is not. This prevents the SensorService and SensorDevice from becoming
out of sync.

Bug: 113594036
Test: CTS SensorOperationTests pass
Test: Created an NDK client that calls setEventRate then waits to call
      enableSensor. During the wait, launched second instance of
      client. Verified that events are not received by the clients
      without this patch, and the SensorService and SensorDevice
      became out-of-sync. With this patch, the SensorService and
      SensorDevice remained in sync, the sensor was activated, and the
      clients received events.

Change-Id: Ifa8281de63d5de7c4a8bbf825982ce28613b3d2c
diff --git a/services/sensorservice/SensorDevice.h b/services/sensorservice/SensorDevice.h
index 71b918f..e8685c2 100644
--- a/services/sensorservice/SensorDevice.h
+++ b/services/sensorservice/SensorDevice.h
@@ -165,6 +165,9 @@
         // requested by the client.
         KeyedVector<void*, BatchParams> batchParams;
 
+        // Flag to track if the sensor is active
+        bool isActive = false;
+
         // Sets batch parameters for this ident. Returns error if this ident is not already present
         // in the KeyedVector above.
         status_t setBatchParamsForIdent(void* ident, int flags, int64_t samplingPeriodNs,