sensorhal: fix incorrect rate/latency retention for alt sensors

When disabling a sensor with alt versions enabled the rate and latency
from the disabled sensor would be used if it was higher (rate) or lower
(latency) than any of the enabled alt versions.

Initialize rate and latency to values such that they will always be
set by the first enabled alt sensor. (0 for rate and max value for
latency)

Test: enable accel at 50Hz; enable uncal accel at 200Hz; disable uncal
accel; verify accel is running at 50Hz, not 200Hz
Bug: 122115010
Change-Id: Iac172495235360fbd15bd76abf9b7fdef4d1f6f5
Signed-off-by: Ben Fennema <fennema@google.com>
diff --git a/sensorhal/hubconnection.cpp b/sensorhal/hubconnection.cpp
index 83392f2..01a5d2d 100644
--- a/sensorhal/hubconnection.cpp
+++ b/sensorhal/hubconnection.cpp
@@ -1668,9 +1668,18 @@
 
     cmd->evtType = EVT_NO_SENSOR_CONFIG_EVENT;
     cmd->sensorType = mSensorState[handle].sensorType;
-    cmd->cmd = mSensorState[handle].enable ? CONFIG_CMD_ENABLE : CONFIG_CMD_DISABLE;
-    cmd->rate = mSensorState[handle].rate;
-    cmd->latency = mSensorState[handle].latency;
+
+    if (mSensorState[handle].enable) {
+        cmd->cmd = CONFIG_CMD_ENABLE;
+        cmd->rate = mSensorState[handle].rate;
+        cmd->latency = mSensorState[handle].latency;
+    } else {
+        cmd->cmd = CONFIG_CMD_DISABLE;
+        // set rate and latency to values that will always be overwritten by the
+        // first enabled alt sensor
+        cmd->rate = UINT32_C(0);
+        cmd->latency = UINT64_MAX;
+    }
 
     for (int i=0; i<MAX_ALTERNATES; ++i) {
         uint8_t alt = mSensorState[handle].alt[i];