summaryrefslogtreecommitdiff
path: root/services/sensorservice/SensorDevice.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'services/sensorservice/SensorDevice.cpp')
-rw-r--r--services/sensorservice/SensorDevice.cpp64
1 files changed, 43 insertions, 21 deletions
diff --git a/services/sensorservice/SensorDevice.cpp b/services/sensorservice/SensorDevice.cpp
index 8a282e2382..5d6f8c773c 100644
--- a/services/sensorservice/SensorDevice.cpp
+++ b/services/sensorservice/SensorDevice.cpp
@@ -132,8 +132,6 @@ SensorDevice::SensorDevice()
}
void SensorDevice::initializeSensorList() {
- float minPowerMa = 0.001; // 1 microAmp
-
checkReturn(mSensors->getSensorsList(
[&](const auto &list) {
const size_t count = list.size();
@@ -145,28 +143,37 @@ void SensorDevice::initializeSensorList() {
convertToSensor(convertToOldSensorInfo(list[i]), &sensor);
if (sensor.type < static_cast<int>(SensorType::DEVICE_PRIVATE_BASE)) {
- if(sensor.resolution == 0) {
+ sensor.resolution = SensorDeviceUtils::resolutionForSensor(sensor);
+
+ // Some sensors don't have a default resolution and will be left at 0.
+ // Don't crash in this case since CTS will verify that devices don't go to
+ // production with a resolution of 0.
+ if (sensor.resolution != 0) {
+ float quantizedRange = sensor.maxRange;
+ SensorDeviceUtils::quantizeValue(
+ &quantizedRange, sensor.resolution, /*factor=*/ 1);
+ // Only rewrite maxRange if the requantization produced a "significant"
+ // change, which is fairly arbitrarily defined as resolution / 8.
+ // Smaller deltas are permitted, as they may simply be due to floating
+ // point representation error, etc.
+ if (fabsf(sensor.maxRange - quantizedRange) > sensor.resolution / 8) {
+ ALOGW("%s's max range %.12f is not a multiple of the resolution "
+ "%.12f - updated to %.12f", sensor.name, sensor.maxRange,
+ sensor.resolution, quantizedRange);
+ sensor.maxRange = quantizedRange;
+ }
+ } else {
// Don't crash here or the device will go into a crashloop.
- ALOGW("%s must have a non-zero resolution", sensor.name);
- // For simple algos, map their resolution to 1 if it's not specified
- sensor.resolution =
- SensorDeviceUtils::defaultResolutionForType(sensor.type);
- }
-
- double promotedResolution = sensor.resolution;
- double promotedMaxRange = sensor.maxRange;
- if (fmod(promotedMaxRange, promotedResolution) != 0) {
- ALOGW("%s's max range %f is not a multiple of the resolution %f",
- sensor.name, sensor.maxRange, sensor.resolution);
- SensorDeviceUtils::quantizeValue(&sensor.maxRange, promotedResolution);
+ ALOGW("%s should have a non-zero resolution", sensor.name);
}
}
// Sanity check and clamp power if it is 0 (or close)
- if (sensor.power < minPowerMa) {
- ALOGI("Reported power %f not deemed sane, clamping to %f",
- sensor.power, minPowerMa);
- sensor.power = minPowerMa;
+ constexpr float MIN_POWER_MA = 0.001; // 1 microAmp
+ if (sensor.power < MIN_POWER_MA) {
+ ALOGI("%s's reported power %f invalid, clamped to %f",
+ sensor.name, sensor.power, MIN_POWER_MA);
+ sensor.power = MIN_POWER_MA;
}
mSensorList.push_back(sensor);
@@ -683,9 +690,9 @@ status_t SensorDevice::activateLocked(void* ident, int handle, int enabled) {
ALOGD_IF(DEBUG_CONNECTIONS, "enable index=%zd", info.batchParams.indexOfKey(ident));
if (isClientDisabledLocked(ident)) {
- ALOGE("SensorDevice::activate, isClientDisabledLocked(%p):true, handle:%d",
+ ALOGW("SensorDevice::activate, isClientDisabledLocked(%p):true, handle:%d",
ident, handle);
- return INVALID_OPERATION;
+ return NO_ERROR;
}
if (info.batchParams.indexOfKey(ident) >= 0) {
@@ -911,6 +918,21 @@ bool SensorDevice::isSensorActive(int handle) const {
return mActivationCount.valueAt(activationIndex).numActiveClients() > 0;
}
+void SensorDevice::onMicSensorAccessChanged(void* ident, int handle, nsecs_t samplingPeriodNs) {
+ Mutex::Autolock _l(mLock);
+ ssize_t activationIndex = mActivationCount.indexOfKey(handle);
+ if (activationIndex < 0) {
+ ALOGW("Handle %d cannot be found in activation record", handle);
+ return;
+ }
+ Info& info(mActivationCount.editValueAt(activationIndex));
+ if (info.hasBatchParamsForIdent(ident)) {
+ ssize_t index = info.batchParams.indexOfKey(ident);
+ BatchParams& params = info.batchParams.editValueAt(index);
+ params.mTSample = samplingPeriodNs;
+ }
+}
+
void SensorDevice::enableAllSensors() {
if (mSensors == nullptr) return;
Mutex::Autolock _l(mLock);