+ entry_ts = get_timestamp_thread();
+
+ /*
+ * The Intel sensor hub seems to have trouble enabling sensors before
+ * a sampling rate has been configured, and setting the sampling rate
+ * after it's been enabled does not seem to revive affected sensors.
+ * The issue does not show up with an up to date ISH firmware but as the
+ * updater is a Windows only tool and is not widely available, implement
+ * a workaround for this behavior. We set the initial sampling rate to
+ * 10 events per second when the sensor is enabled for the first time.
+ */
+
+ if (enabled && sensor_get_quirks(handle) & QUIRK_INITIAL_RATE) {
+ ALOGI("Forcing initial sampling rate\n");
+ sensor_activate(handle, 1, 0);
+ sensor_set_delay(handle, 100000000); /* Start with 100 ms */
+ sensor_activate(handle, 0, 0);
+
+ /* Clear flag for this sensor as do this only once */
+ sensor[handle].quirks ^= QUIRK_INITIAL_RATE;
+ }
+
+ ret = sensor_activate(handle, enabled, 0);
+
+ elapsed_ms = (int) ((get_timestamp_thread() - entry_ts) / 1000000);
+
+ if (elapsed_ms) {
+ if (enabled)
+ ALOGI("Activation of sensor %s took %d ms\n", sensor[handle].friendly_name, elapsed_ms);
+ else
+ ALOGI("Deactivation of sensor %s took %d ms\n", sensor[handle].friendly_name, elapsed_ms);
+ }
+
+ return ret;