: mHandle(0), mType(0),
mMinValue(0), mMaxValue(0), mResolution(0),
mPower(0), mMinDelay(0), mFifoReservedEventCount(0), mFifoMaxEventCount(0),
- mMaxDelay(0), mWakeUpSensor(false)
+ mMaxDelay(0), mFlags(0)
{
}
mResolution = hwSensor->resolution;
mPower = hwSensor->power;
mMinDelay = hwSensor->minDelay;
- mWakeUpSensor = false;
+ mFlags = 0;
// Set fifo event count zero for older devices which do not support batching. Fused
// sensors also have their fifo counts set to zero.
mMaxDelay = 0;
}
- // Ensure existing sensors have correct string type and required
- // permissions.
+ // Ensure existing sensors have correct string type, required permissions and reporting mode.
switch (mType) {
case SENSOR_TYPE_ACCELEROMETER:
mStringType = SENSOR_STRING_TYPE_ACCELEROMETER;
+ mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
break;
case SENSOR_TYPE_AMBIENT_TEMPERATURE:
mStringType = SENSOR_STRING_TYPE_AMBIENT_TEMPERATURE;
+ mFlags |= SENSOR_FLAG_ON_CHANGE_MODE;
break;
case SENSOR_TYPE_GAME_ROTATION_VECTOR:
mStringType = SENSOR_STRING_TYPE_GAME_ROTATION_VECTOR;
+ mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
break;
case SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR:
mStringType = SENSOR_STRING_TYPE_GEOMAGNETIC_ROTATION_VECTOR;
+ mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
break;
case SENSOR_TYPE_GRAVITY:
mStringType = SENSOR_STRING_TYPE_GRAVITY;
+ mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
break;
case SENSOR_TYPE_GYROSCOPE:
mStringType = SENSOR_STRING_TYPE_GYROSCOPE;
+ mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
break;
case SENSOR_TYPE_GYROSCOPE_UNCALIBRATED:
mStringType = SENSOR_STRING_TYPE_GYROSCOPE_UNCALIBRATED;
+ mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
break;
case SENSOR_TYPE_HEART_RATE:
mStringType = SENSOR_STRING_TYPE_HEART_RATE;
mRequiredPermission = SENSOR_PERMISSION_BODY_SENSORS;
+ mFlags |= SENSOR_FLAG_ON_CHANGE_MODE;
break;
case SENSOR_TYPE_LIGHT:
mStringType = SENSOR_STRING_TYPE_LIGHT;
+ mFlags |= SENSOR_FLAG_ON_CHANGE_MODE;
break;
case SENSOR_TYPE_LINEAR_ACCELERATION:
mStringType = SENSOR_STRING_TYPE_LINEAR_ACCELERATION;
+ mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
break;
case SENSOR_TYPE_MAGNETIC_FIELD:
mStringType = SENSOR_STRING_TYPE_MAGNETIC_FIELD;
+ mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
break;
case SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED:
mStringType = SENSOR_STRING_TYPE_MAGNETIC_FIELD_UNCALIBRATED;
+ mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
break;
case SENSOR_TYPE_ORIENTATION:
mStringType = SENSOR_STRING_TYPE_ORIENTATION;
+ mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
break;
case SENSOR_TYPE_PRESSURE:
mStringType = SENSOR_STRING_TYPE_PRESSURE;
+ mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
break;
case SENSOR_TYPE_PROXIMITY:
mStringType = SENSOR_STRING_TYPE_PROXIMITY;
- mWakeUpSensor = true;
+ mFlags |= (SENSOR_FLAG_ON_CHANGE_MODE | SENSOR_FLAG_WAKE_UP);
break;
case SENSOR_TYPE_RELATIVE_HUMIDITY:
mStringType = SENSOR_STRING_TYPE_RELATIVE_HUMIDITY;
+ mFlags |= SENSOR_FLAG_ON_CHANGE_MODE;
break;
case SENSOR_TYPE_ROTATION_VECTOR:
mStringType = SENSOR_STRING_TYPE_ROTATION_VECTOR;
+ mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
break;
case SENSOR_TYPE_SIGNIFICANT_MOTION:
mStringType = SENSOR_STRING_TYPE_SIGNIFICANT_MOTION;
- mWakeUpSensor = true;
+ mFlags |= (SENSOR_FLAG_ONE_SHOT_MODE | SENSOR_FLAG_WAKE_UP);
break;
case SENSOR_TYPE_STEP_COUNTER:
mStringType = SENSOR_STRING_TYPE_STEP_COUNTER;
+ mFlags |= SENSOR_FLAG_ON_CHANGE_MODE;
break;
case SENSOR_TYPE_STEP_DETECTOR:
mStringType = SENSOR_STRING_TYPE_STEP_DETECTOR;
+ mFlags |= SENSOR_FLAG_SPECIAL_REPORTING_MODE;
break;
case SENSOR_TYPE_TEMPERATURE:
mStringType = SENSOR_STRING_TYPE_TEMPERATURE;
+ mFlags |= SENSOR_FLAG_ON_CHANGE_MODE;
break;
case SENSOR_TYPE_NON_WAKE_UP_PROXIMITY_SENSOR:
mStringType = SENSOR_STRING_TYPE_NON_WAKE_UP_PROXIMITY_SENSOR;
+ mFlags |= SENSOR_FLAG_ON_CHANGE_MODE;
break;
case SENSOR_TYPE_WAKE_UP_ACCELEROMETER:
mStringType = SENSOR_STRING_TYPE_WAKE_UP_ACCELEROMETER;
- mWakeUpSensor = true;
+ mFlags |= (SENSOR_FLAG_CONTINUOUS_MODE | SENSOR_FLAG_WAKE_UP);
break;
case SENSOR_TYPE_WAKE_UP_MAGNETIC_FIELD:
mStringType = SENSOR_STRING_TYPE_WAKE_UP_MAGNETIC_FIELD;
- mWakeUpSensor = true;
+ mFlags |= (SENSOR_FLAG_CONTINUOUS_MODE | SENSOR_FLAG_WAKE_UP);
break;
case SENSOR_TYPE_WAKE_UP_ORIENTATION:
mStringType = SENSOR_STRING_TYPE_WAKE_UP_ORIENTATION;
- mWakeUpSensor = true;
+ mFlags |= (SENSOR_FLAG_CONTINUOUS_MODE | SENSOR_FLAG_WAKE_UP);
break;
case SENSOR_TYPE_WAKE_UP_GYROSCOPE:
mStringType = SENSOR_STRING_TYPE_WAKE_UP_GYROSCOPE;
- mWakeUpSensor = true;
+ mFlags |= (SENSOR_FLAG_CONTINUOUS_MODE | SENSOR_FLAG_WAKE_UP);
break;
case SENSOR_TYPE_WAKE_UP_LIGHT:
mStringType = SENSOR_STRING_TYPE_WAKE_UP_LIGHT;
- mWakeUpSensor = true;
+ mFlags |= (SENSOR_FLAG_ON_CHANGE_MODE | SENSOR_FLAG_WAKE_UP);
break;
case SENSOR_TYPE_WAKE_UP_PRESSURE:
mStringType = SENSOR_STRING_TYPE_WAKE_UP_PRESSURE;
- mWakeUpSensor = true;
+ mFlags |= (SENSOR_FLAG_CONTINUOUS_MODE | SENSOR_FLAG_WAKE_UP);
break;
case SENSOR_TYPE_WAKE_UP_GRAVITY:
mStringType = SENSOR_STRING_TYPE_WAKE_UP_GRAVITY;
- mWakeUpSensor = true;
+ mFlags |= (SENSOR_FLAG_CONTINUOUS_MODE | SENSOR_FLAG_WAKE_UP);
break;
case SENSOR_TYPE_WAKE_UP_LINEAR_ACCELERATION:
mStringType = SENSOR_STRING_TYPE_WAKE_UP_LINEAR_ACCELERATION;
- mWakeUpSensor = true;
+ mFlags |= (SENSOR_FLAG_CONTINUOUS_MODE | SENSOR_FLAG_WAKE_UP);
break;
case SENSOR_TYPE_WAKE_UP_ROTATION_VECTOR:
mStringType = SENSOR_STRING_TYPE_WAKE_UP_ROTATION_VECTOR;
- mWakeUpSensor = true;
+ mFlags |= (SENSOR_FLAG_CONTINUOUS_MODE | SENSOR_FLAG_WAKE_UP);
break;
case SENSOR_TYPE_WAKE_UP_RELATIVE_HUMIDITY:
mStringType = SENSOR_STRING_TYPE_WAKE_UP_RELATIVE_HUMIDITY;
- mWakeUpSensor = true;
+ mFlags |= (SENSOR_FLAG_SPECIAL_REPORTING_MODE | SENSOR_FLAG_WAKE_UP);
break;
case SENSOR_TYPE_WAKE_UP_AMBIENT_TEMPERATURE:
mStringType = SENSOR_STRING_TYPE_WAKE_UP_AMBIENT_TEMPERATURE;
- mWakeUpSensor = true;
+ mFlags |= (SENSOR_FLAG_ON_CHANGE_MODE | SENSOR_FLAG_WAKE_UP);
break;
case SENSOR_TYPE_WAKE_UP_MAGNETIC_FIELD_UNCALIBRATED:
mStringType = SENSOR_STRING_TYPE_WAKE_UP_MAGNETIC_FIELD_UNCALIBRATED;
- mWakeUpSensor = true;
+ mFlags |= (SENSOR_FLAG_CONTINUOUS_MODE | SENSOR_FLAG_WAKE_UP);
break;
case SENSOR_TYPE_WAKE_UP_GAME_ROTATION_VECTOR:
mStringType = SENSOR_STRING_TYPE_WAKE_UP_GAME_ROTATION_VECTOR;
- mWakeUpSensor = true;
+ mFlags |= (SENSOR_FLAG_CONTINUOUS_MODE | SENSOR_FLAG_WAKE_UP);
break;
case SENSOR_TYPE_WAKE_UP_GYROSCOPE_UNCALIBRATED:
mStringType = SENSOR_STRING_TYPE_WAKE_UP_GYROSCOPE_UNCALIBRATED;
- mWakeUpSensor = true;
+ mFlags |= (SENSOR_FLAG_CONTINUOUS_MODE | SENSOR_FLAG_WAKE_UP);
break;
case SENSOR_TYPE_WAKE_UP_STEP_DETECTOR:
mStringType = SENSOR_STRING_TYPE_WAKE_UP_STEP_DETECTOR;
- mWakeUpSensor = true;
+ mFlags |= (SENSOR_FLAG_SPECIAL_REPORTING_MODE | SENSOR_FLAG_WAKE_UP);
break;
case SENSOR_TYPE_WAKE_UP_STEP_COUNTER:
mStringType = SENSOR_STRING_TYPE_WAKE_UP_STEP_COUNTER;
- mWakeUpSensor = true;
+ mFlags |= (SENSOR_FLAG_ON_CHANGE_MODE | SENSOR_FLAG_WAKE_UP);
break;
case SENSOR_TYPE_WAKE_UP_GEOMAGNETIC_ROTATION_VECTOR:
mStringType = SENSOR_STRING_TYPE_WAKE_UP_GEOMAGNETIC_ROTATION_VECTOR;
- mWakeUpSensor = true;
+ mFlags |= (SENSOR_FLAG_CONTINUOUS_MODE | SENSOR_FLAG_WAKE_UP);
break;
case SENSOR_TYPE_WAKE_UP_HEART_RATE:
mStringType = SENSOR_STRING_TYPE_WAKE_UP_HEART_RATE;
mRequiredPermission = SENSOR_PERMISSION_BODY_SENSORS;
- mWakeUpSensor = true;
+ mFlags |= (SENSOR_FLAG_ON_CHANGE_MODE | SENSOR_FLAG_WAKE_UP);
+ break;
+ case SENSOR_TYPE_WAKE_UP_TILT_DETECTOR:
+ mStringType = SENSOR_STRING_TYPE_WAKE_UP_TILT_DETECTOR;
+ mFlags |= (SENSOR_FLAG_SPECIAL_REPORTING_MODE | SENSOR_FLAG_WAKE_UP);
break;
case SENSOR_TYPE_WAKE_GESTURE:
mStringType = SENSOR_STRING_TYPE_WAKE_GESTURE;
- mWakeUpSensor = true;
+ mFlags |= (SENSOR_FLAG_ONE_SHOT_MODE | SENSOR_FLAG_WAKE_UP);
break;
default:
// Only pipe the stringType, requiredPermission and flags for custom sensors.
if (halVersion >= SENSORS_DEVICE_API_VERSION_1_2 && hwSensor->requiredPermission) {
mRequiredPermission = hwSensor->requiredPermission;
}
+
if (halVersion >= SENSORS_DEVICE_API_VERSION_1_3) {
- mWakeUpSensor = hwSensor->flags & SENSOR_FLAG_WAKE_UP;
+ mFlags = (int32_t) hwSensor->flags;
+ } else {
+ // This is an OEM defined sensor on an older HAL. Use minDelay to determine the
+ // reporting mode of the sensor.
+ if (mMinDelay > 0) {
+ mFlags |= SENSOR_FLAG_CONTINUOUS_MODE;
+ } else if (mMinDelay == 0) {
+ mFlags |= SENSOR_FLAG_ON_CHANGE_MODE;
+ } else if (mMinDelay < 0) {
+ mFlags |= SENSOR_FLAG_ONE_SHOT_MODE;
+ }
}
break;
}
return mMaxDelay;
}
+int32_t Sensor::getFlags() const {
+ return mFlags;
+}
+
bool Sensor::isWakeUpSensor() const {
- return mWakeUpSensor;
+ return mFlags & SENSOR_FLAG_WAKE_UP;
+}
+
+int32_t Sensor::getReportingMode() const {
+ return ((mFlags & REPORTING_MODE_MASK) >> REPORTING_MODE_SHIFT);
}
size_t Sensor::getFlattenedSize() const
size_t fixedSize =
sizeof(int32_t) * 3 +
sizeof(float) * 4 +
- sizeof(int32_t) * 4 +
- sizeof(bool) * 1;
+ sizeof(int32_t) * 5;
size_t variableSize =
sizeof(uint32_t) + FlattenableUtils::align<4>(mName.length()) +
flattenString8(buffer, size, mStringType);
flattenString8(buffer, size, mRequiredPermission);
FlattenableUtils::write(buffer, size, mMaxDelay);
- FlattenableUtils::write(buffer, size, mWakeUpSensor);
+ FlattenableUtils::write(buffer, size, mFlags);
return NO_ERROR;
}
size_t fixedSize =
sizeof(int32_t) * 3 +
sizeof(float) * 4 +
- sizeof(int32_t) * 4 +
- sizeof(bool) * 1;
+ sizeof(int32_t) * 5;
if (size < fixedSize) {
return NO_MEMORY;
}
return NO_MEMORY;
}
FlattenableUtils::read(buffer, size, mMaxDelay);
- FlattenableUtils::read(buffer, size, mWakeUpSensor);
+ FlattenableUtils::read(buffer, size, mFlags);
return NO_ERROR;
}
s.getHandle(),
s.getRequiredPermission().string());
+ const int reportingMode = s.getReportingMode();
+ if (reportingMode == AREPORTING_MODE_CONTINUOUS) {
+ result.append("continuous |");
+ } else if (reportingMode == AREPORTING_MODE_ON_CHANGE) {
+ result.append("on-change | ");
+ } else if (reportingMode == AREPORTING_MODE_ONE_SHOT) {
+ result.append("one-shot | ");
+ } else {
+ result.append("special-trigger | ");
+ }
+
if (s.getMinDelay() > 0) {
- result.appendFormat(
- "maxRate=%7.2fHz | ", 1e6f / s.getMinDelay());
+ result.appendFormat("maxRate=%7.2fHz | ", 1e6f / s.getMinDelay());
} else {
- result.append(s.getMinDelay() == 0
- ? "on-demand | "
- : "one-shot | ");
+ result.appendFormat("minDelay=%5dus |", s.getMinDelay());
}
+
if (s.getFifoMaxEventCount() > 0) {
result.appendFormat("FifoMax=%d events | ",
s.getFifoMaxEventCount());
void SensorService::cleanupAutoDisabledSensorLocked(const sp<SensorEventConnection>& connection,
sensors_event_t const* buffer, const int count) {
- SensorInterface* sensor;
- status_t err = NO_ERROR;
for (int i=0 ; i<count ; i++) {
int handle = buffer[i].sensor;
- int type = buffer[i].type;
- if (type == SENSOR_TYPE_SIGNIFICANT_MOTION) {
- if (connection->hasSensor(handle)) {
- sensor = mSensorMap.valueFor(handle);
- if (sensor != NULL) {
- sensor->autoDisable(connection.get(), handle);
- }
+ if (connection->hasSensor(handle)) {
+ SensorInterface* sensor = mSensorMap.valueFor(handle);
+ // If this buffer has an event from a one_shot sensor and this connection is registered
+ // for this particular one_shot sensor, try cleaning up the connection.
+ if (sensor != NULL &&
+ sensor->getSensor().getReportingMode() == AREPORTING_MODE_ONE_SHOT) {
+ sensor->autoDisable(connection.get(), handle);
cleanupWithoutDisableLocked(connection, handle);
}
}
// this sensor is already activated, but we are adding a connection that uses it.
// Immediately send down the last known value of the requested sensor if it's not a
// "continuous" sensor.
- if (sensor->getSensor().getMinDelay() == 0) {
+ if (sensor->getSensor().getReportingMode() == AREPORTING_MODE_ON_CHANGE) {
// NOTE: The wake_up flag of this event may get set to
// WAKE_UP_SENSOR_EVENT_NEEDS_ACK if this is a wake_up event.
sensors_event_t& event(mLastEventSeen.editValueFor(handle));
return BAD_VALUE;
}
- if (sensor->getSensor().getType() == SENSOR_TYPE_SIGNIFICANT_MOTION) {
- ALOGE("flush called on Significant Motion sensor");
+ if (sensor->getSensor().getReportingMode() == AREPORTING_MODE_ONE_SHOT) {
+ ALOGE("flush called on a one-shot sensor");
return INVALID_OPERATION;
}
return sensor->flush(connection.get(), handle);