Sensor.cpp changes.

1) Rename TILT_DETECTOR
  2) Set mFlags correctly for wake-up sensors.
  2) Log errors for incorrect sensor flags.

Change-Id: Ia449217d3b8a53353ad6b5c33c544ce37eb1de4f
This commit is contained in:
Aravind Akella 2014-07-29 12:27:41 -07:00
parent 9ae79d869a
commit 64ffcb0944

View File

@ -80,6 +80,10 @@ Sensor::Sensor(struct sensor_t const* hwSensor, int halVersion)
} }
// Ensure existing sensors have correct string type, required permissions and reporting mode. // Ensure existing sensors have correct string type, required permissions and reporting mode.
// Set reportingMode for all android defined sensor types, set wake-up flag only for proximity
// sensor, significant motion, tilt, pick_up gesture, wake gesture and glance gesture on older
// HALs. Newer HALs can define both wake-up and non wake-up proximity sensors.
// All the OEM defined defined sensors have flags set to whatever is provided by the HAL.
switch (mType) { switch (mType) {
case SENSOR_TYPE_ACCELEROMETER: case SENSOR_TYPE_ACCELEROMETER:
mStringType = SENSOR_STRING_TYPE_ACCELEROMETER; mStringType = SENSOR_STRING_TYPE_ACCELEROMETER;
@ -140,7 +144,10 @@ Sensor::Sensor(struct sensor_t const* hwSensor, int halVersion)
break; break;
case SENSOR_TYPE_PROXIMITY: case SENSOR_TYPE_PROXIMITY:
mStringType = SENSOR_STRING_TYPE_PROXIMITY; mStringType = SENSOR_STRING_TYPE_PROXIMITY;
mFlags |= (SENSOR_FLAG_ON_CHANGE_MODE | SENSOR_FLAG_WAKE_UP); mFlags |= SENSOR_FLAG_ON_CHANGE_MODE;
if (halVersion < SENSORS_DEVICE_API_VERSION_1_3) {
mFlags |= SENSOR_FLAG_WAKE_UP;
}
break; break;
case SENSOR_TYPE_RELATIVE_HUMIDITY: case SENSOR_TYPE_RELATIVE_HUMIDITY:
mStringType = SENSOR_STRING_TYPE_RELATIVE_HUMIDITY; mStringType = SENSOR_STRING_TYPE_RELATIVE_HUMIDITY;
@ -152,7 +159,10 @@ Sensor::Sensor(struct sensor_t const* hwSensor, int halVersion)
break; break;
case SENSOR_TYPE_SIGNIFICANT_MOTION: case SENSOR_TYPE_SIGNIFICANT_MOTION:
mStringType = SENSOR_STRING_TYPE_SIGNIFICANT_MOTION; mStringType = SENSOR_STRING_TYPE_SIGNIFICANT_MOTION;
mFlags |= (SENSOR_FLAG_ONE_SHOT_MODE | SENSOR_FLAG_WAKE_UP); mFlags |= SENSOR_FLAG_ONE_SHOT_MODE;
if (halVersion < SENSORS_DEVICE_API_VERSION_1_3) {
mFlags |= SENSOR_FLAG_WAKE_UP;
}
break; break;
case SENSOR_TYPE_STEP_COUNTER: case SENSOR_TYPE_STEP_COUNTER:
mStringType = SENSOR_STRING_TYPE_STEP_COUNTER; mStringType = SENSOR_STRING_TYPE_STEP_COUNTER;
@ -166,21 +176,33 @@ Sensor::Sensor(struct sensor_t const* hwSensor, int halVersion)
mStringType = SENSOR_STRING_TYPE_TEMPERATURE; mStringType = SENSOR_STRING_TYPE_TEMPERATURE;
mFlags |= SENSOR_FLAG_ON_CHANGE_MODE; mFlags |= SENSOR_FLAG_ON_CHANGE_MODE;
break; break;
case SENSOR_TYPE_WAKE_UP_TILT_DETECTOR: case SENSOR_TYPE_TILT_DETECTOR:
mStringType = SENSOR_STRING_TYPE_WAKE_UP_TILT_DETECTOR; mStringType = SENSOR_STRING_TYPE_TILT_DETECTOR;
mFlags |= (SENSOR_FLAG_SPECIAL_REPORTING_MODE | SENSOR_FLAG_WAKE_UP); mFlags |= SENSOR_FLAG_SPECIAL_REPORTING_MODE;
if (halVersion < SENSORS_DEVICE_API_VERSION_1_3) {
mFlags |= SENSOR_FLAG_WAKE_UP;
}
break; break;
case SENSOR_TYPE_WAKE_GESTURE: case SENSOR_TYPE_WAKE_GESTURE:
mStringType = SENSOR_STRING_TYPE_WAKE_GESTURE; mStringType = SENSOR_STRING_TYPE_WAKE_GESTURE;
mFlags |= (SENSOR_FLAG_ONE_SHOT_MODE | SENSOR_FLAG_WAKE_UP); mFlags |= SENSOR_FLAG_ONE_SHOT_MODE;
if (halVersion < SENSORS_DEVICE_API_VERSION_1_3) {
mFlags |= SENSOR_FLAG_WAKE_UP;
}
break; break;
case SENSOR_TYPE_GLANCE_GESTURE: case SENSOR_TYPE_GLANCE_GESTURE:
mStringType = SENSOR_STRING_TYPE_GLANCE_GESTURE; mStringType = SENSOR_STRING_TYPE_GLANCE_GESTURE;
mFlags |= (SENSOR_FLAG_ONE_SHOT_MODE | SENSOR_FLAG_WAKE_UP); mFlags |= SENSOR_FLAG_ONE_SHOT_MODE;
if (halVersion < SENSORS_DEVICE_API_VERSION_1_3) {
mFlags |= SENSOR_FLAG_WAKE_UP;
}
break; break;
case SENSOR_TYPE_PICK_UP_GESTURE: case SENSOR_TYPE_PICK_UP_GESTURE:
mStringType = SENSOR_STRING_TYPE_PICK_UP_GESTURE; mStringType = SENSOR_STRING_TYPE_PICK_UP_GESTURE;
mFlags |= (SENSOR_FLAG_ONE_SHOT_MODE | SENSOR_FLAG_WAKE_UP); mFlags |= SENSOR_FLAG_ONE_SHOT_MODE;
if (halVersion < SENSORS_DEVICE_API_VERSION_1_3) {
mFlags |= SENSOR_FLAG_WAKE_UP;
}
break; break;
default: default:
// Only pipe the stringType, requiredPermission and flags for custom sensors. // Only pipe the stringType, requiredPermission and flags for custom sensors.
@ -206,6 +228,23 @@ Sensor::Sensor(struct sensor_t const* hwSensor, int halVersion)
} }
break; break;
} }
// For the newer HALs log errors if reporting mask flags are set incorrectly.
if (halVersion >= SENSORS_DEVICE_API_VERSION_1_3) {
// Wake-up flag is set here.
mFlags |= (hwSensor->flags & SENSOR_FLAG_WAKE_UP);
if (mFlags != hwSensor->flags) {
int actualReportingMode =
(hwSensor->flags & REPORTING_MODE_MASK) >> REPORTING_MODE_SHIFT;
int expectedReportingMode = (mFlags & REPORTING_MODE_MASK) >> REPORTING_MODE_SHIFT;
if (actualReportingMode != expectedReportingMode) {
ALOGE("Reporting Mode incorrect: sensor %s handle=%d type=%d "
"actual=%d expected=%d",
mName.string(), mHandle, mType, actualReportingMode, expectedReportingMode);
}
}
}
} }
Sensor::~Sensor() Sensor::~Sensor()