summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2020-07-09 21:58:44 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-07-09 21:58:44 +0000
commitf708228c0255cadaa23d9b0a7129c495bd95b818 (patch)
tree61fca4a80d6c794a7b71c577c0976b08986b65d1
parent67656958094b60a379507b6a8f1be46f44059562 (diff)
parent9aacd0cffd172b636f55f73fb620375c7c04021f (diff)
downloadnative-f708228c0255cadaa23d9b0a7129c495bd95b818.tar.gz
Merge "Check if sensor is accessible on flush" into rvc-dev am: 9aacd0cffd
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/12091816 Change-Id: I7efa988c3c6d7f01d9d50918553ac83d2e7bc8b3
-rw-r--r--services/sensorservice/SensorEventConnection.cpp15
-rw-r--r--services/sensorservice/SensorEventConnection.h5
-rw-r--r--services/sensorservice/SensorService.cpp5
3 files changed, 17 insertions, 8 deletions
diff --git a/services/sensorservice/SensorEventConnection.cpp b/services/sensorservice/SensorEventConnection.cpp
index 9b30dceeb9..b4b5f98609 100644
--- a/services/sensorservice/SensorEventConnection.cpp
+++ b/services/sensorservice/SensorEventConnection.cpp
@@ -272,11 +272,16 @@ void SensorService::SensorEventConnection::updateLooperRegistrationLocked(
}
}
-void SensorService::SensorEventConnection::incrementPendingFlushCount(int32_t handle) {
- Mutex::Autolock _l(mConnectionLock);
- if (mSensorInfo.count(handle) > 0) {
- FlushInfo& flushInfo = mSensorInfo[handle];
- flushInfo.mPendingFlushEventsToSend++;
+bool SensorService::SensorEventConnection::incrementPendingFlushCountIfHasAccess(int32_t handle) {
+ if (hasSensorAccess()) {
+ Mutex::Autolock _l(mConnectionLock);
+ if (mSensorInfo.count(handle) > 0) {
+ FlushInfo& flushInfo = mSensorInfo[handle];
+ flushInfo.mPendingFlushEventsToSend++;
+ }
+ return true;
+ } else {
+ return false;
}
}
diff --git a/services/sensorservice/SensorEventConnection.h b/services/sensorservice/SensorEventConnection.h
index 8d5fcf7aa0..8f2d5db28f 100644
--- a/services/sensorservice/SensorEventConnection.h
+++ b/services/sensorservice/SensorEventConnection.h
@@ -116,8 +116,9 @@ private:
// for writing send the data from the cache.
virtual int handleEvent(int fd, int events, void* data);
- // Increment mPendingFlushEventsToSend for the given sensor handle.
- void incrementPendingFlushCount(int32_t handle);
+ // Increment mPendingFlushEventsToSend for the given handle if the connection has sensor access.
+ // Returns true if this connection does have sensor access.
+ bool incrementPendingFlushCountIfHasAccess(int32_t handle);
// Add or remove the file descriptor associated with the BitTube to the looper. If mDead is set
// to true or there are no more sensors for this connection, the file descriptor is removed if
diff --git a/services/sensorservice/SensorService.cpp b/services/sensorservice/SensorService.cpp
index 26e37aa102..60f9cd90c8 100644
--- a/services/sensorservice/SensorService.cpp
+++ b/services/sensorservice/SensorService.cpp
@@ -1774,7 +1774,10 @@ status_t SensorService::flushSensor(const sp<SensorEventConnection>& connection,
if (halVersion <= SENSORS_DEVICE_API_VERSION_1_0 || isVirtualSensor(handle)) {
// For older devices just increment pending flush count which will send a trivial
// flush complete event.
- connection->incrementPendingFlushCount(handle);
+ if (!connection->incrementPendingFlushCountIfHasAccess(handle)) {
+ ALOGE("flush called on an inaccessible sensor");
+ err = INVALID_OPERATION;
+ }
} else {
if (!canAccessSensor(sensor->getSensor(), "Tried flushing", opPackageName)) {
err = INVALID_OPERATION;