+static void swap_sensors (int s1, int s2)
+{
+ struct sensor_t temp_sensor_desc;
+ sensor_info_t temp_sensor;
+
+ /* S1 -> temp */
+ memcpy(&temp_sensor, &sensor[s1], sizeof(sensor_info_t));
+ memcpy(&temp_sensor_desc, &sensor_desc[s1], sizeof(struct sensor_t));
+
+ /* S2 -> S1 */
+ memcpy(&sensor[s1], &sensor[s2], sizeof(sensor_info_t));
+ memcpy(&sensor_desc[s1], &sensor_desc[s2], sizeof(struct sensor_t));
+
+ /* temp -> S2 */
+ memcpy(&sensor[s2], &temp_sensor, sizeof(sensor_info_t));
+ memcpy(&sensor_desc[s2], &temp_sensor_desc, sizeof(struct sensor_t));
+
+ /* Fix-up sensor id mapping, which is stale */
+ sensor_desc[s1].handle = s1;
+ sensor_desc[s2].handle = s2;
+
+ /* Fix up name and vendor buffer pointers, which are potentially stale pointers */
+ sensor_desc[s1].name = sensor_get_name(s1);
+ sensor_desc[s1].vendor = sensor_get_vendor(s1);
+ sensor_desc[s2].name = sensor_get_name(s2);
+ sensor_desc[s2].vendor = sensor_get_vendor(s2);
+}
+
+
+static void reorder_sensors (void)
+{
+ /* Some sensors may be marked as secondary - these need to be listed after other sensors of the same type */
+ int s1, s2;
+
+ for (s1=0; s1<sensor_count-1; s1++)
+ if (sensor[s1].quirks & QUIRK_SECONDARY) {
+ /* Search for subsequent sensors of same type */
+ for (s2 = s1+1; s2<sensor_count; s2++)
+ if (sensor[s2].type == sensor[s1].type && !(sensor[s2].quirks & QUIRK_SECONDARY)) {
+ ALOGI("Sensor S%d has higher priority than S%d, swapping\n", s2, s1);
+ swap_sensors(s1, s2);
+ break;
+ }
+ }
+}
+
+