summaryrefslogtreecommitdiff
path: root/services
diff options
context:
space:
mode:
authorPeng Xu <pengxu@google.com>2017-08-09 19:28:27 -0700
committerPeng Xu <pengxu@google.com>2017-09-20 17:23:44 -0700
commit4cd60011da95e2392dda1eef78aaa6037fb57e19 (patch)
tree1a1311d88b7b8be357dcea87edfbacc5464f5ad1 /services
parent8a2710d96dfdad4e15b410abdc05ac5394ab7bb9 (diff)
downloadnative-4cd60011da95e2392dda1eef78aaa6037fb57e19.tar.gz
Checking exisitence before calling editValueFor in SensorDevice
Bug: 26320541 Test: compiles, test a few sensor and they all works Change-Id: If0859e7560419f3955f29ae108f9268d0a2bbaa9 Merged-In: If0859e7560419f3955f29ae108f9268d0a2bbaa9
Diffstat (limited to 'services')
-rw-r--r--services/sensorservice/SensorDevice.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/services/sensorservice/SensorDevice.cpp b/services/sensorservice/SensorDevice.cpp
index 7d9b0b730a..da3b2758d1 100644
--- a/services/sensorservice/SensorDevice.cpp
+++ b/services/sensorservice/SensorDevice.cpp
@@ -223,8 +223,13 @@ ssize_t SensorDevice::poll(sensors_event_t* buffer, size_t count) {
}
void SensorDevice::autoDisable(void *ident, int handle) {
- Info& info( mActivationCount.editValueFor(handle) );
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));
info.removeBatchParamsForIdent(ident);
}
@@ -235,7 +240,12 @@ status_t SensorDevice::activate(void* ident, int handle, int enabled) {
bool actuateHardware = false;
Mutex::Autolock _l(mLock);
- Info& info( mActivationCount.editValueFor(handle) );
+ ssize_t activationIndex = mActivationCount.indexOfKey(handle);
+ if (activationIndex < 0) {
+ ALOGW("Handle %d cannot be found in activation record", handle);
+ return BAD_VALUE;
+ }
+ Info& info(mActivationCount.editValueAt(activationIndex));
ALOGD_IF(DEBUG_CONNECTIONS,
"SensorDevice::activate: ident=%p, handle=0x%08x, enabled=%d, count=%zu",
@@ -329,7 +339,12 @@ status_t SensorDevice::batch(
ident, handle, flags, samplingPeriodNs, maxBatchReportLatencyNs);
Mutex::Autolock _l(mLock);
- Info& info(mActivationCount.editValueFor(handle));
+ ssize_t activationIndex = mActivationCount.indexOfKey(handle);
+ if (activationIndex < 0) {
+ ALOGW("Handle %d cannot be found in activation record", handle);
+ return BAD_VALUE;
+ }
+ Info& info(mActivationCount.editValueAt(activationIndex));
if (info.batchParams.indexOfKey(ident) < 0) {
BatchParams params(samplingPeriodNs, maxBatchReportLatencyNs);